Container User Selection
Overview
This document explains when gobrave explicitly sets a container user and how that behavior differs between Docker and Kubernetes runtimes.
Where The User Value Comes From
The user value is populated while preparing a DAG node runtime spec.
Input variables:
USERIDGROUPID
If USERID is empty, gobrave does not set a runtime user.
When User Is Specified
Case 1: Docker Runtime
Condition:
- runtime name is
docker USERIDis present
Behavior:
- if
GROUPIDis present, gobrave setsspec.User = "<uid>:<gid>" - otherwise, gobrave sets
spec.User = "<uid>"
This maps to Docker behavior similar to docker run --user.
Case 2: Kubernetes Runtime
Condition:
- runtime name is
k8s,k3s, orkubernetes USERIDis present
Behavior:
- gobrave sets
spec.User = "<uid>" - Kubernetes runtime maps that value to
securityContext.runAsUserwhen parsable
Current behavior does not map GROUPID to runAsGroup.
Case 3: Other Runtime Names
If runtime name does not match the supported branches above, gobrave does not apply user mapping in this path.
Kubernetes Details
In Kubernetes runtime implementation:
spec.Useris parsed as numeric user iduid:gidformat is accepted as input text, but only theuidpart is used- if parsing fails, no explicit
RunAsUseris applied
Practical Notes
- For DAG workloads, set
USERIDwhen you need non-root execution. - For Docker, set both
USERIDandGROUPIDwhen filesystem group ownership matters. - For Kubernetes, setting
GROUPIDalone currently has no effect onrunAsGroup.
Related Files
internal/manager/container_manager.go(runtime-dependentspec.Userassignment)internal/container_runtime/docker/runtime.go(DockerUsermapping)internal/container_runtime/kubernetes/runtime.go(KubernetesRunAsUsermapping)