Commit 72bb04e4 by Patrick Toomey

Add support for setting lxc-execute init UID/GID via configuration file

parent fd9f399b
...@@ -2604,6 +2604,11 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -2604,6 +2604,11 @@ struct lxc_conf *lxc_conf_init(void)
for (i = 0; i < LXC_NS_MAX; i++) for (i = 0; i < LXC_NS_MAX; i++)
new->inherit_ns_fd[i] = -1; new->inherit_ns_fd[i] = -1;
/* if running in a new user namespace, init and COMMAND
* default to running as UID/GID 0 when using lxc-execute */
new->init_uid = 0;
new->init_gid = 0;
return new; return new;
} }
......
...@@ -366,8 +366,8 @@ struct lxc_conf { ...@@ -366,8 +366,8 @@ struct lxc_conf {
/* init command */ /* init command */
char *init_cmd; char *init_cmd;
/* if running in a new user namespace, the UID/GID that COMMAND for /* if running in a new user namespace, the UID/GID that init and COMMAND
* lxc-execute should run under */ * should run under when using lxc-execute */
uid_t init_uid; uid_t init_uid;
gid_t init_gid; gid_t init_gid;
}; };
......
...@@ -104,6 +104,8 @@ static int config_start(const char *, const char *, struct lxc_conf *); ...@@ -104,6 +104,8 @@ static int config_start(const char *, const char *, struct lxc_conf *);
static int config_group(const char *, const char *, struct lxc_conf *); static int config_group(const char *, const char *, struct lxc_conf *);
static int config_environment(const char *, const char *, struct lxc_conf *); static int config_environment(const char *, const char *, struct lxc_conf *);
static int config_init_cmd(const char *, const char *, struct lxc_conf *); static int config_init_cmd(const char *, const char *, struct lxc_conf *);
static int config_init_uid(const char *, const char *, struct lxc_conf *);
static int config_init_gid(const char *, const char *, struct lxc_conf *);
static struct lxc_config_t config[] = { static struct lxc_config_t config[] = {
...@@ -168,6 +170,8 @@ static struct lxc_config_t config[] = { ...@@ -168,6 +170,8 @@ static struct lxc_config_t config[] = {
{ "lxc.group", config_group }, { "lxc.group", config_group },
{ "lxc.environment", config_environment }, { "lxc.environment", config_environment },
{ "lxc.init_cmd", config_init_cmd }, { "lxc.init_cmd", config_init_cmd },
{ "lxc.init_uid", config_init_uid },
{ "lxc.init_gid", config_init_gid },
}; };
struct signame { struct signame {
...@@ -1034,11 +1038,25 @@ static int config_init_cmd(const char *key, const char *value, ...@@ -1034,11 +1038,25 @@ static int config_init_cmd(const char *key, const char *value,
return config_path_item(&lxc_conf->init_cmd, value); return config_path_item(&lxc_conf->init_cmd, value);
} }
static int config_init_uid(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
lxc_conf->init_uid = atoi(value);
return 0;
}
static int config_init_gid(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
lxc_conf->init_gid = atoi(value);
return 0;
}
static int config_hook(const char *key, const char *value, static int config_hook(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
char *copy; char *copy;
if (!value || strlen(value) == 0) if (!value || strlen(value) == 0)
return lxc_clear_hooks(lxc_conf, key); return lxc_clear_hooks(lxc_conf, key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment