Skip to content
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
5 changes: 5 additions & 0 deletions cmd/oci-runtime-tool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var generateFlags = []cli.Flag{
cli.BoolFlag{Name: "process-rlimits-remove-all", Usage: "remove all resource limits for processes inside the container. "},
cli.BoolFlag{Name: "process-terminal", Usage: "specifies whether a terminal is attached to the process"},
cli.IntFlag{Name: "process-uid", Usage: "uid for the process"},
cli.StringFlag{Name: "process-username", Usage: "username for the process"},
cli.StringFlag{Name: "rootfs-path", Value: "rootfs", Usage: "path to the root filesystem"},
cli.BoolFlag{Name: "rootfs-readonly", Usage: "make the container's rootfs readonly"},
cli.StringSliceFlag{Name: "solaris-anet", Usage: "set up networking for Solaris application containers"},
Expand Down Expand Up @@ -210,6 +211,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
g.SetProcessUID(uint32(context.Int("process-uid")))
}

if context.IsSet("process-username") {
g.SetProcessUsername(context.String("process-username"))
}

if context.IsSet("process-gid") {
g.SetProcessGID(uint32(context.Int("process-gid")))
}
Expand Down
1 change: 1 addition & 0 deletions completions/bash/oci-runtime-tool
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ _oci-runtime-tool_generate() {
--process-rlimits-add
--process-rlimits-remove
--process-uid
--process-username
--rootfs-path
--solaris-anet
--solaris-capped-cpu-ncpus
Expand Down
6 changes: 6 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ func (g *Generator) SetProcessUID(uid uint32) {
g.spec.Process.User.UID = uid
}

// SetProcessUsername sets g.spec.Process.User.Username.
func (g *Generator) SetProcessUsername(username string) {
g.initSpecProcess()
g.spec.Process.User.Username = username
}

// SetProcessGID sets g.spec.Process.User.GID.
func (g *Generator) SetProcessGID(gid uint32) {
g.initSpecProcess()
Expand Down
3 changes: 3 additions & 0 deletions man/oci-runtime-tool-generate.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ read the configuration from `config.json`.
**--process-uid**=UID
Sets the UID used within the container.

**--process-username**=""
Sets the username used within the container.

**--rootfs-path**=ROOTFSPATH
Path to the rootfs, which can be an absolute path or relative to bundle path.
e.g the absolute path of rootfs is /to/bundle/rootfs, bundle path is /to/bundle,
Expand Down
15 changes: 12 additions & 3 deletions validation/process_user.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package main

import (
"runtime"

"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
g := util.GetDefaultGenerator()
g.SetProcessUID(10)
g.SetProcessGID(10)
g.AddProcessAdditionalGid(5)

switch runtime.GOOS {
case "linux", "solaris":
g.SetProcessUID(10)
g.SetProcessGID(10)
g.AddProcessAdditionalGid(5)
case "windows":
g.SetProcessUsername("test")
default:
}

err := util.RuntimeInsideValidate(g, nil)
if err != nil {
Expand Down