Skip to content

Commit fa0082c

Browse files
committed
feat(sandbox,podman): deliver corporate proxy credentials via secret file
Proxy credentials were embedded inline in the proxy URL, so they were stored in gateway.toml and exposed in container metadata via 'podman inspect'. Reject inline 'user:pass@' credentials in https_proxy/http_proxy at startup (parsed with the url crate rather than hand-splitting), and add a proxy_auth_file option pointing at a 'user:pass' file. The driver stages that file as a per-sandbox root-only Podman secret, mounts it at a fixed path, and exports only the path in the reserved OPENSHELL_UPSTREAM_PROXY_AUTH_FILE variable, so the credential never appears in config, environment, or container metadata. Reading the file fails closed on a missing, empty, or control-character-bearing value. The supervisor reads the credential from the mounted file and builds the Proxy-Authorization: Basic header, rejecting control characters, and no longer derives credentials from URL userinfo. The auth-file path is added to the child-environment strip list, and the generated gateway.toml is written owner-only (mode 0600). Signed-off-by: Philippe Martin <[email protected]>
1 parent 3c43b52 commit fa0082c

14 files changed

Lines changed: 468 additions & 93 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎architecture/sandbox.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ the corporate proxy is the requested hostname. The workload child's proxy
118118
variables are unaffected — they are always rewritten to point at the local
119119
policy proxy.
120120

121+
Proxy credentials are never embedded in the URL: an inline `user:pass@` is
122+
rejected at startup because it would be stored in `gateway.toml` and exposed in
123+
container metadata. Operators supply credentials via `proxy_auth_file`; the
124+
driver stages them as a root-only secret mounted at a fixed path and exports
125+
only that path in `OPENSHELL_UPSTREAM_PROXY_AUTH_FILE`. The supervisor reads the
126+
file and builds the `Proxy-Authorization: Basic` header, rejecting credentials
127+
containing control characters. The reserved proxy variables — including the
128+
auth-file path — are stripped from workload child processes.
129+
121130
## Credentials
122131

123132
Provider credentials are stored at the gateway and fetched by the supervisor at

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ pub const TLS_KEY_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.key";
7272
/// Container-side mount path for the per-sandbox JWT token.
7373
pub const SANDBOX_TOKEN_MOUNT_PATH: &str = "/etc/openshell/auth/sandbox.jwt";
7474

75+
/// Container-side mount path for the corporate upstream-proxy credentials.
76+
///
77+
/// The file holds the `user:pass` userinfo used to build the
78+
/// `Proxy-Authorization` header. It is delivered through a root-only secret
79+
/// mount so the credential never appears in container environment/metadata.
80+
pub const UPSTREAM_PROXY_AUTH_MOUNT_PATH: &str = "/etc/openshell/auth/upstream-proxy";
81+
7582
/// Return the XDG state path for a driver's sandbox JWT token file.
7683
///
7784
/// The resulting path is `$XDG_STATE_HOME/openshell/<driver_subdir>[/<namespace>]/<sandbox_id>/sandbox.jwt`.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,12 @@ pub const UPSTREAM_HTTP_PROXY: &str = "OPENSHELL_UPSTREAM_HTTP_PROXY";
138138
/// Operator-owned counterpart to [`UPSTREAM_HTTPS_PROXY`]; see that constant
139139
/// for the trust-boundary rationale.
140140
pub const UPSTREAM_NO_PROXY: &str = "OPENSHELL_UPSTREAM_NO_PROXY";
141+
142+
/// Filesystem path (inside the sandbox) to the corporate proxy credentials.
143+
///
144+
/// The file holds `user:pass` userinfo the supervisor turns into a
145+
/// `Proxy-Authorization: Basic` header. Credentials are delivered through this
146+
/// root-only file rather than embedded in the proxy URL, so they never appear
147+
/// in container environment or metadata. Compute drivers write this in the
148+
/// required-variable tier; the value is a path, not a secret.
149+
pub const UPSTREAM_PROXY_AUTH_FILE: &str = "OPENSHELL_UPSTREAM_PROXY_AUTH_FILE";

‎crates/openshell-driver-podman/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tracing = { workspace = true }
3434
tracing-subscriber = { workspace = true }
3535
thiserror = { workspace = true }
3636
miette = { workspace = true }
37+
url = { workspace = true }
3738

