Skip to content

Commit fb9b5b2

Browse files
authored
Merge pull request #269 from kolyshkin/init-labels-opt
label.InitLabels: optimize
2 parents c8bf19e + 74873e2 commit fb9b5b2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

go-selinux/label/label_linux.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
// Valid Label Options
1212
var validOptions = map[string]bool{
13-
"disable": true,
1413
"type": true,
1514
"filetype": true,
1615
"user": true,
@@ -35,9 +34,13 @@ func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
3534
if !selinux.GetEnabled() {
3635
return "", "", nil
3736
}
37+
if len(options) > 0 && options[0] == "disable" {
38+
return "", selinux.PrivContainerMountLabel(), nil
39+
}
3840
processLabel, mountLabel := selinux.ContainerLabels() //nolint:staticcheck // ContainerLabels will be moved to an internal package.
39-
if processLabel == "" {
40-
// processLabel is required; if empty, do nothing.
41+
if processLabel == "" || len(options) == 0 {
42+
// 1. processLabel is required; if empty, do nothing.
43+
// 2. If there are no options to process, we're done.
4144
return processLabel, mountLabel, nil
4245
}
4346
defer func() {
@@ -55,6 +58,8 @@ func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
5558
return "", "", err
5659
}
5760
for _, opt := range options {
61+
// For backward compatibility, process "disable"
62+
// even if it's not the only option.
5863
if opt == "disable" {
5964
selinux.ReleaseLabel(mountLabel)
6065
return "", selinux.PrivContainerMountLabel(), nil

0 commit comments

Comments
 (0)