Skip to content

Commit c08ed98

Browse files
author
n-marton
authored
add parameter to allow the setting of running user for container (#120)
* add parameter to allow the setting of running user for container * use task level user param as source param
1 parent e2430d9 commit c08ed98

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

containerd/containerd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type ContainerConfig struct {
4949
MemoryLimit int64
5050
MemoryHardLimit int64
5151
CPUShares int64
52+
User string
5253
}
5354

5455
func (d *Driver) isContainerdRunning() (bool, error) {
@@ -321,6 +322,10 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
321322
opts = append(opts, oci.WithLinuxNamespace(specs.LinuxNamespace{Type: specs.NetworkNamespace, Path: containerConfig.NetworkNamespacePath}))
322323
}
323324

325+
if containerConfig.User != "" {
326+
opts = append(opts, oci.WithUser(containerConfig.User))
327+
}
328+
324329
ctxWithTimeout, cancel := context.WithTimeout(d.ctxContainerd, 30*time.Second)
325330
defer cancel()
326331

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
469469
containerConfig.MemoryHardLimit = cfg.Resources.NomadResources.Memory.MemoryMaxMB * 1024 * 1024
470470
containerConfig.CPUShares = cfg.Resources.LinuxResources.CPUShares
471471

472+
containerConfig.User = cfg.User
473+
472474
container, err := d.createContainer(&containerConfig, &driverConfig)
473475
if err != nil {
474476
return nil, nil, fmt.Errorf("Error in creating container: %v", err)

0 commit comments

Comments
 (0)