3839
[dev-dependencies]
3940
prost-types = { workspace = true }

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,21 @@ Podman resources after out-of-band container removal or label drift.
345345
| `OPENSHELL_PODMAN_TLS_CA` | `--podman-tls-ca` | unset | Host path to the CA certificate mounted for sandbox mTLS. |
346346
| `OPENSHELL_PODMAN_TLS_CERT` | `--podman-tls-cert` | unset | Host path to the client certificate mounted for sandbox mTLS. |
347347
| `OPENSHELL_PODMAN_TLS_KEY` | `--podman-tls-key` | unset | Host path to the client private key mounted for sandbox mTLS. |
348-
| `OPENSHELL_SANDBOX_HTTPS_PROXY` | `--sandbox-https-proxy` | unset | Corporate forward proxy URL injected into sandbox containers as `HTTPS_PROXY`. The in-container supervisor chains policy-approved upstream dials through it with HTTP CONNECT. Only `http://` proxy URLs are supported. |
349-
| `OPENSHELL_SANDBOX_HTTP_PROXY` | `--sandbox-http-proxy` | unset | Corporate forward proxy URL injected as `HTTP_PROXY` for plain HTTP requests. |
348+
| `OPENSHELL_SANDBOX_HTTPS_PROXY` | `--sandbox-https-proxy` | unset | Corporate forward proxy URL for the supervisor's upstream TLS dials, chained with HTTP CONNECT. Only credential-free `http://` URLs are supported. |
349+
| `OPENSHELL_SANDBOX_HTTP_PROXY` | `--sandbox-http-proxy` | unset | Corporate forward proxy URL for plain HTTP requests. |
350350
| `OPENSHELL_SANDBOX_NO_PROXY` | `--sandbox-no-proxy` | unset | Comma-separated `NO_PROXY` list (hostnames, domain suffixes, IPs, CIDRs) dialed directly instead of through the corporate proxy. |
351-
352-
Through the gateway, the same settings are the `https_proxy`, `http_proxy`, and
353-
`no_proxy` keys under `[openshell.drivers.podman]`; see
354-
`docs/reference/gateway-config.mdx`. Per-sandbox environment values take
355-
precedence over these operator defaults.
351+
| `OPENSHELL_SANDBOX_PROXY_AUTH_FILE` | `--sandbox-proxy-auth-file` | unset | Path to a file containing the proxy credentials as `user:pass`. Staged as a root-only Podman secret so credentials never appear in config or container metadata. |
352+
353+
Through the gateway, the same settings are the `https_proxy`, `http_proxy`,
354+
`no_proxy`, and `proxy_auth_file` keys under `[openshell.drivers.podman]`; see
355+
`docs/reference/gateway-config.mdx`.
356+
357+
This is an operator-owned egress boundary: the supervisor reads it from reserved
358+
`OPENSHELL_UPSTREAM_*` variables written at highest priority, so sandbox and
359+
template environment cannot override it, and the conventional
360+
`HTTPS_PROXY`/`HTTP_PROXY`/`NO_PROXY` variables a sandbox controls do not steer
361+
it. Credentials must be supplied through `proxy_auth_file`; an inline
362+
`user:pass@` in the URL is rejected at startup.
356363

357364
## Rootless-Specific Adaptations
358365

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

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ use std::net::IpAddr;
66
use std::path::PathBuf;
77
use std::str::FromStr;
88

9+
/// Parse a proxy URL, defaulting a missing scheme to `http://`.
10+
///
11+
/// A bare `host:port` (no `://`) is normalized to `http://host:port` so it
12+
/// parses the same way the in-sandbox supervisor treats a scheme-less proxy
13+
/// value. Returns the parsed [`url::Url`] for scheme/userinfo/host inspection.
14+
fn parse_proxy_url(raw: &str) -> Result<url::Url, url::ParseError> {
15+
if raw.contains("://") {
16+
url::Url::parse(raw)
17+
} else {
18+
url::Url::parse(&format!("http://{raw}"))
19+
}
20+
}
21+
922
/// Default Podman bridge network name.
1023
pub const DEFAULT_NETWORK_NAME: &str = "openshell";
1124
pub const MACOS_PODMAN_MACHINE_HOST_GATEWAY_IP: &str = "192.168.127.254";
@@ -154,6 +167,15 @@ pub struct PodmanComputeConfig {
154167
/// `*.svc.cluster.local,10.0.0.0/8`). Destinations matching an entry are
155168
/// dialed directly instead of through the corporate proxy.
156169
pub no_proxy: Option<String>,
170+
/// Path (on the gateway host) to a file containing the corporate proxy
171+
/// credentials as `user:pass`.
172+
///
173+
/// Credentials must be supplied through this file, never embedded in the
174+
/// proxy URL: an inline `user:pass@` in `https_proxy`/`http_proxy` is
175+
/// rejected at startup because it would leak into `gateway.toml` and
176+
/// container metadata. The gateway reads this file at sandbox-create time
177+
/// and delivers it to the supervisor through a root-only secret mount.
178+
pub proxy_auth_file: Option<String>,
157179
}
158180

