feat(shell): scrub ambient credentials from child process environment (#618) - #631
Open
cagdasyurekli wants to merge 1 commit into
Open
feat(shell): scrub ambient credentials from child process environment (#618)#631cagdasyurekli wants to merge 1 commit into
cagdasyurekli wants to merge 1 commit into
Conversation
…andrewyng#618) Scrub ambient credentials from run_shell child environment to prevent accidental leak: - Introduce filter_ambient_env and is_sensitive_env in coworker/tools/shell.py. - Drop AWS_*, AZURE_*, *_API_KEY, *_SECRET_*, *_TOKEN, *_PASSWORD, *_CREDENTIAL patterns from inherited os.environ unless explicitly allowed. - Support [shell] allowed_env and shell_allowed_env in config.toml. - Ensure workspace allowed_env is only trusted when workspace is explicitly trusted. - Pass config.shell_allowed_env to LocalExecutor in coworker/agent.py. - Add comprehensive test coverage in tests/test_shell.py and tests/test_config.py. Closes andrewyng#618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR addresses and closes #618 by preventing ambient cloud credentials and secret tokens from automatically leaking into
run_shellchild processes.Motivation
Currently,
LocalExecutorinherits the entireos.environfrom the parent process. If a developer launches OpenWorker in a terminal session where personal or cloud credentials are exported (AWS_SECRET_ACCESS_KEY,GITHUB_TOKEN,*_API_KEY, etc.), any shell command executed by the agent (or a build script invoked in the workspace) inherits ambient access to those secrets.Proposed Solution & Changes
coworker/tools/shell.py):filter_ambient_envandis_sensitive_envto identify and scrub sensitive environment variable patterns (AWS_*,AZURE_*,*_API_KEY,*_SECRET_*,*_TOKEN,*_PASSWORD,*_CREDENTIAL, etc.) by default.PATH,HOME,USER,SHELL,TERM,LANG,TMPDIR, virtualenv variables, etc.).env={...}passed toLocalExecutortakes precedence as an explicit user override.coworker/config.py):shell_allowed_envfield toConfigsupporting both[shell] allowed_env = [...]andshell_allowed_env = [...]inconfig.toml.allowed_envis only applied if the workspace is explicitly trusted.coworker/agent.py):allowed_env=config.shell_allowed_envtoLocalExecutorwhen instantiating the workspace executor.tests/test_shell.py,tests/test_config.py):Verification
pytest tests/test_shell.py tests/test_config.py -v: 25 passed in 3.97s.Closes #618