{"record":{"id":"bcf3b6d03d6abd02","repo":"cockroachdb/cockroach","slug":"user-current-s","errorCode":null,"errorMessage":"user.Current: %s","messagePattern":"user\\.Current: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/roachtest/run.go","lineNumber":284,"sourceCode":"\tif spec.Skip == \"\" {\n\t\treturn \"\"\n\t}\n\tdetails := spec.Skip\n\tif spec.SkipDetails != \"\" {\n\t\tdetails += \" (\" + spec.SkipDetails + \")\"\n\t}\n\treturn details\n}\n\n// getUser takes the value passed on the command line and comes up with the\n// username to use.\nfunc getUser(userFlag string) string {\n\tif userFlag != \"\" {\n\t\treturn userFlag\n\t}\n\tusr, err := user.Current()\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"user.Current: %s\", err))\n\t}\n\treturn usr.Username\n}\n\nfunc initRunFlagsBinariesAndLibraries(cmd *cobra.Command) error {\n\tif roachtestflags.Local {\n\t\tif roachtestflags.ClusterNames != \"\" {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"cannot specify both an existing cluster (%s) and --local. However, if a local cluster \"+\n\t\t\t\t\t\"already exists, --clusters=local will use it\",\n\t\t\t\troachtestflags.ClusterNames)\n\t\t}\n\t\troachtestflags.Cloud = spec.Local\n\t}\n\n\tif roachtestflags.Count <= 0 {\n\t\treturn fmt.Errorf(\"--count (%d) must by greater than 0\", roachtestflags.Count)\n\t}","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/cockroachdb/cockroach/blob/8812064a015d2faf99d3fc7e15880f94042954b0/pkg/cmd/roachtest/run.go#L266-L302","documentation":"roachtest's getUser falls back to os/user.Current() when no --user flag is given, and panics if that call fails. user.Current fails when the process runs under a UID with no /etc/passwd entry (or passwd/nss resolution is unavailable) — the classic container/CI scenario. The panic aborts the roachtest invocation before any test runs.","triggerScenarios":"Running roachtest without --user under a numeric UID that has no passwd entry: scratch/distroless containers, Kubernetes pods with arbitrary runAsUser, CI runners with dynamic UIDs, or images missing /etc/passwd.","commonSituations":"CI moving roachtest into a minimal container; k8s jobs assigning project-range UIDs; chroot/nsswitch misconfiguration on build agents.","solutions":["Pass --user explicitly: ./roachtest run --user=$USER <test> (any stable string works)","Fix the image: add the uid to /etc/passwd (useradd -u $(id -u) runner) or use a base image that includes passwd","In k8s, set runAsUser to an existing uid or project a generated /etc/passwd file into the pod"],"exampleFix":"# before\n./roachtest run my_test\n\n# after\n./roachtest run --user=ci-runner my_test","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --user in CI and containerized roachtest runs","Ensure the runtime image has /etc/passwd entries for the UID (useradd or projected passwd file)","Prefer images with passwd present (non-scratch) for test tooling"],"tags":["roachtest","environment","containers","ci","go"],"backgroundTag":null,"analyzedSha":"8812064a015d2faf99d3fc7e15880f94042954b0","analyzedAt":"2026-08-15T16:34:17.351Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}