Skip to content

Commit dd340c5

Browse files
committed
apparmor: make pkg/aaparser work on read-only root
This is necessary because normally `apparmor_parser -r` will try to create a temporary directory on the host (which is not allowed if the host has a rootfs). However, the -K option bypasses saving things to the cache (which avoids this issue). % apparmor_parser -r /tmp/docker-profile mkstemp: Read-only file system % apparmor_parser -Kr /tmp/docker-profile % In addition, add extra information to the ensureDefaultAppArmorProfile errors so that problems like this are easier to debug. Fixes: 2f7596a ("apparmor: do not save profile to /etc/apparmor.d") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 4dd3e5b commit dd340c5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

daemon/apparmor_default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func ensureDefaultAppArmorProfile() error {
2828

2929
// Load the profile.
3030
if err := aaprofile.InstallDefault(defaultApparmorProfile); err != nil {
31-
return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", defaultApparmorProfile)
31+
return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded: %s", defaultApparmorProfile, err)
3232
}
3333
}
3434

pkg/aaparser/aaparser.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ func GetVersion() (int, error) {
2222
return parseVersion(output)
2323
}
2424

25-
// LoadProfile runs `apparmor_parser -r` on a specified apparmor profile to
26-
// replace the profile.
25+
// LoadProfile runs `apparmor_parser -Kr` on a specified apparmor profile to
26+
// replace the profile. The `-K` is necessary to make sure that apparmor_parser
27+
// doesn't try to write to a read-only filesystem.
2728
func LoadProfile(profilePath string) error {
28-
_, err := cmd("", "-r", profilePath)
29+
_, err := cmd("", "-Kr", profilePath)
2930
return err
3031
}
3132

0 commit comments

Comments
 (0)