Skip to content

Commit fcc2651

Browse files
committed
fix(sandbox,podman): deliver corporate proxy config on the supervisor argv
The proxy settings were injected as reserved OPENSHELL_UPSTREAM_* container environment variables. The driver only wrote names the operator configured, but container runtimes layer the spec environment over ENV values baked into the sandbox image, so an image could supply NO_PROXY=*, enable hostname CONNECT, or point an unconfigured deployment at an attacker-controlled proxy whenever the operator left a field unset. The settings now travel as supervisor command-line arguments (--upstream-proxy, --upstream-no-proxy, --upstream-proxy-auth-file, --upstream-proxy-auth-allow-insecure, --upstream-proxy-connect-by-hostname) built by the driver from operator config. The driver sets the container entrypoint and command explicitly, so neither sandbox spec/template environment nor image ENV can influence argv, and an omitted flag genuinely means unconfigured — in every supervisor topology, since the supervisor no longer consults its environment for these settings at all. Credentials stay on the root-only secret mount; only the mount path appears on argv. The reserved environment names, their strip-list entries, and the env-based validation surface are removed. UpstreamProxyConfig::from_args replaces from_env, reusing the same shared fail-closed validation and pairing rules keyed by the CLI flag names. Driver tests now assert the argv contract, including that sandbox-supplied environment cannot add, remove, or redirect proxy flags; supervisor tests cover from_args mapping and its pairing rules. Signed-off-by: Philippe Martin <[email protected]>
1 parent 2768c08 commit fcc2651

12 files changed

Lines changed: 390 additions & 332 deletions

File tree

‎architecture/sandbox.md‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ once policy and SSRF checks pass. Only TLS (CONNECT) egress is chained:
109109
plain-HTTP requests always dial the destination directly, because forwarding
110110
plain HTTP through a proxy requires absolute-form request forwarding rather
111111
than CONNECT tunneling and is out of scope. The proxy configuration is an
112-
operator-owned boundary read from reserved `OPENSHELL_UPSTREAM_HTTPS_PROXY` /
113-
`OPENSHELL_UPSTREAM_NO_PROXY` variables that compute drivers write in their
114-
required-variable tier; sandbox and template environment cannot override them.
115-
The conventional `HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox
116-
controls are ignored on this path. Reserved `NO_PROXY` destinations and
112+
operator-owned boundary delivered on the supervisor's command line
113+
(`--upstream-proxy` and friends) by the compute driver; sandbox and template
114+
environment — and `ENV` values baked into the sandbox image — cannot
115+
influence it, since none of these can alter the argv the driver sets. The
116+
conventional `HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox
117+
controls are ignored on this path. Operator `NO_PROXY` destinations and
117118
loopback always dial directly; add driver-injected host aliases (e.g.
118-
`host.containers.internal`) to the reserved `NO_PROXY` list when the corporate
119+
`host.containers.internal`) to the operator `NO_PROXY` list when the corporate
119120
proxy cannot reach the container host. `NO_PROXY` matching is port-aware and
120121
resolution-aware: an entry with a `:port` qualifier only bypasses that port,
121122
and IP/CIDR entries also match hostnames through their validated resolved
@@ -129,40 +130,38 @@ the answer that passed SSRF and `allowed_ips` validation. The hostname still
129130
travels inside the tunnel (TLS SNI, application `Host`). In split-horizon
130131
networks, point the gateway host at the corporate resolver so internal names
131132
validate to their internal addresses; the `proxy_connect_by_hostname`
132-
opt-in (reserved `OPENSHELL_UPSTREAM_PROXY_CONNECT_BY_HOSTNAME`) exists as a
133+
opt-in exists as a
133134
last resort for proxies whose ACLs filter on hostnames and reject IP CONNECT
134135
targets — with it, the proxy resolves the name itself and its ACLs become
135136
the effective egress control for proxied TLS. (Resolving through the proxy's
136137
own DNS view, e.g. DoH tunneled via CONNECT, is a possible future
137138
enhancement and out of scope.) The workload child's proxy variables are
138139
unaffected — they are always rewritten to point at the local policy proxy.
139140

