diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2021-08-03 12:33:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-03 12:33:59 +0000 |
commit | e93661f5e765d84893e2ad5a488682c0a67412d0 (patch) | |
tree | e4b3892449ebc578d4cadc0307559f14ba235967 /libpod | |
parent | d25f8d07b3bbc11be1caa0838a031f0e5dc223a8 (diff) | |
parent | 985c717085be3692bb25b498cdc8016ac00d5640 (diff) | |
download | podman-e93661f5e765d84893e2ad5a488682c0a67412d0.tar.gz podman-e93661f5e765d84893e2ad5a488682c0a67412d0.tar.bz2 podman-e93661f5e765d84893e2ad5a488682c0a67412d0.zip |
Merge pull request #11101 from rhatdan/selinux
Fix handling of user specified container labels
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal.go | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index e7694227a..8ffcccf4c 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -472,20 +472,10 @@ func (c *Container) setupStorage(ctx context.Context) error { c.config.IDMappings.UIDMap = containerInfo.UIDMap c.config.IDMappings.GIDMap = containerInfo.GIDMap - processLabel := containerInfo.ProcessLabel - switch { - case c.ociRuntime.SupportsKVM(): - processLabel, err = selinux.KVMLabel(processLabel) - if err != nil { - return err - } - case c.config.Systemd: - processLabel, err = selinux.InitLabel(processLabel) - if err != nil { - return err - } + processLabel, err := c.processLabel(containerInfo.ProcessLabel) + if err != nil { + return err } - c.config.ProcessLabel = processLabel c.config.MountLabel = containerInfo.MountLabel c.config.StaticDir = containerInfo.Dir @@ -520,6 +510,26 @@ func (c *Container) setupStorage(ctx context.Context) error { return nil } +func (c *Container) processLabel(processLabel string) (string, error) { + if !c.config.Systemd && !c.ociRuntime.SupportsKVM() { + return processLabel, nil + } + ctrSpec, err := c.specFromState() + if err != nil { + return "", err + } + label, ok := ctrSpec.Annotations[define.InspectAnnotationLabel] + if !ok || !strings.Contains(label, "type:") { + switch { + case c.ociRuntime.SupportsKVM(): + return selinux.KVMLabel(processLabel) + case c.config.Systemd: + return selinux.InitLabel(processLabel) + } + } + return processLabel, nil +} + // Tear down a container's storage prior to removal func (c *Container) teardownStorage() error { if c.ensureState(define.ContainerStateRunning, define.ContainerStatePaused) { |