159181
pub const DEFAULT_HEALTH_CHECK_INTERVAL_SECS: u64 = 10;
@@ -211,9 +233,12 @@ impl PodmanComputeConfig {
211233

212234
/// Validate optional corporate proxy configuration.
213235
///
214-
/// The in-container supervisor only supports `http://` forward proxies,
215-
/// so reject other schemes at config time instead of silently ignoring
216-
/// them inside every sandbox.
236+
/// The in-container supervisor only supports `http://` forward proxies, so
237+
/// reject other schemes at config time instead of silently ignoring them
238+
/// inside every sandbox. Credentials must be supplied through
239+
/// `proxy_auth_file`; an inline `user:pass@` in the URL is rejected because
240+
/// it would otherwise be stored in `gateway.toml` and exposed in container
241+
/// metadata.
217242
pub fn validate_proxy_config(&self) -> Result<(), crate::client::PodmanApiError> {
218243
for (field, value) in [
219244
("https_proxy", &self.https_proxy),
@@ -226,15 +251,46 @@ impl PodmanComputeConfig {
226251
"{field} must not be empty when set"
227252
)));
228253
}
229-
if let Some((scheme, _)) = trimmed.split_once("://")
230-
&& !scheme.eq_ignore_ascii_case("http")
231-
{
254+
255+
let parsed = parse_proxy_url(trimmed).map_err(|e| {
256+
crate::client::PodmanApiError::InvalidInput(format!(
257+
"{field} is not a valid proxy URL: {e}"
258+
))
259+
})?;
260+
261+
if !parsed.scheme().eq_ignore_ascii_case("http") {
262+
return Err(crate::client::PodmanApiError::InvalidInput(format!(
263+
"{field} uses unsupported scheme '{}': only http:// forward \
264+
proxies are supported by the sandbox supervisor",
265+
parsed.scheme()
266+
)));
267+
}
268+
if !parsed.username().is_empty() || parsed.password().is_some() {
269+
return Err(crate::client::PodmanApiError::InvalidInput(format!(
270+
"{field} must not embed credentials in the URL; supply them via \
271+
proxy_auth_file so they are not stored in config or container metadata"
272+
)));
273+
}
274+
if parsed.host_str().is_none_or(str::is_empty) {
232275
return Err(crate::client::PodmanApiError::InvalidInput(format!(
233-
"{field} uses unsupported scheme '{scheme}': only http:// forward \
234-
proxies are supported by the sandbox supervisor"
276+
"{field} is missing a proxy host"
235277
)));
236278
}
237279
}
280+
281+
if let Some(path) = self.proxy_auth_file.as_deref() {
282+
if path.trim().is_empty() {
283+
return Err(crate::client::PodmanApiError::InvalidInput(
284+
"proxy_auth_file must not be empty when set".to_string(),
285+
));
286+
}
287+
if self.https_proxy.is_none() && self.http_proxy.is_none() {
288+
return Err(crate::client::PodmanApiError::InvalidInput(
289+
"proxy_auth_file is set but no https_proxy/http_proxy is configured"
290+
.to_string(),
291+
));
292+
}
293+
}
238294
Ok(())
239295
}
240296

@@ -314,6 +370,7 @@ impl Default for PodmanComputeConfig {
314370
https_proxy: None,
315371
http_proxy: None,
316372
no_proxy: None,
373+
proxy_auth_file: None,
317374
}
318375
}
319376
}
@@ -344,6 +401,7 @@ impl std::fmt::Debug for PodmanComputeConfig {
344401
.field("https_proxy", &self.https_proxy.is_some())
345402
.field("http_proxy", &self.http_proxy.is_some())
346403
.field("no_proxy", &self.no_proxy)
404+
.field("proxy_auth_file", &self.proxy_auth_file.is_some())
347405
.finish()
348406
}
349407
}
@@ -496,6 +554,45 @@ mod tests {
496554
assert!(err.to_string().contains("http_proxy"), "{err}");
497555
}
498556

557+
#[test]
558+
fn validate_proxy_config_rejects_inline_credentials() {
559+
for url in [
560+
"http://user:[email protected]:8080",
561+
"http://[email protected]:8080",
562+
"user:[email protected]:8080",
563+
] {
564+
let cfg = PodmanComputeConfig {
565+
https_proxy: Some(url.to_string()),
566+
..PodmanComputeConfig::default()
567+
};
568+
let err = cfg.validate_proxy_config().unwrap_err();
569+
assert!(
570+
err.to_string().contains("proxy_auth_file"),
571+
"{url} should be rejected and point at proxy_auth_file: {err}"
572+
);
573+
}
574+
}
575+
576+
#[test]
577+
fn validate_proxy_config_accepts_auth_file_with_proxy() {
578+
let cfg = PodmanComputeConfig {
579+
https_proxy: Some("http://proxy.corp.com:8080".to_string()),
580+
proxy_auth_file: Some("/etc/openshell/secrets/proxy-auth".to_string()),
581+
..PodmanComputeConfig::default()
582+
};
583+
assert!(cfg.validate_proxy_config().is_ok());
584+
}
585+
586+
#[test]
587+
fn validate_proxy_config_rejects_auth_file_without_proxy() {
588+
let cfg = PodmanComputeConfig {
589+
proxy_auth_file: Some("/etc/openshell/secrets/proxy-auth".to_string()),
590+
..PodmanComputeConfig::default()
591+
};
592+
let err = cfg.validate_proxy_config().unwrap_err();
593+
assert!(err.to_string().contains("proxy_auth_file"), "{err}");
594+
}
595+
499596
// ── TLS config validation ─────────────────────────────────────────
500597

501598
#[test]

0 commit comments

Comments
 (0)