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 ()
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- if err := selinux . ReserveLabelV2 (p ); err != nil {
74+ if err := impl . ReserveLabel (p ); err != nil {
7575 return "" , "" , err
7676 }
7777 processLabel = p
@@ -82,18 +82,18 @@ func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
8282
8383// SetFileLabel modifies the "path" label to the specified file label
8484func SetFileLabel (path string , fileLabel string ) error {
85- if ! selinux .GetEnabled () || fileLabel == "" {
85+ if ! impl .GetEnabled () || fileLabel == "" {
8686 return nil
8787 }
88- return selinux .SetFileLabel (path , fileLabel )
88+ return impl .SetFileLabel (path , fileLabel )
8989}
9090
9191// SetFileCreateLabel tells the kernel the label for all files to be created
9292func SetFileCreateLabel (fileLabel string ) error {
93- if ! selinux .GetEnabled () {
93+ if ! impl .GetEnabled () {
9494 return nil
9595 }
96- return selinux .SetFSCreateLabel (fileLabel )
96+ return impl .SetFSCreateLabel (fileLabel )
9797}
9898
9999// Relabel changes the label of path and all the entries beneath the path.
@@ -102,20 +102,20 @@ func SetFileCreateLabel(fileLabel string) error {
102102//
103103// The path itself is guaranteed to be relabeled last.
104104func Relabel (path string , fileLabel string , shared bool ) error {
105- if ! selinux .GetEnabled () || fileLabel == "" {
105+ if ! impl .GetEnabled () || fileLabel == "" {
106106 return nil
107107 }
108108
109109 if shared {
110- c , err := selinux .NewContext (fileLabel )
110+ c , err := impl .NewContext (fileLabel )
111111 if err != nil {
112112 return err
113113 }
114114
115115 c ["level" ] = "s0"
116116 fileLabel = c .Get ()
117117 }
118- return selinux .Chcon (path , fileLabel , true )
118+ return impl .Chcon (path , fileLabel , true )
119119}
120120
121121// Validate checks that the label does not include unexpected options
0 commit comments