Set USER and LOGNAME environment variables when dropping privileges #465
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a service is configured to run as a non-root user (
@user), finit correctly drops privileges via setuid() and sets HOME and PATH, but does not set the USER and LOGNAME environment variables. They remain set to "root" from boot time.This causes problems for software that determines its identity from the environment rather than getuid(). For example, rootless Podman checks os.Getenv("USER") first when looking up subordinate UID/GID ranges in /etc/subuid and /etc/subgid.
With USER=root but UID=1000, Podman looks up root's subuid entry instead of the actual user's, causing applications like newuidmap to fail. Setting USER and LOGNAME to match the actual user identity follows POSIX conventions and matches the behavior of su, sudo, and login.
https://github.com/containers/podman/blob/fd90d334a3a7a66fd4e07b3fe98a18378bbc55ed/pkg/rootless/rootless_linux.go#L168