forked from docker-archive/libcontainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add label.InitLabels functioni. Allows generation of labels based on …
…options This will allow us to do the following with docker. Customize the way that a labeling system like SELinux will run on a container. --label-opt="user:USER" : Set the label user for the container --label-opt="role:ROLE" : Set the label role for the container --label-opt="type:TYPE" : Set the label type for the container --label-opt="level:LEVEL" : Set the label level for the container --label-opt="disabled" : Turn off label confinement for the container Since we are passing a list of string options instead of a space separated string of options, I will change function calls to use InitLabels instead of GenLabels. Genlabels interface is Deprecated. Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
- Loading branch information
Showing
3 changed files
with
99 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// +build selinux,linux | ||
|
||
package label | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/libcontainer/selinux" | ||
) | ||
|
||
func TestInit(t *testing.T) { | ||
if selinux.SelinuxEnabled() { | ||
var testNull []string | ||
plabel, mlabel, err := InitLabels(testNull) | ||
if err != nil { | ||
t.Log("InitLabels Failed") | ||
t.Fatal(err) | ||
} | ||
testDisabled := []string{"disable"} | ||
plabel, mlabel, err = InitLabels(testDisabled) | ||
if err != nil { | ||
t.Log("InitLabels Disabled Failed") | ||
t.Fatal(err) | ||
} | ||
if plabel != "" { | ||
t.Log("InitLabels Disabled Failed") | ||
t.Fatal() | ||
} | ||
testUser := []string{"user:user_u", "role:user_r", "type:user_t", "level:s0:c1,c15"} | ||
plabel, mlabel, err = InitLabels(testUser) | ||
if err != nil { | ||
t.Log("InitLabels User Failed") | ||
t.Fatal(err) | ||
} | ||
if plabel != "user_u:user_r:user_t:s0:c1,c15" || mlabel != "user_u:object_r:svirt_sandbox_file_t:s0:c1,c15" { | ||
t.Log("InitLabels User Failed") | ||
t.Log(plabel, mlabel) | ||
t.Fatal(err) | ||
} | ||
|
||
testBadData := []string{"user", "role:user_r", "type:user_t", "level:s0:c1,c15"} | ||
plabel, mlabel, err = InitLabels(testBadData) | ||
if err == nil { | ||
t.Log("InitLabels Bad Failed") | ||
t.Fatal(err) | ||
} | ||
} | ||
} |