contrib/apparmor: add tests for generated template, add "header comment", and cleanup whitespace#13270
contrib/apparmor: add tests for generated template, add "header comment", and cleanup whitespace#13270thaJeztah wants to merge 5 commits into
Conversation
558494d to
4392a3e
Compare
There was a problem hiding this comment.
Pull request overview
Adds golden-file based tests for the AppArmor profile generator in contrib/apparmor, updates the template to include a generated-by header comment, and normalizes template whitespace/output formatting.
Changes:
- Introduce golden files covering multiple template configurations (ABI, tunables, abstractions, custom imports, daemon profile, rootlesskit).
- Add a table-driven golden test with an
-updateflag to refresh expected outputs. - Update the template header/upstream reference and adjust whitespace trimming; allow tests to override macro-detection.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| contrib/apparmor/template.go | Adds generated-by header, whitespace trimming tweaks, and loadData macroExists override hook for tests. |
| contrib/apparmor/template_test.go | Adds table-driven golden tests and golden update helper. |
| contrib/apparmor/testdata/default.golden | Golden output for default template. |
| contrib/apparmor/testdata/with-api3.golden | Golden output when ABI 3.0 macro exists. |
| contrib/apparmor/testdata/with-tunables.golden | Golden output when tunables/global is included. |
| contrib/apparmor/testdata/with-abstractions-base.golden | Golden output when abstractions/base exists as an inner import. |
| contrib/apparmor/testdata/with-daemon-profile.golden | Golden output with explicit daemon profile peer. |
| contrib/apparmor/testdata/with-custom-imports.golden | Golden output with custom top-level imports. |
| contrib/apparmor/testdata/with-custom-inner-imports.golden | Golden output with custom inner imports. |
| contrib/apparmor/testdata/with-rootlesskit.golden | Golden output including RootlessKit peer signal rule. |
| contrib/apparmor/apparmor.go | Updates loadData call sites for new signature; doc comment capitalization. |
| contrib/apparmor/apparmor_unsupported.go | Doc comment capitalization consistency (AppArmor). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4392a3e to
0cfca3d
Compare
|
Ah, fun; looks like the profile we detect contains a newline; Diff:
--- Expected
+++ Actual
@@ -16,3 +16,4 @@
# Manager may send signals to container processes.
- signal (receive) peer=unconfined,
+ signal (receive) peer=unconfined
+,
# Container processes may send signals amongst themselves. |
06a22ac to
bb251fe
Compare
bb251fe to
cbb52c4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbb52c4 to
18ccfd6
Compare
| const dir = "/etc/apparmor.d" | ||
|
|
||
| const defaultTemplate = ` | ||
| const defaultTemplate = `# profile generated by github.com/containerd/containerd/v2/contrib/apparmor. |
There was a problem hiding this comment.
Wasn't sure if we wanted to add the DO NOT EDIT. here as well, so left that out for now.
| // Normally profiles are suffixed by " (enforce)". AppArmor profiles cannot | ||
| // contain spaces so this doesn't restrict daemon profile names. | ||
| profile, _, _ = strings.Cut(profile, " ") | ||
| profile = strings.TrimSpace(profile) |
There was a problem hiding this comment.
Looks like this might actually be fixing a bug; a profile with a newline here looks to be invalid; I can open this commit as a separate PR first (in case we need / want to backport it)
Diff:
--- Expected
+++ Actual
@@ -16,3 +16,4 @@
# Manager may send signals to container processes.
- signal (receive) peer=unconfined,
+ signal (receive) peer=unconfined
+,
# Container processes may send signals amongst themselves.
18ccfd6 to
24b1d09
Compare
24b1d09 to
0b211d7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
With testify, expected values go to the left and use sub-tests. Signed-off-by: Sebastiaan van Stijn <[email protected]>
The profile we read from /proc/self/attr/current will contain a newline,
resulting in a stray newline to be added to the profile;
Diff:
--- Expected
+++ Actual
@@ -16,3 +16,4 @@
# Manager may send signals to container processes.
- signal (receive) peer=unconfined,
+ signal (receive) peer=unconfined
+,
# Container processes may send signals amongst themselves.
Trim whitespace to account for newlines and fix handling of whitespace as
AppArmor profile names are allowed to contain spaces when quoted; from the
[apparmor.d(5)] man-page:
PROFILE NAME ( UNQUOTED PROFILE NAME | QUOTED PROFILE NAME )
QUOTED PROFILE NAME = '"' UNQUOTED PROFILE NAME '"'
UNQUOTED PROFILE NAME = (must start with alphanumeric character (after
variable expansion), or '/' AARE have special meanings; see below. May
include VARIABLE. Rules with embedded spaces or tabs must be quoted.)
While we don't use those names in our code, let's make the code correct.
Also update the template to use quotes.
[apparmor.d(5)]: https://manpages.ubuntu.com/manpages/xenial/man5/apparmor.d.5.html
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
- The generated profiles had a leading newline; replace it with something useful. - Trim whitespace / stray newlines for conditional parts. Signed-off-by: Sebastiaan van Stijn <[email protected]>
0b211d7 to
26922ba
Compare
Uh oh!
There was an error while loading. Please reload this page.