summaryrefslogtreecommitdiff
path: root/pkg/selinux/selinux.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-04-22 08:56:37 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-04-22 14:17:59 -0400
commitede8380d37359d6ecf878c6e41db5c0f09bbadad (patch)
treea418374ff34b14466672a6c8385ef439cd3c6bb1 /pkg/selinux/selinux.go
parent703fd505538fdae2165dad47c7a6886ac3ed891e (diff)
downloadpodman-ede8380d37359d6ecf878c6e41db5c0f09bbadad.tar.gz
podman-ede8380d37359d6ecf878c6e41db5c0f09bbadad.tar.bz2
podman-ede8380d37359d6ecf878c6e41db5c0f09bbadad.zip
Move selinux labeling support from pkg/util to pkg/selinux
The goal here is to make the package less heavy and not overload the pkg/util. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/selinux/selinux.go')
-rw-r--r--pkg/selinux/selinux.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/selinux/selinux.go b/pkg/selinux/selinux.go
new file mode 100644
index 000000000..975519cce
--- /dev/null
+++ b/pkg/selinux/selinux.go
@@ -0,0 +1,40 @@
+package selinux
+
+import (
+ "github.com/opencontainers/selinux/go-selinux"
+)
+
+// SELinuxKVMLabel returns labels for running kvm isolated containers
+func SELinuxKVMLabel(cLabel string) (string, error) {
+ if cLabel == "" {
+ // selinux is disabled
+ return "", nil
+ }
+ processLabel, _ := selinux.KVMContainerLabels()
+ selinux.ReleaseLabel(processLabel)
+ return swapSELinuxLabel(cLabel, processLabel)
+}
+
+// SELinuxInitLabel returns labels for running systemd based containers
+func SELinuxInitLabel(cLabel string) (string, error) {
+ if cLabel == "" {
+ // selinux is disabled
+ return "", nil
+ }
+ processLabel, _ := selinux.InitContainerLabels()
+ selinux.ReleaseLabel(processLabel)
+ return swapSELinuxLabel(cLabel, processLabel)
+}
+
+func swapSELinuxLabel(cLabel, processLabel string) (string, error) {
+ dcon, err := selinux.NewContext(cLabel)
+ if err != nil {
+ return "", err
+ }
+ scon, err := selinux.NewContext(processLabel)
+ if err != nil {
+ return "", err
+ }
+ dcon["type"] = scon["type"]
+ return dcon.Get(), nil
+}