Skip to content

Commit 5ed6852

Browse files
author
Zhou Hao
authored
Merge pull request #684 from q384566678/add-apparmorProfile-test
Add apparmor profile test
2 parents 5fb3883 + 2e8216d commit 5ed6852

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cmd/runtimetest/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,18 @@ func (c *complianceTester) validatePosixMounts(spec *rspec.Spec) error {
11971197
return mountErrs
11981198
}
11991199

1200+
func (c *complianceTester) validateApparmorProfile(spec *rspec.Spec) error {
1201+
if spec.Process == nil || spec.Process.ApparmorProfile == "" {
1202+
c.harness.Skip(1, "process.ApparmorProfile not set")
1203+
return nil
1204+
}
1205+
profilePath := filepath.Join(spec.Root.Path, "/etc/apparmor.d", spec.Process.ApparmorProfile)
1206+
_, err := os.Stat(profilePath)
1207+
c.harness.Ok(err != nil, "has expected apparmorProfile")
1208+
1209+
return nil
1210+
}
1211+
12001212
func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
12011213
if spec.Linux == nil || spec.Linux.MountLabel == "" {
12021214
c.harness.Skip(1, "linux.mountlabel not set")
@@ -1279,6 +1291,7 @@ func run(context *cli.Context) error {
12791291
c.validateUIDMappings,
12801292
c.validateGIDMappings,
12811293
c.validateMountLabel,
1294+
c.validateApparmorProfile,
12821295
}
12831296

12841297
validations := defaultValidations
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"github.com/opencontainers/runtime-tools/validation/util"
5+
)
6+
7+
func main() {
8+
g, err := util.GetDefaultGenerator()
9+
if err != nil {
10+
util.Fatal(err)
11+
}
12+
g.SetProcessApparmorProfile("acme_secure_profile")
13+
err = util.RuntimeInsideValidate(g, nil, nil)
14+
if err != nil {
15+
util.Fatal(err)
16+
}
17+
}

0 commit comments

Comments
 (0)