差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
linux:lxc:非特権コンテナメモ [2014/01/20 10:22] – 作成 tenforward | linux:lxc:非特権コンテナメモ [2014/01/20 10:45] (現在) – tenforward | ||
---|---|---|---|
行 1: | 行 1: | ||
* https:// | * https:// | ||
+ | |||
+ | 上記の非特権コンテナの要件に | ||
+ | |||
+ | * Kernel: 3.13 + a couple of staging patches (which Ubuntu has in its kernel) | ||
+ | * User namespaces enabled in the kernel | ||
+ | * A very recent version of shadow that supports subuid/ | ||
+ | * Per-user cgroups on all controllers (which I turned on a couple of weeks ago) | ||
+ | * LXC 1.0 beta2 or higher (released two days ago) | ||
+ | * A version of PAM with a loginuid patch that’s yet to be in any released version | ||
+ | |||
+ | とある. | ||
+ | |||
+ | * まず lxc/ | ||
+ | static bool find_cgroup_hierarchies(struct cgroup_meta_data *meta_data, | ||
+ | bool all_kernel_subsystems, | ||
+ | const char **subsystem_whitelist) | ||
+ | { | ||
+ | FILE *proc_self_cgroup; | ||
+ | char *line = NULL; | ||
+ | size_t sz = 0; | ||
+ | int r; | ||
+ | bool bret = false; | ||
+ | size_t hierarchy_capacity = 0; | ||
+ | |||
+ | proc_self_cgroup = fopen_cloexec("/ | ||
+ | /* if for some reason (because of setns() and pid namespace for example) | ||
+ | , | ||
+ | * /proc/self is not valid, we try / | ||
+ | if (!proc_self_cgroup) | ||
+ | proc_self_cgroup = fopen_cloexec("/ | ||
+ | if (!proc_self_cgroup) | ||
+ | return false; | ||
+ | |||
+ | while (getline(& | ||
+ | /* file format: hierarchy: | ||
+ | * we only extract hierarchy and subsystems | ||
+ | * here */ | ||
+ | </ | ||
+ | * Ubuntu 14.04 だと一般ユーザでログインすると< | ||
+ | uid=1000(karma) gid=1000(karma) groups=1000(karma), | ||
+ | karma@lxctest02: | ||
+ | 11: | ||
+ | 10: | ||
+ | 9: | ||
+ | 8: | ||
+ | 7: | ||
+ | 6: | ||
+ | 5: | ||
+ | 4: | ||
+ | 3: | ||
+ | 2: | ||
+ | * ここは書き込み権がある < | ||
+ | drwxr-xr-x 2 karma karma 0 Jan 20 10:37 / | ||
+ | * ちなみに普通に echo $$ > tasks みたいに cgroup に登録する.以下のコード < | ||
+ | for c in / | ||
+ | do | ||
+ | sudo mkdir $c/karma | ||
+ | sudo chown -R karma: $c/karma | ||
+ | if [ `basename $c` = " | ||
+ | echo 0 > $c/ | ||
+ | echo 0 > $c/ | ||
+ | fi | ||
+ | echo $PID > $c/ | ||
+ | done</ | ||
+ | 11: | ||
+ | 10: | ||
+ | 9: | ||
+ | 8: | ||
+ | 7: | ||
+ | 6: | ||
+ | 5: | ||
+ | 4: | ||
+ | 3: | ||
+ | 2: | ||
+ | * / | ||
+ | const char *e, *n; | ||
+ | char *s; | ||
+ | |||
+ | assert(path); | ||
+ | assert(session); | ||
+ | |||
+ | e = path_startswith(path, | ||
+ | if (!e) | ||
+ | return -ENOENT; | ||
+ | |||
+ | /* Skip the user name */ | ||
+ | e = skip_label(e); | ||
+ | if (!e) | ||
+ | return -ENOENT; | ||
+ | |||
+ | n = strchrnul(e, | ||
+ | if (n - e < 8) | ||
+ | return -ENOENT; | ||
+ | if (memcmp(n - 8, " | ||
+ | return -ENOENT; | ||
+ | |||
+ | s = strndup(e, n - e - 8); | ||
+ | if (!s) | ||
+ | return -ENOMEM; | ||
+ | |||
+ | *session = s; | ||
+ | return 0; | ||
+ | }</ |