aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-22 16:23:37 +0200
committerGitHub <noreply@github.com>2020-04-22 16:23:37 +0200
commit6f28c92865c4ac262bce790ecda2a07d1127760f (patch)
treedf12e88028c231628b7261be72f5d6d0cfce088d
parentb88126a8f859cc75ecfdeddd9ba1cc39c537aa4b (diff)
parentc5fda9be5146d1e3b815f50b60b85cc535aa0215 (diff)
downloadpodman-6f28c92865c4ac262bce790ecda2a07d1127760f.tar.gz
podman-6f28c92865c4ac262bce790ecda2a07d1127760f.tar.bz2
podman-6f28c92865c4ac262bce790ecda2a07d1127760f.zip
Merge pull request #5937 from rhatdan/v1.9
Move selinux labeling support from pkg/util to pkg/selinux
-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..6eb3b5076
--- /dev/null
+++ b/pkg/selinux/selinux.go
@@ -0,0 +1,40 @@
+package util
+
+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
+}