140-
The configuration is fail-closed: a reserved variable that is present but
141-
invalid — a present-but-empty value, an unsupported or malformed proxy URL, an
142-
unreadable auth file, a malformed credential, or an auth file or `NO_PROXY`
143-
list set while no proxy URL is configured — is fatal to supervisor startup
144-
instead of being treated as unset, so a misconfiguration can never silently
145-
degrade to direct dialing or unauthenticated proxy access. Only a fully unset
146-
variable means "no proxy". The driver validates the same rules at
147-
sandbox-create time through validators shared with the supervisor
141+
The configuration is fail-closed: a setting that is present but invalid — an
142+
empty value, an unsupported or malformed proxy URL, an unreadable auth file,
143+
a malformed credential, or an auth file or `NO_PROXY` list set while no proxy
144+
URL is configured — is fatal to supervisor startup instead of being treated
145+
as unset, so a misconfiguration can never silently degrade to direct dialing
146+
or unauthenticated proxy access. Only an omitted argument means "no proxy".
147+
The driver validates the same rules at sandbox-create time through
148+
validators shared with the supervisor
148149
(`openshell_core::driver_utils::parse_upstream_proxy_url` and
149150
`parse_upstream_proxy_credential`).
150151

151152
Proxy credentials are never embedded in the URL: an inline `user:pass@` is
152153
rejected because it would be stored in `gateway.toml` and exposed in container
153154
metadata. Operators supply credentials via `proxy_auth_file`; the driver
154-
stages them as a root-only secret mounted at a fixed path and exports only
155-
that path in `OPENSHELL_UPSTREAM_PROXY_AUTH_FILE`. The supervisor reads the
155+
stages them as a root-only secret mounted at a fixed path and passes only
156+
that path on the supervisor's command line. The supervisor reads the
156157
file and builds the `Proxy-Authorization: Basic` header; a credential that is
157158
empty, contains control characters, or is not in `user:pass` form is fatal on
158-
both sides. The reserved proxy variables —
159-
including the auth-file path — are stripped from workload child processes.
159+
both sides.
160160

161161
The Basic header travels over the plain-TCP connection to the `http://` proxy,
162162
so it is readable on the network path between sandbox host and proxy.
163163
Configuring `proxy_auth_file` therefore requires the explicit opt-in
164-
`proxy_auth_allow_insecure = true`, delivered to the supervisor as the
165-
reserved `OPENSHELL_UPSTREAM_PROXY_AUTH_ALLOW_INSECURE` variable. Both the
164+
`proxy_auth_allow_insecure = true`. Both the
166165
driver (at sandbox-create time) and the supervisor (at startup) reject an
167166
auth file without the acknowledgement, and the acknowledgement without an
168167
auth file, so credentials are never sent in cleartext without an explicit

