Skip to content

Commit

Permalink
func: add suport for selinux label on volume mount
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanadelacuesta committed Feb 13, 2024
1 parent d7c2574 commit 7fece15
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,14 @@ func (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, execOptio
return &exitResult, nil
}

func getSElinuxVolumeLabel(vc VolumeConfig, mc *drivers.MountConfig) string {
if mc.SELinuxLabel != vc.SelinuxLabel && mc.SELinuxLabel != "" {
return mc.SELinuxLabel
}

return vc.SelinuxLabel
}

func (d *Driver) containerMounts(task *drivers.TaskConfig, driverConfig *TaskConfig) ([]spec.Mount, error) {
var binds []spec.Mount
binds = append(binds, spec.Mount{Source: task.TaskDir().SharedAllocDir, Destination: task.Env[taskenv.AllocDir], Type: "bind"})
Expand Down Expand Up @@ -1359,9 +1367,6 @@ func (d *Driver) containerMounts(task *drivers.TaskConfig, driverConfig *TaskCon
if m.Readonly {
bind.Options = append(bind.Options, "ro")
}
if m.SELinuxLabel != "" {
bind.Options = append(bind.Options, m.SELinuxLabel)
}

switch m.PropagationMode {
case nstructs.VolumeMountPropagationPrivate:
Expand All @@ -1373,6 +1378,11 @@ func (d *Driver) containerMounts(task *drivers.TaskConfig, driverConfig *TaskCon
// If PropagationMode is something else or unset, Podman defaults to rprivate
}

selinuxLabel := getSElinuxVolumeLabel(d.config.Volumes, m)
if selinuxLabel != "" && !driverConfig.Privileged {
bind.Options = append(bind.Options, selinuxLabel)
}

binds = append(binds, bind)
}

Expand Down

0 comments on commit 7fece15

Please sign in to comment.