Skip to content

Commit 6447317

Browse files
authored
Merge pull request #614 from q384566678/user-uesrname
generate: add process-username option and fix it's validation
2 parents 3322c45 + fc1bcf5 commit 6447317

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
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,

validation/process_user.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
package main
22

33
import (
4+
"runtime"
5+
46
"github.com/opencontainers/runtime-tools/validation/util"
57
)
68

79
func main() {
810
g := util.GetDefaultGenerator()
9-
g.SetProcessUID(10)
10-
g.SetProcessGID(10)
11-
g.AddProcessAdditionalGid(5)
11+
12+
switch runtime.GOOS {
13+
case "linux", "solaris":
14+
g.SetProcessUID(10)
15+
g.SetProcessGID(10)
16+
g.AddProcessAdditionalGid(5)
17+
case "windows":
18+
g.SetProcessUsername("test")
19+
default:
20+
}
1221

1322
err := util.RuntimeInsideValidate(g, nil)
1423
if err != nil {

0 commit comments

Comments
 (0)