mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-12 09:46:25 +08:00
f4cf808a3d
Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Conflicts: MAINTAINERS cgroups/cgroups.go cgroups/fs/apply_raw.go cgroups/fs/notify_linux.go cgroups/fs/notify_linux_test.go cgroups/systemd/apply_systemd.go config.go configs/config_test.go console/console.go integration/exec_test.go integration/init_test.go integration/template_test.go integration/utils_test.go linux_notify.go linux_notify_test.go mount/init.go mount/mount_config.go mount/pivotroot.go mount/ptmx.go namespaces/create.go namespaces/exec.go namespaces/execin.go namespaces/init.go namespaces/nsenter/nsenter.c namespaces/nsenter/nsenter.go namespaces/utils.go network/network.go network/types.go network/veth.go notify_linux.go notify_linux_test.go nsinit/exec.go nsinit/main.go nsinit/nsenter.go nsinit/oom.go sample_configs/host-pid.json sample_configs/userns.json security/capabilities/capabilities.go update-vendor.sh
35 lines
667 B
Go
35 lines
667 B
Go
// +build apparmor,linux
|
|
|
|
package apparmor
|
|
|
|
// #cgo LDFLAGS: -lapparmor
|
|
// #include <sys/apparmor.h>
|
|
// #include <stdlib.h>
|
|
import "C"
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"unsafe"
|
|
)
|
|
|
|
func IsEnabled() bool {
|
|
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" {
|
|
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
|
return err == nil && len(buf) > 1 && buf[0] == 'Y'
|
|
}
|
|
return false
|
|
}
|
|
|
|
func ApplyProfile(name string) error {
|
|
if name == "" {
|
|
return nil
|
|
}
|
|
cName := C.CString(name)
|
|
defer C.free(unsafe.Pointer(cName))
|
|
|
|
if _, err := C.aa_change_onexec(cName); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|