mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
apparmor: switch IsLoaded to return bool
Signed-off-by: Aleksa Sarai <asarai@suse.de>
(cherry picked from commit e440a57a79
)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
20a7e39728
commit
20d6f23b55
2 changed files with 12 additions and 6 deletions
|
@ -21,7 +21,7 @@ func installDefaultAppArmorProfile() {
|
||||||
// Allow daemon to run if loading failed, but are active
|
// Allow daemon to run if loading failed, but are active
|
||||||
// (possibly through another run, manually, or via system startup)
|
// (possibly through another run, manually, or via system startup)
|
||||||
for _, policy := range apparmorProfiles {
|
for _, policy := range apparmorProfiles {
|
||||||
if err := aaprofile.IsLoaded(policy); err != nil {
|
if loaded, err := aaprofile.IsLoaded(policy); err != nil || !loaded {
|
||||||
logrus.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", policy)
|
logrus.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", policy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,22 +95,28 @@ func InstallDefault(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLoaded checks if a passed profile has been loaded into the kernel.
|
// IsLoaded checks if a profile with the given name has been loaded into the
|
||||||
func IsLoaded(name string) error {
|
// kernel.
|
||||||
|
func IsLoaded(name string) (bool, error) {
|
||||||
file, err := os.Open("/sys/kernel/security/apparmor/profiles")
|
file, err := os.Open("/sys/kernel/security/apparmor/profiles")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
r := bufio.NewReader(file)
|
r := bufio.NewReader(file)
|
||||||
for {
|
for {
|
||||||
p, err := r.ReadString('\n')
|
p, err := r.ReadString('\n')
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(p, name+" ") {
|
if strings.HasPrefix(p, name+" ") {
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue