Skip to content

Commit d37c5be

Browse files
committed
Fix error messages to give information of relabeling failed
Currently if a user does a command like docker: Error response from daemon: operation not supported. With this fix they should see a much more informative error message. docker run -ti -v /proc:/proc:Z fedora sh docker: Error response from daemon: SELinux Relabeling of /proc is not allowed: operation not supported. Signed-off-by: Dan Walsh <[email protected]>
1 parent f516b5d commit d37c5be

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

libcontainer/label/label_selinux.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,18 @@ func Relabel(path string, fileLabel string, shared bool) error {
129129

130130
exclude_paths := map[string]bool{"/": true, "/usr": true, "/etc": true}
131131
if exclude_paths[path] {
132-
return fmt.Errorf("Relabeling of %s is not allowed", path)
132+
return fmt.Errorf("SELinux relabeling of %s is not allowed", path)
133133
}
134134

135135
if shared {
136136
c := selinux.NewContext(fileLabel)
137137
c["level"] = "s0"
138138
fileLabel = c.Get()
139139
}
140-
return selinux.Chcon(path, fileLabel, true)
140+
if err := selinux.Chcon(path, fileLabel, true); err != nil {
141+
return fmt.Errorf("SELinux relabeling of %s is not allowed: %q", path, err)
142+
}
143+
return nil
141144
}
142145

143146
// GetPidLabel will return the label of the process running with the specified pid

0 commit comments

Comments
 (0)