github.com/moby/docker@v26.1.3+incompatible/contrib/apparmor/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "os" 7 "path" 8 "text/template" 9 ) 10 11 type profileData struct{} 12 13 func main() { 14 if len(os.Args) < 2 { 15 log.Fatal("pass a filename to save the profile in.") 16 } 17 18 // parse the arg 19 apparmorProfilePath := os.Args[1] 20 21 // parse the template 22 compiled, err := template.New("apparmor_profile").Parse(dockerProfileTemplate) 23 if err != nil { 24 log.Fatalf("parsing template failed: %v", err) 25 } 26 27 // make sure /etc/apparmor.d exists 28 if err := os.MkdirAll(path.Dir(apparmorProfilePath), 0o755); err != nil { 29 log.Fatal(err) 30 } 31 32 f, err := os.OpenFile(apparmorProfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) 33 if err != nil { 34 log.Fatal(err) 35 } 36 defer f.Close() 37 38 data := profileData{} 39 if err := compiled.Execute(f, data); err != nil { 40 log.Fatalf("executing template failed: %v", err) 41 } 42 43 fmt.Printf("created apparmor profile for version %+v at %q\n", data, apparmorProfilePath) 44 }