Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
- Loading branch information
1 parent
cb4189a
commit 37f137c
Showing
2 changed files
with
9 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
package apparmor | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
var AppArmorEnabled bool | ||
|
||
var ( | ||
ErrAppArmorDisabled = errors.New("Error: AppArmor is not enabled on this system") | ||
) | ||
|
||
func init() { | ||
func IsEnabled() bool { | ||
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") | ||
AppArmorEnabled = err == nil && len(buf) > 1 && buf[0] == 'Y' | ||
return err == nil && len(buf) > 1 && buf[0] == 'Y' | ||
} | ||
|
||
func ApplyProfile(pid int, name string) error { | ||
if !AppArmorEnabled { | ||
return ErrAppArmorDisabled | ||
if !IsEnabled() || name == "" { | ||
return nil | ||
} | ||
|
||
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0) | ||
if err != nil { | ||
log.Printf("error open: %s\n", err) | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil { | ||
log.Printf("changeprofile %s", name) | ||
log.Printf("Error write: %s\n", err) | ||
return err | ||
} else { | ||
log.Printf("Write success!") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters