0eb4ea2f79
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
29 lines
537 B
Go
29 lines
537 B
Go
package apparmor
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
func IsEnabled() bool {
|
|
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
|
return err == nil && len(buf) > 1 && buf[0] == 'Y'
|
|
}
|
|
|
|
func ApplyProfile(pid int, name string) error {
|
|
if !IsEnabled() || name == "" {
|
|
return nil
|
|
}
|
|
|
|
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|