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
7 changes: 5 additions & 2 deletions .agents/skills/debug-openshell-cluster/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ kubectl -n openshell get pod -l app.kubernetes.io/name=helm-chart -o jsonpath="{
```

Sandbox pods using provider token grants should have an
`openshell.io/sandbox-id` annotation, an `openshell.ai/managed-by=openshell`
`openshell.ai/sandbox-id` annotation, an `openshell.ai/managed-by=openshell`
label, supervisor env vars `OPENSHELL_K8S_SA_TOKEN_FILE` and
`OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET`, plus both the projected
`openshell-sa-token` volume and the `spiffe-workload-api` CSI volume.
Expand Down Expand Up @@ -467,7 +467,10 @@ Then inspect sandbox resources in that namespace.
Check the configured sandbox service account when TokenReview bootstrap or
sandbox registration fails. Helm creates a dedicated sandbox service account by
default and writes it to `[openshell.drivers.kubernetes].service_account_name`;
the gateway rejects projected tokens from other service accounts.
the selected Kubernetes compute driver rejects projected tokens from other
service accounts. For an external driver, inspect its logs and confirm it
advertises `supports_sandbox_authentication`; the gateway delegates the opaque
credential over the driver socket and never interprets Kubernetes settings.

```bash
helm -n openshell get values openshell | grep -A3 sandboxServiceAccount
Expand Down
4 changes: 3 additions & 1 deletion .agents/skills/helm-dev-environment/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ annotations to `spiffe://openshell.local/openshell/sandbox/<sandbox-id>`.
OpenShell mounts the SPIFFE CSI Workload API socket at
`/spiffe-workload-api/spire-agent.sock` into sandbox pods for provider token
grants. Supervisor-to-gateway authentication remains on the Kubernetes
ServiceAccount bootstrap and gateway-minted sandbox JWT path.
ServiceAccount bootstrap and gateway-minted sandbox JWT path; the selected
Kubernetes compute driver validates the projected token before the gateway
mints its JWT.

---

Expand Down
26 changes: 6 additions & 20 deletions .github/workflows/build-vm-driver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,17 @@ jobs:
- name: Build VM runtime
run: nix build .#vm-runtime

- name: Compress Linux VM runtime
if: runner.os == 'Linux'
- name: Assemble compressed VM runtime
run: |
install -d target/vm-runtime-compressed
zstd -19 -T0 result/libkrun.so -o target/vm-runtime-compressed/libkrun.so.zst
zstd -19 -T0 result/libkrunfw.so.5 -o target/vm-runtime-compressed/libkrunfw.so.5.zst
zstd -19 -T0 result/gvproxy -o target/vm-runtime-compressed/gvproxy.zst
zstd -19 -T0 result/umoci -o target/vm-runtime-compressed/umoci.zst

- name: Compress macOS VM runtime
if: runner.os == 'macOS'
run: |
install -d target/vm-runtime-compressed
zstd -19 -T0 result/libkrun.dylib -o target/vm-runtime-compressed/libkrun.dylib.zst
zstd -19 -T0 result/libkrunfw.5.dylib -o target/vm-runtime-compressed/libkrunfw.5.dylib.zst
zstd -19 -T0 result/gvproxy -o target/vm-runtime-compressed/gvproxy.zst
zstd -19 -T0 result/umoci -o target/vm-runtime-compressed/umoci.zst

