~ubuntu-branches/ubuntu/precise/lxc/precise-updates

« back to all changes in this revision

Viewing changes to debian/patches/0061-lxc-start-apparmor

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-03-21 08:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20120321082006-bsepg8w3z7qb79xt
Tags: 0.7.5-3ubuntu41
* add lxc-shutdown command:
  - 0060-lxc-shutdown: add the command to the source
  - debian/lxc.upstart: use lxc-shutdown to shut down containers cleanly
  - debian/lxc.default: add LXC_SHUTDOWN_TIMEOUT (default 120s)
* support per-container apparmor policies:  (LP: #953453)
  - 0061-lxc-start-apparmor: add lxc.aa_profile to config file.  If not
    specified, lxc-default profile is used for container.  Otherwise, the
    specified profile is used.
    Note that per-container profiles must be named 'lxc-*'.
  - split debian/lxc-default.apparmor from debian/lxc.apparmor.
  - have /etc/apparmor.d/lxc-containers #include /etc/apparmor.d/lxc/*
  - debian/lxc.postinst: load the new lxc-containers profiles
  - debian/lxc.postrm: remove lxc-containers profiles
  - debian/rules: make new etc/apparmor.d/lxc dir and copy lxc-default into it
  - debian/control: add libapparmor-dev to build-depends
  - debian/lxc.upstart: load apparmor per-container policies at pre-start.
* debian/lxc.apparmor: insert the stricter mount rules for lxc-start
  (LP: #645625) (LP: #942934)
* debian/local/lxc-start-ephemeral: re-enable aufs option (LP: #960262)
* replace upstream lxc-wait with our own bash script (LP: #951181)
  - debian/local/lxc-wait: the script
  - debian/rules: copy the script into place
* 0062-templates-relative-paths: update templates to use relative paths,
  and make lxc-start always accept /var/lib/lxc/CN/rootfs as target prefix,
  to make lvm containers work.  (LP: #960860)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: support per-container apparmor profiles
 
2
 It doesn't yet support selinux or smack.
 
3
Author: Serge Hallyn <serge.hallyn@canonical.com>
 
4
Forwarded: no
 
5
 
 
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
 
10
@@ -193,6 +193,7 @@
 
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
 
15
  */
 
16
 struct lxc_conf {
 
17
        char *fstab;
 
18
@@ -211,6 +212,7 @@
 
19
        struct lxc_rootfs rootfs;
 
20
        char *ttydir;
 
21
        int close_all_fds;
 
22
+       char *aa_profile;
 
23
 };
 
24
 
 
25
 /*
 
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
 
30
@@ -44,6 +44,7 @@
 
31
 #include <sys/wait.h>
 
32
 #include <sys/un.h>
 
33
 #include <sys/poll.h>
 
34
+#include <sys/apparmor.h>
 
35
 
 
36
 #ifdef HAVE_SYS_SIGNALFD_H
 
37
 #  include <sys/signalfd.h>
 
38
@@ -492,7 +493,7 @@
 
39
                 return -1;
 
40
         }
 
41
         if (wait(&status) < 0) {
 
42
-                SYSERROR("unexpected wait error: %m\n");
 
43
+                SYSERROR("unexpected wait error: %m");
 
44
                 return -1;
 
45
         }
 
46
 
 
47
@@ -502,6 +503,36 @@
 
48
        return 0;
 
49
 }
 
50
 
 
51
+#if 0
 
52
+/* aa_getcon is not working right now.  Use our hand-rolled version below */
 
53
+static int aa_am_unconfined(void)
 
54
+{
 
55
+       char *con;
 
56
+       int ret = 0;
 
57
+       if (aa_getcon(&con, NULL) == 0 && strcmp(con, "unconfined") == 0)
 
58
+               ret = 1;
 
59
+       free(con);
 
60
+       return ret;
 
61
+}
 
62
+#else
 
63
+static int aa_am_unconfined(void)
 
64
+{
 
65
+       int ret;
 
66
+       char path[100], p[100];
 
67
+       sprintf(path, "/proc/%d/attr/current", getpid());
 
68
+       FILE *f = fopen(path, "r");
 
69
+       if (!f)
 
70
+               return 0;
 
71
+       ret = fscanf(f, "%99s", p);
 
72
+       fclose(f);
 
73
+       if (ret < 1)
 
74
+               return 0;
 
75
+       if (strcmp(p, "unconfined") == 0)
 
76
+               return 1;
 
77
+       return 0;
 
78
+}
 
79
+#endif
 
80
+
 
81
 static int do_start(void *data)
 
82
 {
 
83
        struct lxc_handler *handler = data;
 
84
@@ -546,6 +577,31 @@
 
85
 
 
86
        close(handler->sigfd);
 
87
 
 
88
+#define AA_DEF_PROFILE "lxc-container-default"
 
89
+
 
90
+       if (!handler->conf->aa_profile)
 
91
+               handler->conf->aa_profile = AA_DEF_PROFILE;
 
92
+
 
93
+       if (strcmp(handler->conf->aa_profile, "unconfined") == 0 &&
 
94
+           aa_am_unconfined()) {
 
95
+               INFO("apparmor profile unchanged");
 
96
+               goto skip_profile;
 
97
+       }
 
98
+
 
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.
 
103
+        */
 
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);
 
107
+               return -1;
 
108
+       }
 
109
+       INFO("changed apparmor profile to %s", handler->conf->aa_profile);
 
110
+
 
111
+skip_profile:
 
112
+
 
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;
 
125
 
 
126
        return new;
 
127
 }
 
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
 
132
@@ -48,6 +48,7 @@
 
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 *);
 
140
@@ -82,6 +83,7 @@
 
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         },
 
148
@@ -571,6 +573,24 @@
 
149
 
 
150
        return 0;
 
151
 }
 
152
+
 
153
+static int config_aa_profile(const char *key, char *value,
 
154
+                         struct lxc_conf *lxc_conf)
 
155
+{
 
156
+       char *path;
 
157
+
 
158
+       if (!value || strlen(value) == 0)
 
159
+               return 0;
 
160
+       path = strdup(value);
 
161
+       if (!path) {
 
162
+               SYSERROR("failed to strdup '%s': %m", value);
 
163
+               return -1;
 
164
+       }
 
165
+
 
166
+       lxc_conf->aa_profile = path;
 
167
+
 
168
+       return 0;
 
169
+}
 
170
 
 
171
 static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf)
 
172
 {
 
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
 
177
@@ -60,7 +60,7 @@
 
178
        -shared \
 
179
        -Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
 
180
 
 
181
-liblxc_so_LDADD = -lutil $(CAP_LIBS)
 
182
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
 
183
 
 
184
 bin_SCRIPTS = \
 
185
        lxc-ps \
 
186
@@ -96,7 +96,7 @@
 
187
        lxc-init
 
188
 
 
189
 AM_LDFLAGS=-Wl,-E -Wl,-rpath -Wl,$(libdir)
 
190
-LDADD=liblxc.so @CAP_LIBS@
 
191
+LDADD=liblxc.so @CAP_LIBS@ -lapparmor
 
192
 
 
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
 
199
@@ -368,7 +368,7 @@
 
200
        -shared \
 
201
        -Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
 
202
 
 
203
-liblxc_so_LDADD = -lutil $(CAP_LIBS)
 
204
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
 
205
 bin_SCRIPTS = \
 
206
        lxc-ps \
 
207
        lxc-netstat \
 
208
@@ -383,7 +383,7 @@
 
209
        lxc-destroy
 
210
 
 
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