Skip to content

Commit 4609271

Browse files
Merge pull request #27420 from givensuman/T-27095-add-apparmor-quadlet-key
Add AppArmor key to quadlet containers
2 parents 516ff38 + e7b50c3 commit 4609271

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ Valid options for `[Container]` are listed below:
305305
| AddDevice=/dev/foo | --device /dev/foo |
306306
| AddHost=example\.com:192.168.10.11 | --add-host example.com:192.168.10.11 |
307307
| Annotation="XYZ" | --annotation "XYZ" |
308+
| AppArmor="alternate-profile" | --security-opt apparmor=alternate-profile |
308309
| AutoUpdate=registry | --label "io.containers.autoupdate=registry" |
309310
| CgroupsMode=no-conmon | --cgroups=no-conmon |
310311
| ContainerName=name | --name name |
@@ -428,6 +429,10 @@ similar to `Environment`.
428429

429430
This key can be listed multiple times.
430431

432+
### `AppArmor=`
433+
434+
Sets the apparmor confinement profile for the container. A value of `unconfined` turns off apparmor confinement.
435+
431436
### `AutoUpdate=`
432437

433438
Indicates whether the container will be auto-updated ([podman-auto-update(1)](podman-auto-update.1.md)). The following values are supported:

pkg/systemd/quadlet/quadlet.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const (
6262
KeyAddHost = "AddHost"
6363
KeyAllTags = "AllTags"
6464
KeyAnnotation = "Annotation"
65+
KeyAppArmor = "AppArmor"
6566
KeyArch = "Arch"
6667
KeyArtifact = "Artifact"
6768
KeyAuthFile = "AuthFile"
@@ -248,6 +249,7 @@ var (
248249
KeyAddDevice: true,
249250
KeyAddHost: true,
250251
KeyAnnotation: true,
252+
KeyAppArmor: true,
251253
KeyAutoUpdate: true,
252254
KeyCgroupsMode: true,
253255
KeyContainerName: true,
@@ -775,6 +777,11 @@ func ConvertContainer(container *parser.UnitFile, unitsInfoMap map[string]*UnitI
775777
podman.add("--security-opt", fmt.Sprintf("label=level:%s", securityLabelLevel))
776778
}
777779

780+
apparmor, hasApparmor := container.Lookup(ContainerGroup, KeyAppArmor)
781+
if hasApparmor && len(apparmor) > 0 {
782+
podman.add("--security-opt", fmt.Sprintf("apparmor=%s", apparmor))
783+
}
784+
778785
devices := container.LookupAllStrv(ContainerGroup, KeyAddDevice)
779786
for _, device := range devices {
780787
if device[0] == '-' {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## assert-podman-final-args localhost/imagename
2+
## assert-podman-args "--security-opt" "apparmor=someprofilename"
3+
4+
[Container]
5+
Image=localhost/imagename
6+
AppArmor=someprofilename

test/e2e/quadlet_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ BOGUS=foo
896896
runSuccessQuadletTestCase,
897897
Entry("Basic container", "basic.container"),
898898
Entry("annotation.container", "annotation.container"),
899+
Entry("apparmor.container", "apparmor.container"),
899900
Entry("autoupdate.container", "autoupdate.container"),
900901
Entry("basepodman.container", "basepodman.container"),
901902
Entry("capabilities.container", "capabilities.container"),

0 commit comments

Comments
 (0)