[PR #399] [MERGED] fix(scripts): forward environment explicitly for sudo-rs compatibility #403

Closed
opened 2026-10-29 14:23:02 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kvcache-ai/AgentENV/pull/399
Author: @yingdi-shan
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @yingdi-shan

Base: main ← Head: fix/sudo-rs-env-forwarding


📝 Commits (1)

  • 09c5df2 fix(scripts): forward environment explicitly for sudo-rs compatibility

📊 Changes

1 file changed (+4 additions, -2 deletions)

View changed files

📝 scripts/run-with-capabilities.sh (+4 -2)

📄 Description

What

Make scripts/run-with-capabilities.sh forward the caller's environment through env(1) when escalating with sudo, instead of relying on sudo -E.

Why

GitHub's ubuntu-latest runners moved to Ubuntu 26.04, which ships sudo-rs as sudo. sudo-rs rejects -E (sudo: preserving the entire environment is not supported, '-E' is ignored), so the wrapper dropped AENV_HOME_PATH, AENV_DEPS_PATH, AENV_UBLK_DAEMON_BINARY_PATH and the target/debug PATH prefix. The privileged side then fell back to /tmp/aenv-test-<uid>, and every --test integration case panicked in tests/common/mod.rs:29 because regctl and the ublk daemon could not be found there.

Failing run: https://github.com/kvcache-ai/AgentENV/actions/runs/39378372269 (job agentenv-tests, image ubuntu-26.04). The previous passing run used ubuntu-24.04.

N/A: CI breakage caused by the runner image migration; no issue filed.

Scope and non-goals

Only the sudo re-exec line in the capability wrapper changes. Workflow runs-on pins and other sudo usages are out of scope.

Design and behavior changes

The non-root branch now captures env -0 into an array and runs exec sudo env "${caller_env[@]}" "$0" "$@". This keeps the previous -E behavior: the full caller environment reaches the root re-exec, which then drops to the runtime user with setpriv. Behavior on hosts with classic sudo is unchanged.

Compatibility and operations

  • Public API or generated protocol: N/A
  • Configuration or defaults: N/A
  • Snapshot manifest, artifact layout, or storage format: N/A
  • Upgrade and rollback: N/A, dev/CI script only
  • Host requirements, permissions, ports, or dependencies: works with both classic sudo and sudo-rs; still requires passwordless sudo as before

Validation

  • make fmt
  • make clippy
  • make test-unit
  • Relevant Rust integration tests
  • make -C services test (required when services/ changes)
  • Generated clients/server regenerated with the documented make target
  • Documentation updated
  • Benchmarks or performance comparison completed

Commands and results:

# As uid 1000 with classic sudo 1.9.15 (env_reset on, no -E):
PATH="/opt/fake-bin:$PATH" AENV_HOME_PATH=<scratch>/home AENV_RUNTIME_PATH=<scratch>/run \
  AENV_DEPS_PATH=/some/deps FOO=$'a b\nc' scripts/run-with-capabilities.sh sh -c '...'
  -> uid 1000, AENV_* values, multi-line FOO and PATH prefix preserved, CapEff 0000000000201000
bash scripts/tests/verify-capability-runner.sh   -> PASS
shellcheck scripts/run-with-capabilities.sh       -> clean
bash -n scripts/run-with-capabilities.sh          -> ok

Skipped checks and reasons: Rust fmt/clippy/unit suites not run (no Rust changes). sudo-rs is not available locally; this PR's Integration Tests run on an Ubuntu 26.04 runner is the end-to-end check. make test-agent-integration was not run locally.

Risks and reviewer notes

The wrapper was already documented as not being a privilege boundary. Passing variables via env bypasses sudo's env filtering, which -E mostly did as well. A very large caller environment could in theory hit argv limits, which is not a concern for CI or dev shells.

Checklist

  • The PR contains one coherent change and no unrelated formatting or refactoring.
  • New behavior is covered by tests, or I explained why testing is impractical.
  • Logs and examples contain no credentials, tokens, or private registry information.
  • I did not manually edit generated code without updating its source and regenerating it.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kvcache-ai/AgentENV/pull/399 **Author:** [@yingdi-shan](https://github.com/yingdi-shan) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@yingdi-shan](https://github.com/yingdi-shan) **Base:** `main` ← **Head:** `fix/sudo-rs-env-forwarding` --- ### 📝 Commits (1) - [`09c5df2`](https://github.com/kvcache-ai/AgentENV/commit/09c5df2d9166cc879a701be5e6c2c25156279419) fix(scripts): forward environment explicitly for sudo-rs compatibility ### 📊 Changes **1 file changed** (+4 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `scripts/run-with-capabilities.sh` (+4 -2) </details> ### 📄 Description ## What Make `scripts/run-with-capabilities.sh` forward the caller's environment through `env(1)` when escalating with sudo, instead of relying on `sudo -E`. ## Why GitHub's `ubuntu-latest` runners moved to Ubuntu 26.04, which ships sudo-rs as `sudo`. sudo-rs rejects `-E` (`sudo: preserving the entire environment is not supported, '-E' is ignored`), so the wrapper dropped `AENV_HOME_PATH`, `AENV_DEPS_PATH`, `AENV_UBLK_DAEMON_BINARY_PATH` and the `target/debug` `PATH` prefix. The privileged side then fell back to `/tmp/aenv-test-<uid>`, and every `--test integration` case panicked in `tests/common/mod.rs:29` because regctl and the ublk daemon could not be found there. Failing run: https://github.com/kvcache-ai/AgentENV/actions/runs/39378372269 (job `agentenv-tests`, image `ubuntu-26.04`). The previous passing run used `ubuntu-24.04`. ## Related issue N/A: CI breakage caused by the runner image migration; no issue filed. ## Scope and non-goals Only the sudo re-exec line in the capability wrapper changes. Workflow `runs-on` pins and other sudo usages are out of scope. ## Design and behavior changes The non-root branch now captures `env -0` into an array and runs `exec sudo env "${caller_env[@]}" "$0" "$@"`. This keeps the previous `-E` behavior: the full caller environment reaches the root re-exec, which then drops to the runtime user with `setpriv`. Behavior on hosts with classic sudo is unchanged. ## Compatibility and operations - Public API or generated protocol: N/A - Configuration or defaults: N/A - Snapshot manifest, artifact layout, or storage format: N/A - Upgrade and rollback: N/A, dev/CI script only - Host requirements, permissions, ports, or dependencies: works with both classic sudo and sudo-rs; still requires passwordless sudo as before ## Validation - [ ] `make fmt` - [ ] `make clippy` - [ ] `make test-unit` - [ ] Relevant Rust integration tests - [ ] `make -C services test` (required when `services/` changes) - [ ] Generated clients/server regenerated with the documented `make` target - [ ] Documentation updated - [ ] Benchmarks or performance comparison completed Commands and results: ```text # As uid 1000 with classic sudo 1.9.15 (env_reset on, no -E): PATH="/opt/fake-bin:$PATH" AENV_HOME_PATH=<scratch>/home AENV_RUNTIME_PATH=<scratch>/run \ AENV_DEPS_PATH=/some/deps FOO=$'a b\nc' scripts/run-with-capabilities.sh sh -c '...' -> uid 1000, AENV_* values, multi-line FOO and PATH prefix preserved, CapEff 0000000000201000 bash scripts/tests/verify-capability-runner.sh -> PASS shellcheck scripts/run-with-capabilities.sh -> clean bash -n scripts/run-with-capabilities.sh -> ok ``` Skipped checks and reasons: Rust fmt/clippy/unit suites not run (no Rust changes). sudo-rs is not available locally; this PR's Integration Tests run on an Ubuntu 26.04 runner is the end-to-end check. `make test-agent-integration` was not run locally. ## Risks and reviewer notes The wrapper was already documented as not being a privilege boundary. Passing variables via `env` bypasses sudo's env filtering, which `-E` mostly did as well. A very large caller environment could in theory hit argv limits, which is not a concern for CI or dev shells. ## Checklist - [x] The PR contains one coherent change and no unrelated formatting or refactoring. - [x] New behavior is covered by tests, or I explained why testing is impractical. - [x] Logs and examples contain no credentials, tokens, or private registry information. - [x] I did not manually edit generated code without updating its source and regenerating it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 14:23:02 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/AgentENV#403
No description provided.