{"record":{"id":"f5b832e943d576c5","repo":"juicedata/juicefs","slug":"current-user-s","errorCode":null,"errorMessage":"current user: %s","messagePattern":"current user: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/object/nfs.go","lineNumber":462,"sourceCode":"func (n *nfsStore) findOwnerGroup(attr *nfs.Fattr) (string, string) {\n\treturn utils.UserName(int(attr.UID)), utils.GroupName(int(attr.GID))\n}\n\nfunc (n *nfsStore) getOwnerGroup(info os.FileInfo) (string, string) {\n\tif st, match := info.(*nfs.Fattr); match {\n\t\treturn n.findOwnerGroup(st)\n\t}\n\tif st, match := info.Sys().(*nfs.Fattr); match {\n\t\treturn n.findOwnerGroup(st)\n\t}\n\treturn \"\", \"\"\n}\n\nfunc newNFSStore(addr, username, pass, token string) (ObjectStorage, error) {\n\tif username == \"\" {\n\t\tu, err := user.Current()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"current user: %s\", err)\n\t\t}\n\t\tusername = u.Username\n\t}\n\tb := strings.Split(addr, \":\")\n\tif len(b) != 2 {\n\t\treturn nil, fmt.Errorf(\"invalid NFS address %s\", addr)\n\t}\n\thost := b[0]\n\tpath := b[1]\n\tmount, err := nfs.DialMount(host, time.Second*3)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to dial MOUNT service %s: %v\", addr, err)\n\t}\n\tauth := rpc.NewAuthUnix(username, uint32(utils.GetCurrentUID()), uint32(utils.GetCurrentGID()))\n\ttarget, err := mount.Mount(path, auth.Auth())\n\ttarget.Config.DirCount = 1 << 17\n\t// Readdir returns up to 1M at a time, even if MaxCount is set larger\n\ttarget.Config.MaxCount = 1 << 20","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/nfs.go#L444-L480","documentation":"When newNFSStore is called with an empty username, it falls back to the current OS user via user.Current(). If that lookup fails (the process cannot determine its uid/username), the error is wrapped as 'current user: ...'.","triggerScenarios":"Creating an NFS object store without a username while user.Current() fails — typically in static binaries built without cgo where user lookup needs NSS, or in restricted sandboxes.","commonSituations":"CGO_ENABLED=0 static builds where os/user can't consult NSS; minimal containers lacking /etc/passwd; environments where getpwuid fails.","solutions":["Pass an explicit username in the NFS URL (user@host:/path) so the current-user lookup is skipped.","Ensure /etc/passwd exists and contains the current uid, or rebuild with cgo enabled for NSS lookups.","Run in an environment where getuid/getpwuid resolve (non-sandboxed container with a passwd file)."],"exampleFix":"// before\nnewNFSStore(\"nfs-server:/export/data\", \"\", \"\", \"\")\n// after\nnewNFSStore(\"nfs-server:/export/data\", \"myuser\", \"\", \"\")","handlingStrategy":"fallback","validationCode":"if username == \"\" {\n\tif _, err := user.Current(); err != nil {\n\t\treturn fmt.Errorf(\"cannot determine current user; pass an explicit username: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"store, err := newNFSStore(addr, username, pass, \"\")\nif err != nil && strings.Contains(err.Error(), \"current user\") {\n\t// retry with an explicit username\n\tstore, err = newNFSStore(addr, \"nobody\", pass, \"\")\n}","preventionTips":["Always supply an explicit username for NFS storage URLs.","Avoid CGO_ENABLED=0 static builds when NSS user lookup is required.","Ensure /etc/passwd is present in minimal container images."],"tags":["nfs","user-lookup","static-binary"],"backgroundTag":"user-not-found","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}