Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions architecture/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ SONAMEs.

The workload-side `openshell-sandbox` binary is statically linked with musl so
drivers can stage it into an arbitrary agent image without depending on that
image's libc. The supervisor is also statically linked: release images use the
default musl build, while distribution-specific builds may select the
`glibc-static` variant.
image's libc. The separate `openshell-supervisor` binary is dynamically linked
with GNU libc and uses the same glibc 2.28 compatibility floor as the gateway.

## Container Builds

Expand All @@ -115,11 +114,8 @@ package-managed VM support does not raise the package runtime requirement.
Gateway staging and release workflows set up the Zig C/C++ wrapper before
bundled Z3 builds and verify the maximum referenced `GLIBC_*` symbol version
before publishing or copying artifacts.
Supervisor binaries are static in every configuration. The default `musl`
variant uses `cargo zigbuild` when available, including native CPU
architectures, so C dependencies are compiled for the musl target instead of the
host GNU libc target. The `glibc-static` variant uses plain `cargo build` with
`+crt-static` and requires a native per-architecture build. Local Docker image tasks infer the
Supervisor staging uses the GNU build path and verifies the glibc 2.28 floor.
Sandbox staging uses the static musl build path. Local Docker image tasks infer the
target architecture from `DOCKER_PLATFORM` when set. Otherwise, they require
valid container engine host metadata and fail when the engine query is
unavailable or reports an unsupported architecture, avoiding host-kernel
Expand Down Expand Up @@ -184,9 +180,16 @@ Runtime layout:
- **Sandbox**: Alpine-based `openshell/sandbox` image containing the static
musl `/openshell-sandbox` binary and its static VM guest-init helper.
Drivers stage this binary into the workload trust domain.
- **Supervisor**: Debian-based `openshell/supervisor` image containing only the
dynamically linked GNU `/openshell-supervisor` binary. GNU supervisor builds
must not reference `GLIBC_*` symbols newer than `GLIBC_2.28`.
- **Supervisor**: digest-pinned `gcr.io/distroless/base-nossl-debian13` base
with the dynamically linked GNU `/openshell-supervisor` binary. The base
supplies glibc and CA roots without a shell, package manager, OpenSSL or zlib.
GNU supervisor builds must not reference `GLIBC_*` symbols newer than
`GLIBC_2.28`. Image defaults remain UID 0 and working directory `/`; compute
drivers set the runtime identity and writable mounts. Docker stages private
files with the same numeric identity as the supervisor so archive uploads
preserve access regardless of the base image's default user. Health probes execute
the supervisor binary directly. Base updates require refreshing the
multi-architecture digest and rebuilding the image.

Gateway image builds bake the corresponding supervisor image tag into the
gateway binary so Docker sandboxes do not depend on `:latest` by default.
Expand Down
2 changes: 2 additions & 0 deletions architecture/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ enhancement and out of scope.) Workload proxy variables are removed from the
protected launch environment; transparent socket mediation does not depend on
them.

The canonical main process receives the declared workload environment before
supervisor-only values are stripped and provider placeholders are injected.
Template environment is treated like user-provided sandbox environment. It can
shape the workload child, but it cannot override driver-controlled identity,
gateway callback, TLS, relay socket, proxy, provider, or supervisor coordination
Expand Down
12 changes: 9 additions & 3 deletions architecture/security-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ proxy.
| `foo.**.example.com` | No | — | Recursive wildcard outside the first label is not allowed. |
| `foo**.example.com` | No | — | Recursive `**` mixed inside a label; allowed only as the entire first label. |

Validation rejects the disallowed patterns at policy load time with a message
that names the offending host. Exact hosts and IP addresses do not use this
path.
Validation rejects the disallowed patterns at policy load time. OPA load errors omit the supplied hostname. Exact hosts and IP addresses do not use this wildcard-validation path.

## TLS and L7 Inspection

Expand Down Expand Up @@ -201,6 +199,14 @@ configure the separately isolated supervisor. When a supervisor override is
combined with injected provider credentials, the supervisor emits a
high-severity detection finding at startup naming the inactive controls.

## Policy Load Diagnostics

`OpaEngine` bounds the error messages returned when loading or reloading policy from files, strings, or protobuf. Each message contains at most eight error items and 512 UTF-8 bytes, including its heading, separators, and any `additional violations omitted` marker. The loader reports complete, fixed categories and discards authored names, values, paths, source snippets, and nested error chains.

Typed validation categories distinguish process identity, filesystem paths and limits, Landlock compatibility, endpoint hosts and ports, credential signing and rewriting, MCP configuration, and middleware configuration. Opaque L7 errors identify the protocol-configuration or policy-validation stage; endpoint conflicts report ambiguous selectors. YAML errors retain a fixed parser category and numeric line and column when available. File I/O, Rego loading, and internal policy-data errors use fixed messages.

