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 container creation's selinux_opts attribute #139

Merged
merged 3 commits into from
Nov 14, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FEATURES:

IMPROVEMENTS:

* config: Add `selinux_opts` option [[GH-139](https://github.com/hashicorp/nomad-driver-podman/pull/139)]
* perf: Use ping api instead of system info for fingerprinting [[GH-186](https://github.com/hashicorp/nomad-driver-podman/pull/186)]
* runtime: Prevent concurrent image pulls of same imageRef [[GH-159](https://github.com/hashicorp/nomad-driver-podman/pull/159)]

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ config {
}
```

* **selinux_opts** - (Optional) A list of process labels the container will use.

```
config {
selinux_opts = [
"type:my_container.process"
]
}
```

* **sysctl** - (Optional) A key-value map of sysctl configurations to set to the containers on start.

```hcl
Expand Down
5 changes: 5 additions & 0 deletions api/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ type InspectContainerHostConfig struct {
// capabilities listed in the container's spec, compared against a set
// of default capabilities.
CapDrop []string `json:"CapDrop"`
// SelinuxProcessLabel is the process label the container will use.
// If SELinux is enabled and this is not specified, a label will be
// automatically generated if not specified.
// Optional.
SelinuxOpts []string `json:"SelinuxOpts"`
// Dns is a list of DNS nameservers that will be added to the
// container's resolv.conf
Dns []string `json:"Dns"`
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
"command": hclspec.NewAttr("command", "string", false),
"cap_add": hclspec.NewAttr("cap_add", "list(string)", false),
"cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false),
"selinux_opts": hclspec.NewAttr("selinux_opts", "list(string)", false),
"cpu_hard_limit": hclspec.NewAttr("cpu_hard_limit", "bool", false),
"cpu_cfs_period": hclspec.NewAttr("cpu_cfs_period", "number", false),
"devices": hclspec.NewAttr("devices", "list(string)", false),
Expand Down Expand Up @@ -130,6 +131,7 @@ type TaskConfig struct {
Volumes []string `codec:"volumes"`
CapAdd []string `codec:"cap_add"`
CapDrop []string `codec:"cap_drop"`
SelinuxOpts []string `codec:"selinux_opts"`
Command string `codec:"command"`
Devices []string `codec:"devices"`
Entrypoint string `codec:"entrypoint"`
Expand Down
1 change: 1 addition & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
// Security config options
createOpts.ContainerSecurityConfig.CapAdd = driverConfig.CapAdd
createOpts.ContainerSecurityConfig.CapDrop = driverConfig.CapDrop
createOpts.ContainerSecurityConfig.SelinuxOpts = driverConfig.SelinuxOpts
createOpts.ContainerSecurityConfig.User = cfg.User
createOpts.ContainerSecurityConfig.Privileged = driverConfig.Privileged
createOpts.ContainerSecurityConfig.ReadOnlyFilesystem = driverConfig.ReadOnlyRootfs
Expand Down
17 changes: 16 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,16 @@ func TestPodmanDriver_DefaultCaps(t *testing.T) {
require.Contains(t, inspectData.EffectiveCaps, "CAP_CHOWN")
}

// check modified capabilities (CapAdd/CapDrop)
// check default process label
func TestPodmanDriver_DefaultProcessLabel(t *testing.T) {
taskCfg := newTaskConfig("", busyboxLongRunningCmd)
inspectData := startDestroyInspect(t, taskCfg, "defaultprocesslabel")

// a default container gets "disable" process label
require.Contains(t, inspectData.ProcessLabel, "label=disable")
}

// check modified capabilities (CapAdd/CapDrop/SelinuxOpts)
func TestPodmanDriver_Caps(t *testing.T) {
taskCfg := newTaskConfig("", busyboxLongRunningCmd)
// cap_add = [
Expand All @@ -1347,13 +1356,19 @@ func TestPodmanDriver_Caps(t *testing.T) {
// "MKNOD",
// ]
taskCfg.CapDrop = []string{"CHOWN"}
// selinux_opts = [
// "disable",
// ]
taskCfg.SelinuxOpts = []string{"disable"}

inspectData := startDestroyInspect(t, taskCfg, "caps")

// we added SYS_TIME, so we should see it in inspect
require.Contains(t, inspectData.EffectiveCaps, "CAP_SYS_TIME")
// we dropped CAP_CHOWN, so we should NOT see it in inspect
require.NotContains(t, inspectData.EffectiveCaps, "CAP_CHOWN")
// we added "disable" process label, so we should see it in inspect
require.Contains(t, inspectData.ProcessLabel, "label=disable")
}

// check enabled tty option
Expand Down