Skip to content

Commit

Permalink
set process labels in pkg/spec
Browse files Browse the repository at this point in the history
Set the (default) process labels in `pkg/spec`. This way, we can also
query libpod.conf and disable labeling if needed.

Fixes: containers#5087
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg authored and snj33v committed May 31, 2020
1 parent 439c473 commit 1f28ea6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 0 additions & 3 deletions cmd/podman/shared/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,6 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
Sysctl: sysctl,
}

if err := secConfig.SetLabelOpts(runtime, pid, ipc); err != nil {
return nil, err
}
if err := secConfig.SetSecurityOpts(runtime, c.StringArray("security-opt")); err != nil {
return nil, err
}
Expand Down
26 changes: 19 additions & 7 deletions pkg/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,35 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
}

// SECURITY OPTS
var runtimeConfig *libpodconfig.Config

if runtime != nil {
runtimeConfig, err = runtime.GetConfig()
if err != nil {
return nil, err
}
}

g.SetProcessNoNewPrivileges(config.Security.NoNewPrivs)

if !config.Security.Privileged {
g.SetProcessApparmorProfile(config.Security.ApparmorProfile)
}

blockAccessToKernelFilesystems(config, &g)

var runtimeConfig *libpodconfig.Config

if runtime != nil {
runtimeConfig, err = runtime.GetConfig()
if err != nil {
// Unless already set via the CLI, check if we need to disable process
// labels or set the defaults.
if len(config.Security.LabelOpts) == 0 && runtimeConfig != nil {
if !runtimeConfig.EnableLabeling {
// Disabled in the config.
config.Security.LabelOpts = append(config.Security.LabelOpts, "disable")
} else if err := config.Security.SetLabelOpts(runtime, &config.Pid, &config.Ipc); err != nil {
// Defaults!
return nil, err
}
}

blockAccessToKernelFilesystems(config, &g)

// RESOURCES - PIDS
if config.Resources.PidsLimit > 0 {
// if running on rootless on a cgroupv1 machine or using the cgroupfs manager, pids
Expand Down

0 comments on commit 1f28ea6

Please sign in to comment.