Skip to content

Commit 7c5f941

Browse files
author
Zhou Hao
committed
generate: add process-username option
Signed-off-by: Zhou Hao <[email protected]>
1 parent 3322c45 commit 7c5f941

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ var generateFlags = []cli.Flag{
113113
cli.BoolFlag{Name: "process-rlimits-remove-all", Usage: "remove all resource limits for processes inside the container. "},
114114
cli.BoolFlag{Name: "process-terminal", Usage: "specifies whether a terminal is attached to the process"},
115115
cli.IntFlag{Name: "process-uid", Usage: "uid for the process"},
116+
cli.StringFlag{Name: "process-username", Usage: "username for the process"},
116117
cli.StringFlag{Name: "rootfs-path", Value: "rootfs", Usage: "path to the root filesystem"},
117118
cli.BoolFlag{Name: "rootfs-readonly", Usage: "make the container's rootfs readonly"},
118119
cli.StringSliceFlag{Name: "solaris-anet", Usage: "set up networking for Solaris application containers"},
@@ -210,6 +211,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
210211
g.SetProcessUID(uint32(context.Int("process-uid")))
211212
}
212213

214+
if context.IsSet("process-username") {
215+
g.SetProcessUsername(context.String("process-username"))
216+
}
217+
213218
if context.IsSet("process-gid") {
214219
g.SetProcessGID(uint32(context.Int("process-gid")))
215220
}

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ _oci-runtime-tool_generate() {
387387
--process-rlimits-add
388388
--process-rlimits-remove
389389
--process-uid
390+
--process-username
390391
--rootfs-path
391392
--solaris-anet
392393
--solaris-capped-cpu-ncpus

generate/generate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ func (g *Generator) SetProcessUID(uid uint32) {
361361
g.spec.Process.User.UID = uid
362362
}
363363

364+
// SetProcessUsername sets g.spec.Process.User.Username.
365+
func (g *Generator) SetProcessUsername(username string) {
366+
g.initSpecProcess()
367+
g.spec.Process.User.Username = username
368+
}
369+
364370
// SetProcessGID sets g.spec.Process.User.GID.
365371
func (g *Generator) SetProcessGID(gid uint32) {
366372
g.initSpecProcess()

man/oci-runtime-tool-generate.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ read the configuration from `config.json`.
441441
**--process-uid**=UID
442442
Sets the UID used within the container.
443443

444+
**--process-username**=""
445+
Sets the username used within the container.
446+
444447
**--rootfs-path**=ROOTFSPATH
445448
Path to the rootfs, which can be an absolute path or relative to bundle path.
446449
e.g the absolute path of rootfs is /to/bundle/rootfs, bundle path is /to/bundle,

0 commit comments

Comments
 (0)