podman
1package selinux
2
3import (
4"github.com/opencontainers/selinux/go-selinux"
5)
6
7// KVMLabel returns labels for running kvm isolated containers
8func KVMLabel(cLabel string) (string, error) {
9if cLabel == "" {
10// selinux is disabled
11return "", nil
12}
13processLabel, _ := selinux.KVMContainerLabels()
14selinux.ReleaseLabel(processLabel)
15return swapSELinuxLabel(cLabel, processLabel)
16}
17
18// InitLabel returns labels for running systemd based containers
19func InitLabel(cLabel string) (string, error) {
20if cLabel == "" {
21// selinux is disabled
22return "", nil
23}
24processLabel, _ := selinux.InitContainerLabels()
25selinux.ReleaseLabel(processLabel)
26return swapSELinuxLabel(cLabel, processLabel)
27}
28
29func swapSELinuxLabel(cLabel, processLabel string) (string, error) {
30dcon, err := selinux.NewContext(cLabel)
31if err != nil {
32return "", err
33}
34scon, err := selinux.NewContext(processLabel)
35if err != nil {
36return "", err
37}
38dcon["type"] = scon["type"]
39return dcon.Get(), nil
40}
41