Use user from OCI config per default

We have to use the user from the OCI configuration to have the right set
of user permissions inside container.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
Sascha Grunert 2020-04-20 15:02:14 +02:00
parent f7a19bb301
commit ae69696fcd
No known key found for this signature in database
GPG Key ID: 8CE029DD1A866E52
2 changed files with 16 additions and 2 deletions

View File

@ -37,6 +37,7 @@ type containerConfig struct {
Pid int Pid int
Rootfs string Rootfs string
Env map[string]string Env map[string]string
User string
Nvidia *nvidiaConfig Nvidia *nvidiaConfig
} }
@ -47,7 +48,14 @@ type Root struct {
// github.com/opencontainers/runtime-spec/blob/v1.0.0/specs-go/config.go#L30-L57 // github.com/opencontainers/runtime-spec/blob/v1.0.0/specs-go/config.go#L30-L57
type Process struct { type Process struct {
Env []string `json:"env,omitempty"` Env []string `json:"env,omitempty"`
User User `json:"user"`
}
// User specifies specific user (and group) information for the container process.
type User struct {
UID uint32 `json:"uid"`
GID uint32 `json:"gid"`
} }
// We use pointers to structs, similarly to the latest version of runtime-spec: // We use pointers to structs, similarly to the latest version of runtime-spec:
@ -260,6 +268,7 @@ func getContainerConfig(hook HookConfig) (config containerConfig) {
Pid: h.Pid, Pid: h.Pid,
Rootfs: s.Root.Path, Rootfs: s.Root.Path,
Env: env, Env: env,
User: fmt.Sprintf("%d:%d", s.Process.User.UID, s.Process.User.GID),
Nvidia: getNvidiaConfig(env), Nvidia: getNvidiaConfig(env),
} }
} }

View File

@ -112,9 +112,14 @@ func doPrestart() {
if cli.Ldcache != nil { if cli.Ldcache != nil {
args = append(args, fmt.Sprintf("--ldcache=%s", *cli.Ldcache)) args = append(args, fmt.Sprintf("--ldcache=%s", *cli.Ldcache))
} }
// The CLI user has a higher priority than the OCI config user
user := container.User
if cli.User != nil { if cli.User != nil {
args = append(args, fmt.Sprintf("--user=%s", *cli.User)) user = *cli.User
} }
args = append(args, fmt.Sprintf("--user=%s", user))
args = append(args, "configure") args = append(args, "configure")
if cli.Ldconfig != nil { if cli.Ldconfig != nil {