Skip to content

feat(server): support injecting env vars into egress container#1069

Open
Pangjiping wants to merge 2 commits into
mainfrom
feat/egress-env-injection
Open

feat(server): support injecting env vars into egress container#1069
Pangjiping wants to merge 2 commits into
mainfrom
feat/egress-env-injection

Conversation

@Pangjiping

Copy link
Copy Markdown
Collaborator

Summary

  • Route OPENSANDBOX_EGRESS_* prefixed env vars from CreateSandboxRequest.env to the egress sidecar container instead of the main sandbox container
  • Block reserved internal vars (OPENSANDBOX_EGRESS_RULES, OPENSANDBOX_EGRESS_MODE, OPENSANDBOX_EGRESS_TOKEN) with 400 error
  • Zero API/SDK/spec changes — uses existing env field with prefix convention

Closes #968

Test plan

  • Unit tests for _split_egress_env: prefix splitting, empty/None input, reserved var rejection, MITMPROXY_TRANSPARENT allowed
  • Unit tests for apply_egress_to_spec with extra_env: injection, None value handling, empty dict noop
  • All 478 existing k8s tests pass

🤖 Generated with Claude Code

…ENSANDBOX_EGRESS_ prefix

Env vars in CreateSandboxRequest.env with the OPENSANDBOX_EGRESS_ prefix
are now automatically routed to the egress sidecar container instead of
the main sandbox container. This enables users to configure egress
behavior (e.g., mitmproxy scripts, log level, DNS settings) at sandbox
creation time without requiring a custom egress image.

Reserved internal vars (RULES, MODE, TOKEN) are rejected with 400 to
prevent overriding server-managed state.

Closes #968

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eaeadabc80

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/opensandbox_server/services/k8s/create_helpers.py
Comment thread server/opensandbox_server/services/k8s/create_helpers.py
Comment thread server/opensandbox_server/services/k8s/egress_helper.py
Comment thread server/opensandbox_server/services/constants.py
- Mirror OPENSANDBOX_EGRESS_MITMPROXY_TRANSPARENT to sandbox container
  so execd bootstrap.sh can trust the MITM CA in manual MITM path
- Move _build_create_workload_context into try block so reserved env var
  ValueError is caught and returned as 400 instead of 500
- Skip user-supplied MITMPROXY_TRANSPARENT in extra_env when
  credential_proxy_enabled to prevent overriding the internal value
- Reserve OPENSANDBOX_EGRESS_HTTP_ADDR to prevent users from changing
  the egress listen address and breaking readiness probes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dee470ea2c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/opensandbox_server/services/k8s/egress_helper.py
Comment on lines +51 to +56
if key.startswith(EGRESS_ENV_PREFIX):
if key in RESERVED_EGRESS_ENV_VARS:
raise ValueError(
f"Environment variable '{key}' is reserved and cannot be overridden"
)
egress_env[key] = value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve prefixed envs when no sidecar exists

For Kubernetes create requests that do not include networkPolicy, this branch still removes every non-reserved OPENSANDBOX_EGRESS_... variable from the sandbox env and stores it only in egress_env. Because _build_create_workload_context only sets an egress image/token when request.network_policy is present, apply_egress_to_spec() returns without creating a sidecar, so these variables are silently injected nowhere instead of into the requested sandbox runtime. Only split these keys when an egress sidecar will actually be created, or reject this combination explicitly.

Useful? React with 👍 / 👎.

Comment on lines +100 to +102
if credential_proxy_enabled and name == OPENSANDBOX_EGRESS_MITMPROXY_TRANSPARENT:
continue
env.append({"name": name, "value": value or ""})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject insecure MITM when using credential proxy

When credentialProxy.enabled is true, a request can still pass OPENSANDBOX_EGRESS_MITMPROXY_SSL_INSECURE=true through env, and this loop appends it to the egress sidecar. The credential vault explicitly refuses to operate in that mode (components/egress/pkg/credentialvault/vault.go:373-378), so credential-vault writes for that sandbox fail even though the create request asked the server to provision credential proxy support. Filter or reject this env var on the credential-proxy path the same way the transparent MITM flag is protected.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/server feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support injecting environment variables into egress container

2 participants