55 "fmt"
66 "strings"
77
8- "github.com/opencontainers/selinux/go-selinux "
8+ "github.com/opencontainers/selinux/internal/impl "
99)
1010
1111// Valid Label Options
@@ -27,32 +27,32 @@ var ErrIncompatibleLabel = errors.New("bad SELinux option: z and Z can not be us
2727// If the disabled flag is passed in, the process label will not be set, but the mount label will be set
2828// to the container_file label with the maximum category. This label is not usable by any confined label.
2929func InitLabels (options []string ) (plabel string , mlabel string , retErr error ) {
30- if ! selinux .GetEnabled () {
30+ if ! impl .GetEnabled () {
3131 return "" , "" , nil
3232 }
33- processLabel , mountLabel := selinux .ContainerLabels () //nolint:staticcheck // ContainerLabels will be moved to an internal package.
33+ processLabel , mountLabel := impl .ContainerLabels () //nolint:staticcheck // ContainerLabels will be moved to an internal package.
3434 if processLabel == "" {
3535 // processLabel is required; if empty, do nothing.
3636 return processLabel , mountLabel , nil
3737 }
3838 defer func () {
3939 if retErr != nil {
40- selinux .ReleaseLabel (mountLabel )
40+ impl .ReleaseLabel (mountLabel )
4141 }
4242 }()
43- pcon , err := selinux .NewContext (processLabel )
43+ pcon , err := impl .NewContext (processLabel )
4444 if err != nil {
4545 return "" , "" , err
4646 }
4747 mcsLevel := pcon ["level" ]
48- mcon , err := selinux .NewContext (mountLabel )
48+ mcon , err := impl .NewContext (mountLabel )
4949 if err != nil {
5050 return "" , "" , err
5151 }
5252 for _ , opt := range options {
5353 if opt == "disable" {
54- selinux .ReleaseLabel (mountLabel )
55- return "" , selinux .PrivContainerMountLabel (), nil
54+ impl .ReleaseLabel (mountLabel )
55+ return "" , impl .PrivContainerMountLabel (), nil
5656 }
5757 k , v , ok := strings .Cut (opt , ":" )
5858 if ! ok || ! validOptions [k ] {
@@ -69,9 +69,9 @@ func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
6969 }
7070 if p := pcon .Get (); p != processLabel {
7171 if pcon ["level" ] != mcsLevel {
72- selinux .ReleaseLabel (processLabel )
72+ impl .ReleaseLabel (processLabel )
7373 }
74- selinux .ReserveLabel (p )
74+ impl .ReserveLabel (p )
7575 processLabel = p
7676 }
7777 mountLabel = mcon .Get ()
@@ -80,18 +80,18 @@ func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
8080
8181// SetFileLabel modifies the "path" label to the specified file label
8282func SetFileLabel (path string , fileLabel string ) error {
83- if ! selinux .GetEnabled () || fileLabel == "" {
83+ if ! impl .GetEnabled () || fileLabel == "" {
8484 return nil
8585 }
86- return selinux .SetFileLabel (path , fileLabel )
86+ return impl .SetFileLabel (path , fileLabel )
8787}
8888
8989// SetFileCreateLabel tells the kernel the label for all files to be created
9090func SetFileCreateLabel (fileLabel string ) error {
91- if ! selinux .GetEnabled () {
91+ if ! impl .GetEnabled () {
9292 return nil
9393 }
94- return selinux .SetFSCreateLabel (fileLabel )
94+ return impl .SetFSCreateLabel (fileLabel )
9595}
9696
9797// Relabel changes the label of path and all the entries beneath the path.
@@ -100,20 +100,20 @@ func SetFileCreateLabel(fileLabel string) error {
100100//
101101// The path itself is guaranteed to be relabeled last.
102102func Relabel (path string , fileLabel string , shared bool ) error {
103- if ! selinux .GetEnabled () || fileLabel == "" {
103+ if ! impl .GetEnabled () || fileLabel == "" {
104104 return nil
105105 }
106106
107107 if shared {
108- c , err := selinux .NewContext (fileLabel )
108+ c , err := impl .NewContext (fileLabel )
109109 if err != nil {
110110 return err
111111 }
112112
113113 c ["level" ] = "s0"
114114 fileLabel = c .Get ()
115115 }
116- return selinux .Chcon (path , fileLabel , true )
116+ return impl .Chcon (path , fileLabel , true )
117117}
118118
119119// Validate checks that the label does not include unexpected options
0 commit comments