@@ -78,19 +78,37 @@ func ReleaseLabel(label string) error {
7878// Deprecated: use selinux.DupSecOpt
7979var DupSecOpt = selinux .DupSecOpt
8080
81+ // FormatMountLabel returns a string to be used by the mount command. Using
82+ // the SELinux `context` mount option. Changing labels of files on mount
83+ // points with this option can never be changed.
8184// FormatMountLabel returns a string to be used by the mount command.
8285// The format of this string will be used to alter the labeling of the mountpoint.
8386// The string returned is suitable to be used as the options field of the mount command.
8487// If you need to have additional mount point options, you can pass them in as
8588// the first parameter. Second parameter is the label that you wish to apply
8689// to all content in the mount point.
8790func FormatMountLabel (src , mountLabel string ) string {
91+ return FormatMountLabelByType (src , mountLabel , "context" )
92+ }
93+
94+ // FormatMountLabelByType returns a string to be used by the mount command.
95+ // Allow caller to specify the mount options. For example using the SELinux
96+ // `fscontext` mount option would allow certain container processes to change
97+ // labels of files created on the mount points, where as `context` option does
98+ // not.
99+ // FormatMountLabelByType returns a string to be used by the mount command.
100+ // The format of this string will be used to alter the labeling of the mountpoint.
101+ // The string returned is suitable to be used as the options field of the mount command.
102+ // If you need to have additional mount point options, you can pass them in as
103+ // the first parameter. Second parameter is the label that you wish to apply
104+ // to all content in the mount point.
105+ func FormatMountLabelByType (src , mountLabel , contextType string ) string {
88106 if mountLabel != "" {
89107 switch src {
90108 case "" :
91- src = fmt .Sprintf ("context =%q" , mountLabel )
109+ src = fmt .Sprintf ("%s =%q" , contextType , mountLabel )
92110 default :
93- src = fmt .Sprintf ("%s,context =%q" , src , mountLabel )
111+ src = fmt .Sprintf ("%s,%s =%q" , src , contextType , mountLabel )
94112 }
95113 }
96114 return src
0 commit comments