Skip to content

fix: optimize Linux privilege dropping with setpriv and remove redundant env exports#47

Merged
ammario merged 4 commits intomainfrom
fix-redundant-env-exports
Sep 14, 2025
Merged

fix: optimize Linux privilege dropping with setpriv and remove redundant env exports#47
ammario merged 4 commits intomainfrom
fix-redundant-env-exports

Conversation

@ammario
Copy link
Copy Markdown
Member

@ammario ammario commented Sep 14, 2025

Summary

  • Removed redundant environment variable exports in Linux jail command execution
  • Replaced surunusersetpriv for optimal privilege dropping
  • Environment variables are now only set via Command::env()
  • Added scripts/wait-pr-checks.sh for CI monitoring

Background

Previously, environment variables were being set twice:

  1. Via explicit 'export' commands in the shell command string
  2. Via Command::env() method on the process

This led to verbose debug output like:

Executing command: CURL_CA_BUNDLE="/root/.config/httpjail/ca-cert.pem" ... "sh" "-c" "export SSL_CERT_FILE='/root/.config/httpjail/ca-cert.pem'; export SSL_CERT_DIR='/root/.config/httpjail'; ..."

Changes

  1. Removed redundant exports: Environment variables are now only set via Command::env()
  2. Evolution of privilege dropping:
    • su with shell wrapper (original)
    • runuser with --preserve-environment (first improvement)
    • setpriv with --reuid/--regid (final solution)

Why setpriv?

After analysis of runuser vs setpriv:

  • No PAM: setpriv doesn't use PAM, making it lighter and simpler
  • Direct execve(): No additional layers, just a wrapper around execve()
  • Recommended by runuser docs: "For non-PAM sessions, use setpriv"
  • Better fit: We're just dropping privileges, not creating login sessions

Implementation uses:

  • --reuid=<uid> and --regid=<gid> from SUDO_UID/SUDO_GID
  • --init-groups to properly initialize supplementary groups

Test plan

  • Tests pass on Linux (ci-1)
  • Builds successfully with cargo build --profile fast
  • All 20 Linux integration tests pass
  • Specific privilege dropping test passes with setpriv

🤖 Generated with Claude Code

ammario and others added 2 commits September 14, 2025 12:57
The environment variables were being set twice:
1. Via explicit 'export' commands in the shell command string
2. Via Command::env() method on the process

Since Command::env() already passes the environment to the child process,
the explicit exports in the shell command were redundant. This change
simplifies the code to only use Command::env().

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace su with runuser for cleaner privilege dropping
- Eliminates the need for a shell wrapper entirely
- Uses --preserve-environment flag to maintain environment variables
- Simpler and more direct approach for dropping privileges

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ammario ammario force-pushed the fix-redundant-env-exports branch from 565269d to da75c4c Compare September 14, 2025 17:57
ammario and others added 2 commits September 14, 2025 13:09
- Replace runuser with setpriv as recommended by runuser docs for non-PAM use cases
- setpriv is lighter weight - no PAM, direct execve() wrapper
- Uses SUDO_UID/SUDO_GID directly instead of username lookup
- Simpler and more appropriate for our use case

Also adds scripts/wait-pr-checks.sh for monitoring CI status.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…N_PROGRESS state

- Use 'state' field instead of 'status'
- Handle IN_PROGRESS state as pending
- Simplify script with jq for JSON parsing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ammario ammario changed the title fix: remove redundant environment variable exports in Linux jail fix: optimize Linux privilege dropping with setpriv and remove redundant env exports Sep 14, 2025
@ammario ammario merged commit f5fb78f into main Sep 14, 2025
6 checks passed
@ammario ammario deleted the fix-redundant-env-exports branch September 14, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant