From 27ebd7d6f074620992be2fe3046cc188701d439f Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 18 Jul 2019 10:01:45 +0200 Subject: Add DefaultContent API to retrieve apparmor profile content The default apparmor profile is not stored on disk which causes confusion when debugging the content of the profile. To solve this, we now add an additional API which returns the profile as byte slice. Signed-off-by: Sascha Grunert --- pkg/apparmor/apparmor_linux.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pkg/apparmor/apparmor_linux.go') diff --git a/pkg/apparmor/apparmor_linux.go b/pkg/apparmor/apparmor_linux.go index 0d01f41e9..479600408 100644 --- a/pkg/apparmor/apparmor_linux.go +++ b/pkg/apparmor/apparmor_linux.go @@ -4,6 +4,7 @@ package apparmor import ( "bufio" + "bytes" "fmt" "io" "os" @@ -104,6 +105,18 @@ func InstallDefault(name string) error { return cmd.Wait() } +// DefaultContent returns the default profile content as byte slice. The +// profile is named as the provided `name`. The function errors if the profile +// generation fails. +func DefaultContent(name string) ([]byte, error) { + p := profileData{Name: name} + var bytes bytes.Buffer + if err := p.generateDefault(&bytes); err != nil { + return nil, err + } + return bytes.Bytes(), nil +} + // IsLoaded checks if a profile with the given name has been loaded into the // kernel. func IsLoaded(name string) (bool, error) { -- cgit v1.2.3-54-g00ecf