- name: Add openshell-sandbox to VM runtime
run: zstd -19 -T0 sandbox/openshell-sandbox -o target/vm-runtime-compressed/openshell-sandbox.zst
compressed_dir="${RUNNER_TEMP}/vm-runtime-compressed"
install -d "$compressed_dir"
cp result/compressed/*.zst "$compressed_dir/"
zstd -19 -T1 sandbox/openshell-sandbox -o "$compressed_dir/openshell-sandbox.zst"

- name: Build openshell-driver-vm
uses: ./.github/actions/build-rust-binary
env:
OPENSHELL_VM_RUNTIME_COMPRESSED_DIR: ${{ github.workspace }}/target/vm-runtime-compressed
OPENSHELL_VM_RUNTIME_COMPRESSED_DIR: ${{ runner.temp }}/vm-runtime-compressed
with:
package: openshell-driver-vm
binary: openshell-driver-vm
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ These pipelines connect skills into end-to-end workflows. Individual skill files
| `crates/openshell-router/` | Privacy router | Privacy-aware LLM routing |
| `crates/openshell-bootstrap/` | Gateway metadata | Gateway registration metadata, auth token storage, mTLS bundle storage |
| `crates/openshell-gateway-interceptors/` | Gateway interceptors | Intercepts and transforms configured gRPC requests at the gateway routing boundary |
| `crates/openshell-ocsf/` | OCSF logging | OCSF v1.7.0 event types, builders, shorthand/JSONL formatters, tracing layers |
| `crates/openshell-ocsf/` | OCSF logging | OCSF v1.8.0 event types, builders, shorthand/JSONL formatters, tracing layers |
| `crates/openshell-otel/` | OpenTelemetry support | Shared OTLP trace provider, resource, and tracing-layer construction |
| `crates/openshell-otel-test-support/` | OpenTelemetry test support | Shared loopback OTLP collector fixture for tracing tests |
| `crates/openshell-core/` | Shared core | Common types, configuration, error handling |
Expand Down
7 changes: 6 additions & 1 deletion architecture/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ Runtime layout:
`/usr/libexec/openshell/openshell-driver-vm` in Linux packages and published
as a release artifact. Linux GNU VM driver binaries must not reference
`GLIBC_*` symbols newer than `GLIBC_2.28`; release workflows verify this
before publishing artifacts.
before publishing artifacts. Nix produces the platform-specific compressed
runtime inputs. CI combines them with the matching supervisor artifact in a
runner-temporary directory outside Cargo's `target/` before the shared Rust
cache action runs. An explicitly configured VM runtime bundle is required to
contain every non-empty embedding input; the driver build fails before
packaging when an input is absent or empty.
- **Supervisor**: Alpine base with `nftables`, static binary at
`/openshell-sandbox` (musl by default; see `SUPERVISOR_LIBC` above). Static
linkage keeps the binary usable when the image is mounted/extracted into
Expand Down
26 changes: 19 additions & 7 deletions architecture/compute-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ The driver reports this behavior through
in-process and external drivers. Older drivers omit the field and retain the
conservative operator-managed behavior.

Drivers that can verify a platform-native sandbox credential advertise
`GetCapabilities.supports_sandbox_authentication`. On the path-scoped
`IssueSandboxToken` exchange, the gateway forwards the opaque bearer credential
to that selected driver through `AuthenticateSandbox`. The driver returns only
the authenticated sandbox ID. The gateway then verifies that its durable
sandbox record exists and mints the gateway JWT. The driver socket is therefore
a sandbox-identity trust boundary, but it does not grant user or administrator
authority.

## Deletion Lifecycle

Lifecycle requests use per-sandbox gates to serialize stop, start, and
Expand Down Expand Up @@ -465,20 +474,23 @@ watcher emits only sandbox CR changes, not platform events.

### SA Token Authentication

The gateway's `K8sServiceAccountAuthenticator` adapts its `NamespaceValidator`
per mode (`crates/openshell-server/src/auth/k8s_sa.rs`):
The Kubernetes driver's `AuthenticateSandbox` implementation applies its named
`[openshell.drivers.kubernetes]` configuration per mode:

- **Shared:** `Exact` — accepts only the single configured namespace.
- **Managed:** `Prefix` — accepts any namespace starting with `openshell-{gateway_id}-`.
- **Operator:** `Allowlist` — accepts namespaces present in the dynamic
`BTreeSet` populated by the label/file watchers. Starts empty (fail-closed)
until the first watcher update.

These checks rely on an ownership invariant. In shared and managed modes, the
gateway and its trusted Agent Sandbox controller exclusively administer the
sandbox namespace, Sandbox CRs, sandbox pods, and configured sandbox
ServiceAccount. Other principals must not create or mutate those resources or
use that ServiceAccount. In operator mode, the platform operator retains
It validates the projected token with Kubernetes `TokenReview`, checks the live
pod UID, and verifies the pod's controlling Sandbox CR UID and sandbox ID before
returning the identity to the gateway. These checks rely on an ownership
invariant. In shared and managed modes, the Kubernetes driver and its trusted
Agent Sandbox controller exclusively administer the sandbox namespace, Sandbox
CRs, sandbox pods, and configured sandbox ServiceAccount. Other principals must
not create or mutate those resources or use that ServiceAccount. In operator
mode, the platform operator retains
namespace lifecycle ownership, but must preserve the same exclusive control of
Sandbox CRs and the pods and ServiceAccount used for sandbox token bootstrap.
An allowlisted namespace is therefore a trust grant, not a tenant isolation
Expand Down
11 changes: 6 additions & 5 deletions architecture/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,12 @@ identity inspection without client-side token decoding.
Sandbox secrets are gateway-signed JWTs bound to a single sandbox ID. Docker,
Podman, and VM drivers deliver the initial token through supervisor-only
runtime material; Kubernetes supervisors exchange a projected ServiceAccount
token through `IssueSandboxToken`. The gateway validates that projected token
with Kubernetes `TokenReview`, requires the configured sandbox service account,
checks the returned pod binding against the live pod UID, and verifies the pod's
controlling `Sandbox` ownerReference against the live Sandbox CR UID and
sandbox-id label before minting the gateway JWT. The bootstrap path accepts
token through `IssueSandboxToken`. The gateway delegates that opaque credential
to the selected compute driver's `AuthenticateSandbox` RPC. A capable driver is
trusted to return the authenticated sandbox ID, while the gateway still requires
a matching durable sandbox record before minting a JWT. The Kubernetes driver
uses its own named configuration to run TokenReview and verify the live pod and
controlling Sandbox CR. The bootstrap path accepts
both `agents.x-k8s.io/v1beta1` ownerReferences from newer Agent Sandbox
controllers and `agents.x-k8s.io/v1alpha1` ownerReferences from existing
deployments. Supervisors renew gateway JWTs in memory before expiry only while
Expand Down
9 changes: 8 additions & 1 deletion architecture/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,14 @@ sandbox workload directly. The relay supports:
- Attachment to the canonical main process through the `openshell-main` SSH
subsystem. The supervisor owns its retained PTY or pipes, a 1 MiB replay
buffer, and a single stdin lease across client disconnects.
- Independent shell and command execution sessions.
- Independent interactive shell sessions.
- Command execution. Commands run through a login shell (`bash -lc`) by default,
so the first of the user's `.bash_profile`, `.bash_login`, or `.profile` is
sourced (and `.bashrc` only if that file sources it). Callers set
`ExecSandboxRequest.no_login_shell` to skip those files; the gateway signals
this to the supervisor over the SSH `OPENSHELL_NO_LOGIN_SHELL` env request,
which selects `bash -c` instead of `bash -lc`. Note `bash -c` still reads
`BASH_ENV` when the child environment sets it.
- Tar-based file sync.
- Port forwarding where supported by the CLI/TUI surface.

Expand Down
22 changes: 21 additions & 1 deletion crates/openshell-cli/src/commands/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ pub fn parse_duration_to_ms(s: &str) -> Result<i64> {
));
}
};
Ok(num * multiplier)
num.checked_mul(multiplier).ok_or_else(|| {
miette::miette!("duration out of range: {s} (must fit in milliseconds as a 64-bit integer)")
})
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1073,6 +1075,24 @@ mod tests {
assert!(err.to_string().contains("invalid duration"));
}

#[test]
fn parse_duration_to_ms_rejects_out_of_range_values_without_overflowing() {
let err = parse_duration_to_ms("9223372036854775807h").expect_err("overflow should error");
assert!(err.to_string().contains("duration out of range"));

let err = parse_duration_to_ms("-9223372036854775808h").expect_err("overflow should error");
assert!(err.to_string().contains("duration out of range"));
}

#[test]
fn parse_duration_to_ms_accepts_the_largest_representable_duration() {
let max_hours = i64::MAX / 3_600_000;
assert_eq!(
parse_duration_to_ms(&format!("{max_hours}h")).expect("parse"),
max_hours * 3_600_000
);
}

#[test]
fn platform_progress_events_update_borrowed_display_without_duplicate_steps() {
let event = PlatformEvent {
Expand Down
11 changes: 11 additions & 0 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,15 @@ enum SandboxCommands {
#[arg(long, overrides_with = "tty")]
no_tty: bool,

/// Run the command without sourcing shell login/profile startup files.
///
/// Default sources them so tool-specific env (`VIRTUAL_ENV`, etc.) is
/// available. Use this for automation and managed checks that need
/// predictable startup behavior — sandbox-user startup files cannot run
/// before the requested command.
#[arg(long)]
no_login_shell: bool,

/// Set a non-secret environment variable for the command.
/// Do not use this option for API keys, tokens, or other secrets; attach
/// a provider to the sandbox instead. Repeatable.
Expand Down Expand Up @@ -3245,6 +3254,7 @@ async fn run_async() -> Result<()> {
no_tty,
envs,
command,
no_login_shell,
} => {
let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?;
// Resolve --tty / --no-tty into an Option<bool> override.
Expand All @@ -3264,6 +3274,7 @@ async fn run_async() -> Result<()> {
timeout,
tty_override,
&env_map,
no_login_shell,
&tls,
&cli.workspace,
)
Expand Down
5 changes: 5 additions & 0 deletions crates/openshell-cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ pub async fn sandbox_exec_grpc(
timeout_seconds: u32,
tty_override: Option<bool>,
environment: &HashMap<String, String>,
no_login_shell: bool,
tls: &TlsOptions,
workspace: &str,
) -> Result<i32> {
Expand Down Expand Up @@ -1552,6 +1553,7 @@ pub async fn sandbox_exec_grpc(
workdir,
timeout_seconds,
environment,
no_login_shell,
)
.await;
}
Expand All @@ -1566,6 +1568,7 @@ pub async fn sandbox_exec_grpc(
timeout_seconds,
stdin: stdin_payload,
tty,
no_login_shell,
..Default::default()
})
.await
Expand Down Expand Up @@ -1915,6 +1918,7 @@ async fn sandbox_exec_interactive_grpc(
workdir: Option<&str>,
timeout_seconds: u32,
environment: &HashMap<String, String>,
no_login_shell: bool,
) -> Result<i32> {
#[cfg(unix)]
use openshell_core::proto::ExecSandboxWindowResize;
Expand All @@ -1933,6 +1937,7 @@ async fn sandbox_exec_interactive_grpc(
command: command.to_vec(),
workdir: workdir.unwrap_or_default().to_string(),
environment: environment.clone(),
no_login_shell,
timeout_seconds,
stdin: Vec::new(),
tty: true,
Expand Down
4 changes: 2 additions & 2 deletions crates/openshell-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,8 @@ pub struct GatewayJwtConfig {
pub public_key_path: PathBuf,
/// Path to the `kid` value (plain text, one line).
pub kid_path: PathBuf,
/// Stable gateway identity embedded in `iss`/`aud`. Defaults to the
/// hostname-or-`openshell` placeholder if unset.
/// Stable gateway identity embedded in `iss`/`aud`. Defaults to
/// `openshell`.
#[serde(default = "default_gateway_id")]
pub gateway_id: String,
/// Token lifetime in seconds. A value of 0 disables expiration and is
Expand Down
24 changes: 24 additions & 0 deletions crates/openshell-core/src/driver_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ pub fn openshell_sandbox_label_selector() -> String {
format!("{LABEL_MANAGED_BY}={LABEL_MANAGED_BY_VALUE},{LABEL_SANDBOX_ID}")
}

// ---------------------------------------------------------------------------
// Sandbox condition reason strings set by compute drivers.
// ---------------------------------------------------------------------------

/// Ready-condition reason when a container exits on its own.
///
/// Covers an ordinary application exit or crash (exit 0, a non-zero error code,
/// or an uncaught fault). This is a terminal reason: gateway startup does NOT
/// auto-restart it, so a genuine failure keeps its error signal instead of
/// being relaunched.
pub const CONDITION_EXITED: &str = "ContainerExited";

/// Ready-condition reason when a container was terminated by an external signal.
///
/// SIGKILL/SIGTERM (exit 137/143) is what a Podman/Docker machine or daemon
/// restart does to running containers. Distinct from `CONDITION_EXITED` so
/// gateway startup can recover machine-restart victims while leaving ordinary
/// application exits terminal.
pub const CONDITION_RUNTIME_RESTART: &str = "ContainerRuntimeRestart";

/// Ready-condition reason when a container is explicitly stopped via the
/// runtime API (e.g. `podman stop`, gateway-initiated shutdown).
pub const CONDITION_STOPPED: &str = "ContainerStopped";

// ---------------------------------------------------------------------------

/// Path to the sandbox supervisor binary inside the container image.
Expand Down
2 changes: 1 addition & 1 deletion crates/openshell-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub const REGISTERED_SETTINGS: &[RegisteredSetting] = &[
kind: SettingValueKind::Bool,
allowed_string_values: None,
},
// When true the sandbox writes OCSF v1.7.0 JSONL records to
// When true the sandbox writes OCSF v1.8.0 JSONL records to
// `/var/log/openshell-ocsf*.log` (daily rotation, 3 files) in addition
// to the human-readable shorthand log. Defaults to false (no JSONL written).
RegisteredSetting {
Expand Down
Loading
Loading