‎crates/openshell-core/src/driver_utils.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ pub const UPSTREAM_PROXY_AUTH_MOUNT_PATH: &str = "/etc/openshell/auth/upstream-p
8484
/// Produced by [`parse_upstream_proxy_url`], which is the single source of
8585
/// truth for what counts as a valid upstream proxy URL. Compute drivers use
8686
/// it to reject bad operator config at sandbox-create time, and the
87-
/// in-container supervisor applies the same rules to the reserved
88-
/// `OPENSHELL_UPSTREAM_*` variables so a value one side accepts is never
89-
/// rejected (or silently ignored) by the other.
87+
/// in-container supervisor applies the same rules to its driver-supplied
88+
/// arguments so a value one side accepts is never rejected (or silently
89+
/// ignored) by the other.
9090
#[derive(Debug, Clone, PartialEq, Eq)]
9191
pub struct UpstreamProxyAddr {
9292
/// Proxy hostname, IPv4, or IPv6 address (IPv6 without brackets).

‎crates/openshell-core/src/sandbox_env.rs‎

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -115,56 +115,7 @@ pub const SANDBOX_UID: &str = "OPENSHELL_SANDBOX_UID";
115115
/// supervisor drops privileges to a group other than the UID's primary group.
116116
pub const SANDBOX_GID: &str = "OPENSHELL_SANDBOX_GID";
117117

118-
/// Corporate forward-proxy URL the supervisor chains TLS (CONNECT) egress
119-
/// through, e.g. `http://proxy.corp.com:8080`.
120-
///
121-
/// This is an operator-owned egress boundary. Compute drivers set it from
122-
/// gateway configuration in the supervisor's required-variable tier so that
123-
/// sandbox spec/template environment cannot override it. The supervisor reads
124-
/// *only* this reserved name — never the conventional `HTTPS_PROXY` /
125-
/// `ALL_PROXY` variables, which the sandbox creator controls and which are
126-
/// reserved for pointing the workload child at the local policy proxy.
127-
pub const UPSTREAM_HTTPS_PROXY: &str = "OPENSHELL_UPSTREAM_HTTPS_PROXY";
128-
129-
/// Comma-separated `NO_PROXY`-style list of destinations the supervisor dials
130-
/// directly instead of chaining through the corporate proxy.
131-
///
132-
/// Operator-owned counterpart to [`UPSTREAM_HTTPS_PROXY`]; see that constant
133-
/// for the trust-boundary rationale.
134-
pub const UPSTREAM_NO_PROXY: &str = "OPENSHELL_UPSTREAM_NO_PROXY";
135-
136-
/// Filesystem path (inside the sandbox) to the corporate proxy credentials.
137-
///
138-
/// The file holds `user:pass` userinfo the supervisor turns into a
139-
/// `Proxy-Authorization: Basic` header. Credentials are delivered through this
140-
/// root-only file rather than embedded in the proxy URL, so they never appear
141-
/// in container environment or metadata. Compute drivers write this in the
142-
/// required-variable tier; the value is a path, not a secret.
143-
pub const UPSTREAM_PROXY_AUTH_FILE: &str = "OPENSHELL_UPSTREAM_PROXY_AUTH_FILE";
144-
145-
/// Explicit operator acknowledgement (`true`) that the proxy credential is
146-
/// sent as a cleartext `Proxy-Authorization: Basic` header over the plain-TCP
147-
/// connection to the `http://` corporate proxy.
148-
///
149-
/// Basic auth is base64, not encryption, so anyone on the network path
150-
/// between the sandbox host and the proxy can recover the credential. The
151-
/// supervisor refuses to send credentials without this acknowledgement:
152-
/// [`UPSTREAM_PROXY_AUTH_FILE`] set without this variable equal to `true` is
153-
/// a fatal startup error, as is this variable set without an auth file.
154-
/// Compute drivers write it in the required-variable tier from the driver's
155-
/// `proxy_auth_allow_insecure` setting.
156-
pub const UPSTREAM_PROXY_AUTH_ALLOW_INSECURE: &str = "OPENSHELL_UPSTREAM_PROXY_AUTH_ALLOW_INSECURE";
157-
158-
/// Explicit operator opt-out (`true`) that sends the destination *hostname*
159-
/// in the CONNECT request to the corporate proxy instead of a validated IP.
160-
///
161-
/// By default the supervisor CONNECTs to an address that already passed
162-
/// SSRF and `allowed_ips` validation, so the proxy performs no DNS
163-
/// resolution and the connection is bound to the validated answer. With
164-
/// this opt-out the proxy resolves the name itself: hostname-filtering
165-
/// proxy ACLs keep working, but a name whose resolution differs at the
166-
/// proxy (split-horizon DNS, rebinding) can reach destinations the sandbox
167-
/// policy never approved — the proxy's own ACLs become the effective
168-
/// egress control. Compute drivers write it in the required-variable tier
169-
/// from the driver's `proxy_connect_by_hostname` setting.
170-
pub const UPSTREAM_PROXY_CONNECT_BY_HOSTNAME: &str = "OPENSHELL_UPSTREAM_PROXY_CONNECT_BY_HOSTNAME";
118+
// The corporate upstream-proxy configuration deliberately has no reserved
119+
// environment variables: it travels on the supervisor's argv
120+
// (`--upstream-proxy` and friends), which a sandbox image cannot forge the
121+
// way it could bake `ENV` values.

‎crates/openshell-driver-podman/README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ Through the gateway, the same settings are the `https_proxy`, `no_proxy`,
356356
`proxy_connect_by_hostname` keys under `[openshell.drivers.podman]`; see
357357
`docs/reference/gateway-config.mdx`.
358358

359-
This is an operator-owned egress boundary: the supervisor reads it from reserved
360-
`OPENSHELL_UPSTREAM_*` variables written at highest priority, so sandbox and
361-
template environment cannot override it, and the conventional
362-
`HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox controls do not steer
363-
it. Credentials must be supplied through `proxy_auth_file`; an inline
364-
`user:pass@` in the URL is rejected at startup.
359+
This is an operator-owned egress boundary: the driver passes the settings on
360+
the supervisor's command line, so sandbox and template environment — and any
361+
`ENV` baked into the sandbox image — cannot override them, and the
362+
conventional `HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox
363+
controls do not steer it. Credentials must be supplied through
364+
`proxy_auth_file`; an inline `user:pass@` in the URL is rejected at startup.
365365

366366
Basic auth over an `http://` proxy is cleartext on the wire: anyone on the
367367
network path between the sandbox host and the proxy can recover the

‎crates/openshell-driver-podman/src/config.rs‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,18 @@ pub struct PodmanComputeConfig {
134134
/// Set to `0` to disable health checks entirely.
135135
/// Defaults to [`DEFAULT_HEALTH_CHECK_INTERVAL_SECS`] (10 seconds).
136136
pub health_check_interval_secs: u64,
137-
/// Corporate forward proxy URL injected into sandbox containers as the
138-
/// reserved `OPENSHELL_UPSTREAM_HTTPS_PROXY` supervisor variable
137+
/// Corporate forward proxy URL passed to the in-container supervisor
139138
/// (e.g. `http://proxy.corp.com:8080`).
140139
///
141-
/// The in-container supervisor chains policy-approved TLS tunnels
142-
/// through this proxy with HTTP CONNECT instead of dialing upstream
143-
/// destinations directly. Only `http://` proxy URLs in explicit
144-
/// `http://host:port` form (scheme and port required) are supported.
145-
/// This is an operator-owned egress boundary: it is written in the
146-
/// required-variable tier so sandbox/template environment cannot override
147-
/// it, and the conventional `HTTPS_PROXY` variables are not used.
140+
/// The supervisor chains policy-approved TLS tunnels through this proxy
141+
/// with HTTP CONNECT instead of dialing upstream destinations directly.
142+
/// Only `http://` proxy URLs in explicit `http://host:port` form (scheme
143+
/// and port required) are supported. This is an operator-owned egress
144+
/// boundary delivered on the supervisor's command line, so
145+
/// sandbox/template environment cannot override it, and the conventional
146+
/// `HTTPS_PROXY` variables are not used.
148147
pub https_proxy: Option<String>,
149-
/// Comma-separated `NO_PROXY` list injected as the reserved
150-
/// `OPENSHELL_UPSTREAM_NO_PROXY` variable (e.g.
148+
/// Comma-separated `NO_PROXY` list passed alongside the proxy URL (e.g.
151149
/// `*.svc.cluster.local,10.0.0.0/8`). Destinations matching an entry are
152150
/// dialed directly instead of through the corporate proxy. Entries take
153151
/// an optional `:port` qualifier that limits them to that destination

0 commit comments

Comments
 (0)