Bazel fails to start up if $USER is not set plus no valid UID can be retrieved
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Bazel tries to [get user name to figure out output_user_root](https://github.com/bazelbuild/bazel/blob/756be22f6445d6052a0a9cce66fdb7f7b3a8f300/src/main/cpp/startup_options.cc#L124) even if `--output_user_root` is passed in. However, `GetUserName` is a fallible call in an environment where $USER is unset, and `getuid` or `getpwuid` don't work properly. Such situation is possible in isolated environments like processed launched by nsjail.
The only option seems to be setting $USER, which is actually unused if `--output_user_root` is specified. I'd expect setting `--output_user_root` to be good enough for getting around this.
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
```
# install nsjail, then
./nsjail -Mo --chroot / --user 99999 --group 99999 -- /bin/sh -i
...
sh-5.1$ bazel
FATAL: $USER is not set, and unable to look up name of current user: (error: 0): Success
```
### Which operating system are you running Bazel on?
Linux 5.18.16-1rodete1-amd64
### What is the output of `bazel info release`?
release 5.3.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Start in src/main/cpp/startup_options.cc at the GetUserName call linked in the report, then reproduce the failure in the provided nsjail environment with $USER unset and no valid UID lookup. Check that supplying --output_user_root avoids the user-name lookup and that Bazel starts successfully in this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, linux
- Domain
- build-system, cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100