{"record":{"id":"a2a3cf98121824d9","repo":"netbirdio/netbird","slug":"get-current-user-v-a2a3cf","errorCode":null,"errorMessage":"get current user: %v","messagePattern":"get current user: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/cmd/up.go","lineNumber":127,"sourceCode":"\t}\n\n\tdnsLabelsValidated, err = validateDnsLabels(dnsLabels)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx := internal.CtxInitState(cmd.Context())\n\n\tif hostName != \"\" {\n\t\t// nolint\n\t\tctx = context.WithValue(ctx, system.DeviceNameCtxKey, hostName)\n\t}\n\n\tpm := profilemanager.NewProfileManager()\n\n\tusername, err := user.Current()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get current user: %v\", err)\n\t}\n\n\tvar profileSwitched bool\n\t// switch profile if provided\n\tif profileName != \"\" {\n\t\tif err := switchOrCreateProfile(cmd.Context(), pm, profileName, username.Username); err != nil {\n\t\t\treturn fmt.Errorf(\"switch profile: %v\", err)\n\t\t}\n\t\tprofileSwitched = true\n\t}\n\n\tactiveProf, err := pm.GetActiveProfile()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get active profile: %v\", err)\n\t}\n\n\tif foregroundMode {\n\t\treturn runInForegroundMode(ctx, cmd, activeProf)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/up.go#L109-L145","documentation":"Thrown by upFunc (client/cmd/up.go:127) when os/user.Current() fails. The username is needed to attribute profiles ('netbird up' stores who created a profile). In a cgo-disabled build Go parses /etc/passwd directly, so the lookup fails when the current UID has no passwd entry; with cgo it can also fail on NSS errors. The command aborts before profile handling.","triggerScenarios":"Running 'netbird up' in a container as a numeric UID absent from /etc/passwd (docker/podman --user 1000123:1000123, scratch images, K8s runAsNode-like arbitrary UIDs); /etc/passwd unreadable or malformed; NSS misconfiguration on the host.","commonSituations":"CI runners and distroless/scratch containers with random UIDs; hardening policies (OpenShift-assigned UIDs); chroot environments without a passwd file.","solutions":["Run the container with a UID that exists in its /etc/passwd, or add an entry for the UID (useradd / nss_wrapper passwd file)","Use an image that ships /etc/passwd (not scratch) or bind-mount one containing the runtime UID","On hosts, verify 'id' works in the same shell/context before running netbird"],"exampleFix":"// before\nusername, err := user.Current()\nif err != nil {\n    return fmt.Errorf(\"get current user: %v\", err)\n}\n\n// after: fall back to an env-derived name for profile attribution\nusername, err := user.Current()\nif err != nil {\n    fallback := os.Getenv(\"USER\")\n    if fallback == \"\" {\n        return fmt.Errorf(\"get current user: %w\", err)\n    }\n    log.Warnf(\"user.Current failed (%v), using $USER for profile attribution\", err)\n    username = &user.User{Username: fallback}\n}","handlingStrategy":"fallback","validationCode":"if _, err := user.Current(); err != nil {\n    log.Warnf(\"no passwd entry for uid %d - add one or set USER\", os.Getuid())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run containers with a UID that exists in /etc/passwd or ship a passwd entry","Prefer images that include /etc/passwd over scratch for netbird workloads","Verify 'id' resolves in the same context before running netbird up"],"tags":["cli","os","container","user-lookup","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}