1
Description: support per-container apparmor profiles
2
It doesn't yet support selinux or smack.
3
Author: Serge Hallyn <serge.hallyn@canonical.com>
6
Index: lxc-shutdownv2/src/lxc/conf.h
7
===================================================================
8
--- lxc-shutdownv2.orig/src/lxc/conf.h 2012-03-19 15:52:10.383218000 -0500
9
+++ lxc-shutdownv2/src/lxc/conf.h 2012-03-19 16:04:26.453848556 -0500
11
* @tty_info : tty data
12
* @console : console data
13
* @ttydir : directory (under /dev) in which to create console and ttys
14
+ * @aa_profile : apparmor profile to switch to
19
struct lxc_rootfs rootfs;
26
Index: lxc-shutdownv2/src/lxc/start.c
27
===================================================================
28
--- lxc-shutdownv2.orig/src/lxc/start.c 2012-03-19 15:52:10.383218000 -0500
29
+++ lxc-shutdownv2/src/lxc/start.c 2012-03-20 23:48:04.405747772 -0500
34
+#include <sys/apparmor.h>
36
#ifdef HAVE_SYS_SIGNALFD_H
37
# include <sys/signalfd.h>
41
if (wait(&status) < 0) {
42
- SYSERROR("unexpected wait error: %m\n");
43
+ SYSERROR("unexpected wait error: %m");
52
+/* aa_getcon is not working right now. Use our hand-rolled version below */
53
+static int aa_am_unconfined(void)
57
+ if (aa_getcon(&con, NULL) == 0 && strcmp(con, "unconfined") == 0)
63
+static int aa_am_unconfined(void)
66
+ char path[100], p[100];
67
+ sprintf(path, "/proc/%d/attr/current", getpid());
68
+ FILE *f = fopen(path, "r");
71
+ ret = fscanf(f, "%99s", p);
75
+ if (strcmp(p, "unconfined") == 0)
81
static int do_start(void *data)
83
struct lxc_handler *handler = data;
86
close(handler->sigfd);
88
+#define AA_DEF_PROFILE "lxc-container-default"
90
+ if (!handler->conf->aa_profile)
91
+ handler->conf->aa_profile = AA_DEF_PROFILE;
93
+ if (strcmp(handler->conf->aa_profile, "unconfined") == 0 &&
94
+ aa_am_unconfined()) {
95
+ INFO("apparmor profile unchanged");
99
+ /* aa_change_onexec makes more sense since we want to transition when
100
+ * /sbin/init is exec'd. But the transitions doesn't seem to work
101
+ * then (refused). aa_change_onexec will work since we're doing it
102
+ * right before the exec, so we'll just use that for now.
104
+ //if (aa_change_onexec(handler->conf->aa_profile) < 0) {
105
+ if (aa_change_profile(handler->conf->aa_profile) < 0) {
106
+ SYSERROR("failed to change apparmor profile to %s", handler->conf->aa_profile);
109
+ INFO("changed apparmor profile to %s", handler->conf->aa_profile);
113
/* after this call, we are in error because this
114
* ops should not return as it execs */
115
if (handler->ops->start(handler, handler->data))
116
Index: lxc-shutdownv2/src/lxc/conf.c
117
===================================================================
118
--- lxc-shutdownv2.orig/src/lxc/conf.c 2012-03-19 15:52:10.383218000 -0500
119
+++ lxc-shutdownv2/src/lxc/conf.c 2012-03-19 16:04:26.457848571 -0500
120
@@ -1523,6 +1523,7 @@
121
lxc_list_init(&new->network);
122
lxc_list_init(&new->mount_list);
123
lxc_list_init(&new->caps);
124
+ new->aa_profile = NULL;
128
Index: lxc-shutdownv2/src/lxc/confile.c
129
===================================================================
130
--- lxc-shutdownv2.orig/src/lxc/confile.c 2012-03-19 15:52:10.383218000 -0500
131
+++ lxc-shutdownv2/src/lxc/confile.c 2012-03-19 16:04:26.457848571 -0500
133
static int config_pts(const char *, char *, struct lxc_conf *);
134
static int config_tty(const char *, char *, struct lxc_conf *);
135
static int config_ttydir(const char *, char *, struct lxc_conf *);
136
+static int config_aa_profile(const char *, char *, struct lxc_conf *);
137
static int config_cgroup(const char *, char *, struct lxc_conf *);
138
static int config_mount(const char *, char *, struct lxc_conf *);
139
static int config_rootfs(const char *, char *, struct lxc_conf *);
141
{ "lxc.pts", config_pts },
142
{ "lxc.tty", config_tty },
143
{ "lxc.devttydir", config_ttydir },
144
+ { "lxc.aa_profile", config_aa_profile },
145
{ "lxc.cgroup", config_cgroup },
146
{ "lxc.mount", config_mount },
147
{ "lxc.rootfs.mount", config_rootfs_mount },
153
+static int config_aa_profile(const char *key, char *value,
154
+ struct lxc_conf *lxc_conf)
158
+ if (!value || strlen(value) == 0)
160
+ path = strdup(value);
162
+ SYSERROR("failed to strdup '%s': %m", value);
166
+ lxc_conf->aa_profile = path;
171
static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf)
173
Index: lxc-shutdownv2/src/lxc/Makefile.am
174
===================================================================
175
--- lxc-shutdownv2.orig/src/lxc/Makefile.am 2012-03-19 15:52:10.383218000 -0500
176
+++ lxc-shutdownv2/src/lxc/Makefile.am 2012-03-19 16:04:26.457848571 -0500
179
-Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
181
-liblxc_so_LDADD = -lutil $(CAP_LIBS)
182
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
189
AM_LDFLAGS=-Wl,-E -Wl,-rpath -Wl,$(libdir)
190
-LDADD=liblxc.so @CAP_LIBS@
191
+LDADD=liblxc.so @CAP_LIBS@ -lapparmor
193
lxc_attach_SOURCES = lxc_attach.c
194
lxc_cgroup_SOURCES = lxc_cgroup.c
195
Index: lxc-shutdownv2/src/lxc/Makefile.in
196
===================================================================
197
--- lxc-shutdownv2.orig/src/lxc/Makefile.in 2012-03-19 15:52:10.383218000 -0500
198
+++ lxc-shutdownv2/src/lxc/Makefile.in 2012-03-19 16:04:26.461848590 -0500
201
-Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
203
-liblxc_so_LDADD = -lutil $(CAP_LIBS)
204
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
211
AM_LDFLAGS = -Wl,-E -Wl,-rpath -Wl,$(libdir)
212
-LDADD = liblxc.so @CAP_LIBS@
213
+LDADD = liblxc.so @CAP_LIBS@ -lapparmor
214
lxc_attach_SOURCES = lxc_attach.c
215
lxc_cgroup_SOURCES = lxc_cgroup.c
216
lxc_checkpoint_SOURCES = lxc_checkpoint.c