A candidate rejected during validation does not replace the active engine or advance its generation. The supervisor separately applies `policy_validation_failure_mode` and may publish a quarantine generation as described below. The diagnostic bounds cover returned OPA load errors; accepted-policy warnings, runtime request diagnostics, and gateway-authored policy parser messages have separate reporting contracts.

## Live Updates

The gateway stores sandbox-authored policy revisions separately from derived
Expand Down
4 changes: 4 additions & 0 deletions crates/openshell-driver-docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4723,6 +4723,10 @@ async fn stage_docker_supervisor_bundle(
),
ContainerCreateBody {
image: Some(config.supervisor_image_id.clone()),
// Docker's copyUIDGID upload uses Config.User when it is set,
// overriding the archive's numeric ownership. Match the reader
// explicitly instead of inheriting the staging image's user.
user: Some(format!("{SUPERVISOR_UID}:{SUPERVISOR_GID}")),
entrypoint: Some(vec![SUPERVISOR_IMAGE_CONTROL_BINARY_PATH.to_string()]),
labels: Some(docker_auxiliary_container_labels(
sandbox,
Expand Down
65 changes: 59 additions & 6 deletions crates/openshell-sandbox/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ fn apply_canonical_process_environment(
interactive: bool,
user_environment: &HashMap<String, String>,
) {
cmd.envs(user_environment);
let (session_user, session_home) = session_user_and_home(policy, workspace.home());
// Resolve a shell present in the sandbox image (minimal images such as
// Alpine ship only `/bin/sh`, not bash). Runs in the supervisor.
Expand Down Expand Up @@ -562,16 +563,16 @@ impl ProcessHandle {
// inherited environment. The entrypoint drops to the sandbox user
// before `exec`; without this strip, sandbox code could recover
// supervisor credentials from its inherited environment.
strip_supervisor_only_env(&mut cmd);

inject_provider_env(&mut cmd, provider_env);
apply_canonical_process_environment(
&mut cmd,
policy,
workspace,
interactive,
&configured_user_environment(),
);
strip_supervisor_only_env(&mut cmd);

inject_provider_env(&mut cmd, provider_env);

if let Some(dir) = workspace.root() {
cmd.current_dir(dir);
Expand Down Expand Up @@ -727,16 +728,16 @@ impl ProcessHandle {

// Strip supervisor-only identity material from the entrypoint's
// inherited environment.
strip_supervisor_only_env(&mut cmd);

inject_provider_env(&mut cmd, provider_env);
apply_canonical_process_environment(
&mut cmd,
policy,
workspace,
interactive,
&configured_user_environment(),
);
strip_supervisor_only_env(&mut cmd);

inject_provider_env(&mut cmd, provider_env);

if let Some(dir) = workspace.root() {
cmd.current_dir(dir);
Expand Down Expand Up @@ -2241,6 +2242,58 @@ mod tests {
assert_eq!(variables.get("TERM"), Some(&"xterm-256color"));
}

#[cfg(unix)]
#[tokio::test]
async fn canonical_process_receives_declared_environment_and_home() {
let current_user = User::from_uid(nix::unistd::geteuid()).unwrap().unwrap();
let policy = policy_with_process(ProcessPolicy {
run_as_user: Some(current_user.name),
run_as_group: None,
});
for interactive in [false, true] {
let mut cmd = Command::new("/usr/bin/env");
cmd.env_clear().stdout(StdStdio::piped());
let declared = HashMap::from([
("APPLICATION_AGENT".into(), "researcher".into()),
(
openshell_core::sandbox_env::SANDBOX_TOKEN.into(),
"must-not-reach-child".into(),
),
("ANTHROPIC_API_KEY".into(), "caller-value".into()),
("HOME".into(), "/sandbox".into()),
]);
apply_canonical_process_environment(
&mut cmd,
&policy,
&ResolvedWorkspace::default(),
interactive,
&declared,
);
strip_supervisor_only_env(&mut cmd);
inject_provider_env(
&mut cmd,
&HashMap::from([(
"ANTHROPIC_API_KEY".into(),
"openshell:resolve:env:ANTHROPIC_API_KEY".into(),
)]),
);
let output = cmd.output().await.expect("run environment probe");
assert!(output.status.success());
let environment = String::from_utf8(output.stdout).unwrap();
let variables: HashMap<_, _> = environment
.lines()
.filter_map(|line| line.split_once('='))
.collect();
assert_eq!(variables.get("APPLICATION_AGENT"), Some(&"researcher"));
assert!(!variables.contains_key(openshell_core::sandbox_env::SANDBOX_TOKEN));
assert_eq!(
variables.get("ANTHROPIC_API_KEY"),
Some(&"openshell:resolve:env:ANTHROPIC_API_KEY")
);
assert_eq!(variables.get("HOME"), Some(&"/sandbox"));
}
}

/// Unknown names may yield `Ok(None)` (`… not found …`) or `Err` when NSS fails first
/// (e.g. `ENOENT: No such file or directory`).
fn assert_unknown_identity_lookup_failed(msg: &str) {
Expand Down
Loading
Loading