Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SecurityLabelNested flag in quadlet #18795

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Valid options for `[Container]` are listed below:
| SecurityLabelDisable=true | --security-opt label=disable |
| SecurityLabelFileType=usr_t | --security-opt label=filetype:usr_t |
| SecurityLabelLevel=s0:c1,c2 | --security-opt label=level:s0:c1,c2 |
| SecurityLabelNested=true | --security-opt label=nested |
| SecurityLabelType=spc_t | --security-opt label=type:spc_t |
| Timezone=local | --tz local |
| Tmpfs=/work | --tmpfs /work |
Expand Down Expand Up @@ -424,6 +425,10 @@ Set the label file type for the container files.

Set the label process level for the container processes.

### `SecurityLabelNested=`

Allow SecurityLabels to function within the container. This allows separation of containers created within the container.

### `SecurityLabelType=`

Set the label process type for the container processes.
Expand Down
7 changes: 7 additions & 0 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const (
KeySecurityLabelDisable = "SecurityLabelDisable"
KeySecurityLabelFileType = "SecurityLabelFileType"
KeySecurityLabelLevel = "SecurityLabelLevel"
KeySecurityLabelNested = "SecurityLabelNested"
KeySecurityLabelType = "SecurityLabelType"
KeySecret = "Secret"
KeyTimezone = "Timezone"
Expand Down Expand Up @@ -156,6 +157,7 @@ var (
KeySecurityLabelDisable: true,
KeySecurityLabelFileType: true,
KeySecurityLabelLevel: true,
KeySecurityLabelNested: true,
KeySecurityLabelType: true,
KeySecret: true,
KeyTmpfs: true,
Expand Down Expand Up @@ -414,6 +416,11 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
podman.add("--security-opt", "label:disable")
}

securityLabelNested := container.LookupBooleanWithDefault(ContainerGroup, KeySecurityLabelNested, false)
if securityLabelNested {
podman.add("--security-opt", "label:nested")
}

securityLabelType, _ := container.Lookup(ContainerGroup, KeySecurityLabelType)
if len(securityLabelType) > 0 {
podman.add("--security-opt", fmt.Sprintf("label=type:%s", securityLabelType))
Expand Down
1 change: 1 addition & 0 deletions test/e2e/quadlet/disableselinux.container
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args "--security-opt" "label:disable"

[Container]
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/quadlet/nestedselinux.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## assert-podman-args "--security-opt" "label:nested"

[Container]
Image=localhost/imagename
SecurityLabelNested=true
1 change: 1 addition & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ var _ = Describe("quadlet system generator", func() {
Entry("capabilities.container", "capabilities.container"),
Entry("capabilities2.container", "capabilities2.container"),
Entry("disableselinux.container", "disableselinux.container"),
Entry("nestedselinux.container", "nestedselinux.container"),
Entry("devices.container", "devices.container"),
Entry("env.container", "env.container"),
Entry("escapes.container", "escapes.container"),
Expand Down