Last active
February 20, 2023 18:10
-
-
Save robbmanes/133b2768d6e53ab44e4a00e638a84c27 to your computer and use it in GitHub Desktop.
Go program that tests the container labeling capabilites of `go-selinux/label`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/opencontainers/selinux/go-selinux/label" | |
) | |
// Mirroring the behavior found here: | |
// https://github.com/containers/podman/blob/8432ed7488e9c62738f9308fcc03f2ae9c2cd615/libpod/util_linux.go#L110-L129 | |
func main() { | |
path := "/home/rmanes/Downloads" | |
_, mountLabel, err := label.InitLabels([]string{}) | |
if err != nil { | |
fmt.Errorf("Error getting default labels: %w", err) | |
} | |
// Deprecated | |
// https://github.com/opencontainers/selinux/blob/main/go-selinux/label/label.go#L61 | |
if err := label.ReleaseLabel(mountLabel); err != nil { | |
fmt.Errorf("Error releasing label: %q, %w", mountLabel, err) | |
} | |
if err := label.Relabel(path, mountLabel, true); err != nil { | |
fmt.Errorf("Error relabeling path %s with label %q: %w", path, mountLabel, err) | |
} | |
fmt.Printf("Completed path \"%s\" relabeling with label %q.", path, mountLabel) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment