diff --git a/pkg/aa/profile.go b/pkg/aa/profile.go index 69f3e844d..4797a9219 100644 --- a/pkg/aa/profile.go +++ b/pkg/aa/profile.go @@ -100,7 +100,11 @@ func (p *AppArmorProfile) NestAttachments() string { } else { res := []string{} for _, attachment := range p.Attachments { - res = append(res, attachment[1:]) + if strings.HasPrefix(attachment, "/") { + res = append(res, attachment[1:]) + } else { + res = append(res, attachment) + } } return "/{" + strings.Join(res, ",") + "}" } diff --git a/pkg/aa/profile_test.go b/pkg/aa/profile_test.go index 7524bb52d..1f083a2da 100644 --- a/pkg/aa/profile_test.go +++ b/pkg/aa/profile_test.go @@ -185,6 +185,21 @@ func TestAppArmorProfile_NestAttachments(t *testing.T) { }, want: "/{{usr/,}libexec/geoclue,{usr/,}libexec/geoclue-2.0/demos/agent}", }, + { + name: "null", + Attachments: []string{}, + want: "", + }, + { + name: "empty", + Attachments: []string{""}, + want: "", + }, + { + name: "not valid aare", + Attachments: []string{"/file", "relative"}, + want: "/{file,relative}", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {