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

config: Set custom apparmor profile or disable apparmor #188

Merged
merged 1 commit into from
Aug 31, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## UNRELEASED

FEATURES:

* config: Set custom apparmor profile or disable apparmor. [[GH-188](https://github.com/hashicorp/nomad-driver-podman/pull/188)]

IMPROVEMENTS:

* perf: Use ping api instead of system info for fingerprinting [[GH-186](https://github.com/hashicorp/nomad-driver-podman/pull/186)]
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ config {
}
```

* **apparmor_profile** - (Optional) Name of a apparmor profile to be used instead of the default profile. The special value `unconfined` disables apparmor for this container:

```
config {
apparmor_profile = "your-profile"
}
```

* **force_pull** - (Optional) true or false (default). Always pull the latest image on container start.

```hcl
Expand Down
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var (
// taskConfigSpec is the hcl specification for the driver config section of
// a task within a job. It is returned in the TaskConfigSchema RPC
taskConfigSpec = hclspec.NewObject(map[string]*hclspec.Spec{
"args": hclspec.NewAttr("args", "list(string)", false),
"apparmor_profile": hclspec.NewAttr("apparmor_profile", "string", false),
"args": hclspec.NewAttr("args", "list(string)", false),
"auth": hclspec.NewBlock("auth", false, hclspec.NewObject(map[string]*hclspec.Spec{
"username": hclspec.NewAttr("username", "string", false),
"password": hclspec.NewAttr("password", "string", false),
Expand Down Expand Up @@ -121,6 +122,7 @@ type PluginConfig struct {

// TaskConfig is the driver configuration of a task within a job
type TaskConfig struct {
ApparmorProfile string `codec:"apparmor_profile"`
Args []string `codec:"args"`
Auth AuthConfig `codec:"auth"`
Ports []string `codec:"ports"`
Expand Down
1 change: 1 addition & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
createOpts.ContainerSecurityConfig.User = cfg.User
createOpts.ContainerSecurityConfig.Privileged = driverConfig.Privileged
createOpts.ContainerSecurityConfig.ReadOnlyFilesystem = driverConfig.ReadOnlyRootfs
createOpts.ContainerSecurityConfig.ApparmorProfile = driverConfig.ApparmorProfile

// Network config options
if cfg.DNS != nil {
Expand Down
29 changes: 29 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,35 @@ func TestPodmanDriver_Privileged(t *testing.T) {
require.True(t, inspectData.HostConfig.Privileged)
}

// check apparmor default value
func TestPodmanDriver_AppArmorDefault(t *testing.T) {
d := podmanDriverHarness(t, nil)

// Skip test if apparmor is not available
if !getPodmanDriver(t, d).systemInfo.Host.Security.AppArmorEnabled {
t.Skip("Skipping AppArmor test ")
}

defaultCfg := newTaskConfig("", busyboxLongRunningCmd)
defaultInspectResult := startDestroyInspect(t, defaultCfg, "aa-default")
require.Contains(t, defaultInspectResult.AppArmorProfile, "containers-default")
}

// check apparmor option
func TestPodmanDriver_AppArmorUnconfined(t *testing.T) {
d := podmanDriverHarness(t, nil)

// Skip test if apparmor is not available
if !getPodmanDriver(t, d).systemInfo.Host.Security.AppArmorEnabled {
t.Skip("Skipping AppArmor test ")
}

unconfinedCfg := newTaskConfig("", busyboxLongRunningCmd)
unconfinedCfg.ApparmorProfile = "unconfined"
unconfinedInspectResult := startDestroyInspect(t, unconfinedCfg, "aa-unconfined")
require.Equal(t, "unconfined", unconfinedInspectResult.AppArmorProfile)
}

// check ulimit option
func TestPodmanDriver_Ulimit(t *testing.T) {
taskCfg := newTaskConfig("", busyboxLongRunningCmd)
Expand Down