@@ -11,7 +11,7 @@ import (
1111 "io"
1212 "os"
1313 "os/exec"
14- "path"
14+ "path/filepath "
1515 "strings"
1616 "text/template"
1717)
@@ -53,7 +53,7 @@ func (p *profileData) generateDefault(out io.Writer) error {
5353
5454// macroExists checks if the passed macro exists.
5555func macroExists (m string ) bool {
56- _ , err := os .Stat (path .Join (profileDirectory , m ))
56+ _ , err := os .Stat (filepath .Join (profileDirectory , m ))
5757 return err == nil
5858}
5959
@@ -63,7 +63,7 @@ func InstallDefault(name string) error {
6363 // Figure out the daemon profile.
6464 daemonProfile := "unconfined"
6565 if currentProfile , err := os .ReadFile ("/proc/self/attr/current" ); err == nil {
66- // Normally profiles are suffixed by " (enforcing )" or similar. AppArmor
66+ // Normally profiles are suffixed by " (enforce )" or similar. AppArmor
6767 // profiles cannot contain spaces so this doesn't restrict daemon profile
6868 // names.
6969 if profile , _ , _ := strings .Cut (string (currentProfile ), " " ); profile != "" {
@@ -72,14 +72,14 @@ func InstallDefault(name string) error {
7272 }
7373
7474 // Install to a temporary directory.
75- tmpFile , err := os .CreateTemp ("" , name )
75+ tmpFile , err := os .CreateTemp ("" , "apparmor-profile-" )
7676 if err != nil {
7777 return err
7878 }
7979
8080 defer func () {
8181 _ = tmpFile .Close ()
82- _ = os .Remove (tmpFile .Name ())
82+ _ = os .Remove (tmpFile .Name ()) // #nosec G703 -- ignore "G703: Path traversal via taint analysis (gosec)"
8383 }()
8484
8585 p := profileData {
@@ -110,6 +110,9 @@ func isLoaded(name string, fileName string) (bool, error) {
110110
111111 scanner := bufio .NewScanner (file )
112112 for scanner .Scan () {
113+ // Normally profiles are suffixed by " (enforce)" or similar. AppArmor
114+ // profiles cannot contain spaces so this doesn't restrict daemon profile
115+ // names.
113116 if prefix , _ , ok := strings .Cut (scanner .Text (), " " ); ok && prefix == name {
114117 return true , nil
115118 }
@@ -126,7 +129,7 @@ func isLoaded(name string, fileName string) (bool, error) {
126129// replace the profile. The `-K` is necessary to make sure that apparmor_parser
127130// doesn't try to write to a read-only filesystem.
128131func loadProfile (profilePath string ) error {
129- c := exec .Command ("apparmor_parser" , "-Kr" , profilePath )
132+ c := exec .Command ("apparmor_parser" , "-Kr" , profilePath ) // #nosec G204 G702 -- Ignore "Subprocess launched with variable (gosec)"
130133 c .Dir = ""
131134
132135 if output , err := c .CombinedOutput (); err != nil {
0 commit comments