diff --git a/.github/workflows/branch-checks.yml b/.github/workflows/branch-checks.yml index 613793092b..80573e3871 100644 --- a/.github/workflows/branch-checks.yml +++ b/.github/workflows/branch-checks.yml @@ -294,6 +294,7 @@ jobs: cargo fmt --manifest-path tests/tmachine/Cargo.toml --all -- --check cargo fmt --manifest-path tests/runner/Cargo.toml --all -- --check cargo fmt --manifest-path tests/suites/conformance/Cargo.toml --all -- --check + cargo fmt --manifest-path tests/suites/drivers/docker/Cargo.toml --all -- --check cargo fmt --manifest-path tests/suites/drivers/podman/Cargo.toml --all -- --check cargo fmt --manifest-path tests/suites/features/Cargo.toml --all -- --check cargo fmt --manifest-path tests/support/Cargo.toml --all -- --check @@ -359,6 +360,7 @@ jobs: cargo clippy --locked --manifest-path tests/tmachine/Cargo.toml --all-targets -- -D warnings cargo clippy --locked --manifest-path tests/runner/Cargo.toml --all-targets -- -D warnings cargo clippy --locked --manifest-path tests/suites/conformance/Cargo.toml --workspace --all-targets -- -D warnings + cargo clippy --locked --manifest-path tests/suites/drivers/docker/Cargo.toml --workspace --all-targets -- -D warnings cargo clippy --locked --manifest-path tests/suites/drivers/podman/Cargo.toml --workspace --all-targets -- -D warnings cargo clippy --locked --manifest-path tests/suites/features/Cargo.toml --workspace --all-targets -- -D warnings cargo clippy --locked --manifest-path tests/support/Cargo.toml --all-targets -- -D warnings diff --git a/.github/workflows/branch-e2e.yml b/.github/workflows/branch-e2e.yml index 71e193beac..1c311c18b7 100644 --- a/.github/workflows/branch-e2e.yml +++ b/.github/workflows/branch-e2e.yml @@ -247,7 +247,7 @@ jobs: set -euo pipefail # Retry dependency preparation, then build once. nix build --no-link .#openshell-test-runner || nix build --no-link .#openshell-test-runner - for family in features drivers/podman; do + for family in features drivers/docker drivers/podman; do nix run .#openshell-test-runner -- build \ --family "$family" --out "artifacts/e2e-bundles/${family//\//-}" done @@ -257,6 +257,12 @@ jobs: path: artifacts/e2e-bundles/features retention-days: 5 if-no-files-found: error + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: openshell-e2e-bundle-drivers-docker-x86_64-unknown-linux-musl + path: artifacts/e2e-bundles/drivers-docker + retention-days: 5 + if-no-files-found: error - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: openshell-e2e-bundle-drivers-podman-x86_64-unknown-linux-musl diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 361737cb7a..39cbbfb9c3 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -10,8 +10,8 @@ # results. With `prebuilt`, the rows run what the caller built once for the # run instead: conformance rows the static `openshell-conformance`, the other # rows their family's test bundle. The `family` input selects the rows of one -# family, including the workspaces under it (drivers selects drivers/podman); -# leave it empty to run every row. +# family, including the workspaces under it (drivers selects drivers/docker +# and drivers/podman); leave it empty to run every row. name: E2E Suites @@ -90,6 +90,9 @@ jobs: {"environment":"ubuntu-docker-rootful-cdi","installer":"deb","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-cdi","installer":"rpm","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootless-cdi","installer":"rpm","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful-driver-config","installer":"deb","family":"features","package":"driver-config","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootful-driver-config","installer":"rpm","family":"features","package":"driver-config","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootless-driver-config","installer":"rpm","family":"features","package":"driver-config","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-docker-rootful-keycloak","installer":"deb","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"oci-image","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"oci-image","gateway":"openshell","runner":"ubuntu-24.04"}, @@ -99,9 +102,20 @@ jobs: {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"host-gateway","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"routable-host-ip","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"routable-host-ip","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"}, {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"connect-ssh-supervision","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"resource-limits","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"ocsf","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"ocsf","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"ocsf","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootless-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful","installer":"deb","family":"drivers/docker","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-userns-default","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-userns-auto","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-userns-keep-id","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"}, diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml index dcf7c8027d..a1c6434756 100644 --- a/.github/workflows/rust-cache.yml +++ b/.github/workflows/rust-cache.yml @@ -96,7 +96,7 @@ jobs: run: | set -euo pipefail nix build --no-link .#openshell-test-runner || nix build --no-link .#openshell-test-runner - for family in features drivers/podman; do + for family in features drivers/docker drivers/podman; do nix run .#openshell-test-runner -- build \ --family "$family" --out "$RUNNER_TEMP/e2e-bundles/${family//\//-}" done diff --git a/CI.md b/CI.md index 200a8b6785..813595c671 100644 --- a/CI.md +++ b/CI.md @@ -176,11 +176,11 @@ selected. DEB and RPM packages build only when integration qualification is sele the DEB on Ubuntu with Docker and installs the CLI and gateway RPMs on Fedora with rootful and rootless Podman. These lanes run conformance using the matching runtime images. Release Dev, Release, and Pre-release use the same package installers. -The feature suites (`tests/suites/features`) and the Podman driver suite -(`tests/suites/drivers/podman`) run the same way, on the package installers; the -driver suite's environments merge their Podman settings into the packaged -gateway's configuration (see `TESTING.md`). The `e2e-podman` lane runs on the -RPM installer as well. The driver suite and `e2e-podman` run +The feature suites (`tests/suites/features`) and the Docker and Podman driver +suites (`tests/suites/drivers/{docker,podman}`) run the same way, on the package +installers; the Podman driver suite's environments merge their Podman settings +into the packaged gateway's configuration (see `TESTING.md`). The `e2e-podman` +lane runs on the RPM installer as well. The driver suites and `e2e-podman` run only in `Branch E2E Checks`. The manual Integration Tests workflow runs the remaining tmachine testsuites, such as `e2e-podman`, and downloads the packages selected by its matrix. diff --git a/TESTING.md b/TESTING.md index 4e642f338e..0c7f86da4d 100644 --- a/TESTING.md +++ b/TESTING.md @@ -345,6 +345,11 @@ can run the suite. The expectations characterize the sandbox's behavior today, not a specification, and the `echo-socket` check needs `perl` in the workload image, which the default image has. +The `-driver-config` environments let callers pass driver config with +volume and bind mounts, and turn off resource admission, which blocks bind +mounts. The driver-config suite (`tests/suites/features/driver-config`) runs +there on Docker and Podman. + ### Python E2E (`e2e/python/`) `mise run e2e:python` builds `openshell/e2e-python:dev` from @@ -567,8 +572,7 @@ nix run .#generate-podman-e2e-ci-tests The `e2e-podman` testsuite runs a nextest archive built with the corresponding Rust feature and preloads its Python workload image into the rootless Podman store. The E2E archive excludes binaries that still depend on wrapper-owned -gateway controls, SPIFFE fixtures, the caller driver-config setting, or other -guest setup. `tests/tmachine/artifacts.nix` keeps the follow-up exclusions explicit and uses +gateway controls, SPIFFE fixtures, or other guest setup. `tests/tmachine/artifacts.nix` keeps the follow-up exclusions explicit and uses the same filter for the generated inventory, so excluded binaries cannot appear as false passes or silently re-enter the archive. @@ -576,9 +580,12 @@ Driver suites live in `tests/suites/drivers/`, with the package named after the driver. Each driver suite is its own workspace with its own lockfile, so a change to one driver's tests or dependencies doesn't touch another's. Add a new one to the `rust:format`, `rust:format:check` and `rust:lint` tasks, the -matching lines in `branch-checks.yml`, and `ALIGNED_WORKSPACES`. The Podman -driver suite (`tests/suites/drivers/podman`) compares OpenShell and direct -Podman user-namespace mappings. +matching lines in `branch-checks.yml`, `ALIGNED_WORKSPACES`, and the bundle +builds in `branch-e2e.yml` and `rust-cache.yml`. The Docker and Podman driver +suites (`tests/suites/drivers/{docker,podman}`) check what the driver does with +a sandbox's containers when its workload stops or an ephemeral sandbox +finishes. The Podman suite also compares OpenShell and direct Podman +user-namespace mappings. Each `fedora-podman-{rootful,rootless}-userns-` environment configures the gateway with one mode (`default`, `auto`, `keep-id` or `private`) and works with every installer; CI runs it with `rpm`: @@ -650,6 +657,14 @@ rootful and rootless, and the `k3s` and `k3s-ha` installers. The tests run on the K3s node, so the K3s installers set the chart's `server.hostGatewayIP` to the node's address. +The `routable-host-ip` feature suite (`tests/suites/features/routable-host-ip`) +checks that a policy endpoint whose host is an IP literal reaches that address, +with or without `allowed_ips`. The sandbox uses the address +`host.openshell.internal` resolves to, which must be one the supervisor lets an +IP literal reach. Rootless Podman's is link-local and always blocked, so CI runs +the suite on Docker rootful, Podman rootful, and the `k3s` and `k3s-ha` +installers. + The `connect-ssh-supervision` feature suite (`tests/suites/features/connect-ssh-supervision`) checks how `sandbox connect` supervises its `ssh` process: it reconnects after losing the SSH transport and diff --git a/e2e/rust/Cargo.lock b/e2e/rust/Cargo.lock index 17eb2b5e0c..b68c749916 100644 --- a/e2e/rust/Cargo.lock +++ b/e2e/rust/Cargo.lock @@ -298,49 +298,6 @@ dependencies = [ "hybrid-array", ] -[[package]] -name = "bollard" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee04c4c84f1f811b017f2fbb7dd8815c976e7ca98593de9c1e2afad0f636bff4" -dependencies = [ - "base64 0.22.1", - "bollard-stubs", - "bytes", - "futures-core", - "futures-util", - "hex", - "http", - "http-body-util", - "hyper", - "hyper-named-pipe", - "hyper-util", - "hyperlocal", - "log", - "pin-project-lite", - "serde", - "serde_derive", - "serde_json", - "serde_urlencoded", - "thiserror", - "tokio", - "tokio-util", - "tower-service", - "url", - "winapi", -] - -[[package]] -name = "bollard-stubs" -version = "1.52.1-rc.29.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0a8ca8799131c1837d1282c3f81f31e76ceb0ce426e04a7fe1ccee3287c066" -dependencies = [ - "serde", - "serde_json", - "serde_repr", -] - [[package]] name = "borrow-or-share" version = "0.2.4" @@ -1224,20 +1181,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "hyper-named-pipe" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fab3637d6b04a8037af8a266fdf6cf92ea957e8c53981a2bf6136572531025bf" -dependencies = [ - "hex", - "hyper", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "hyper-rustls" version = "0.27.9" @@ -1288,21 +1231,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hyperlocal" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "986c5ce3b994526b3cd75578e62554abd09f0899d6206de48b3e96ab34ccc8c7" -dependencies = [ - "hex", - "http-body-util", - "hyper", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "iana-time-zone" version = "0.1.65" @@ -2004,7 +1932,6 @@ name = "openshell-e2e" version = "0.1.0" dependencies = [ "base64 0.22.1", - "bollard", "bytes", "flate2", "futures-util", @@ -2832,18 +2759,6 @@ dependencies = [ "syn 3.0.3", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "serde_yaml" version = "0.9.34+deprecated" @@ -3845,28 +3760,6 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c" -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-core" version = "0.62.2" diff --git a/e2e/rust/Cargo.toml b/e2e/rust/Cargo.toml index 1e0e822236..9c8b5a1d0e 100644 --- a/e2e/rust/Cargo.toml +++ b/e2e/rust/Cargo.toml @@ -99,11 +99,6 @@ name = "additional_ca" path = "tests/additional_ca.rs" required-features = ["e2e-additional-ca"] -[[test]] -name = "driver_config_volume" -path = "tests/driver_config_volume.rs" -required-features = ["e2e-local-container-driver"] - [[test]] name = "gateway_start" path = "tests/gateway_start.rs" @@ -139,11 +134,6 @@ name = "podman_corporate_proxy" path = "tests/podman_corporate_proxy.rs" required-features = ["e2e-podman"] -[[test]] -name = "podman_resource_limits" -path = "tests/podman_resource_limits.rs" -required-features = ["e2e-podman"] - [[test]] name = "provider_refresh_handles" path = "tests/provider_refresh_handles.rs" @@ -189,11 +179,6 @@ name = "credential_drivers" path = "tests/credential_drivers.rs" required-features = ["e2e-kubernetes-credential-drivers"] -[[test]] -name = "websocket_conformance" -path = "tests/websocket_conformance.rs" -required-features = ["e2e-host-gateway"] - [[test]] name = "user_namespaces" path = "tests/user_namespaces.rs" @@ -204,21 +189,6 @@ name = "host_gateway_alias" path = "tests/host_gateway_alias.rs" required-features = ["e2e-host-gateway"] -[[test]] -name = "forward_proxy_l7_bypass" -path = "tests/forward_proxy_l7_bypass.rs" -required-features = ["e2e-host-gateway"] - -[[test]] -name = "forward_proxy_graphql_l7" -path = "tests/forward_proxy_graphql_l7.rs" -required-features = ["e2e-host-gateway"] - -[[test]] -name = "forward_proxy_jsonrpc_l7" -path = "tests/forward_proxy_jsonrpc_l7.rs" -required-features = ["e2e-host-gateway"] - [[test]] name = "workspace_lifecycle" path = "tests/workspace_lifecycle.rs" @@ -229,11 +199,6 @@ name = "supervisor_middleware_http_hooks" path = "tests/supervisor_middleware_http_hooks.rs" required-features = ["e2e-docker"] -[[test]] -name = "proxy_egress_pipeline" -path = "tests/proxy_egress_pipeline.rs" -required-features = ["e2e-host-gateway"] - [[test]] name = "workspace_namespace_managed" path = "tests/workspace_namespace_managed.rs" @@ -259,7 +224,6 @@ openshell-crypto = { path = "../../crates/openshell-crypto" } openshell-otel-test-support = { path = "../../crates/openshell-otel-test-support" } opentelemetry-proto = { version = "0.33", default-features = false, features = ["gen-tonic", "trace"] } base64 = "0.22" -bollard = "0.20" bytes = "1" futures-util = "0.3" http-body-util = "0.1" diff --git a/e2e/rust/e2e-podman.sh b/e2e/rust/e2e-podman.sh index d5a54741b7..de39ddf2cc 100755 --- a/e2e/rust/e2e-podman.sh +++ b/e2e/rust/e2e-podman.sh @@ -22,17 +22,10 @@ source "${ROOT}/e2e/support/conformance.sh" # unfiltered e2e:podman task remains available while the omitted targets are # stabilized and can be added here. PODMAN_CI_TESTS=( - bypass_detection ephemeral_cleanup - driver_config_volume edge_tunnel_e2e - forward_proxy_graphql_l7 - forward_proxy_jsonrpc_l7 - forward_proxy_l7_bypass host_gateway_alias - live_policy_update local_driver_token_restart - no_proxy ocsf_jsonl_conformance otlp_relay podman_corporate_proxy diff --git a/e2e/rust/src/harness/sandbox.rs b/e2e/rust/src/harness/sandbox.rs index 9f57a29daa..bf71208f98 100644 --- a/e2e/rust/src/harness/sandbox.rs +++ b/e2e/rust/src/harness/sandbox.rs @@ -647,26 +647,6 @@ impl SandboxGuard { Ok(combined) } - /// Spawn `openshell forward start` as a background process. - /// - /// Returns the child process handle. The caller is responsible for killing - /// it (or it will be killed on drop since `kill_on_drop(true)` is set). - /// - /// # Errors - /// - /// Returns an error if the process cannot be spawned. - pub fn spawn_forward(&self, port: u16) -> Result { - let mut cmd = openshell_cmd(); - cmd.arg("forward") - .arg("start") - .arg(port.to_string()) - .arg(&self.name); - cmd.stdout(Stdio::piped()).stderr(Stdio::piped()); - - cmd.spawn() - .map_err(|e| format!("failed to spawn port forward: {e}")) - } - /// Delete the sandbox explicitly. /// /// Also kills the background child process if one exists. This is called diff --git a/e2e/rust/tests/bypass_detection.rs b/e2e/rust/tests/bypass_detection.rs deleted file mode 100644 index 569e3a60d6..0000000000 --- a/e2e/rust/tests/bypass_detection.rs +++ /dev/null @@ -1,79 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! Verify that direct TCP bypass attempts fail promptly at the sandbox -//! syscall boundary instead of reaching the runtime's external network. -//! -//! This test is implementation-agnostic — it validates the observable -//! behavior rather than a particular packet-filter implementation. - -#![cfg(feature = "e2e")] - -use openshell_e2e::harness::sandbox::SandboxGuard; - -/// Python script that attempts a raw TCP connect bypassing the proxy. -/// -/// `socket.connect()` does not honor proxy environment variables. The script -/// reports the outcome and wall-clock time so the test can assert that the -/// sandbox's seccomp mediation blocks it before the outer fence is needed. -/// -/// Target 198.51.100.1 is RFC 5737 TEST-NET-2 — documentation-only address -/// space that will never route. -fn bypass_attempt_script() -> &'static str { - r#" -import json, socket, time - -start = time.monotonic() -result = "unknown" -try: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(10) - s.connect(("198.51.100.1", 80)) - result = "connected" - s.close() -except ConnectionRefusedError: - result = "refused" -except PermissionError: - result = "denied" -except socket.timeout: - result = "timeout" -except OSError as e: - result = f"error:{e}" - -elapsed_ms = int((time.monotonic() - start) * 1000) -print(json.dumps({"bypass_result": result, "elapsed_ms": elapsed_ms}), flush=True) -"# -} - -/// A direct TCP connection bypassing supervision should be denied without -/// waiting for the socket's network timeout. -#[tokio::test] -async fn bypass_attempt_is_rejected_fast() { - let guard = SandboxGuard::create(&["--", "python3", "-c", bypass_attempt_script()]) - .await - .expect("sandbox create"); - - let json_line = guard - .create_output - .lines() - .find(|l| l.contains("bypass_result")) - .unwrap_or_else(|| panic!("no bypass_result JSON in output:\n{}", guard.create_output)); - - let parsed: serde_json::Value = serde_json::from_str(json_line.trim()) - .unwrap_or_else(|e| panic!("failed to parse JSON '{json_line}': {e}")); - - let result = parsed["bypass_result"].as_str().unwrap(); - let elapsed_ms = parsed["elapsed_ms"].as_u64().unwrap(); - - assert_eq!( - result, "denied", - "expected seccomp mediation to deny the direct connect, got '{result}' after {elapsed_ms}ms.\n\ - Full output:\n{}", - guard.create_output - ); - - assert!( - elapsed_ms < 8000, - "bypass rejection took {elapsed_ms}ms — expected < 8000ms." - ); -} diff --git a/e2e/rust/tests/driver_config_volume.rs b/e2e/rust/tests/driver_config_volume.rs deleted file mode 100644 index bcef6a429c..0000000000 --- a/e2e/rust/tests/driver_config_volume.rs +++ /dev/null @@ -1,539 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e-local-container-driver")] - -use std::fs; -use std::io::Write; -use std::os::unix::fs::PermissionsExt; -use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::time::{SystemTime, UNIX_EPOCH}; - -use bollard::Docker; -use bollard::models::{ContainerCreateBody, HostConfig, Mount, MountTypeEnum, VolumeCreateRequest}; -use bollard::query_parameters::{ - CreateContainerOptionsBuilder, CreateImageOptionsBuilder, LogsOptions, RemoveContainerOptions, - RemoveVolumeOptionsBuilder, StartContainerOptions, WaitContainerOptions, -}; -use futures_util::TryStreamExt; -#[cfg(feature = "e2e-docker")] -use openshell_e2e::harness::container::ImageGuard; -use openshell_e2e::harness::container::e2e_driver; -use openshell_e2e::harness::sandbox::SandboxGuard; -use serde_json::{Map, Value}; - -const TEST_IMAGE: &str = "nvcr.io/nvidia/base/ubuntu:24.04"; -const VOLUME_TARGET: &str = "/sandbox/e2e-volume"; -const BIND_TARGET: &str = "/sandbox/e2e-bind"; -#[cfg(feature = "e2e-docker")] -const OCI_VOLUME_TARGET: &str = "/workspace/project/e2e-volume"; -#[cfg(feature = "e2e-docker")] -const OCI_USER_DOCKERFILE: &str = r#"FROM public.ecr.aws/docker/library/python:3.13-slim - -RUN apt-get update && apt-get install -y --no-install-recommends iproute2 \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /workspace/project -RUN chown 2234:2235 . -USER 2234:2235 -CMD ["sleep", "infinity"] -"#; - -static NEXT_VOLUME_ID: AtomicU64 = AtomicU64::new(0); - -struct VolumeGuard { - docker: Docker, - name: String, -} - -impl VolumeGuard { - async fn create(driver: &str) -> Result { - let name = unique_volume_name(driver); - let docker = connect_container_api(driver).await?; - docker - .create_volume(VolumeCreateRequest { - name: Some(name.clone()), - ..Default::default() - }) - .await - .map_err(|err| format!("create {driver} volume {name}: {err}"))?; - Ok(Self { docker, name }) - } -} - -impl Drop for VolumeGuard { - fn drop(&mut self) { - let docker = self.docker.clone(); - let name = self.name.clone(); - tokio::spawn(async move { - let _ = docker - .remove_volume( - &name, - Some(RemoveVolumeOptionsBuilder::new().force(true).build()), - ) - .await; - }); - } -} - -#[tokio::test] -async fn sandbox_mounts_existing_driver_config_volume() { - let driver = e2e_driver().expect("OPENSHELL_E2E_DRIVER must be set by the e2e wrapper"); - assert!( - matches!(driver.as_str(), "docker" | "podman"), - "driver_config volume e2e requires docker or podman, got {driver}" - ); - - let volume = VolumeGuard::create(&driver) - .await - .expect("create named test volume"); - - seed_volume(&volume).await.expect("seed named test volume"); - - let driver_config = format!( - r#"{{"{driver}":{{"mounts":[{{"type":"volume","source":"{}","target":"{VOLUME_TARGET}","read_only":false}}]}}}}"#, - volume.name - ); - let mut sandbox = SandboxGuard::create(&[ - "--driver-config-json", - &driver_config, - "--", - "sh", - "-lc", - "set -eu; test \"$(cat /sandbox/e2e-volume/input.txt)\" = host-volume-ok; printf sandbox-volume-ok > /sandbox/e2e-volume/output.txt; cat /sandbox/e2e-volume/output.txt", - ]) - .await - .expect("sandbox create with driver-config volume"); - - assert!( - sandbox.create_output.contains("sandbox-volume-ok"), - "sandbox should read and write the mounted volume:\n{}", - sandbox.create_output - ); - - sandbox.cleanup().await; - verify_volume(&volume) - .await - .expect("verify sandbox wrote to named test volume"); -} - -#[tokio::test] -#[cfg(feature = "e2e-docker")] -async fn oci_workspace_preparation_skips_nested_volume_ownership() { - let driver = e2e_driver().expect("OPENSHELL_E2E_DRIVER must be set by the e2e wrapper"); - assert!( - driver == "docker", - "OCI workspace mount e2e requires docker, got {driver}" - ); - - let volume = VolumeGuard::create(&driver) - .await - .expect("create named test volume"); - seed_volume(&volume).await.expect("seed named test volume"); - - let image_context = tempfile::tempdir().expect("create OCI image context"); - let dockerfile = image_context.path().join("Dockerfile"); - fs::write(&dockerfile, OCI_USER_DOCKERFILE).expect("write OCI image Dockerfile"); - let image = ImageGuard::build( - &format!("{driver}-oci-user"), - &dockerfile, - image_context.path(), - ) - .expect("build OCI-user image with selected container engine"); - - let driver_config = format!( - r#"{{"{driver}":{{"mounts":[{{"type":"volume","source":"{}","target":"{OCI_VOLUME_TARGET}","read_only":false}}]}}}}"#, - volume.name - ); - let mut sandbox = SandboxGuard::create_keep_with_args( - &[ - "--from", - image.tag(), - "--driver-config-json", - &driver_config, - "--no-tty", - ], - &[ - "sh", - "-lc", - "set -eu; test \"$(id -u):$(id -g)\" = 2234:2235; \ - test \"$(pwd -P)\" = /workspace/project; test \"$HOME\" = /workspace/project; \ - test \"$(stat -c %u:%g /workspace/project/e2e-volume/input.txt)\" = 0:0; \ - touch direct-write; echo Ready; sleep infinity", - ], - "Ready", - ) - .await - .expect("create OCI-user sandbox with nested volume"); - - let ssh_output = sandbox - .exec(&[ - "sh", - "-lc", - "set -eu; test \"$(pwd -P)\" = /workspace/project; \ - test \"$HOME\" = /workspace/project; \ - test \"$(stat -c %u:%g /workspace/project/e2e-volume/input.txt)\" = 0:0; \ - touch ssh-write; echo nested-mount-owner-ok", - ]) - .await - .expect("SSH child should preserve nested volume ownership"); - assert!( - ssh_output.contains("nested-mount-owner-ok"), - "expected nested mount ownership marker:\n{ssh_output}" - ); - - sandbox.cleanup().await; - verify_volume_ownership(&volume) - .await - .expect("nested volume ownership should remain unchanged"); -} - -#[tokio::test] -async fn sandbox_mounts_enabled_driver_config_bind() { - let driver = e2e_driver().expect("OPENSHELL_E2E_DRIVER must be set by the e2e wrapper"); - assert!( - matches!(driver.as_str(), "docker" | "podman"), - "driver_config bind e2e requires docker or podman, got {driver}" - ); - - let cwd = std::env::current_dir().expect("resolve current dir"); - let host_dir = tempfile::Builder::new() - .prefix("openshell-e2e-driver-config-bind-") - .tempdir_in(cwd) - .expect("create bind mount host dir"); - fs::set_permissions(host_dir.path(), fs::Permissions::from_mode(0o777)) - .expect("make bind mount host dir writable by sandbox user"); - let input_path = host_dir.path().join("input.txt"); - fs::write(&input_path, "host-bind-ok").expect("seed bind mount host dir"); - fs::set_permissions(&input_path, fs::Permissions::from_mode(0o666)) - .expect("make bind mount input readable by sandbox user"); - - let bind_source = bind_mount_source_path(&driver, host_dir.path()); - let bind_mount = serde_json::json!({ - "type": "bind", - "source": bind_source, - "target": BIND_TARGET, - "read_only": false, - "selinux_label": "private" - }); - let driver_config = driver_config_mount_json(&driver, &bind_mount); - // Host bind mounts are explicitly unsafe: this test validates driver mount - // wiring, not Landlock enforcement over Docker Desktop's fakeowner mounts. - let policy = write_bind_mount_policy().expect("write bind mount policy"); - let policy_path = policy.path().to_str().expect("policy path must be utf-8"); - let mut sandbox = SandboxGuard::create(&[ - "--policy", - policy_path, - "--driver-config-json", - &driver_config, - "--", - "sh", - "-lc", - "set -eu; test \"$(cat /sandbox/e2e-bind/input.txt)\" = host-bind-ok; printf sandbox-bind-ok > /sandbox/e2e-bind/output.txt; cat /sandbox/e2e-bind/output.txt", - ]) - .await - .expect("sandbox create with driver-config bind mount"); - - assert!( - sandbox.create_output.contains("sandbox-bind-ok"), - "sandbox should read and write the bind mount:\n{}", - sandbox.create_output - ); - - sandbox.cleanup().await; - let output = fs::read_to_string(host_dir.path().join("output.txt")) - .expect("read sandbox output from bind mount host dir"); - assert_eq!(output, "sandbox-bind-ok"); -} - -fn write_bind_mount_policy() -> Result { - let mut file = - tempfile::NamedTempFile::new().map_err(|err| format!("create bind policy: {err}"))?; - file.write_all( - br#"version: 1 - -filesystem_policy: - include_workdir: false - read_only: - - "/bin" - - "/dev" - - "/etc" - - "/lib" - - "/proc" - - "/usr" - read_write: - - "/sandbox/e2e-bind" - - "/tmp" - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox -"#, - ) - .map_err(|err| format!("write bind policy: {err}"))?; - Ok(file) -} - -async fn seed_volume(volume: &VolumeGuard) -> Result<(), String> { - run_volume_container( - volume, - "seed", - false, - "set -eu; chmod 0777 /vol; printf host-volume-ok > /vol/input.txt", - ) - .await?; - Ok(()) -} - -async fn verify_volume(volume: &VolumeGuard) -> Result<(), String> { - let output = run_volume_container( - volume, - "verify", - true, - "set -eu; test \"$(cat /vol/input.txt)\" = host-volume-ok; test \"$(cat /vol/output.txt)\" = sandbox-volume-ok; echo volume-ok", - ) - .await?; - if !output.contains("volume-ok") { - return Err(format!( - "volume verification did not print expected marker:\n{output}" - )); - } - Ok(()) -} - -#[cfg(feature = "e2e-docker")] -async fn verify_volume_ownership(volume: &VolumeGuard) -> Result<(), String> { - let output = run_volume_container( - volume, - "verify-owner", - true, - "set -eu; test \"$(stat -c %u:%g /vol/input.txt)\" = 0:0; echo owner-ok", - ) - .await?; - if !output.contains("owner-ok") { - return Err(format!( - "volume ownership verification did not print expected marker:\n{output}" - )); - } - Ok(()) -} - -async fn run_volume_container( - volume: &VolumeGuard, - purpose: &str, - read_only: bool, - script: &str, -) -> Result { - ensure_test_image(&volume.docker).await?; - - let container_name = format!("{}-{purpose}", volume.name); - let create_options = CreateContainerOptionsBuilder::new() - .name(&container_name) - .build(); - let host_config = HostConfig { - mounts: Some(vec![Mount { - target: Some("/vol".to_string()), - source: Some(volume.name.clone()), - typ: Some(MountTypeEnum::VOLUME), - read_only: Some(read_only), - ..Default::default() - }]), - ..Default::default() - }; - volume - .docker - .create_container( - Some(create_options), - ContainerCreateBody { - image: Some(TEST_IMAGE.to_string()), - user: Some("0:0".to_string()), - entrypoint: Some(vec!["sh".to_string()]), - cmd: Some(vec!["-lc".to_string(), script.to_string()]), - attach_stdout: Some(true), - attach_stderr: Some(true), - host_config: Some(host_config), - ..Default::default() - }, - ) - .await - .map_err(|err| format!("create helper container {container_name}: {err}"))?; - - let result = run_created_container(volume, &container_name).await; - let remove_result = volume - .docker - .remove_container(&container_name, None::) - .await; - - match (result, remove_result) { - (Ok(output), Ok(())) => Ok(output), - (Ok(_), Err(err)) => Err(format!("remove helper container {container_name}: {err}")), - (Err(err), Ok(())) => Err(err), - (Err(err), Err(remove_err)) => Err(format!( - "{err}\nremove helper container {container_name}: {remove_err}" - )), - } -} - -async fn ensure_test_image(docker: &Docker) -> Result<(), String> { - if docker.inspect_image(TEST_IMAGE).await.is_ok() { - return Ok(()); - } - - let pull_events = docker - .create_image( - Some( - CreateImageOptionsBuilder::new() - .from_image(TEST_IMAGE) - .build(), - ), - None, - None, - ) - .try_collect::>() - .await - .map_err(|err| format!("pull helper image {TEST_IMAGE}: {err}"))?; - - let pull_errors = pull_events - .iter() - .filter_map(|event| { - event - .error_detail - .as_ref() - .and_then(|detail| detail.message.as_deref()) - }) - .collect::>(); - if pull_errors.is_empty() { - return Ok(()); - } - - Err(format!( - "pull helper image {TEST_IMAGE} failed:\n{}", - pull_errors.join("\n") - )) -} - -async fn run_created_container( - volume: &VolumeGuard, - container_name: &str, -) -> Result { - volume - .docker - .start_container(container_name, None::) - .await - .map_err(|err| format!("start helper container {container_name}: {err}"))?; - - let wait_result = volume - .docker - .wait_container(container_name, None::) - .try_collect::>() - .await; - let logs = volume - .docker - .logs( - container_name, - Some(LogsOptions { - stdout: true, - stderr: true, - tail: "all".to_string(), - ..Default::default() - }), - ) - .try_collect::>() - .await - .map(|chunks| { - chunks - .into_iter() - .map(|chunk| chunk.to_string()) - .collect::() - }); - - match (wait_result, logs) { - (Ok(_), Ok(output)) => Ok(output), - (Ok(_), Err(err)) => Err(format!( - "read helper container {container_name} logs: {err}" - )), - (Err(err), Ok(output)) => Err(format!( - "helper container {container_name} failed: {err}\n{output}" - )), - (Err(err), Err(log_err)) => Err(format!( - "helper container {container_name} failed: {err}\nread logs failed: {log_err}" - )), - } -} - -async fn connect_container_api(driver: &str) -> Result { - let docker = match driver { - "docker" => Docker::connect_with_local_defaults() - .map_err(|err| format!("connect to Docker API: {err}"))?, - "podman" => { - let socket = podman_socket_path()?; - let socket_display = socket.display().to_string(); - Docker::connect_with_unix( - socket - .to_str() - .ok_or_else(|| format!("podman socket path is not UTF-8: {socket_display}"))?, - 120, - bollard::API_DEFAULT_VERSION, - ) - .map_err(|err| format!("connect to Podman Docker-compatible API: {err}"))? - } - other => return Err(format!("unsupported e2e driver for volume API: {other}")), - }; - docker - .ping() - .await - .map_err(|err| format!("ping {driver} Docker-compatible API: {err}"))?; - Ok(docker) -} - -fn podman_socket_path() -> Result { - let path = std::env::var_os("OPENSHELL_PODMAN_SOCKET").ok_or_else(|| { - "OPENSHELL_PODMAN_SOCKET must be set by e2e/with-podman-gateway.sh".to_string() - })?; - Ok(PathBuf::from(path)) -} - -fn unique_volume_name(driver: &str) -> String { - let nanos = SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("system clock should be after Unix epoch") - .as_nanos(); - let sequence = NEXT_VOLUME_ID.fetch_add(1, Ordering::Relaxed); - format!( - "openshell-e2e-driver-config-volume-{driver}-{}-{nanos}-{sequence}", - std::process::id() - ) -} - -fn driver_config_mount_json(driver: &str, mount: &Value) -> String { - let mut root = Map::new(); - root.insert( - driver.to_string(), - serde_json::json!({ - "mounts": [mount] - }), - ); - Value::Object(root).to_string() -} - -fn bind_mount_source_path(driver: &str, path: &Path) -> PathBuf { - if driver == "docker" { - github_actions_host_work_path(path).unwrap_or_else(|| path.to_path_buf()) - } else { - path.to_path_buf() - } -} - -fn github_actions_host_work_path(path: &Path) -> Option { - if std::env::var("GITHUB_ACTIONS").ok().as_deref() != Some("true") { - return None; - } - - let relative = path.strip_prefix("/__w").ok()?; - let mapped = Path::new("/home/runner/_work").join(relative); - mapped.exists().then_some(mapped) -} diff --git a/e2e/rust/tests/forward_proxy_graphql_l7.rs b/e2e/rust/tests/forward_proxy_graphql_l7.rs deleted file mode 100644 index 5c25556cfa..0000000000 --- a/e2e/rust/tests/forward_proxy_graphql_l7.rs +++ /dev/null @@ -1,415 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! E2E tests for GraphQL L7 inspection through transparent interception. -//! -//! The upstream server deliberately does not implement GraphQL. `OpenShell` -//! parses and enforces GraphQL before forwarding, so any HTTP server that -//! accepts POST /graphql is enough to prove allowed requests reach upstream -//! and denied requests are stopped by the sandbox proxy. - -#![cfg(feature = "e2e")] - -use std::io::Write; - -use openshell_e2e::harness::container::ContainerHttpServer; -use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::NamedTempFile; - -const TEST_SERVER_ALIAS: &str = "graphql-l7.openshell.test"; - -async fn start_test_server() -> Result { - let script = r#"from http.server import BaseHTTPRequestHandler, HTTPServer - -class Handler(BaseHTTPRequestHandler): - def read_chunked(self): - while True: - size_line = self.rfile.readline() - if not size_line: - return - size = int(size_line.split(b";", 1)[0].strip(), 16) - if size == 0: - while self.rfile.readline().strip(): - pass - return - self.rfile.read(size) - self.rfile.read(2) - def do_GET(self): - if self.path == "/" or self.path.startswith("/graphql?"): - self.send_response(200) - else: - self.send_response(418) - self.end_headers() - self.wfile.write(b'{"ok":true}') - def do_POST(self): - if self.headers.get("Transfer-Encoding", "").lower() == "chunked": - self.read_chunked() - else: - _ = self.rfile.read(int(self.headers.get("Content-Length", "0"))) - self.send_response(200) - self.send_header("Content-Type", "application/json") - self.end_headers() - self.wfile.write(b'{"ok":true}') - def log_message(self, format, *args): - pass - -HTTPServer(("0.0.0.0", 8000), Handler).serve_forever() -"#; - - ContainerHttpServer::start_python(TEST_SERVER_ALIAS, script).await -} - -fn write_graphql_policy(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - test_graphql_l7: - name: test_graphql_l7 - endpoints: - - host: {host} - port: {port} - protocol: graphql - enforcement: enforce - persisted_queries: allow_registered - graphql_persisted_queries: - abc123: - operation_type: query - operation_name: Viewer - fields: [viewer] - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" - rules: - - allow: - operation_type: query - fields: [viewer] - - allow: - operation_type: mutation - fields: [createIssue] - deny_rules: - - operation_type: mutation - fields: [deleteRepository] - binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -#[tokio::test] -#[allow(clippy::too_many_lines)] -async fn graphql_l7_enforces_high_level_and_raw_transparent_paths() { - let server = start_test_server().await.expect("start test server"); - let policy = write_graphql_policy(&server.host, server.port).expect("write custom policy"); - let policy_path = policy - .path() - .to_str() - .expect("temp policy path should be utf-8") - .to_string(); - - let script = format!( - r#" -import json -import socket -import time -import urllib.error -import urllib.parse -import urllib.request - -HOST = {host:?} -PORT = {port} -DETAILS = {{}} - -QUERY_VIEWER = "query Viewer {{ viewer {{ login }} }}" -QUERY_REPOSITORY = "query Repo {{ repository(owner:\"o\", name:\"r\") {{ id }} }}" -MUTATION_CREATE = "mutation Create {{ createIssue(input:{{repositoryId:\"r\", title:\"t\", body:\"b\"}}) {{ issue {{ id }} }} }}" -MUTATION_DELETE = "mutation Delete {{ deleteRepository(input:{{repositoryId:\"r\"}}) {{ clientMutationId }} }}" - -def forward_status(query): - body = json.dumps({{"query": query}}).encode() - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/graphql", - data=body, - headers={{"Content-Type": "application/json"}}, - method="POST", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - error.read() - return error.code - -def forward_get_status(query): - encoded = urllib.parse.urlencode({{"query": query}}) - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/graphql?{{encoded}}", - method="GET", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - error.read() - return error.code - -def forward_duplicate_get_status(): - safe = urllib.parse.quote_plus(QUERY_VIEWER) - unsafe = urllib.parse.quote_plus(MUTATION_DELETE) - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/graphql?query={{safe}}&query={{unsafe}}", - method="GET", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - error.read() - return error.code - -def forward_persisted_get_status(hash_value): - extensions = json.dumps({{"persistedQuery": {{"version": 1, "sha256Hash": hash_value}}}}) - encoded = urllib.parse.urlencode({{"operationName": "Viewer", "extensions": extensions}}) - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/graphql?{{encoded}}", - method="GET", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - error.read() - return error.code - -def forward_chunked_status(query): - target = f"{{HOST}}:{{PORT}}" - body = json.dumps({{"query": query}}).encode() - chunk = f"{{len(body):x}}\r\n".encode() + body + b"\r\n0\r\n\r\n" - - with socket.create_connection((HOST, PORT), timeout=15) as sock: - request = ( - f"POST /graphql HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Content-Type: application/json\r\n" - f"Transfer-Encoding: chunked\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() + chunk - sock.sendall(request) - response, body = read_response(sock) - DETAILS["forward_chunked_query_allowed_detail"] = body.decode(errors="replace") - return status_code(response, "forward_chunked_response") - -def read_until(sock, marker): - data = b"" - while marker not in data: - chunk = sock.recv(4096) - if not chunk: - break - data += chunk - return data - -def read_response(sock): - response = read_until(sock, b"\r\n\r\n") - headers, _, body = response.partition(b"\r\n\r\n") - content_length = 0 - for line in headers.split(b"\r\n")[1:]: - if line.lower().startswith(b"content-length:"): - content_length = int(line.split(b":", 1)[1].strip()) - break - while len(body) < content_length: - chunk = sock.recv(4096) - if not chunk: - break - body += chunk - return response, body - -def status_code(response, label): - parts = response.split() - if len(parts) < 2: - DETAILS[f"{{label}}_raw"] = response.decode(errors="replace") - raise RuntimeError(f"{{label}}: malformed HTTP response: {{response!r}}") - try: - return int(parts[1]) - except ValueError as error: - DETAILS[f"{{label}}_raw"] = response.decode(errors="replace") - raise RuntimeError(f"{{label}}: non-numeric HTTP status: {{response!r}}") from error - -def raw_http_status(label, request): - last_error = None - for attempt in range(5): - try: - with socket.create_connection((HOST, PORT), timeout=15) as sock: - sock.sendall(request) - sock.shutdown(socket.SHUT_WR) - response = read_until(sock, b"\r\n\r\n") - return status_code(response, f"{{label}}_response") - except (OSError, RuntimeError) as error: - last_error = error - DETAILS[f"{{label}}_attempt_{{attempt + 1}}_error"] = str(error) - time.sleep(0.2) - - raise RuntimeError(f"{{label}}: failed after 5 attempts: {{last_error}}") - -def raw_status(query, label): - target = f"{{HOST}}:{{PORT}}" - body = json.dumps({{"query": query}}).encode() - - request = ( - f"POST /graphql HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Content-Type: application/json\r\n" - f"Content-Length: {{len(body)}}\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() + body - return raw_http_status(label, request) - -def raw_get_status(query, label): - target = f"{{HOST}}:{{PORT}}" - encoded = urllib.parse.urlencode({{"query": query}}) - - request = ( - f"GET /graphql?{{encoded}} HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() - return raw_http_status(label, request) - -def raw_duplicate_get_status(): - target = f"{{HOST}}:{{PORT}}" - safe = urllib.parse.quote_plus(QUERY_VIEWER) - unsafe = urllib.parse.quote_plus(MUTATION_DELETE) - - request = ( - f"GET /graphql?query={{safe}}&query={{unsafe}} HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() - return raw_http_status("raw_duplicate_get_denied", request) - -def raw_persisted_get_status(hash_value, label): - target = f"{{HOST}}:{{PORT}}" - extensions = json.dumps({{"persistedQuery": {{"version": 1, "sha256Hash": hash_value}}}}) - encoded = urllib.parse.urlencode({{"operationName": "Viewer", "extensions": extensions}}) - - request = ( - f"GET /graphql?{{encoded}} HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() - return raw_http_status(label, request) - -def raw_chunked_status(query): - target = f"{{HOST}}:{{PORT}}" - body = json.dumps({{"query": query}}).encode() - chunk = f"{{len(body):x}}\r\n".encode() + body + b"\r\n0\r\n\r\n" - - request = ( - f"POST /graphql HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Content-Type: application/json\r\n" - f"Transfer-Encoding: chunked\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() + chunk - return raw_http_status("raw_chunked_query_allowed", request) - -results = {{ - "forward_query_allowed": forward_status(QUERY_VIEWER), - "forward_get_query_allowed": forward_get_status(QUERY_VIEWER), - "forward_duplicate_get_denied": forward_duplicate_get_status(), - "forward_persisted_get_allowed": forward_persisted_get_status("abc123"), - "forward_unregistered_persisted_get_denied": forward_persisted_get_status("missing"), - "forward_chunked_query_allowed": forward_chunked_status(QUERY_VIEWER), - "forward_unlisted_field_denied": forward_status(QUERY_REPOSITORY), - "forward_mutation_allowed": forward_status(MUTATION_CREATE), - "forward_deny_rule_denied": forward_status(MUTATION_DELETE), - "raw_query_allowed": raw_status(QUERY_VIEWER, "raw_query_allowed"), - "raw_get_query_allowed": raw_get_status(QUERY_VIEWER, "raw_get_query_allowed"), - "raw_duplicate_get_denied": raw_duplicate_get_status(), - "raw_persisted_get_allowed": raw_persisted_get_status("abc123", "raw_persisted_get_allowed"), - "raw_unregistered_persisted_get_denied": raw_persisted_get_status("missing", "raw_unregistered_persisted_get_denied"), - "raw_chunked_query_allowed": raw_chunked_status(QUERY_VIEWER), - "raw_unlisted_field_denied": raw_status(QUERY_REPOSITORY, "raw_unlisted_field_denied"), - "raw_mutation_allowed": raw_status(MUTATION_CREATE, "raw_mutation_allowed"), - "raw_deny_rule_denied": raw_status(MUTATION_DELETE, "raw_deny_rule_denied"), -}} -results.update(DETAILS) -print(json.dumps(results, sort_keys=True)) -"#, - host = server.host, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - - for (key, expected) in [ - ("forward_query_allowed", 200), - ("forward_get_query_allowed", 200), - ("forward_duplicate_get_denied", 403), - ("forward_persisted_get_allowed", 200), - ("forward_unregistered_persisted_get_denied", 403), - ("forward_chunked_query_allowed", 200), - ("forward_unlisted_field_denied", 403), - ("forward_mutation_allowed", 200), - ("forward_deny_rule_denied", 403), - ("raw_query_allowed", 200), - ("raw_get_query_allowed", 200), - ("raw_duplicate_get_denied", 403), - ("raw_persisted_get_allowed", 200), - ("raw_unregistered_persisted_get_denied", 403), - ("raw_chunked_query_allowed", 200), - ("raw_unlisted_field_denied", 403), - ("raw_mutation_allowed", 200), - ("raw_deny_rule_denied", 403), - ] { - let expected_fragment = format!(r#""{key}": {expected}"#); - assert!( - guard.create_output.contains(&expected_fragment), - "expected {key}={expected}, got:\n{}", - guard.create_output - ); - } -} diff --git a/e2e/rust/tests/forward_proxy_jsonrpc_l7.rs b/e2e/rust/tests/forward_proxy_jsonrpc_l7.rs deleted file mode 100644 index b46dac1313..0000000000 --- a/e2e/rust/tests/forward_proxy_jsonrpc_l7.rs +++ /dev/null @@ -1,498 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! E2E tests for JSON-RPC L7 inspection through transparent interception. -//! -//! The upstream server deliberately does not implement JSON-RPC. `OpenShell` -//! parses and enforces JSON-RPC before forwarding, so any HTTP server that -//! accepts POST /rpc is enough to prove allowed requests reach upstream -//! and denied requests are stopped by the sandbox proxy. - -#![cfg(feature = "e2e")] - -use std::io::Write; - -use openshell_e2e::harness::container::ContainerHttpServer; -use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::NamedTempFile; - -const RULES_TEST_SERVER_ALIAS: &str = "jsonrpc-l7-rules.openshell.test"; -const AUDIT_TEST_SERVER_ALIAS: &str = "jsonrpc-l7-audit.openshell.test"; - -async fn start_test_server(alias: &str) -> Result { - let script = r#"from http.server import BaseHTTPRequestHandler, HTTPServer - -class Handler(BaseHTTPRequestHandler): - def read_body(self): - if self.headers.get("Transfer-Encoding", "").lower() == "chunked": - data = b"" - while True: - size_line = self.rfile.readline() - if not size_line: - break - size = int(size_line.split(b";", 1)[0].strip(), 16) - if size == 0: - while self.rfile.readline().strip(): - pass - break - data += self.rfile.read(size) - self.rfile.read(2) - return data - return self.rfile.read(int(self.headers.get("Content-Length", "0"))) - - def do_GET(self): - self.send_response(200) - self.end_headers() - - def do_POST(self): - self.read_body() - self.send_response(200) - self.send_header("Content-Type", "application/json") - self.end_headers() - self.wfile.write(b'{"jsonrpc":"2.0","id":1,"result":{}}') - - def log_message(self, format, *args): - pass - -HTTPServer(("0.0.0.0", 8000), Handler).serve_forever() -"#; - - ContainerHttpServer::start_python(alias, script).await -} - -fn write_jsonrpc_policy(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - test_jsonrpc_l7: - name: test_jsonrpc_l7 - endpoints: - - host: {host} - port: {port} - path: /rpc - protocol: json-rpc - enforcement: enforce - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" - json_rpc: - max_body_bytes: 65536 - rules: - - allow: - method: initialize - - allow: - method: tools/list - - allow: - method: tools/call - deny_rules: - - method: tools/delete - binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -fn write_jsonrpc_default_audit_policy(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - test_jsonrpc_l7_audit: - name: test_jsonrpc_l7_audit - endpoints: - - host: {host} - port: {port} - path: /rpc - protocol: json-rpc - allowed_ips: - - "10.0.0.0/8" - - "100.64.0.0/10" - - "172.0.0.0/8" - - "198.18.0.0/15" - - "192.168.0.0/16" - - "fc00::/7" - json_rpc: - max_body_bytes: 65536 - rules: - - allow: - method: initialize - binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -#[tokio::test] -#[allow(clippy::too_many_lines)] -async fn jsonrpc_l7_enforces_high_level_and_raw_transparent_paths() { - let server = start_test_server(RULES_TEST_SERVER_ALIAS) - .await - .expect("start test server"); - let policy = write_jsonrpc_policy(&server.host, server.port).expect("write custom policy"); - let policy_path = policy - .path() - .to_str() - .expect("temp policy path should be utf-8") - .to_string(); - - let script = format!( - r#" -import json -import socket -import time -import urllib.error -import urllib.request - -HOST = {host:?} -PORT = {port} -DETAILS = {{ - "debug_target": {{"host": HOST, "port": PORT}}, -}} - -def text(data): - return data.decode(errors="replace") - -def selected_headers(headers): - return {{ - key.lower(): value - for key, value in headers.items() - if key.lower() in ("content-type", "content-length", "server") - }} - -def record_http_error(label, error, request_body): - response_body = error.read() - DETAILS[f"{{label}}_request"] = request_body - DETAILS[f"{{label}}_response"] = {{ - "status": error.code, - "reason": str(error.reason), - "headers": selected_headers(error.headers), - "body": text(response_body), - }} - return error.code - -def post_jsonrpc(label, method, params=None, req_id=1): - body = {{"jsonrpc": "2.0", "id": req_id, "method": method}} - if params is not None: - body["params"] = params - encoded = json.dumps(body).encode() - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/rpc", - data=encoded, - headers={{"Content-Type": "application/json"}}, - method="POST", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - return record_http_error(label, error, body) - -def post_jsonrpc_batch(label, requests): - encoded = json.dumps(requests).encode() - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/rpc", - data=encoded, - headers={{"Content-Type": "application/json"}}, - method="POST", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - return record_http_error(label, error, requests) - -def post_invalid_json(label): - encoded = b"not valid json {{" - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/rpc", - data=encoded, - headers={{"Content-Type": "application/json", "Content-Length": str(len(encoded))}}, - method="POST", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - return record_http_error(label, error, text(encoded)) - -def read_until(sock, marker): - data = b"" - while marker not in data: - chunk = sock.recv(4096) - if not chunk: - break - data += chunk - return data - -def read_response(sock): - response = read_until(sock, b"\r\n\r\n") - headers, _, body = response.partition(b"\r\n\r\n") - content_length = 0 - for line in headers.split(b"\r\n")[1:]: - if line.lower().startswith(b"content-length:"): - content_length = int(line.split(b":", 1)[1].strip()) - break - while len(body) < content_length: - chunk = sock.recv(4096) - if not chunk: - break - body += chunk - return response, body - -def status_code(response, label): - parts = response.split() - if len(parts) < 2: - DETAILS[f"{{label}}_raw"] = response.decode(errors="replace") - raise RuntimeError(f"{{label}}: malformed HTTP response: {{response!r}}") - try: - return int(parts[1]) - except ValueError as error: - DETAILS[f"{{label}}_raw"] = response.decode(errors="replace") - raise RuntimeError(f"{{label}}: non-numeric HTTP status: {{response!r}}") from error - -def record_raw_response(label, response, body=b""): - code = status_code(response, label) - if code != 200: - DETAILS[f"{{label}}_raw"] = text(response) - if body: - DETAILS[f"{{label}}_body"] = text(body) - return code - -def raw_http_status(label, request): - last_error = None - for attempt in range(5): - try: - with socket.create_connection((HOST, PORT), timeout=15) as sock: - sock.sendall(request) - sock.shutdown(socket.SHUT_WR) - response, body = read_response(sock) - return record_raw_response(f"{{label}}_response", response, body) - except (OSError, RuntimeError) as error: - last_error = error - DETAILS[f"{{label}}_attempt_{{attempt + 1}}_error"] = str(error) - time.sleep(0.2) - - raise RuntimeError(f"{{label}}: failed after 5 attempts: {{last_error}}") - -def raw_jsonrpc_status(method, params, label): - target = f"{{HOST}}:{{PORT}}" - body = {{"jsonrpc": "2.0", "id": 1, "method": method}} - if params is not None: - body["params"] = params - encoded = json.dumps(body).encode() - request = ( - f"POST /rpc HTTP/1.1\r\n" - f"Host: {{target}}\r\n" - f"Content-Type: application/json\r\n" - f"Content-Length: {{len(encoded)}}\r\n" - f"Connection: close\r\n" - f"\r\n" - ).encode() + encoded - return raw_http_status(label, request) - -results = {{ - # forward proxy — method-only allow rules - "forward_method_initialize_allowed": post_jsonrpc("forward_method_initialize_allowed", "initialize", {{"protocolVersion": "2025-11-25", "capabilities": {{}}}}), - "forward_method_tools_list_allowed": post_jsonrpc("forward_method_tools_list_allowed", "tools/list"), - - # forward proxy — method allow/deny rules - "forward_method_tools_call_allowed": post_jsonrpc("forward_method_tools_call_allowed", "tools/call", {{"name": "read_status"}}), - "forward_method_tools_call_with_unmatched_params_allowed": post_jsonrpc("forward_method_tools_call_with_unmatched_params_allowed", "tools/call", {{"name": "blocked_action", "arguments": {{"scope": "ignored"}}}}), - "forward_method_tools_delete_denied": post_jsonrpc("forward_method_tools_delete_denied", "tools/delete", {{"name": "purge_cache"}}), - - # forward proxy — batch: all requests allowed - "forward_batch_all_allowed": post_jsonrpc_batch("forward_batch_all_allowed", [ - {{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}}, - {{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {{"name": "read_status"}}}}, - ]), - - # forward proxy — batch: one denied request causes full batch denial - "forward_batch_one_denied": post_jsonrpc_batch("forward_batch_one_denied", [ - {{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}}, - {{"jsonrpc": "2.0", "id": 2, "method": "tools/delete", "params": {{"name": "purge_cache"}}}}, - ]), - - # forward proxy — invalid JSON body fails closed before generic rules apply - "forward_invalid_json_denied": post_invalid_json("forward_invalid_json_denied"), - - # raw socket path — representative allowed and denied cases - "raw_method_initialize_allowed": raw_jsonrpc_status("initialize", {{"protocolVersion": "2025-11-25", "capabilities": {{}}}}, "raw_method_initialize_allowed"), - "raw_method_tools_list_allowed": raw_jsonrpc_status("tools/list", None, "raw_method_tools_list_allowed"), - "raw_method_tools_call_allowed": raw_jsonrpc_status("tools/call", {{"name": "read_status"}}, "raw_method_tools_call_allowed"), - "raw_method_tools_call_with_unmatched_params_allowed": raw_jsonrpc_status("tools/call", {{"name": "blocked_action", "arguments": {{"scope": "ignored"}}}}, "raw_method_tools_call_with_unmatched_params_allowed"), - "raw_method_tools_delete_denied": raw_jsonrpc_status("tools/delete", {{"name": "purge_cache"}}, "raw_method_tools_delete_denied"), -}} -results.update(DETAILS) -print(json.dumps(results, sort_keys=True)) -"#, - host = server.host, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - - for (key, expected) in [ - // forward proxy — allowed - ("forward_method_initialize_allowed", 200), - ("forward_method_tools_list_allowed", 200), - ("forward_method_tools_call_allowed", 200), - ( - "forward_method_tools_call_with_unmatched_params_allowed", - 200, - ), - // forward proxy — method denied - ("forward_method_tools_delete_denied", 403), - // forward proxy — batch - ("forward_batch_all_allowed", 200), - ("forward_batch_one_denied", 403), - // forward proxy — parse error - ("forward_invalid_json_denied", 403), - // raw socket path — allowed - ("raw_method_initialize_allowed", 200), - ("raw_method_tools_list_allowed", 200), - ("raw_method_tools_call_allowed", 200), - ("raw_method_tools_call_with_unmatched_params_allowed", 200), - // raw socket path — method denied - ("raw_method_tools_delete_denied", 403), - ] { - let expected_fragment = format!(r#""{key}": {expected}"#); - assert!( - guard.create_output.contains(&expected_fragment), - "expected {key}={expected}, got:\n{}", - guard.create_output - ); - } -} - -#[tokio::test] -async fn jsonrpc_forward_proxy_hard_denies_response_frames_in_default_audit_mode() { - let server = start_test_server(AUDIT_TEST_SERVER_ALIAS) - .await - .expect("start test server"); - let policy = - write_jsonrpc_default_audit_policy(&server.host, server.port).expect("write custom policy"); - let policy_path = policy - .path() - .to_str() - .expect("temp policy path should be utf-8") - .to_string(); - - let script = format!( - r#" -import json -import urllib.error -import urllib.request - -HOST = {host:?} -PORT = {port} - -def post_jsonrpc(body): - encoded = json.dumps(body).encode() - request = urllib.request.Request( - f"http://{{HOST}}:{{PORT}}/rpc", - data=encoded, - headers={{"Content-Type": "application/json"}}, - method="POST", - ) - try: - with urllib.request.urlopen(request, timeout=15) as response: - response.read() - return response.status - except urllib.error.HTTPError as error: - error.read() - return error.code - -results = {{ - "forward_unknown_method_audited": post_jsonrpc({{"jsonrpc": "2.0", "id": 1, "method": "unknown/method"}}), - "forward_response_frame_hard_denied": post_jsonrpc({{"jsonrpc": "2.0", "id": 1, "result": {{}}}}), -}} -print(json.dumps(results, sort_keys=True)) -"#, - host = server.host, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - - for (key, expected) in [ - ("forward_unknown_method_audited", 200), - ("forward_response_frame_hard_denied", 403), - ] { - let expected_fragment = format!(r#""{key}": {expected}"#); - assert!( - guard.create_output.contains(&expected_fragment), - "expected {key}={expected}, got:\n{}", - guard.create_output - ); - } -} diff --git a/e2e/rust/tests/forward_proxy_l7_bypass.rs b/e2e/rust/tests/forward_proxy_l7_bypass.rs deleted file mode 100644 index f274f20e93..0000000000 --- a/e2e/rust/tests/forward_proxy_l7_bypass.rs +++ /dev/null @@ -1,239 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! Regression tests: the forward proxy path must evaluate L7 rules for -//! endpoints that have them configured. Allowed requests (e.g. GET on a -//! read-only endpoint) should succeed; denied requests (e.g. POST) should -//! receive 403. - -#![cfg(feature = "e2e")] - -use std::io::Write; - -use openshell_e2e::harness::container::ContainerHttpServer; -use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::NamedTempFile; - -async fn start_test_server(alias: &str) -> Result { - let script = r#"from http.server import BaseHTTPRequestHandler, HTTPServer - -class Handler(BaseHTTPRequestHandler): - def do_GET(self): - if self.headers.get("Upgrade"): - self.send_response(101) - self.send_header("Connection", "Upgrade") - self.send_header("Upgrade", "websocket") - self.send_header("Sec-WebSocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=") - self.end_headers() - return - self.send_response(200) - self.end_headers() - self.wfile.write(b'{"ok":true}') - def do_DELETE(self): - self.send_response(200) - self.end_headers() - self.wfile.write(b'{"ok":true}') - def log_message(self, format, *args): - pass - -HTTPServer(("0.0.0.0", 8000), Handler).serve_forever() -"#; - - ContainerHttpServer::start_python(alias, script).await -} - -fn write_policy_with_l7_rules(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - test_l7: - name: test_l7 - endpoints: - - host: {host} - port: {port} - protocol: rest - enforcement: enforce - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" - rules: - - allow: - method: GET - path: /allowed - binaries: - - path: /usr/bin/curl - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -/// GET /allowed should succeed — the L7 policy explicitly allows it. -#[tokio::test] -async fn forward_proxy_allows_l7_permitted_request() { - let server = start_test_server("rest-l7-allow.openshell.test") - .await - .expect("start test server"); - let policy = - write_policy_with_l7_rules(&server.host, server.port).expect("write custom policy"); - let policy_path = policy - .path() - .to_str() - .expect("temp policy path should be utf-8") - .to_string(); - - let script = format!( - r#" -import urllib.request, urllib.error, json, sys -url = "http://{host}:{port}/allowed" -try: - resp = urllib.request.urlopen(url, timeout=15) - last = {{"status": resp.status, "error": None}} -except urllib.error.HTTPError as e: - last = {{"status": e.code, "error": str(e)}} -except Exception as e: - last = {{"status": -1, "error": str(e)}} -print(json.dumps(last)) -"#, - host = server.host, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - - // L7 policy allows GET /allowed — should succeed. - assert!( - guard.create_output.contains("\"status\": 200"), - "expected 200 for L7-allowed GET, got:\n{}", - guard.create_output - ); -} - -/// POST /allowed should be denied — the L7 policy only allows GET. -#[tokio::test] -async fn forward_proxy_denies_l7_blocked_request() { - let server = start_test_server("rest-l7-deny.openshell.test") - .await - .expect("start test server"); - let policy = - write_policy_with_l7_rules(&server.host, server.port).expect("write custom policy"); - let policy_path = policy - .path() - .to_str() - .expect("temp policy path should be utf-8") - .to_string(); - - let script = format!( - r#" -import urllib.request, urllib.error, json, sys -url = "http://{host}:{port}/allowed" -req = urllib.request.Request(url, data=b"test", method="POST") -try: - resp = urllib.request.urlopen(req, timeout=15) - print(json.dumps({{"status": resp.status, "error": None}})) -except urllib.error.HTTPError as e: - print(json.dumps({{"status": e.code, "error": str(e)}})) -except Exception as e: - print(json.dumps({{"status": -1, "error": str(e)}})) -"#, - host = server.host, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - - // L7 policy denies POST — should return 403. - assert!( - guard.create_output.contains("\"status\": 403"), - "expected 403 for L7-denied POST, got:\n{}", - guard.create_output - ); -} - -/// A permitted GET cannot switch a REST endpoint into an uninspected tunnel. -#[tokio::test] -async fn rest_upgrade_is_refused_in_enforce_and_audit_modes() { - let server = start_test_server("rest-upgrade.openshell.test") - .await - .expect("start backend"); - for enforcement in ["enforce", "audit"] { - let source = write_policy_with_l7_rules(&server.host, server.port).unwrap(); - let policy = std::fs::read_to_string(source.path()).unwrap().replace( - "enforcement: enforce", - &format!("enforcement: {enforcement}"), - ); - let mut file = NamedTempFile::new().unwrap(); - file.write_all(policy.as_bytes()).unwrap(); - file.flush().unwrap(); - let policy_path = file.path().to_str().unwrap(); - let script = format!( - r#" -import socket -for target in ["/allowed", "http://{host}:{port}/allowed"]: - s = socket.create_connection(("{host}", {port}), timeout=15) - request = ("GET " + target + " HTTP/1.1\r\nHost: {host}:{port}\r\n" - "Connection: Upgrade\r\nUpgrade: websocket\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nSec-WebSocket-Version: 13\r\n\r\n") - s.sendall(request.encode()) - response = b"" - while True: - chunk = s.recv(4096) - if not chunk: - break - response += chunk - s.close() - assert response.startswith(b"HTTP/1.1 403"), response - assert b"unsupported_l7_protocol" in response, response - assert b"REST endpoints" in response, response -print("REST_UPGRADE_REFUSED") -"#, - host = server.host, - port = server.port - ); - let guard = - SandboxGuard::create(&["--policy", policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - assert!( - guard.create_output.contains("REST_UPGRADE_REFUSED"), - "{enforcement}: {}", - guard.create_output - ); - } -} diff --git a/e2e/rust/tests/host_gateway_alias.rs b/e2e/rust/tests/host_gateway_alias.rs index e3f8cb1c9f..2f5647356b 100644 --- a/e2e/rust/tests/host_gateway_alias.rs +++ b/e2e/rust/tests/host_gateway_alias.rs @@ -4,76 +4,14 @@ #![cfg(feature = "e2e")] use std::io::Write; -use std::process::Stdio; -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::container::is_e2e_driver; use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::{Builder as TempFileBuilder, NamedTempFile}; +use tempfile::NamedTempFile; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; use tokio::net::TcpListener; use tokio::task::JoinHandle; -const BINDING_PROVIDER_A_NAME: &str = "e2e-static-endpoint-binding-provider-a"; -const BINDING_PROVIDER_B_NAME: &str = "e2e-static-endpoint-binding-provider-b"; -const BINDING_PROFILE_A_ID: &str = "e2e-static-endpoint-binding-a"; -const BINDING_PROFILE_B_ID: &str = "e2e-static-endpoint-binding-b"; - -async fn run_cli(args: &[&str]) -> Result { - let mut cmd = openshell_cmd(); - cmd.args(args).stdout(Stdio::piped()).stderr(Stdio::piped()); - - let output = cmd - .output() - .await - .map_err(|e| format!("failed to spawn openshell {}: {e}", args.join(" ")))?; - - let stdout = String::from_utf8_lossy(&output.stdout).to_string(); - let stderr = String::from_utf8_lossy(&output.stderr).to_string(); - let combined = format!("{stdout}{stderr}"); - - if !output.status.success() { - return Err(format!( - "openshell {} failed (exit {:?}):\n{combined}", - args.join(" "), - output.status.code() - )); - } - - Ok(combined) -} - -async fn wait_for_sandbox_logs( - sandbox_name: &str, - expected: impl Fn(&str) -> bool, -) -> Result { - let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(10); - - loop { - let logs = run_cli(&[ - "logs", - sandbox_name, - "-n", - "500", - "--since", - "2m", - "--source", - "sandbox", - ]) - .await?; - if expected(&logs) { - return Ok(logs); - } - if tokio::time::Instant::now() >= deadline { - return Err(format!( - "timed out waiting for expected sandbox logs:\n{logs}" - )); - } - tokio::time::sleep(std::time::Duration::from_millis(250)).await; - } -} - struct HostServer { port: u16, task: JoinHandle<()>, @@ -81,13 +19,6 @@ struct HostServer { impl HostServer { async fn start(response_body: &str) -> Result { - Self::start_with_auth_check(response_body, None).await - } - - async fn start_with_auth_check( - response_body: &str, - expected_authorization: Option<&str>, - ) -> Result { let listener = TcpListener::bind(("0.0.0.0", 0)) .await .map_err(|e| format!("bind host test server: {e}"))?; @@ -96,14 +27,12 @@ impl HostServer { .map_err(|e| format!("read host test server address: {e}"))? .port(); let response_body = response_body.as_bytes().to_vec(); - let expected_authorization = expected_authorization.map(str::to_string); let task = tokio::spawn(async move { loop { let Ok((mut stream, _)) = listener.accept().await else { break; }; let body = response_body.clone(); - let expected_authorization = expected_authorization.clone(); tokio::spawn(async move { let mut request = Vec::new(); let mut buf = [0_u8; 1024]; @@ -119,17 +48,6 @@ impl HostServer { break; } } - - let body = expected_authorization.map_or(body, |expected| { - let request = String::from_utf8_lossy(&request); - format!( - r#"{{"authorized":{}}}"#, - request.lines().any(|line| { - line.eq_ignore_ascii_case(&format!("Authorization: {expected}")) - }) - ) - .into_bytes() - }); let response = format!( "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", body.len() @@ -147,114 +65,11 @@ impl HostServer { } } -fn write_binding_profile( - id: &str, - display_name: &str, - env_var: &str, - host: &str, - port: u16, -) -> Result { - let mut file = TempFileBuilder::new() - .suffix(".yaml") - .tempfile() - .map_err(|e| format!("create provider profile: {e}"))?; - let profile = format!( - r#"id: {id} -display_name: {display_name} -category: other -credentials: - - name: bound_token - env_vars: [{env_var}] - required: true - auth_style: bearer - header_name: authorization -endpoints: - - host: {host} - port: {port} - path: /allowed/** - protocol: rest - access: full - enforcement: enforce -binaries: [/usr/bin/bash] -"# - ); - file.write_all(profile.as_bytes()) - .map_err(|e| format!("write provider profile: {e}"))?; - file.flush() - .map_err(|e| format!("flush provider profile: {e}"))?; - Ok(file) -} - -fn write_binding_policy(port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create binding policy: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: [/bin, /usr, /lib, /proc, /dev/urandom, /app, /etc, /var/log] - read_write: [/sandbox, /tmp, /dev/null] - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - binding_test: - name: binding_test - endpoints: - - host: host.openshell.internal - port: {port} - path: /** - protocol: rest - access: full - enforcement: enforce - - host: host.docker.internal - port: {port} - path: /** - protocol: rest - access: full - enforcement: enforce - binaries: - - path: /usr/bin/bash -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write binding policy: {e}"))?; - file.flush() - .map_err(|e| format!("flush binding policy: {e}"))?; - Ok(file) -} - impl Drop for HostServer { fn drop(&mut self) { self.task.abort(); } } - -async fn delete_provider(name: &str) { - let mut cmd = openshell_cmd(); - cmd.arg("provider") - .arg("delete") - .arg(name) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - -async fn delete_provider_profile(id: &str) { - let mut cmd = openshell_cmd(); - cmd.arg("profile") - .arg("delete") - .arg(id) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - fn write_policy(port: u16) -> Result { let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; let policy = format!( @@ -340,229 +155,3 @@ async fn sandbox_reaches_host_openshell_internal_via_host_gateway_alias() { guard.create_output ); } - -#[tokio::test] -async fn sandbox_receives_eof_after_closing_http_response() { - for response in [ - "HTTP/1.0 200 OK\r\nContent-Length: 3\r\n\r\nOK\n", - "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 3\r\n\r\nOK\n", - "HTTP/1.1 200 OK\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nOK\n\r\n0\r\n\r\n", - ] { - let listener = TcpListener::bind(("0.0.0.0", 0)).await.unwrap(); - let port = listener.local_addr().unwrap().port(); - let server = HostServer { - port, - task: tokio::spawn(async move { - let (mut stream, _) = listener.accept().await.unwrap(); - stream.set_nodelay(true).expect("disable Nagle on fixture"); - let mut request = Vec::new(); - while !request.ends_with(b"\r\n\r\n") { - request.push(stream.read_u8().await.unwrap()); - assert!(request.len() < 4096); - } - stream.write_all(response.as_bytes()).await.unwrap(); - stream.shutdown().await.unwrap(); - }), - }; - let policy = write_policy(server.port).unwrap(); - let command = format!( - r#"set -eu -exec 3<>/dev/tcp/host.openshell.internal/{port} -printf 'GET / HTTP/1.1\r\nHost: host.openshell.internal:{port}\r\n\r\n' >&3 -while true; do - line= - if IFS= read -r -t 5 line <&3; then - printf '%s\n' "$line" - else - status=$? - [ "$status" -eq 1 ] || {{ echo EOF_TIMEOUT; exit 1; }} - [ -z "$line" ] || printf '%s\n' "$line" - break - fi -done -printf 'RESPONSE_EOF\n' -"#, - ); - let mut sandbox = SandboxGuard::create(&[ - "--policy", - policy.path().to_str().unwrap(), - "--no-auto-providers", - "--", - "/usr/bin/bash", - "-c", - &command, - ]) - .await - .expect("closing response must finish without a client timeout"); - assert!( - sandbox.create_output.lines().any(|line| line == "OK"), - "{}", - sandbox.create_output - ); - assert!( - sandbox.create_output.contains("RESPONSE_EOF"), - "{}", - sandbox.create_output - ); - assert!( - !sandbox.create_output.contains("EOF_TIMEOUT"), - "{}", - sandbox.create_output - ); - sandbox.cleanup().await; - } -} - -#[tokio::test] -async fn static_provider_credentials_are_bound_to_profile_endpoints() { - let server = HostServer::start_with_auth_check("", Some("Bearer e2e-bound-secret")) - .await - .expect("start credential echo server"); - let profile_a = write_binding_profile( - BINDING_PROFILE_A_ID, - "E2E static endpoint binding A", - "BOUND_TOKEN_A", - "host.openshell.internal", - server.port, - ) - .expect("write provider A binding profile"); - let profile_b = write_binding_profile( - BINDING_PROFILE_B_ID, - "E2E static endpoint binding B", - "BOUND_TOKEN_B", - "host.docker.internal", - server.port, - ) - .expect("write provider B binding profile"); - let policy = write_binding_policy(server.port).expect("write binding policy"); - let profile_a_path = profile_a.path().to_string_lossy().into_owned(); - let profile_b_path = profile_b.path().to_string_lossy().into_owned(); - let policy_path = policy.path().to_string_lossy().into_owned(); - - delete_provider(BINDING_PROVIDER_A_NAME).await; - delete_provider(BINDING_PROVIDER_B_NAME).await; - delete_provider_profile(BINDING_PROFILE_A_ID).await; - delete_provider_profile(BINDING_PROFILE_B_ID).await; - run_cli(&["profile", "import", "--file", &profile_a_path]) - .await - .expect("import provider A endpoint-binding profile"); - run_cli(&["profile", "import", "--file", &profile_b_path]) - .await - .expect("import provider B endpoint-binding profile"); - run_cli(&[ - "provider", - "create", - "--name", - BINDING_PROVIDER_A_NAME, - "--type", - BINDING_PROFILE_A_ID, - "--credential", - "BOUND_TOKEN_A=e2e-bound-secret", - ]) - .await - .expect("create endpoint-bound provider A"); - run_cli(&[ - "provider", - "create", - "--name", - BINDING_PROVIDER_B_NAME, - "--type", - BINDING_PROFILE_B_ID, - "--credential", - "BOUND_TOKEN_B=e2e-provider-b-secret", - ]) - .await - .expect("create endpoint-bound provider B"); - - let command = format!( - r#" -http_request() {{ - local host="$1" path="$2" status_line line - HTTP_STATUS= HTTP_BODY= - if ! exec 3<>"/dev/tcp/$host/{port}"; then - HTTP_STATUS=connect-denied - return 1 - fi - printf 'GET %s HTTP/1.1\r\nHost: %s:{port}\r\nAuthorization: Bearer %s\r\nConnection: close\r\n\r\n' "$path" "$host" "$BOUND_TOKEN_A" >&3 - IFS= read -r status_line <&3 || return 1 - status_line="${{status_line%$'\r'}}" - HTTP_STATUS="${{status_line#* }}" - HTTP_STATUS="${{HTTP_STATUS%% *}}" - while IFS= read -r line <&3; do - line="${{line%$'\r'}}" - [[ -z "$line" ]] && break - done - while IFS= read -r line <&3 || [[ -n "$line" ]]; do HTTP_BODY+="$line"; done - exec 3>&- 3<&- -}} -http_request host.openshell.internal /allowed/check; allowed="$HTTP_BODY" -http_request host.docker.internal /allowed/check || true; host_denied="$HTTP_STATUS" -http_request host.openshell.internal /other/check; path_denied="$HTTP_STATUS" -printf 'ALLOWED=%s HOST_DENIED=%s PATH_DENIED=%s\n' "$allowed" "$host_denied" "$path_denied" -"#, - port = server.port, - ); - let mut guard = SandboxGuard::create(&[ - "--policy", - &policy_path, - "--provider", - BINDING_PROVIDER_A_NAME, - "--provider", - BINDING_PROVIDER_B_NAME, - "--no-auto-providers", - "--", - "/usr/bin/bash", - "-c", - &command, - ]) - .await - .expect("run endpoint-binding requests"); - - let logs = wait_for_sandbox_logs(&guard.name, |logs| { - logs.contains("openshell.provider_credential.endpoint_mismatch") - && logs.contains("credential_endpoint_mismatch") - }) - .await - .expect("fetch endpoint mismatch logs"); - assert!( - guard - .create_output - .contains(r#"ALLOWED={"authorized":true}"#), - "credential should resolve at the bound endpoint:\n{}\nlogs:\n{logs}", - guard.create_output, - ); - let expected_host_denial = if is_e2e_driver("podman") { - "HOST_DENIED=connect-denied" - } else { - "HOST_DENIED=403" - }; - assert!( - guard.create_output.contains(expected_host_denial), - "same placeholder must be denied at an unbound host:\n{}", - guard.create_output - ); - assert!( - guard.create_output.contains("PATH_DENIED=403"), - "same placeholder must be denied at an unbound path on its bound host:\n{}", - guard.create_output - ); - - assert!( - logs.contains("openshell.provider_credential.endpoint_mismatch") - && logs.contains("credential_endpoint_mismatch"), - "OCSF logs should explain the endpoint-binding denial without secret material:\n{logs}" - ); - assert!( - !logs.contains("e2e-bound-secret") - && !logs.contains("e2e-provider-b-secret") - && !logs.contains("BOUND_TOKEN_A") - && !logs.contains("BOUND_TOKEN_B"), - "OCSF logs must not contain credential values or environment keys:\n{logs}" - ); - - guard.cleanup().await; - delete_provider(BINDING_PROVIDER_A_NAME).await; - delete_provider(BINDING_PROVIDER_B_NAME).await; - delete_provider_profile(BINDING_PROFILE_A_ID).await; - delete_provider_profile(BINDING_PROFILE_B_ID).await; -} diff --git a/e2e/rust/tests/live_policy_update.rs b/e2e/rust/tests/live_policy_update.rs deleted file mode 100644 index b6a35c8898..0000000000 --- a/e2e/rust/tests/live_policy_update.rs +++ /dev/null @@ -1,704 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! E2E tests for live policy updates on a running sandbox. -//! -//! Covers the full round-trip: -//! - Create sandbox with policy A -//! - Verify initial policy version via `policy get` -//! - Push same policy A again -> no version bump (idempotent) -//! - Push different policy B -> new version, `--wait` for sandbox to load it -//! - Verify policy history via `policy list` -//! -//! These tests replace the Python e2e tests `test_live_policy_update_and_logs` -//! and `test_live_policy_update_from_empty_network_policies`, which were flaky -//! due to hard-coded 90s poll timeouts. The Rust tests use the CLI's built-in -//! `--wait` flag for reliable synchronization. -//! -//! Note: the removed Python tests also covered `GetSandboxLogs` RPC and -//! verified actual proxy connectivity after policy update. Those are tracked -//! as follow-up coverage gaps -- the proxy enforcement path is covered by the -//! existing L4/L7/SSRF Python e2e tests, and log fetching needs a dedicated -//! test. - -#![cfg(feature = "e2e")] - -use std::fmt::Write as _; -use std::io::Write; -use std::process::Stdio; - -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::output::{extract_field, strip_ansi}; -use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::NamedTempFile; - -const SPARSE_POLICY: &str = include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/../../examples/policy-advisor/sandbox-policy.yaml" -)); - -// --------------------------------------------------------------------------- -// Policy YAML builders -// --------------------------------------------------------------------------- - -/// Build a policy YAML that allows any binary to reach the given hosts on -/// port 443. Keep its filesystem paths aligned with the empty-network policy -/// so live network updates do not remove startup filesystem access. -/// -/// NOTE: The indentation in the format string is load-bearing YAML structure. -fn write_policy(hosts: &[&str]) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - - let mut network_rules = String::new(); - for (i, host) in hosts.iter().enumerate() { - let _ = write!( - network_rules, - r#" rule_{i}: - name: rule_{i} - endpoints: - - host: {host} - port: 443 - binaries: - - path: "/**" -"# - ); - } - - let policy = format!( - r"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /bin - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -network_policies: -{network_rules}" - ); - - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -/// Build a minimal policy YAML with no network rules. Both /bin and /usr -/// are readable so shell entrypoints work on merged and unmerged images. -fn write_empty_network_policy() -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - - let policy = r"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /bin - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort -"; - - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -fn write_sparse_policy() -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - file.write_all(SPARSE_POLICY.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -// --------------------------------------------------------------------------- -// CLI helpers -// --------------------------------------------------------------------------- - -struct CliResult { - success: bool, - output: String, - exit_code: Option, -} - -/// Run an `openshell` CLI command and return the result. -async fn run_cli(args: &[&str]) -> CliResult { - let mut cmd = openshell_cmd(); - cmd.args(args).stdout(Stdio::piped()).stderr(Stdio::piped()); - - let output = cmd.output().await.expect("spawn openshell command"); - let stdout = String::from_utf8_lossy(&output.stdout).to_string(); - let stderr = String::from_utf8_lossy(&output.stderr).to_string(); - let combined = strip_ansi(&format!("{stdout}{stderr}")); - - CliResult { - success: output.status.success(), - output: combined, - exit_code: output.status.code(), - } -} - -/// Extract the policy version number from `policy get` output. -/// -/// Uses the shared `extract_field` helper to find `Version: ` or -/// `Revision: ` in CLI tabular output. -fn extract_version(output: &str) -> Option { - extract_field(output, "Version") - .or_else(|| extract_field(output, "Revision")) - .and_then(|v| v.parse::().ok()) -} - -/// Extract the policy hash from `policy get` output. -fn extract_hash(output: &str) -> Option { - extract_field(output, "Hash").or_else(|| extract_field(output, "Policy hash")) -} - -/// Check that a version number appears in `policy list` output as a -/// distinct field value (not just a substring of some other number). -/// -/// Looks for the version number preceded by whitespace or at the start -/// of a line, to avoid matching "2" inside "12" or timestamps. -fn list_output_contains_version(output: &str, version: u32) -> bool { - let v = version.to_string(); - output.lines().any(|line| { - line.split_whitespace() - .any(|word| word == v || word.starts_with(&format!("{v} "))) - }) -} - -// --------------------------------------------------------------------------- -// Tests -// --------------------------------------------------------------------------- - -/// Read the effective policy through the same CLI boundary used by operators. -async fn l7_scope_snapshot(name: &str) -> serde_json::Value { - let result = run_cli(&["policy", "get", name, "--full", "--output", "json"]).await; - assert!(result.success, "policy snapshot failed: {}", result.output); - let snapshot: serde_json::Value = - serde_json::from_str(&result.output).expect("policy get returns JSON"); - assert!(snapshot["version"].as_u64().is_some()); - assert!( - snapshot["hash"] - .as_str() - .is_some_and(|hash| !hash.is_empty()) - ); - assert!(snapshot["policy"]["network_policies"].is_object()); - snapshot -} - -/// Incomplete declarations reject without a revision; an explicit target -/// changes only its endpoint even when another rule shares the host and ports. -#[tokio::test] -#[allow(clippy::too_many_lines)] -async fn l7_append_target_scope_round_trip() { - let mut policy = write_empty_network_policy().expect("write base policy"); - policy - .write_all( - br" -network_policies: - internal_api: - name: internal_api - binaries: - - path: /usr/bin/curl - - path: /usr/bin/python3 - endpoints: - - host: api.example.com - ports: [443, 8443] - protocol: rest - access: read-only - - host: other.example.com - port: 443 - protocol: rest - access: read-only - sibling: - name: sibling - binaries: - - path: /usr/bin/wget - endpoints: - - host: api.example.com - ports: [443, 8443] - protocol: rest - access: read-only -", - ) - .expect("write scoped policy"); - policy.flush().expect("flush scoped policy"); - let path = policy.path().to_str().expect("UTF-8 policy path"); - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", path, "--no-tty"], - &["sh", "-c", "echo Ready && sleep infinity"], - "Ready", - ) - .await - .expect("create scoped-policy sandbox"); - let before = l7_scope_snapshot(&guard.name).await; - - // Check each independent axis with the other fully declared, so a guard - // requiring both mismatches at once cannot satisfy this regression. - for (ports, binaries) in [ - ( - "api.example.com:443:POST:/admin", - vec!["/usr/bin/curl", "/usr/bin/python3"], - ), - ( - "api.example.com:443,8443:POST:/admin", - vec!["/usr/bin/curl"], - ), - ] { - let mut args = vec![ - "policy", - "update", - &guard.name, - "--rule-name", - "internal_api", - "--add-allow", - ports, - ]; - for binary in binaries { - args.extend(["--binary", binary]); - } - let rejected = run_cli(&args).await; - assert!( - !rejected.success, - "partial scope was accepted: {}", - rejected.output - ); - let unchanged = l7_scope_snapshot(&guard.name).await; - for field in ["version", "hash", "policy"] { - assert_eq!(unchanged[field], before[field], "rejection changed {field}"); - } - } - - let common = [ - "policy", - "update", - &guard.name, - "--rule-name", - "internal_api", - "--binary", - "/usr/bin/curl", - "--binary", - "/usr/bin/python3", - ]; - let mut allow_args = common.to_vec(); - allow_args.extend([ - "--add-allow", - "api.example.com:443,8443:POST:/admin", - "--wait", - ]); - let accepted = run_cli(&allow_args).await; - assert!( - accepted.success, - "explicit allow failed: {}", - accepted.output - ); - let after_allow = l7_scope_snapshot(&guard.name).await; - assert!(after_allow["version"].as_u64() > before["version"].as_u64()); - assert_ne!(after_allow["hash"], before["hash"]); - let rules = &after_allow["policy"]["network_policies"]; - assert_eq!( - rules["sibling"], - before["policy"]["network_policies"]["sibling"] - ); - assert_eq!( - rules["internal_api"]["endpoints"][1], - before["policy"]["network_policies"]["internal_api"]["endpoints"][1] - ); - assert!( - rules["internal_api"]["endpoints"][0]["rules"] - .as_array() - .expect("allow rules") - .iter() - .any(|rule| rule["allow"]["method"] == "POST" && rule["allow"]["path"] == "/admin") - ); - - let mut deny_args = common.to_vec(); - deny_args.extend([ - "--add-deny", - "api.example.com:443,8443:POST:/admin/private", - "--wait", - ]); - let denied = run_cli(&deny_args).await; - assert!(denied.success, "explicit deny failed: {}", denied.output); - let after_deny = l7_scope_snapshot(&guard.name).await; - assert!(after_deny["version"].as_u64() > after_allow["version"].as_u64()); - assert_eq!( - after_deny["policy"]["network_policies"]["sibling"], - before["policy"]["network_policies"]["sibling"] - ); - assert!( - after_deny["policy"]["network_policies"]["internal_api"]["endpoints"][0]["deny_rules"] - .as_array() - .expect("deny rules") - .iter() - .any(|rule| rule["method"] == "POST" && rule["path"] == "/admin/private") - ); - guard.cleanup().await; -} - -/// Test the full live policy update lifecycle: -/// -/// 1. Create sandbox with policy A and `--keep` -/// 2. Verify initial version >= 1 -/// 3. Push same policy A -> version unchanged (idempotent) -/// 4. Push policy B (adds example.com) with `--wait` -> new version -/// 5. Push policy B again -> idempotent -/// 6. Verify policy list shows both versions -#[tokio::test] -#[allow(clippy::too_many_lines)] -async fn live_policy_update_round_trip() { - // --- Write two distinct policy files --- - let policy_a = write_policy(&["api.anthropic.com"]).expect("write policy A"); - let policy_b = write_policy(&["api.anthropic.com", "example.com"]).expect("write policy B"); - - let policy_a_path = policy_a - .path() - .to_str() - .expect("policy A path should be utf-8") - .to_string(); - let policy_b_path = policy_b - .path() - .to_str() - .expect("policy B path should be utf-8") - .to_string(); - - // --- Create a long-running sandbox with its startup-only policy fields --- - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &policy_a_path, "--no-tty"], - &["sh", "-c", "echo Ready && sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox with policy A"); - - // --- Verify initial policy version --- - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!( - r.success, - "policy get should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - let initial_version = extract_version(&r.output).unwrap_or_else(|| { - panic!( - "could not parse version from policy get output:\n{}", - r.output - ) - }); - assert!( - initial_version >= 1, - "initial policy version should be >= 1, got {initial_version}" - ); - - let initial_hash = extract_hash(&r.output); - - // --- Push same policy A again -> should be idempotent --- - let r = run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &policy_a_path, - "--wait", - "--timeout", - "120", - ]) - .await; - assert!( - r.success, - "policy set A (repeat) should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!( - r.success, - "policy get after repeat should succeed:\n{}", - r.output - ); - - let repeat_version = extract_version(&r.output) - .unwrap_or_else(|| panic!("could not parse version after repeat:\n{}", r.output)); - assert_eq!( - repeat_version, initial_version, - "same policy should not bump version: expected {initial_version}, got {repeat_version}" - ); - - if let (Some(ih), Some(rh)) = (&initial_hash, &extract_hash(&r.output)) { - assert_eq!(ih, rh, "same policy should produce same hash"); - } - - // --- Push policy B -> should create new version --- - let r = run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &policy_b_path, - "--wait", - "--timeout", - "120", - ]) - .await; - assert!( - r.success, - "policy set B should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!( - r.success, - "policy get after B should succeed:\n{}", - r.output - ); - - let new_version = extract_version(&r.output) - .unwrap_or_else(|| panic!("could not parse version after B:\n{}", r.output)); - assert!( - new_version > initial_version, - "different policy should bump version: expected > {initial_version}, got {new_version}" - ); - - if let (Some(ih), Some(nh)) = (&initial_hash, &extract_hash(&r.output)) { - assert_ne!(ih, nh, "different policy should produce different hash"); - } - - // --- Push policy B again -> idempotent --- - let r = run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &policy_b_path, - "--wait", - "--timeout", - "120", - ]) - .await; - assert!( - r.success, - "policy set B (repeat) should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!( - r.success, - "policy get after B repeat should succeed:\n{}", - r.output - ); - - let repeat_b_version = extract_version(&r.output) - .unwrap_or_else(|| panic!("could not parse version after B repeat:\n{}", r.output)); - assert_eq!( - repeat_b_version, new_version, - "same policy B should not bump version: expected {new_version}, got {repeat_b_version}" - ); - - // --- Verify policy list shows revision history --- - let r = run_cli(&["policy", "list", &guard.name]).await; - assert!( - r.success, - "policy list should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - // Both versions should appear in the list output. - assert!( - list_output_contains_version(&r.output, new_version), - "policy list should contain version {new_version}:\n{}", - r.output - ); - assert!( - list_output_contains_version(&r.output, initial_version), - "policy list should contain initial version {initial_version}:\n{}", - r.output - ); - - guard.cleanup().await; -} - -/// Test live policy update from an initially empty network policy: -/// -/// 1. Create sandbox with no network rules and `--keep` -/// 2. Push policy with a network rule using `--wait` -/// 3. Verify the version bumped -#[tokio::test] -async fn live_policy_update_from_empty_network_policies() { - let empty_policy = write_empty_network_policy().expect("write empty network policy"); - let full_policy = write_policy(&["example.com"]).expect("write full policy"); - - let empty_path = empty_policy - .path() - .to_str() - .expect("empty policy path should be utf-8") - .to_string(); - let full_path = full_policy - .path() - .to_str() - .expect("full policy path should be utf-8") - .to_string(); - - // Create the sandbox with the empty network policy so subsequent live - // updates retain the same startup-only filesystem, landlock, and process - // fields. - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &empty_path, "--no-tty"], - &["sh", "-c", "echo Ready && sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox with empty network policy"); - - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!( - r.success, - "policy get (empty) should succeed:\n{}", - r.output - ); - - let initial_version = extract_version(&r.output) - .unwrap_or_else(|| panic!("could not parse version from empty policy:\n{}", r.output)); - - // Push policy with network rules. - let r = run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &full_path, - "--wait", - "--timeout", - "120", - ]) - .await; - assert!( - r.success, - "policy set (full) should succeed (exit {:?}):\n{}", - r.exit_code, r.output - ); - - let r = run_cli(&["policy", "get", &guard.name]).await; - assert!(r.success, "policy get (full) should succeed:\n{}", r.output); - - let new_version = extract_version(&r.output).unwrap_or_else(|| { - panic!( - "could not parse version after adding network rules:\n{}", - r.output - ) - }); - assert!( - new_version > initial_version, - "adding network rules should create new version > {initial_version}, got {new_version}" - ); - - guard.cleanup().await; -} - -/// Regression for #2159: a sparse initial policy that the supervisor enriches -/// with baseline filesystem paths during startup must have its resulting -/// revision acknowledged as loaded, not left `Pending`. -/// -/// Reproduction (matches the maintainer's triage): create a sandbox with the -/// network-only `examples/policy-advisor/sandbox-policy.yaml`. The supervisor -/// adds baseline filesystem paths, syncs the enriched policy back to the -/// gateway (creating revision 2, superseding revision 1), builds the OPA engine -/// and then acknowledges revision 2 as loaded. Before the fix, revision 2 -/// stayed `Pending` even though the sandbox was `Ready` and the policy was -/// effective. -/// -/// NOTE: This exercises the Docker-backed supervisor built from this branch. -/// The exact `policy list` status wording ("Loaded"/"Superseded") may differ by -/// CLI version; the assertions below key on the effective version reaching 2 and -/// no revision remaining `Pending` once the acknowledgement lands. -#[tokio::test] -async fn initial_sparse_policy_is_acknowledged_as_loaded() { - let sparse_policy = write_sparse_policy().expect("write sparse policy fixture"); - let sparse_policy_path = sparse_policy - .path() - .to_str() - .expect("sparse policy path is not UTF-8"); - - let mut guard = SandboxGuard::create_keep_with_args( - &[ - "--name", - "e2e-sparse-enrich", - "--policy", - sparse_policy_path, - "--no-tty", - ], - &["sh", "-c", "echo Ready && sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox with sparse policy"); - - // The enriched revision (2) is synced during startup; the acknowledgement - // (LOADED) is delivered by the supervisor's poll loop shortly after Ready. - // Poll until the effective policy is version 2 and no revision is Pending. - let mut acknowledged = false; - let mut last_list = String::new(); - for _ in 0..30 { - let get = run_cli(&["policy", "get", &guard.name]).await; - let version = get.success.then(|| extract_version(&get.output)).flatten(); - - let list = run_cli(&["policy", "list", &guard.name]).await; - last_list = list.output.clone(); - let pending = list.output.to_lowercase().contains("pending"); - - if version == Some(2) && list.success && !pending { - acknowledged = true; - break; - } - tokio::time::sleep(std::time::Duration::from_secs(2)).await; - } - - assert!( - acknowledged, - "enriched initial policy should reach revision 2 with no Pending revision.\n\ - last `policy list` output:\n{last_list}" - ); - - // Both the superseded original (1) and the loaded enriched revision (2) - // must appear in the revision history. - assert!( - list_output_contains_version(&last_list, 2), - "policy list should contain revision 2:\n{last_list}" - ); - assert!( - list_output_contains_version(&last_list, 1), - "policy list should contain revision 1:\n{last_list}" - ); - - guard.cleanup().await; -} diff --git a/e2e/rust/tests/mcp_sessionless.rs b/e2e/rust/tests/mcp_sessionless.rs deleted file mode 100644 index bf2261efa1..0000000000 --- a/e2e/rust/tests/mcp_sessionless.rs +++ /dev/null @@ -1,381 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! MCP request profiles through the sandbox's transparent network interception. -//! -//! A shared fixture serves legacy initialization, sessionless discovery, named -//! tools, and a bounded subscription stream. Upstream receipts distinguish a -//! policy denial from a tool request accepted by the fixture. - -#![cfg(feature = "e2e-host-gateway")] - -use std::io::Write; - -use openshell_e2e::harness::container::ContainerHttpServer; -use openshell_e2e::harness::sandbox::SandboxGuard; -use tempfile::NamedTempFile; - -const SERVER_ALIAS: &str = "mcp-sessionless.openshell.test"; - -const SERVER_SCRIPT: &str = r#" -import json -from http.server import BaseHTTPRequestHandler, HTTPServer - -SESSIONLESS_VERSION = "2026-07-28" -received = [] - -class Handler(BaseHTTPRequestHandler): - def reply(self, status, payload, content_type="application/json"): - self.send_response(status) - self.send_header("Content-Type", content_type) - self.send_header("Content-Length", str(len(payload))) - self.end_headers() - self.wfile.write(payload) - - def do_GET(self): - # The container fixture's readiness probe uses the root URL. - self.reply(200 if self.path == "/" else 405, b"") - - def read_body(self): - if self.headers.get("Transfer-Encoding", "").lower() != "chunked": - return self.rfile.read(int(self.headers.get("Content-Length", "0"))) - body = bytearray() - while True: - size = int(self.rfile.readline().split(b";", 1)[0].strip(), 16) - if size == 0: - while self.rfile.readline().strip(): - pass - return bytes(body) - body.extend(self.rfile.read(size)) - self.rfile.read(2) - - def do_POST(self): - message = json.loads(self.read_body()) - method = message["method"] - params = message.get("params", {}) - version = (params.get("protocolVersion") if method == "initialize" - else self.headers.get("MCP-Protocol-Version")) - # Record parsed requests before fixture admission so rejected revisions - # and tool attempts stay visible. HTTPServer handles requests serially. - received.append([version, method, params.get("name")]) - if self.path != "/mcp" or version not in SUPPORTED_VERSIONS: - self.reply(400, b"request revision did not reach the fixture intact") - return - if version == SESSIONLESS_VERSION: - meta = params.get("_meta", {}) - if (self.headers.get("MCP-Protocol-Version") != version - or self.headers.get("Mcp-Method") != method - or meta.get("io.modelcontextprotocol/protocolVersion") != version - or meta.get("io.modelcontextprotocol/clientCapabilities") != {} - or (method == "tools/call" - and self.headers.get("Mcp-Name") != params["name"])): - self.reply(400, b"request metadata did not reach the fixture intact") - return - - if method == "initialize" and version != SESSIONLESS_VERSION: - result = { - "protocolVersion": version, - "capabilities": {"tools": {}}, - "serverInfo": {"name": "openshell-profile-fixture", "version": "1"}, - } - elif method == "notifications/initialized" and version != SESSIONLESS_VERSION: - self.reply(202, b"") - return - elif method == "server/discover" and version == SESSIONLESS_VERSION: - result = { - "supportedVersions": [version], - "capabilities": {"tools": {"listChanged": True}}, - "ttlMs": 0, - "cacheScope": "private", - "_meta": { - "io.modelcontextprotocol/serverInfo": { - "name": "openshell-sessionless-fixture", "version": "1" - } - }, - } - elif method == "tools/call": - # Both tool names work upstream; OpenShell owns the policy denial. - result = { - "content": [{"type": "text", "text": params["name"]}], - "isError": False, - "_meta": {"fixtureRequests": list(received)}, - } - if version == SESSIONLESS_VERSION: - result["resultType"] = "complete" - elif method == "subscriptions/listen" and version == SESSIONLESS_VERSION: - subscription_meta = {"io.modelcontextprotocol/subscriptionId": message["id"]} - events = [ - { - "jsonrpc": "2.0", - "method": "notifications/subscriptions/acknowledged", - "params": {"notifications": params["notifications"], "_meta": subscription_meta}, - }, - { - "jsonrpc": "2.0", - "method": "notifications/tools/list_changed", - "params": {"_meta": subscription_meta}, - }, - { - "jsonrpc": "2.0", - "id": message["id"], - "result": {"resultType": "complete", "_meta": subscription_meta}, - }, - ] - body = "".join("event: message\ndata: " + json.dumps(event) + "\n\n" for event in events) - self.reply(200, body.encode(), "text/event-stream") - return - else: - self.reply(400, b"unexpected method for the selected fixture revision") - return - - self.reply(200, json.dumps({"jsonrpc": "2.0", "id": message["id"], "result": result}).encode()) - - def log_message(self, format, *args): - pass - -HTTPServer(("0.0.0.0", 8000), Handler).serve_forever() -"#; - -const CLIENT_HELPERS: &str = r#" -import json -import urllib.error -import urllib.request -# Direct client connections pass through the sandbox's transparent interception. -opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) - -def post(request_id, method, params, version): - params = dict(params) - headers = { - "Content-Type": "application/json", - "Accept": "application/json, text/event-stream", - } - if method != "initialize": - headers["MCP-Protocol-Version"] = version - if version == "2026-07-28": - params["_meta"] = { - "io.modelcontextprotocol/protocolVersion": version, - "io.modelcontextprotocol/clientCapabilities": {}, - "io.modelcontextprotocol/clientInfo": {"name": "openshell-e2e", "version": "1"}, - } - headers["Mcp-Method"] = method - if method == "tools/call": - headers["Mcp-Name"] = params["name"] - message = {"jsonrpc": "2.0", "method": method, "params": params} - if request_id is not None: - message["id"] = request_id - request = urllib.request.Request( - f"http://{HOST}:{PORT}/mcp", - data=json.dumps(message).encode(), - headers=headers, - method="POST", - ) - try: - with opener.open(request, timeout=15) as response: - return response.status, response.headers.get_content_type(), response.read() - except urllib.error.HTTPError as error: - return error.code, error.headers.get_content_type(), error.read() -"#; - -const CLIENT_SCRIPT: &str = r#" -VERSION = "2026-07-28" - -status, content_type, body = post(1, "server/discover", {}, VERSION) -assert status == 200, ("discovery", status, body) -assert content_type == "application/json", content_type -discovery = json.loads(body) -assert discovery["id"] == 1, discovery -assert discovery["result"]["supportedVersions"] == [VERSION], discovery - -status, _, body = post(2, "tools/call", {"name": "read_status", "arguments": {}}, VERSION) -assert status == 200, ("allowed tool", status, body) -tool = json.loads(body) -assert tool["id"] == 2, tool -assert tool["result"]["content"] == [{"type": "text", "text": "read_status"}], tool - -status, _, body = post(3, "tools/call", {"name": "read_details", "arguments": {}}, VERSION) -assert status == 403, ("denied tool", status, body) - -status, content_type, body = post(4, "subscriptions/listen", {"notifications": {"toolsListChanged": True}}, VERSION) -assert status == 200, ("subscription", status, body) -assert content_type == "text/event-stream", (content_type, body) -events = [json.loads(line[6:]) for line in body.decode().splitlines() if line.startswith("data: ")] -assert len(events) == 3, events -assert events[0]["method"] == "notifications/subscriptions/acknowledged", events -assert events[0]["params"]["notifications"] == {"toolsListChanged": True}, events -assert events[1]["method"] == "notifications/tools/list_changed", events -assert events[1]["params"]["_meta"]["io.modelcontextprotocol/subscriptionId"] == 4, events -assert events[2]["id"] == 4 and events[2]["result"]["resultType"] == "complete", events - -print("MCP_SESSIONLESS_OK discovery=200 allowed_tool=200 denied_tool=403 subscription=200") -"#; - -const PROFILE_CLIENT_SCRIPT: &str = r#" -expected_receipts = [] -for version in SELECTED_VERSIONS: - if version == "2026-07-28": - status, _, body = post(1, "server/discover", {}, version) - assert status == 200, (version, "discovery", status, body) - assert json.loads(body)["result"]["supportedVersions"] == [version], body - expected_receipts.append([version, "server/discover", None]) - else: - status, _, body = post(1, "initialize", { - "protocolVersion": version, - "capabilities": {}, - "clientInfo": {"name": "openshell-e2e", "version": "1"}, - }, version) - assert status == 200, (version, "initialize", status, body) - assert json.loads(body)["result"]["protocolVersion"] == version, body - expected_receipts.append([version, "initialize", None]) - status, _, body = post(None, "notifications/initialized", {}, version) - assert status == 202, (version, "initialized", status, body) - expected_receipts.append([version, "notifications/initialized", None]) - - status, _, body = post(2, "tools/call", {"name": "read_status", "arguments": {}}, version) - assert status == 200, (version, "allowed tool", status, body) - tool = json.loads(body) - assert tool["id"] == 2, tool - assert tool["result"]["content"] == [{"type": "text", "text": "read_status"}], tool - expected_receipts.append([version, "tools/call", "read_status"]) - assert tool["result"]["_meta"]["fixtureRequests"] == expected_receipts, tool - - status, _, body = post(3, "tools/call", {"name": "read_details", "arguments": {}}, version) - assert status == 403, (version, "denied tool", status, body) - - # The fixture accepts both tools. A later allowed call proves the denial - # came from the proxy and no denied operation reached the upstream. - status, _, body = post(4, "tools/call", {"name": "read_status", "arguments": {}}, version) - assert status == 200, (version, "receipt tool", status, body) - receipt = json.loads(body) - assert receipt["id"] == 4, receipt - expected_receipts.append([version, "tools/call", "read_status"]) - assert receipt["result"]["_meta"]["fixtureRequests"] == expected_receipts, receipt - print(f"MCP_PROFILE_OK version={version} allowed_tool=200 denied_tool=403 receipts=verified") -"#; - -async fn start_server(alias: &str, versions: &[&str]) -> Result { - let versions = serde_json::to_string(versions).map_err(|err| err.to_string())?; - let script = format!("SUPPORTED_VERSIONS = {versions}\n{SERVER_SCRIPT}"); - ContainerHttpServer::start_python(alias, &script).await -} - -fn write_policy(host: &str, port: u16, versions: &[&str]) -> Result { - let mut file = NamedTempFile::new().map_err(|err| format!("create temp policy: {err}"))?; - let legacy_rules = if versions.iter().any(|version| *version != "2026-07-28") { - " - allow:\n method: initialize\n - allow:\n method: notifications/initialized\n" - } else { - "" - }; - let versions = serde_json::to_string(versions).map_err(|err| err.to_string())?; - let policy = format!( - r#"version: 1 -filesystem_policy: - include_workdir: true - read_only: [/usr, /lib, /proc, /dev/urandom, /app, /etc, /var/log] - read_write: [/sandbox, /tmp, /dev/null] -landlock: - compatibility: best_effort -process: - run_as_user: sandbox - run_as_group: sandbox -network_policies: - mcp_sessionless: - name: mcp_sessionless - endpoints: - - host: {host} - port: {port} - path: /mcp - protocol: mcp - enforcement: enforce - allowed_ips: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7"] - mcp: - versions: {versions} - max_body_bytes: 65536 - rules: -{legacy_rules} - allow: - method: server/discover - - allow: - method: tools/call - tool: read_status - - allow: - method: subscriptions/listen - deny_rules: - - method: tools/call - tool: read_details - binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|err| format!("write temp policy: {err}"))?; - file.flush() - .map_err(|err| format!("flush temp policy: {err}"))?; - Ok(file) -} - -async fn run_client( - server: &ContainerHttpServer, - versions: &[&str], - client: &str, -) -> Result { - let policy = write_policy(&server.host, server.port, versions)?; - let policy_path = policy - .path() - .to_str() - .ok_or("temp policy path is not UTF-8")?; - let selected_versions = serde_json::to_string(versions).map_err(|err| err.to_string())?; - let script = format!( - "HOST = {:?}\nPORT = {}\nSELECTED_VERSIONS = {selected_versions}\n{CLIENT_HELPERS}\n{client}", - server.host, server.port - ); - SandboxGuard::create(&["--policy", policy_path, "--", "python3", "-c", &script]).await -} - -#[tokio::test] -async fn sessionless_discovery_tools_and_subscription_use_request_metadata() { - let versions = ["2026-07-28"]; - let server = start_server(SERVER_ALIAS, &versions) - .await - .expect("start sessionless MCP fixture"); - let sandbox = run_client(&server, &versions, CLIENT_SCRIPT) - .await - .expect("run sessionless MCP client in sandbox"); - - assert!( - sandbox.create_output.contains( - "MCP_SESSIONLESS_OK discovery=200 allowed_tool=200 denied_tool=403 subscription=200" - ), - "expected completed sessionless MCP assertions, got:\n{}", - sandbox.create_output - ); -} - -#[tokio::test] -async fn legacy_and_multi_version_profiles_authorize_tools_through_sandbox() { - for versions in [ - &["2025-03-26"][..], - &["2025-06-18"][..], - &["2025-11-25", "2026-07-28"][..], - ] { - // Each scenario starts with fresh upstream receipts. Its distinct alias - // avoids the sessionless test's fixture, and cleanup precedes alias reuse. - let server = start_server("mcp-profiles.openshell.test", versions) - .await - .unwrap_or_else(|err| panic!("{versions:?}: start MCP fixture: {err}")); - let mut sandbox = run_client(&server, versions, PROFILE_CLIENT_SCRIPT) - .await - .unwrap_or_else(|err| panic!("{versions:?}: run MCP sandbox client: {err}")); - for version in versions { - let marker = format!( - "MCP_PROFILE_OK version={version} allowed_tool=200 denied_tool=403 receipts=verified" - ); - assert!( - sandbox.create_output.contains(&marker), - "{versions:?}: expected completed {version} assertions, got:\n{}", - sandbox.create_output - ); - } - sandbox.cleanup().await; - } -} diff --git a/e2e/rust/tests/ocsf_console.rs b/e2e/rust/tests/ocsf_console.rs deleted file mode 100644 index fbd2f6318b..0000000000 --- a/e2e/rust/tests/ocsf_console.rs +++ /dev/null @@ -1,160 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e-docker")] - -//! Full OCSF collection through supervisor stderr, without filesystem access. - -use std::time::Duration; - -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::sandbox::SandboxGuard; -use serde_json::Value; -use tokio::process::Command; -use tokio::time::{Instant, sleep}; - -async fn cli(args: &[&str]) -> String { - let output = openshell_cmd().args(args).output().await.unwrap(); - assert!( - output.status.success(), - "CLI failed: {}", - String::from_utf8_lossy(&output.stderr) - ); - format!( - "{}{}", - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ) -} - -async fn docker(args: &[&str]) -> (String, String) { - let output = Command::new("docker").args(args).output().await.unwrap(); - assert!( - output.status.success(), - "Docker failed: {}", - String::from_utf8_lossy(&output.stderr) - ); - ( - String::from_utf8_lossy(&output.stdout).into_owned(), - String::from_utf8_lossy(&output.stderr).into_owned(), - ) -} - -fn json_records(stderr: &str) -> Vec { - stderr - .lines() - .filter_map(|line| { - let (_, payload) = line.split_once(" OCSF-JSON ")?; - assert!(!payload.contains('\x1b')); - Some(serde_json::from_str(payload).expect("complete JSON record on one line")) - }) - .collect() -} - -#[tokio::test] -async fn network_events_are_json_on_supervisor_stderr_only() { - let mut sandbox = SandboxGuard::create(&["--from", "nvcr.io/nvidia/base/ubuntu:24.04"]) - .await - .expect("create sandbox"); - let filter = format!("label=openshell.ai/sandbox-name={}", sandbox.name); - let (containers, _) = docker(&[ - "ps", - "-q", - "--filter", - &filter, - "--filter", - "label=openshell.ai/isolation-role=supervisor", - ]) - .await; - let ids: Vec<_> = containers.lines().collect(); - assert_eq!(ids.len(), 1, "expected one supervisor: {containers}"); - let supervisor = ids[0]; - let (workload, _) = docker(&[ - "ps", - "-q", - "--filter", - &filter, - "--filter", - "label=openshell.ai/isolation-role=sandbox", - ]) - .await; - let workload_ids: Vec<_> = workload.lines().collect(); - assert_eq!(workload_ids.len(), 1, "expected one workload: {workload}"); - let (image_uid, _) = docker(&["inspect", "--format", "{{.Image}}", workload_ids[0]]).await; - let (_, before) = docker(&["logs", supervisor]).await; - assert!(json_records(&before).is_empty(), "JSON must be opt-in"); - - cli(&[ - "settings", - "set", - &sandbox.name, - "--key", - "ocsf_json_enabled", - "--value", - "true", - ]) - .await; - let started = Instant::now(); - let records = loop { - cli(&[ - "sandbox", - "exec", - &sandbox.name, - "--timeout", - "10", - "--", - "bash", - "-c", - "echo > /dev/tcp/1.1.1.1/443 || true", - ]) - .await; - let (stdout, stderr) = docker(&["logs", supervisor]).await; - assert!( - !stdout.contains(" OCSF-JSON "), - "audit JSON should be on stderr" - ); - let records = json_records(&stderr); - if records.iter().any(|record| { - record["class_uid"] == 4001 - && record["dst_endpoint"]["port"] == 443 - && record["action"] == "Denied" - }) { - assert!( - stderr.contains(" OCSF NET:OPEN "), - "shorthand remains available" - ); - break records; - } - assert!( - started.elapsed() < Duration::from_secs(40), - "no JSON network denial in stderr: {stderr}" - ); - sleep(Duration::from_secs(1)).await; - }; - for record in records { - assert_eq!(record["metadata"]["version"], "1.8.0"); - assert!( - record["metadata"]["uid"] - .as_str() - .is_some_and(|uid| !uid.is_empty()) - ); - assert_eq!(record["device"]["container"]["name"], sandbox.name); - assert_eq!( - record["device"]["container"]["image"]["uid"], - image_uid.trim() - ); - assert_eq!( - record["device"]["container"]["image"]["name"], - "nvcr.io/nvidia/base/ubuntu:24.04" - ); - } - // Allow the existing best-effort push batch to reach the gateway. - sleep(Duration::from_secs(2)).await; - let gateway_logs = cli(&["logs", &sandbox.name, "--source", "sandbox", "-n", "200"]).await; - assert!(gateway_logs.contains("NET:OPEN")); - assert!( - !gateway_logs.contains("OCSF-JSON"), - "gateway stream must remain unchanged" - ); - sandbox.cleanup().await; -} diff --git a/e2e/rust/tests/podman_resource_limits.rs b/e2e/rust/tests/podman_resource_limits.rs deleted file mode 100644 index 225f77ff8f..0000000000 --- a/e2e/rust/tests/podman_resource_limits.rs +++ /dev/null @@ -1,89 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e-podman")] - -//! Podman-specific E2E coverage verifying that declared sandbox CPU/memory -//! resource limits are actually enforced by cgroups inside the workload, not -//! just echoed back by the API/template layer. -//! -//! The conformance `templates` suite already verifies that -//! `sandbox template create --cpu ... --memory ...` is stored and returned -//! correctly, but it never inspects the resulting container's real resource -//! state. This test creates a sandbox with those flags directly and reads the -//! cgroup v2 interface files from inside the sandbox itself, so it exercises -//! the actual enforcement boundary the workload experiences. - -use openshell_e2e::harness::sandbox::SandboxGuard; - -const CGROUP_READ_POLICY: &str = r"version: 1 -filesystem_policy: - include_workdir: true - read_only: [/usr, /lib, /lib64, /proc, /etc, /sys/fs/cgroup] - read_write: [/sandbox, /tmp, /dev/null] -landlock: - compatibility: best_effort -network_policies: {} -"; - -const CPU_REQUEST: &str = "500m"; -const MEMORY_REQUEST: &str = "512Mi"; - -// "500m" (500 millicores) becomes a 50000us quota over Podman's 100000us -// (100ms) CFS period — see -// crates/openshell-driver-podman/src/container.rs's parse_cpu_to_microseconds. -// Verified directly against a real `podman run --cpus=0.5` container, whose -// cpu.max reads "50000 100000". -const EXPECTED_CPU_MAX: &str = "50000 100000"; - -// "512Mi" (mebibytes) becomes exactly 512 * 1024 * 1024 bytes — see -// crates/openshell-driver-podman/src/container.rs's parse_memory_to_bytes. -// Verified directly against a real `podman run --memory=512m` container, -// whose memory.max reads "536870912". -const EXPECTED_MEMORY_MAX: &str = "536870912"; - -#[tokio::test] -async fn sandbox_resource_limits_are_enforced_via_cgroups() { - if std::env::var("OPENSHELL_E2E_DRIVER").as_deref() != Ok("podman") { - eprintln!("Skipping Podman resource-limit test: e2e driver is not podman"); - return; - } - - let policy = tempfile::NamedTempFile::new().expect("create cgroup read policy file"); - std::fs::write(policy.path(), CGROUP_READ_POLICY).expect("write cgroup read policy"); - let policy_path = policy.path().to_str().expect("policy path is UTF-8"); - let mut sandbox = SandboxGuard::create(&[ - "--cpu", - CPU_REQUEST, - "--memory", - MEMORY_REQUEST, - "--policy", - policy_path, - ]) - .await - .expect("sandbox create with resource limits should succeed"); - - let memory_max = sandbox - .exec(&["cat", "/sys/fs/cgroup/memory.max"]) - .await - .expect("read memory.max from sandbox cgroup") - .trim() - .to_string(); - assert_eq!( - memory_max, EXPECTED_MEMORY_MAX, - "sandbox cgroup should enforce the declared {MEMORY_REQUEST} memory limit, got {memory_max}" - ); - - let cpu_max = sandbox - .exec(&["cat", "/sys/fs/cgroup/cpu.max"]) - .await - .expect("read cpu.max from sandbox cgroup") - .trim() - .to_string(); - assert_eq!( - cpu_max, EXPECTED_CPU_MAX, - "sandbox cgroup should enforce the declared {CPU_REQUEST} CPU limit, got {cpu_max}" - ); - - sandbox.cleanup().await; -} diff --git a/e2e/rust/tests/port_forward.rs b/e2e/rust/tests/port_forward.rs deleted file mode 100644 index e91919d177..0000000000 --- a/e2e/rust/tests/port_forward.rs +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e")] - -//! E2E test: TCP port forwarding through a sandbox. -//! -//! Prerequisites: -//! - A running openshell gateway (`mise run gateway:docker`) -//! - The `openshell` binary (built automatically from the workspace) - -use std::time::Duration; - -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::net::TcpStream; - -use openshell_e2e::harness::port::{find_free_port, wait_for_port}; -use openshell_e2e::harness::sandbox::SandboxGuard; - -/// Python script that runs a single-threaded TCP echo server inside the -/// sandbox. It prints `echo-server-ready` to stdout once listening, which -/// the harness uses as the readiness marker. -fn echo_server_script(port: u16) -> String { - format!( - r" -import socket, sys, signal -signal.signal(signal.SIGHUP, signal.SIG_IGN) -signal.signal(signal.SIGTERM, lambda *_: sys.exit(0)) -port = {port} -sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -sock.bind(('127.0.0.1', port)) -sock.listen(1) -sock.settimeout(300) -print('echo-server-ready', flush=True) -try: - while True: - conn, _ = sock.accept() - data = conn.recv(4096) - if data: - conn.sendall(b'echo:' + data) - conn.close() -except (socket.timeout, OSError): - pass -finally: - sock.close() -" - ) -} - -/// Create a sandbox with a TCP echo server, forward the port locally, send -/// data through it, and verify the echoed response. -#[tokio::test] -async fn port_forward_echo() { - let port = find_free_port(); - let script = echo_server_script(port); - - // --------------------------------------------------------------- - // Step 1 — Create a sandbox with the echo server running. - // --------------------------------------------------------------- - let mut guard = SandboxGuard::create_keep(&["python3", "-c", &script], "echo-server-ready") - .await - .expect("sandbox create with echo server"); - - // --------------------------------------------------------------- - // Step 2 — Start port forwarding in the background. - // --------------------------------------------------------------- - let mut forward_child = guard.spawn_forward(port).expect("spawn port forward"); - - // Wait for the local port to accept connections. - wait_for_port("127.0.0.1", port, Duration::from_secs(30)) - .await - .expect("local port should open for forwarding"); - - // Give the SSH tunnel a moment to fully establish the direct-tcpip channel. - tokio::time::sleep(Duration::from_secs(2)).await; - - // --------------------------------------------------------------- - // Step 3 — Send data through the forwarded port and verify response. - // --------------------------------------------------------------- - let expected = "echo:hello-nav"; - let mut last_response = String::new(); - - for attempt in 1..=5 { - match try_echo(port).await { - Ok(resp) if resp.starts_with(expected) => { - last_response = resp; - break; - } - Ok(resp) => { - last_response = resp; - eprintln!("attempt {attempt}: unexpected response '{last_response}', retrying..."); - } - Err(e) => { - eprintln!("attempt {attempt}: connection error: {e}, retrying..."); - } - } - tokio::time::sleep(Duration::from_secs(2)).await; - } - - assert!( - last_response.starts_with(expected), - "expected response starting with '{expected}', got '{last_response}'" - ); - - // --------------------------------------------------------------- - // Cleanup — kill forward process, then sandbox guard handles the rest. - // --------------------------------------------------------------- - let _ = forward_child.kill().await; - let _ = forward_child.wait().await; - guard.cleanup().await; -} - -/// Attempt to send `hello-nav\n` to the echo server and read the response. -#[allow( - clippy::disallowed_methods, - reason = "the e2e workspace does not depend on openshell-core" -)] -async fn try_echo(port: u16) -> Result { - let mut stream = TcpStream::connect(format!("127.0.0.1:{port}")) - .await - .map_err(|e| format!("connect: {e}"))?; - - stream - .write_all(b"hello-nav\n") - .await - .map_err(|e| format!("write: {e}"))?; - - let mut buf = vec![0u8; 4096]; - let n = tokio::time::timeout(Duration::from_secs(10), stream.read(&mut buf)) - .await - .map_err(|_| "read timeout".to_string())? - .map_err(|e| format!("read: {e}"))?; - - let response = String::from_utf8_lossy(&buf[..n]) - .trim_end_matches(['\r', '\n']) - .to_string(); - - Ok(response) -} diff --git a/e2e/rust/tests/proxy_egress_pipeline.rs b/e2e/rust/tests/proxy_egress_pipeline.rs deleted file mode 100644 index 09eda47615..0000000000 --- a/e2e/rust/tests/proxy_egress_pipeline.rs +++ /dev/null @@ -1,1683 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e")] - -//! E2E coverage for the transparent sandbox egress pipeline. -//! -//! Workloads connect directly to their requested destinations. Seccomp -//! notification diverts those sockets to the supervisor without proxy -//! environment variables or explicit CONNECT requests. These tests cover: -//! - live policy reloads affect new requests and close a pre-existing HTTP -//! stream before its next request is forwarded; -//! - `tls: skip` selects a byte-transparent TCP relay; -//! - provider placeholders in HTTP headers and opted-in REST bodies are -//! resolved without appearing in test output. - -use std::io::{self, Error, ErrorKind, Write}; -use std::process::Stdio; -use std::sync::{ - Arc, Mutex, - atomic::{AtomicUsize, Ordering}, -}; - -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::container::{SupportContainer, e2e_network_name}; -use openshell_e2e::harness::sandbox::SandboxGuard; -use serde_json::Value; -use serial_test::serial; -use tempfile::{Builder as TempFileBuilder, NamedTempFile}; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::net::{TcpListener, TcpStream}; -use tokio::task::JoinHandle; - -const TEST_SERVER_HOST: &str = "host.openshell.internal"; -const PROVIDER_NAME: &str = "e2e-proxy-egress-credentials"; -const PROVIDER_PROFILE_ID: &str = "e2e-proxy-egress-credentials"; -const TOKEN_ENV: &str = "PROXY_E2E_TOKEN"; -const TEST_SECRET: &str = "sk-e2e-proxy-egress-secret"; -const PLACEHOLDER_PREFIX: &str = "openshell:resolve:env:"; -const PRIVATE_ALLOWED_IPS: &str = r#" allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7""#; -static PROVIDER_LOCK: Mutex<()> = Mutex::new(()); - -async fn run_cli(args: &[&str]) -> Result { - let mut cmd = openshell_cmd(); - cmd.args(args).stdout(Stdio::piped()).stderr(Stdio::piped()); - - let output = cmd - .output() - .await - .map_err(|error| format!("failed to spawn openshell {}: {error}", args.join(" ")))?; - let stdout = String::from_utf8_lossy(&output.stdout); - let stderr = String::from_utf8_lossy(&output.stderr); - let combined = format!("{stdout}{stderr}"); - - if !output.status.success() { - return Err(format!( - "openshell {} failed (exit {:?}):\n{combined}", - args.join(" "), - output.status.code() - )); - } - - Ok(combined) -} - -async fn wait_for_sandbox_logs( - sandbox_name: &str, - expected: impl Fn(&str) -> bool, -) -> Result { - let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(10); - - loop { - let logs = run_cli(&[ - "logs", - sandbox_name, - "-n", - "500", - "--since", - "2m", - "--source", - "sandbox", - ]) - .await?; - if expected(&logs) { - return Ok(logs); - } - if tokio::time::Instant::now() >= deadline { - return Err(format!( - "timed out waiting for expected sandbox logs:\n{logs}" - )); - } - tokio::time::sleep(std::time::Duration::from_millis(250)).await; - } -} - -async fn delete_provider(name: &str) { - let mut cmd = openshell_cmd(); - cmd.args(["provider", "delete", name]) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - -async fn delete_provider_profile(id: &str) { - let mut cmd = openshell_cmd(); - cmd.args(["profile", "delete", id]) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - -async fn create_bound_provider(name: &str) -> Result { - let credential = format!("{TOKEN_ENV}={TEST_SECRET}"); - run_cli(&[ - "provider", - "create", - "--name", - name, - "--type", - PROVIDER_PROFILE_ID, - "--credential", - &credential, - ]) - .await -} - -fn write_credential_profile(port: u16) -> Result { - let mut file = TempFileBuilder::new() - .suffix(".yaml") - .tempfile() - .map_err(|error| format!("create provider profile: {error}"))?; - let profile = format!( - r#"id: {PROVIDER_PROFILE_ID} -display_name: E2E proxy egress credentials -category: other -credentials: - - name: proxy_e2e_token - env_vars: [{TOKEN_ENV}] - required: true - auth_style: bearer - header_name: authorization -endpoints: - - host: {TEST_SERVER_HOST} - port: {port} - path: /probe - protocol: rest - access: full - enforcement: enforce - request_body_credential_rewrite: true - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" -binaries: ["/**"] -"# - ); - file.write_all(profile.as_bytes()) - .map_err(|error| format!("write provider profile: {error}"))?; - file.flush() - .map_err(|error| format!("flush provider profile: {error}"))?; - Ok(file) -} - -fn write_policy_document( - host: &str, - port: u16, - endpoint_options: &str, - network_middlewares: &str, -) -> Result { - let mut file = NamedTempFile::new().map_err(|error| format!("create policy: {error}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -{network_middlewares} -network_policies: - proxy_egress_test: - name: proxy_egress_test - endpoints: - - host: {host} - port: {port} -{endpoint_options} -{PRIVATE_ALLOWED_IPS} - binaries: - - path: "/**" -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|error| format!("write policy: {error}"))?; - file.flush() - .map_err(|error| format!("flush policy: {error}"))?; - Ok(file) -} - -fn write_policy(host: &str, port: u16, endpoint_options: &str) -> Result { - write_policy_document(host, port, endpoint_options, "") -} - -fn write_middleware_policy( - host: &str, - port: u16, - endpoint_options: &str, - on_error: &str, -) -> Result { - let network_middlewares = format!( - r#"network_middlewares: - regex-redactor: - name: Redact API tokens - middleware: openshell/regex - order: 10 - config: - mode: redact - on_error: {on_error} - endpoints: - include: ["{host}"] - exclude: [] -"# - ); - write_policy_document(host, port, endpoint_options, &network_middlewares) -} - -fn write_denied_policy() -> Result { - let mut file = NamedTempFile::new().map_err(|error| format!("create policy: {error}"))?; - let policy = r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: {} -"#; - file.write_all(policy.as_bytes()) - .map_err(|error| format!("write policy: {error}"))?; - file.flush() - .map_err(|error| format!("flush policy: {error}"))?; - Ok(file) -} - -fn write_ambiguous_policy(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|error| format!("create policy: {error}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: [/usr, /lib, /proc, /dev/urandom, /app, /etc, /var/log] - read_write: [/sandbox, /tmp, /dev/null] - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - terminating: - name: terminating - endpoints: - - host: {host} - port: {port} -{PRIVATE_ALLOWED_IPS} - binaries: - - path: "/**" - passthrough: - name: passthrough - endpoints: - - host: {host} - port: {port} - tls: skip -{PRIVATE_ALLOWED_IPS} - binaries: - - path: "/**" -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|error| format!("write policy: {error}"))?; - file.flush() - .map_err(|error| format!("flush policy: {error}"))?; - Ok(file) -} - -fn write_destination_denial_policy() -> Result { - let mut file = NamedTempFile::new().map_err(|error| format!("create policy: {error}"))?; - let policy = r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: [/usr, /lib, /proc, /dev/urandom, /app, /etc, /var/log] - read_write: [/sandbox, /tmp, /dev/null] - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - destination_denials: - name: destination_denials - endpoints: - - { host: 169.254.169.254, port: 80 } - - { host: 127.0.0.1, port: 80 } - - { host: 203.0.113.10, port: 6443 } - - host: 203.0.113.10 - port: 8080 - allowed_ips: ["198.51.100.0/24"] - binaries: - - path: "/**" -"#; - file.write_all(policy.as_bytes()) - .map_err(|error| format!("write policy: {error}"))?; - file.flush() - .map_err(|error| format!("flush policy: {error}"))?; - Ok(file) -} - -fn write_ip_literal_success_policy( - explicit_ip: &str, - implicit_ip: &str, - port: u16, -) -> Result { - let mut file = NamedTempFile::new().map_err(|error| format!("create policy: {error}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: [/usr, /lib, /proc, /dev/urandom, /app, /etc, /var/log] - read_write: [/sandbox, /tmp, /dev/null] - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - destination_successes: - name: destination_successes - endpoints: - - host: {ip} - port: {port} - allowed_ips: ["{explicit_ip}/32"] - - host: {implicit_ip} - port: {port} - binaries: - - path: "/**" -"#, - ip = explicit_ip, - ); - file.write_all(policy.as_bytes()) - .map_err(|error| format!("write policy: {error}"))?; - file.flush() - .map_err(|error| format!("flush policy: {error}"))?; - Ok(file) -} - -fn policy_path(file: &NamedTempFile) -> String { - file.path() - .to_str() - .expect("temporary policy path should be utf-8") - .to_string() -} - -async fn read_until(stream: &mut TcpStream, marker: &[u8]) -> io::Result> { - let mut data = Vec::new(); - let mut buffer = [0_u8; 4096]; - loop { - let read = stream.read(&mut buffer).await?; - if read == 0 { - return Ok(data); - } - data.extend_from_slice(&buffer[..read]); - if data.windows(marker.len()).any(|window| window == marker) { - return Ok(data); - } - } -} - -fn header_end(bytes: &[u8]) -> Option { - bytes - .windows(4) - .position(|window| window == b"\r\n\r\n") - .map(|position| position + 4) -} - -fn content_length(headers: &[u8]) -> io::Result { - let text = - std::str::from_utf8(headers).map_err(|error| Error::new(ErrorKind::InvalidData, error))?; - Ok(text - .lines() - .find_map(|line| { - let (name, value) = line.split_once(':')?; - name.trim() - .eq_ignore_ascii_case("content-length") - .then(|| value.trim().parse::().ok()) - .flatten() - }) - .unwrap_or(0)) -} - -async fn read_http_request(stream: &mut TcpStream) -> io::Result>> { - let mut request = read_until(stream, b"\r\n\r\n").await?; - if request.is_empty() { - return Ok(None); - } - let headers_end = header_end(&request) - .ok_or_else(|| Error::new(ErrorKind::UnexpectedEof, "incomplete HTTP headers"))?; - let body_length = content_length(&request[..headers_end])?; - let total_length = headers_end + body_length; - while request.len() < total_length { - let mut buffer = vec![0_u8; total_length - request.len()]; - let read = stream.read(&mut buffer).await?; - if read == 0 { - return Err(Error::new(ErrorKind::UnexpectedEof, "incomplete HTTP body")); - } - request.extend_from_slice(&buffer[..read]); - } - request.truncate(total_length); - Ok(Some(request)) -} - -struct KeepAliveHttpServer { - port: u16, - connections: Arc, - task: JoinHandle<()>, -} - -impl KeepAliveHttpServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|error| format!("bind HTTP server: {error}"))?; - let port = listener - .local_addr() - .map_err(|error| format!("read HTTP server address: {error}"))? - .port(); - let connections = Arc::new(AtomicUsize::new(0)); - let task_connections = Arc::clone(&connections); - let task = tokio::spawn(async move { - while let Ok((stream, _)) = listener.accept().await { - task_connections.fetch_add(1, Ordering::AcqRel); - tokio::spawn(async move { - let _ = handle_keep_alive_connection(stream).await; - }); - } - }); - Ok(Self { - port, - connections, - task, - }) - } - - fn connection_count(&self) -> usize { - self.connections.load(Ordering::Acquire) - } -} - -impl Drop for KeepAliveHttpServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -async fn handle_keep_alive_connection(mut stream: TcpStream) -> io::Result<()> { - while let Some(request) = read_http_request(&mut stream).await? { - let close = String::from_utf8_lossy(&request) - .lines() - .any(|line| line.eq_ignore_ascii_case("connection: close")); - let connection = if close { "close" } else { "keep-alive" }; - let response = - format!("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: {connection}\r\n\r\nok"); - stream.write_all(response.as_bytes()).await?; - if close { - return Ok(()); - } - } - Ok(()) -} - -struct EchoServer { - port: u16, - observed: Arc>>, - task: JoinHandle<()>, -} - -struct RequestBodyEchoServer { - port: u16, - task: JoinHandle<()>, -} - -impl RequestBodyEchoServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|error| format!("bind request body echo server: {error}"))?; - let port = listener - .local_addr() - .map_err(|error| format!("read request body echo server address: {error}"))? - .port(); - let task = tokio::spawn(async move { - while let Ok((stream, _)) = listener.accept().await { - tokio::spawn(async move { - let _ = handle_request_body_echo(stream).await; - }); - } - }); - Ok(Self { port, task }) - } -} - -impl Drop for RequestBodyEchoServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -async fn handle_request_body_echo(mut stream: TcpStream) -> io::Result<()> { - let request = read_http_request(&mut stream) - .await? - .ok_or_else(|| Error::new(ErrorKind::UnexpectedEof, "missing HTTP request"))?; - let headers_end = header_end(&request) - .ok_or_else(|| Error::new(ErrorKind::UnexpectedEof, "incomplete HTTP headers"))?; - let body = &request[headers_end..]; - let response = format!( - "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", - body.len() - ); - stream.write_all(response.as_bytes()).await?; - stream.write_all(body).await -} - -struct PipelineProbeServer { - port: u16, - observed: Arc>>, - task: JoinHandle<()>, -} - -impl PipelineProbeServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|error| format!("bind pipeline probe: {error}"))?; - let port = listener - .local_addr() - .map_err(|error| format!("read pipeline probe address: {error}"))? - .port(); - let observed = Arc::new(Mutex::new(Vec::new())); - let observed_task = observed.clone(); - let task = tokio::spawn(async move { - while let Ok((mut stream, _)) = listener.accept().await { - let observed = observed_task.clone(); - tokio::spawn(async move { - let mut request = Vec::new(); - let mut buffer = [0_u8; 4096]; - loop { - match tokio::time::timeout( - std::time::Duration::from_millis(200), - stream.read(&mut buffer), - ) - .await - { - Ok(Ok(0)) | Err(_) => break, - Ok(Ok(read)) => request.extend_from_slice(&buffer[..read]), - Ok(Err(_)) => return, - } - } - observed.lock().unwrap().extend_from_slice(&request); - // Keep the first response reusable so the queued request reaches policy evaluation. - let _ = stream - .write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok") - .await; - }); - } - }); - Ok(Self { - port, - observed, - task, - }) - } - - fn observed_request(&self) -> Vec { - self.observed.lock().unwrap().clone() - } -} - -impl Drop for PipelineProbeServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -impl EchoServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|error| format!("bind echo server: {error}"))?; - let port = listener - .local_addr() - .map_err(|error| format!("read echo server address: {error}"))? - .port(); - let observed = Arc::new(Mutex::new(Vec::new())); - let task_observed = Arc::clone(&observed); - let task = tokio::spawn(async move { - while let Ok((mut stream, _)) = listener.accept().await { - let observed = Arc::clone(&task_observed); - tokio::spawn(async move { - let mut buffer = [0_u8; 4096]; - loop { - let Ok(read) = stream.read(&mut buffer).await else { - break; - }; - if read == 0 { - break; - } - observed.lock().unwrap().extend_from_slice(&buffer[..read]); - if stream.write_all(&buffer[..read]).await.is_err() { - break; - } - } - }); - } - }); - Ok(Self { - port, - observed, - task, - }) - } - - fn observed_bytes(&self) -> Vec { - self.observed.lock().unwrap().clone() - } -} - -impl Drop for EchoServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -struct CredentialProbeServer { - port: u16, - task: JoinHandle<()>, -} - -impl CredentialProbeServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|error| format!("bind credential probe: {error}"))?; - let port = listener - .local_addr() - .map_err(|error| format!("read credential probe address: {error}"))? - .port(); - let task = tokio::spawn(async move { - while let Ok((stream, _)) = listener.accept().await { - tokio::spawn(async move { - let _ = handle_credential_probe(stream).await; - }); - } - }); - Ok(Self { port, task }) - } -} - -impl Drop for CredentialProbeServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -async fn handle_credential_probe(mut stream: TcpStream) -> io::Result<()> { - let request = read_http_request(&mut stream) - .await? - .ok_or_else(|| Error::new(ErrorKind::UnexpectedEof, "missing HTTP request"))?; - let headers_end = header_end(&request) - .ok_or_else(|| Error::new(ErrorKind::UnexpectedEof, "incomplete HTTP headers"))?; - let headers = String::from_utf8_lossy(&request[..headers_end]); - let expected_authorization = format!("Bearer {TEST_SECRET}"); - let header_resolved = headers.lines().any(|line| { - line.split_once(':').is_some_and(|(name, value)| { - name.eq_ignore_ascii_case("authorization") && value.trim() == expected_authorization - }) - }); - let body_resolved = request[headers_end..] - .windows(TEST_SECRET.len()) - .any(|window| window == TEST_SECRET.as_bytes()); - let saw_placeholder = request - .windows(PLACEHOLDER_PREFIX.len()) - .any(|window| window == PLACEHOLDER_PREFIX.as_bytes()); - let body = serde_json::json!({ - "body_resolved": body_resolved, - "header_resolved": header_resolved, - "saw_placeholder": saw_placeholder, - }) - .to_string(); - let response = format!( - "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", - body.len() - ); - stream.write_all(response.as_bytes()).await -} - -fn transparent_status_script(host: &str, port: u16) -> String { - format!( - r#" -import json -import socket - -HOST = {host:?} -PORT = {port} - -def read_headers(sock): - data = b"" - while b"\r\n\r\n" not in data: - chunk = sock.recv(4096) - if not chunk: - break - data += chunk - return data - -def status(response): - parts = response.split(None, 2) - return int(parts[1]) if len(parts) > 1 else 0 - -def request_status(path): - target = f"{{HOST}}:{{PORT}}" - try: - with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall( - f"GET {{path}} HTTP/1.1\r\n" - f"Host: {{target}}\r\nConnection: close\r\n\r\n".encode() - ) - return status(read_headers(sock)) - except OSError as error: - return {{"errno": error.errno, "error": repr(error)}} - -print(json.dumps({{ - "first": request_status("/first"), - "second": request_status("/second"), -}}, sort_keys=True)) -"#, - host = host, - port = port, - ) -} - -fn persistent_transparent_script(host: &str, port: u16) -> String { - format!( - r#" -import json -import os -import socket -import time - -HOST = {host:?} -PORT = {port} -READY = "/tmp/proxy-reload-ready" -GO = "/tmp/proxy-reload-go" -RESULT = "/tmp/proxy-reload-result" - -def read_response(sock): - data = b"" - while b"\r\n\r\n" not in data: - chunk = sock.recv(4096) - if not chunk: - return 0 - data += chunk - headers, body = data.split(b"\r\n\r\n", 1) - length = 0 - for line in headers.split(b"\r\n")[1:]: - if line.lower().startswith(b"content-length:"): - length = int(line.split(b":", 1)[1].strip()) - while len(body) < length: - chunk = sock.recv(4096) - if not chunk: - return 0 - body += chunk - return int(headers.split(None, 2)[1]) - -target = f"{{HOST}}:{{PORT}}" -failed_closed = False -second_status = 0 -try: - with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall( - f"GET /before-reload HTTP/1.1\r\nHost: {{target}}\r\nConnection: keep-alive\r\n\r\n".encode() - ) - if read_response(sock) != 200: - raise RuntimeError("initial tunneled request was denied") - open(READY, "w").close() - deadline = time.monotonic() + 120 - while not os.path.exists(GO) and time.monotonic() < deadline: - time.sleep(0.1) - if not os.path.exists(GO): - raise RuntimeError("timed out waiting for policy reload signal") - try: - sock.sendall( - f"GET /after-reload HTTP/1.1\r\nHost: {{target}}\r\nConnection: close\r\n\r\n".encode() - ) - second_status = read_response(sock) - except OSError: - second_status = 0 - failed_closed = second_status != 200 -finally: - with open(RESULT, "w") as result: - json.dump({{"failed_closed": failed_closed, "second_status": second_status}}, result, sort_keys=True) -"#, - host = host, - port = port, - ) -} - -async fn wait_for_sandbox_file(guard: &SandboxGuard, path: &str, log_path: &str) -> String { - let script = format!( - r#"import os, time -deadline = time.monotonic() + 60 -while not os.path.exists({path:?}) and time.monotonic() < deadline: - time.sleep(0.1) -if not os.path.exists({path:?}): - if os.path.exists({log_path:?}): - print(open({log_path:?}).read()) - raise SystemExit("timed out waiting for {path}") -print(open({path:?}).read()) -"# - ); - guard - .exec(&["python3", "-c", &script]) - .await - .unwrap_or_else(|error| panic!("wait for sandbox file {path}: {error}")) -} - -fn parse_json_line(output: &str) -> Value { - output - .lines() - .filter_map(|line| serde_json::from_str::(line.trim()).ok()) - .next_back() - .unwrap_or_else(|| panic!("missing JSON result in sandbox output:\n{output}")) -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn policy_reload_updates_transparent_requests_and_closes_existing_http_stream() { - let server = KeepAliveHttpServer::start() - .await - .expect("start keep-alive HTTP server"); - let policy_a = write_policy(TEST_SERVER_HOST, server.port, "").expect("write policy A"); - let policy_b = write_denied_policy().expect("write policy B"); - let policy_a_path = policy_path(&policy_a); - let policy_b_path = policy_path(&policy_b); - - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &policy_a_path], - &["sh", "-c", "echo Ready; sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox"); - - run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &policy_a_path, - "--wait", - "--timeout", - "120", - ]) - .await - .expect("wait for policy A"); - - let persistent_script = persistent_transparent_script(TEST_SERVER_HOST, server.port); - guard - .exec(&[ - "sh", - "-c", - "nohup python3 -c \"$1\" >/tmp/proxy-reload-client.log 2>&1 &", - "proxy-reload-client", - &persistent_script, - ]) - .await - .expect("start persistent transparent client"); - wait_for_sandbox_file( - &guard, - "/tmp/proxy-reload-ready", - "/tmp/proxy-reload-client.log", - ) - .await; - - let status_script = transparent_status_script(TEST_SERVER_HOST, server.port); - let before = guard - .exec(&["python3", "-c", &status_script]) - .await - .expect("exercise transparent requests before reload"); - let before = parse_json_line(&before); - assert_eq!( - before["first"], 200, - "first request before reload: {before}" - ); - assert_eq!( - before["second"], 200, - "second request before reload: {before}" - ); - - run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &policy_b_path, - "--wait", - "--timeout", - "120", - ]) - .await - .expect("publish and wait for policy B"); - - guard - .exec(&["sh", "-c", "touch /tmp/proxy-reload-go"]) - .await - .expect("release persistent transparent client"); - let stale_tunnel = wait_for_sandbox_file( - &guard, - "/tmp/proxy-reload-result", - "/tmp/proxy-reload-client.log", - ) - .await; - let stale_tunnel = parse_json_line(&stale_tunnel); - assert_eq!( - stale_tunnel["failed_closed"], true, - "existing transparent HTTP stream forwarded after policy reload: {stale_tunnel}" - ); - - let after = guard - .exec(&["python3", "-c", &status_script]) - .await - .expect("exercise transparent requests after reload"); - let after = parse_json_line(&after); - assert_ne!(after["first"], 200, "first request after reload: {after}"); - assert_ne!(after["second"], 200, "second request after reload: {after}"); - - guard.cleanup().await; -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn ambiguous_policy_update_is_rejected_without_replacing_active_policy() { - let server = KeepAliveHttpServer::start() - .await - .expect("start keep-alive HTTP server"); - let valid_policy = write_policy(TEST_SERVER_HOST, server.port, "").expect("write valid policy"); - let ambiguous_policy = - write_ambiguous_policy(TEST_SERVER_HOST, server.port).expect("write ambiguous policy"); - let valid_policy_path = policy_path(&valid_policy); - let ambiguous_policy_path = policy_path(&ambiguous_policy); - - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &valid_policy_path], - &["sh", "-c", "echo Ready; sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox"); - - run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &valid_policy_path, - "--wait", - "--timeout", - "120", - ]) - .await - .expect("wait for valid policy"); - - let status_script = transparent_status_script(TEST_SERVER_HOST, server.port); - let before = guard - .exec(&["python3", "-c", &status_script]) - .await - .expect("exercise transparent requests before invalid update"); - let before = parse_json_line(&before); - assert_eq!( - before["first"], 200, - "first request before update: {before}" - ); - assert_eq!( - before["second"], 200, - "second request before update: {before}" - ); - let history_before = run_cli(&["policy", "list", &guard.name]) - .await - .expect("list policy history before rejected update"); - let connections_before_rejection = server.connection_count(); - - let update_error = run_cli(&[ - "policy", - "set", - &guard.name, - "--policy", - &ambiguous_policy_path, - "--wait", - "--timeout", - "120", - ]) - .await - .expect_err("ambiguous policy must be rejected before persistence"); - assert!( - update_error.contains("ambiguity validation failed"), - "policy update should explain the ambiguity:\n{update_error}" - ); - - let history_after = run_cli(&["policy", "list", &guard.name]) - .await - .expect("list policy history after rejected update"); - assert_eq!( - history_after, history_before, - "rejected policy must not create a revision" - ); - - let after_rejection = guard - .exec(&["python3", "-c", &status_script]) - .await - .expect("exercise transparent requests after rejected update"); - let after_rejection = parse_json_line(&after_rejection); - assert_eq!( - after_rejection["first"], 200, - "first request should keep using the active valid policy: {after_rejection}" - ); - assert_eq!( - after_rejection["second"], 200, - "second request should keep using the active valid policy: {after_rejection}" - ); - assert!( - server.connection_count() > connections_before_rejection, - "active-policy requests should still contact the upstream server" - ); - - guard.cleanup().await; -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn transparent_destination_denials_fail_connect_with_eacces() { - let policy = write_destination_denial_policy().expect("write destination denial policy"); - let policy_path = policy_path(&policy); - let script = r#" -import json -import socket - -targets = { - "metadata": ("169.254.169.254", 80), - "control_plane": ("203.0.113.10", 6443), - "outside_allowed_ips": ("203.0.113.10", 8080), -} -result = {} -for name, target in targets.items(): - try: - with socket.create_connection(target, timeout=10): - result[name] = 0 - except OSError as error: - result[name] = error.errno -print(json.dumps(result, sort_keys=True)) -"#; - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", script]) - .await - .expect("sandbox create"); - let result = parse_json_line(&guard.create_output); - for name in ["metadata", "control_plane", "outside_allowed_ips"] { - assert_eq!(result[name], 13, "{name} should fail with EACCES: {result}"); - } -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn explicit_allowed_ips_and_implicit_ip_literals_succeed_transparently() { - if e2e_network_name().is_none() { - eprintln!("skipping IP-literal success assertions without a shared container network"); - return; - } - - const HTTP_SERVER: &str = r#" -from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer - -class Handler(BaseHTTPRequestHandler): - def do_GET(self): - body = b"ok" - self.send_response(200) - self.send_header("Content-Length", str(len(body))) - self.end_headers() - self.wfile.write(body) - - def log_message(self, format, *args): - pass - -ThreadingHTTPServer(("0.0.0.0", 8000), Handler).serve_forever() -"#; - let explicit_server = - SupportContainer::start_python("explicit-ip.openshell.test", HTTP_SERVER, 8000) - .await - .expect("start explicit allowed_ips support container"); - let implicit_server = - SupportContainer::start_python("implicit-ip.openshell.test", HTTP_SERVER, 8000) - .await - .expect("start implicit IP-literal support container"); - let explicit_ip = explicit_server.ip().expect("explicit support container IP"); - let implicit_ip = implicit_server.ip().expect("implicit support container IP"); - let policy = write_ip_literal_success_policy(&explicit_ip, &implicit_ip, 8000) - .expect("write IP literal policy"); - let policy_path = policy_path(&policy); - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &policy_path], - &["sh", "-c", "echo Ready; sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox"); - - for (mode, destination) in [ - ("explicit_allowed_ips", explicit_ip.as_str()), - ("implicit_ip_literal", implicit_ip.as_str()), - ] { - let output = guard - .exec(&[ - "python3", - "-c", - &transparent_status_script(destination, 8000), - ]) - .await - .unwrap_or_else(|error| panic!("exercise {mode}: {error}")); - let statuses = parse_json_line(&output); - assert_eq!(statuses["first"], 200, "{mode} first request: {statuses}"); - assert_eq!(statuses["second"], 200, "{mode} second request: {statuses}"); - } - - guard.cleanup().await; -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn tls_skip_connect_relays_opaque_bytes_bidirectionally() { - let server = EchoServer::start().await.expect("start TCP echo server"); - let policy = write_policy(TEST_SERVER_HOST, server.port, " tls: skip") - .expect("write tls: skip policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import socket - -HOST = {host:?} -PORT = {port} -PAYLOAD = bytes([0x00, 0xff, 0x13, 0x37, 0x80, 0x0a]) + b"not-http-or-tls" + bytes(range(64)) - -with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall(PAYLOAD) - echoed = b"" - while len(echoed) < len(PAYLOAD): - chunk = sock.recv(len(PAYLOAD) - len(echoed)) - if not chunk: - break - echoed += chunk - if echoed != PAYLOAD: - raise RuntimeError("opaque payload changed in transit") -print("RAW_RELAY_OK") -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - assert!( - guard.create_output.contains("RAW_RELAY_OK"), - "raw relay did not preserve the opaque payload:\n{}", - guard.create_output - ); -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn middleware_redacts_transparent_request_bodies() { - let server = RequestBodyEchoServer::start() - .await - .expect("start request body echo server"); - let policy = write_middleware_policy(TEST_SERVER_HOST, server.port, "", "fail_closed") - .expect("write middleware policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import json -import socket - -HOST = {host:?} -PORT = {port} -SECRET = "sk-1234567890abcdef" - -def read_response(sock): - data = b"" - while b"\r\n\r\n" not in data: - chunk = sock.recv(4096) - if not chunk: - raise RuntimeError("incomplete response headers") - data += chunk - headers, body = data.split(b"\r\n\r\n", 1) - length = 0 - for line in headers.split(b"\r\n")[1:]: - if line.lower().startswith(b"content-length:"): - length = int(line.split(b":", 1)[1].strip()) - while len(body) < length: - chunk = sock.recv(4096) - if not chunk: - break - body += chunk - status = int(headers.split(None, 2)[1]) - if status != 200: - raise RuntimeError(f"request failed with HTTP {{status}}: {{body!r}}") - return json.loads(body[:length]) - -def request_bytes(target): - body = json.dumps({{"api_key": SECRET}}, separators=(",", ":")).encode() - return ( - f"POST {{target}} HTTP/1.1\r\n" - f"Host: {{HOST}}:{{PORT}}\r\n" - "Content-Type: application/json\r\n" - f"Content-Length: {{len(body)}}\r\n" - "Connection: close\r\n\r\n" - ).encode() + body - -def request_once(): - with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall(request_bytes("/middleware")) - return read_response(sock) - -print(json.dumps({{"first": request_once(), "second": request_once()}}, sort_keys=True)) -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - let result = parse_json_line(&guard.create_output); - for request in ["first", "second"] { - assert_eq!( - result[request]["api_key"], "[REDACTED]", - "{request} did not deliver the middleware-transformed body: {result}" - ); - } -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn fail_closed_middleware_blocks_uninspectable_transparent_payload_before_upstream() { - let server = EchoServer::start().await.expect("start TCP echo server"); - let policy = write_middleware_policy(TEST_SERVER_HOST, server.port, "", "fail_closed") - .expect("write fail-closed middleware policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import socket - -HOST = {host:?} -PORT = {port} -PAYLOAD = bytes([0x00, 0xff, 0x13, 0x37]) + b"not-http-or-tls" - -with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall(PAYLOAD) - denial = b"" - while True: - try: - chunk = sock.recv(4096) - except ConnectionResetError: - break - if not chunk: - break - denial += chunk - if denial and ( - b"HTTP/1.1 403 Forbidden" not in denial - or b"unsupported_l7_protocol" not in denial - ): - raise RuntimeError(f"missing fail-closed middleware denial: {{denial!r}}") -print("UNINSPECTABLE_MIDDLEWARE_BLOCKED") -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let mut guard = SandboxGuard::create_keep_with_args( - &["--policy", &policy_path], - &["sh", "-c", "echo Ready; sleep infinity"], - "Ready", - ) - .await - .expect("create keep sandbox"); - let output = guard - .exec(&["python3", "-c", &script]) - .await - .expect("exercise uninspectable fail-closed middleware"); - assert!( - output.contains("UNINSPECTABLE_MIDDLEWARE_BLOCKED"), - "uninspectable payload was not blocked:\n{output}" - ); - tokio::time::sleep(std::time::Duration::from_millis(200)).await; - assert!( - server.observed_bytes().is_empty(), - "uninspectable payload reached upstream before middleware denial" - ); - - let logs = wait_for_sandbox_logs(&guard.name, |logs| { - logs.contains("openshell.middleware.traffic_uninspectable") - && logs - .contains("Unsupported tunnel protocol cannot be inspected by required middleware") - }) - .await - .expect("fetch sandbox logs after middleware denial"); - assert!( - logs.contains("openshell.middleware.traffic_uninspectable") - && logs - .contains("Unsupported tunnel protocol cannot be inspected by required middleware"), - "OCSF logs should explain the fail-closed denial:\n{logs}" - ); - - guard.cleanup().await; -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn fail_open_middleware_bypasses_uninspectable_transparent_tls_skip() { - let server = EchoServer::start().await.expect("start TCP echo server"); - let policy = write_middleware_policy( - TEST_SERVER_HOST, - server.port, - " tls: skip", - "fail_open", - ) - .expect("write fail-open middleware policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import socket - -HOST = {host:?} -PORT = {port} -PAYLOAD = bytes([0x00, 0xff, 0x13, 0x37, 0x80]) + b"middleware-bypass" - -with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall(PAYLOAD) - echoed = b"" - while len(echoed) < len(PAYLOAD): - chunk = sock.recv(len(PAYLOAD) - len(echoed)) - if not chunk: - break - echoed += chunk - if echoed != PAYLOAD: - raise RuntimeError(f"fail-open middleware did not preserve raw relay: {{echoed!r}}") -print("UNINSPECTABLE_MIDDLEWARE_BYPASSED") -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - assert!( - guard - .create_output - .contains("UNINSPECTABLE_MIDDLEWARE_BYPASSED"), - "fail-open middleware did not bypass uninspectable traffic:\n{}", - guard.create_output - ); - assert_eq!( - server.observed_bytes(), - [0x00, 0xff, 0x13, 0x37, 0x80] - .into_iter() - .chain(*b"middleware-bypass") - .collect::>(), - "upstream did not receive the unchanged fail-open payload" - ); -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn transparent_pipeline_never_reaches_upstream_as_first_request_overflow() { - let server = PipelineProbeServer::start() - .await - .expect("start pipeline probe server"); - let endpoint_options = r#" protocol: rest - enforcement: enforce - rules: - - allow: - method: GET - path: "/allowed""#; - let policy = write_policy(TEST_SERVER_HOST, server.port, endpoint_options) - .expect("write pipeline policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import socket - -target = "{host}:{port}" -first = ( - f"GET /allowed HTTP/1.1\r\n" - f"Host: {{target}}\r\nConnection: keep-alive\r\n\r\n" -) -second = ( - f"POST /blocked HTTP/1.1\r\n" - f"Host: {{target}}\r\nContent-Length: 0\r\n\r\n" -) -with socket.create_connection(({host:?}, {port}), timeout=10) as sock: - sock.sendall((first + second).encode()) - response = b"" - while True: - chunk = sock.recv(4096) - if not chunk: - break - response += chunk -responses = response.count(b"HTTP/1.1 ") -first_status = response.split(b"\r\n", 1)[0] -if responses != 2 or b" 200 " not in first_status or b"HTTP/1.1 403 Forbidden" not in response: - raise RuntimeError(f"unexpected pipelined response: {{response!r}}") -print("TRANSPARENT_PIPELINE_DENIED") -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - assert!( - guard.create_output.contains("TRANSPARENT_PIPELINE_DENIED"), - "transparent HTTP stream did not deny the disallowed pipelined request:\n{}", - guard.create_output - ); - - let observed = String::from_utf8(server.observed_request()).expect("upstream HTTP request"); - assert!(observed.starts_with("GET /allowed HTTP/1.1\r\n")); - assert!( - !observed.to_ascii_lowercase().contains("\r\nconnection:"), - "shared relay must remove hop-by-hop connection headers:\n{observed}" - ); - assert!(!observed.contains("/blocked")); -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn chunked_pipeline_is_authorized_separately_before_reaching_upstream() { - let server = PipelineProbeServer::start() - .await - .expect("start pipeline probe server"); - let endpoint_options = r#" protocol: rest - enforcement: enforce - rules: - - allow: - method: POST - path: "/allowed""#; - let policy = write_policy(TEST_SERVER_HOST, server.port, endpoint_options) - .expect("write pipeline policy"); - let policy_path = policy_path(&policy); - let script = format!( - r#" -import socket - -target = "{host}:{port}" -first = ( - f"POST /allowed HTTP/1.1\r\n" - f"Host: {{target}}\r\nTransfer-Encoding: chunked\r\nConnection: keep-alive\r\n\r\n" - f"0\r\n\r\n" -) -second = ( - f"DELETE /blocked HTTP/1.1\r\n" - f"Host: {{target}}\r\nContent-Length: 0\r\n\r\n" -) -with socket.create_connection(({host:?}, {port}), timeout=10) as sock: - sock.sendall((first + second).encode()) - response = b"" - while True: - chunk = sock.recv(4096) - if not chunk: - break - response += chunk -responses = response.count(b"HTTP/1.1 ") -first_status = response.split(b"\r\n", 1)[0] -if responses != 2 or b" 200 " not in first_status or b"HTTP/1.1 403 Forbidden" not in response: - raise RuntimeError(f"unexpected chunked pipeline response: {{response!r}}") -print("CHUNKED_PIPELINE_DENIED") -"#, - host = TEST_SERVER_HOST, - port = server.port, - ); - - let guard = SandboxGuard::create(&["--policy", &policy_path, "--", "python3", "-c", &script]) - .await - .expect("sandbox create"); - assert!( - guard.create_output.contains("CHUNKED_PIPELINE_DENIED"), - "transparent HTTP stream did not evaluate the chunked pipeline separately:\n{}", - guard.create_output - ); - - let observed = String::from_utf8(server.observed_request()).expect("upstream HTTP request"); - assert!(observed.starts_with("POST /allowed HTTP/1.1\r\n")); - assert!(observed.ends_with("0\r\n\r\n")); - assert!(!observed.contains("/blocked")); -} - -#[tokio::test] -#[serial(proxy_egress_pipeline)] -async fn http_credentials_are_rewritten_in_transparent_headers_and_bodies() { - let _provider_lock = PROVIDER_LOCK - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner); - delete_provider(PROVIDER_NAME).await; - delete_provider_profile(PROVIDER_PROFILE_ID).await; - - let result = async { - let server = CredentialProbeServer::start().await?; - let profile = write_credential_profile(server.port)?; - let profile_path = profile.path().to_string_lossy().into_owned(); - run_cli(&["profile", "import", "--file", &profile_path]).await?; - create_bound_provider(PROVIDER_NAME).await?; - let endpoint_options = r#" path: /probe - protocol: rest - enforcement: enforce - request_body_credential_rewrite: true - access: full"#; - let policy = write_policy(TEST_SERVER_HOST, server.port, endpoint_options)?; - let policy_path = policy_path(&policy); - let script = format!( - r#" -import json -import os -import socket - -HOST = {host:?} -PORT = {port} -TOKEN = os.environ[{token_env:?}] - -def read_response(sock): - data = b"" - while b"\r\n\r\n" not in data: - chunk = sock.recv(4096) - if not chunk: - raise RuntimeError("incomplete response headers") - data += chunk - headers, body = data.split(b"\r\n\r\n", 1) - length = 0 - for line in headers.split(b"\r\n")[1:]: - if line.lower().startswith(b"content-length:"): - length = int(line.split(b":", 1)[1].strip()) - while len(body) < length: - chunk = sock.recv(4096) - if not chunk: - break - body += chunk - code = int(headers.split(None, 2)[1]) - if code != 200: - raise RuntimeError(f"request failed with HTTP {{code}}") - return json.loads(body[:length]) - -def request_bytes(target): - body = json.dumps({{"credential": TOKEN}}, separators=(",", ":")).encode() - return ( - f"POST {{target}} HTTP/1.1\r\n" - f"Host: {{HOST}}:{{PORT}}\r\n" - f"Authorization: Bearer {{TOKEN}}\r\n" - "Content-Type: application/json\r\n" - f"Content-Length: {{len(body)}}\r\n" - "Connection: close\r\n\r\n" - ).encode() + body - -def request_once(): - with socket.create_connection((HOST, PORT), timeout=10) as sock: - sock.sendall(request_bytes("/probe")) - return read_response(sock) - -print(json.dumps({{"first": request_once(), "second": request_once()}}, sort_keys=True)) -"#, - host = TEST_SERVER_HOST, - port = server.port, - token_env = TOKEN_ENV, - ); - - SandboxGuard::create(&[ - "--policy", - &policy_path, - "--provider", - PROVIDER_NAME, - "--", - "python3", - "-c", - &script, - ]) - .await - } - .await; - - delete_provider(PROVIDER_NAME).await; - delete_provider_profile(PROVIDER_PROFILE_ID).await; - - let guard = result.expect("sandbox create"); - let result = parse_json_line(&guard.create_output); - for request in ["first", "second"] { - assert_eq!( - result[request]["header_resolved"], true, - "{request} header placeholder was not resolved: {result}" - ); - assert_eq!( - result[request]["body_resolved"], true, - "{request} body placeholder was not resolved: {result}" - ); - assert_eq!( - result[request]["saw_placeholder"], false, - "{request} leaked an unresolved placeholder upstream: {result}" - ); - } - assert!( - !guard.create_output.contains(TEST_SECRET), - "sandbox output exposed the raw provider credential:\n{}", - guard.create_output - ); - assert!( - !guard.create_output.contains(PLACEHOLDER_PREFIX), - "sandbox output exposed an unresolved provider placeholder:\n{}", - guard.create_output - ); -} diff --git a/e2e/rust/tests/websocket_conformance.rs b/e2e/rust/tests/websocket_conformance.rs deleted file mode 100644 index 1150e020bc..0000000000 --- a/e2e/rust/tests/websocket_conformance.rs +++ /dev/null @@ -1,517 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e")] - -//! E2E regression: WebSocket credential placeholders are resolved on the -//! sandbox path after an RFC 6455 upgrade. -//! -//! The sandbox process sends its provider-managed placeholder in a masked text -//! frame. The local upstream only reports whether it saw the real secret and -//! whether any placeholder survived; it never echoes payload bytes, placeholder -//! text, or secret material back into test output. - -use std::io::{self, Error, ErrorKind, Write}; -use std::process::Stdio; -use std::sync::Mutex; - -use base64::Engine as _; -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::sandbox::SandboxGuard; -use sha1::{Digest, Sha1}; -use tempfile::{Builder as TempFileBuilder, NamedTempFile}; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::net::{TcpListener, TcpStream}; -use tokio::task::JoinHandle; - -const WEBSOCKET_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; -const PROVIDER_NAME: &str = "e2e-websocket-conformance"; -const PROVIDER_PROFILE_ID: &str = "e2e-websocket-conformance"; -const TEST_SERVER_HOST: &str = "host.openshell.internal"; -const TEST_SECRET: &str = "sk-e2e-websocket-conformance-secret"; -const TOKEN_ENV: &str = "WS_E2E_TOKEN"; -const PLACEHOLDER_PREFIX: &str = "openshell:resolve:env:"; -static PROVIDER_LOCK: Mutex<()> = Mutex::new(()); - -async fn run_cli(args: &[&str]) -> Result { - let mut cmd = openshell_cmd(); - cmd.args(args).stdout(Stdio::piped()).stderr(Stdio::piped()); - - let output = cmd - .output() - .await - .map_err(|e| format!("failed to spawn openshell {}: {e}", args.join(" ")))?; - - let stdout = String::from_utf8_lossy(&output.stdout).to_string(); - let stderr = String::from_utf8_lossy(&output.stderr).to_string(); - let combined = format!("{stdout}{stderr}"); - - if !output.status.success() { - return Err(format!( - "openshell {} failed (exit {:?}):\n{combined}", - args.join(" "), - output.status.code() - )); - } - - Ok(combined) -} - -async fn delete_provider(name: &str) { - let mut cmd = openshell_cmd(); - cmd.arg("provider") - .arg("delete") - .arg(name) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - -async fn delete_provider_profile(id: &str) { - let mut cmd = openshell_cmd(); - cmd.args(["profile", "delete", id]) - .stdout(Stdio::null()) - .stderr(Stdio::null()); - let _ = cmd.status().await; -} - -async fn create_bound_provider(name: &str) -> Result { - let credential = format!("{TOKEN_ENV}={TEST_SECRET}"); - run_cli(&[ - "provider", - "create", - "--name", - name, - "--type", - PROVIDER_PROFILE_ID, - "--credential", - &credential, - ]) - .await -} - -fn write_credential_profile(port: u16) -> Result { - let mut file = TempFileBuilder::new() - .suffix(".yaml") - .tempfile() - .map_err(|error| format!("create provider profile: {error}"))?; - let profile = format!( - r#"id: {PROVIDER_PROFILE_ID} -display_name: E2E WebSocket conformance credentials -category: other -credentials: - - name: websocket_token - env_vars: [{TOKEN_ENV}] - required: true - auth_style: bearer - header_name: authorization -endpoints: - - host: {TEST_SERVER_HOST} - port: {port} - path: /ws - protocol: websocket - enforcement: enforce - access: read-write - websocket_credential_rewrite: true - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" -binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(profile.as_bytes()) - .map_err(|error| format!("write provider profile: {error}"))?; - file.flush() - .map_err(|error| format!("flush provider profile: {error}"))?; - Ok(file) -} - -struct WebSocketProbeServer { - port: u16, - task: JoinHandle<()>, -} - -impl WebSocketProbeServer { - async fn start() -> Result { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .map_err(|e| format!("bind websocket probe server: {e}"))?; - let port = listener - .local_addr() - .map_err(|e| format!("read websocket probe server address: {e}"))? - .port(); - let task = tokio::spawn(async move { - loop { - let Ok((stream, _)) = listener.accept().await else { - break; - }; - tokio::spawn(async move { - let _ = handle_websocket_probe_connection(stream).await; - }); - } - }); - - Ok(Self { port, task }) - } -} - -impl Drop for WebSocketProbeServer { - fn drop(&mut self) { - self.task.abort(); - } -} - -async fn recv_until(stream: &mut TcpStream, marker: &[u8]) -> io::Result> { - let mut data = Vec::new(); - let mut buf = [0_u8; 1024]; - loop { - let read = stream.read(&mut buf).await?; - if read == 0 { - return Ok(data); - } - data.extend_from_slice(&buf[..read]); - if data.windows(marker.len()).any(|window| window == marker) { - return Ok(data); - } - } -} - -async fn read_websocket_text(stream: &mut TcpStream) -> io::Result { - let mut header = [0_u8; 2]; - stream.read_exact(&mut header).await?; - let length = match header[1] & 0x7F { - len @ 0..=125 => usize::from(len), - 126 => { - let mut bytes = [0_u8; 2]; - stream.read_exact(&mut bytes).await?; - usize::from(u16::from_be_bytes(bytes)) - } - 127 => { - let mut bytes = [0_u8; 8]; - stream.read_exact(&mut bytes).await?; - usize::try_from(u64::from_be_bytes(bytes)) - .map_err(|_| Error::new(ErrorKind::InvalidData, "websocket frame too large"))? - } - _ => unreachable!(), - }; - - let mut mask = [0_u8; 4]; - if header[1] & 0x80 != 0 { - stream.read_exact(&mut mask).await?; - } else { - mask = [0, 0, 0, 0]; - } - - let mut payload = vec![0_u8; length]; - stream.read_exact(&mut payload).await?; - if header[1] & 0x80 != 0 { - for (index, byte) in payload.iter_mut().enumerate() { - *byte ^= mask[index % mask.len()]; - } - } - - String::from_utf8(payload).map_err(|e| { - Error::new( - ErrorKind::InvalidData, - format!("invalid websocket text: {e}"), - ) - }) -} - -async fn send_websocket_text(stream: &mut TcpStream, payload: &str) -> io::Result<()> { - let data = payload.as_bytes(); - let mut frame = Vec::with_capacity(data.len() + 10); - frame.push(0x81); - if data.len() < 126 { - frame.push( - u8::try_from(data.len()) - .map_err(|_| Error::new(ErrorKind::InvalidData, "websocket frame too large"))?, - ); - } else if data.len() <= usize::from(u16::MAX) { - frame.push(126); - frame.extend_from_slice( - &u16::try_from(data.len()) - .map_err(|_| Error::new(ErrorKind::InvalidData, "websocket frame too large"))? - .to_be_bytes(), - ); - } else { - frame.push(127); - frame.extend_from_slice( - &u64::try_from(data.len()) - .map_err(|_| Error::new(ErrorKind::InvalidData, "websocket frame too large"))? - .to_be_bytes(), - ); - } - frame.extend_from_slice(data); - stream.write_all(&frame).await -} - -fn header_value(request: &str, name: &str) -> Option { - request.lines().find_map(|line| { - let (header, value) = line.split_once(':')?; - if header.trim().eq_ignore_ascii_case(name) { - Some(value.trim().to_string()) - } else { - None - } - }) -} - -fn websocket_accept_for_key(key: &str) -> String { - let mut hasher = Sha1::new(); - hasher.update(key.as_bytes()); - hasher.update(WEBSOCKET_GUID.as_bytes()); - base64::engine::general_purpose::STANDARD.encode(hasher.finalize()) -} - -async fn handle_websocket_probe_connection(mut stream: TcpStream) -> io::Result<()> { - let request_bytes = recv_until(&mut stream, b"\r\n\r\n").await?; - let request = String::from_utf8_lossy(&request_bytes); - if !request.to_ascii_lowercase().contains("upgrade: websocket") { - stream - .write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok") - .await?; - return Ok(()); - } - - let accept = header_value(&request, "Sec-WebSocket-Key") - .map(|key| websocket_accept_for_key(&key)) - .ok_or_else(|| Error::new(ErrorKind::InvalidData, "missing Sec-WebSocket-Key"))?; - let response = format!( - "HTTP/1.1 101 Switching Protocols\r\n\ - Upgrade: websocket\r\n\ - Connection: Upgrade\r\n\ - Sec-WebSocket-Accept: {accept}\r\n\ - \r\n" - ); - stream.write_all(response.as_bytes()).await?; - - let text = read_websocket_text(&mut stream).await?; - let response = format!( - r#"{{"saw_placeholder": {}, "saw_secret": {}}}"#, - text.contains(PLACEHOLDER_PREFIX), - text.contains(TEST_SECRET) - ); - send_websocket_text(&mut stream, &response).await -} - -fn write_websocket_policy(host: &str, port: u16) -> Result { - let mut file = NamedTempFile::new().map_err(|e| format!("create temp policy file: {e}"))?; - let policy = format!( - r#"version: 1 - -filesystem_policy: - include_workdir: true - read_only: - - /usr - - /lib - - /proc - - /dev/urandom - - /app - - /etc - - /var/log - read_write: - - /sandbox - - /tmp - - /dev/null - -landlock: - compatibility: best_effort - -process: - run_as_user: sandbox - run_as_group: sandbox - -network_policies: - websocket_conformance: - name: websocket_conformance - endpoints: - - host: {host} - port: {port} - protocol: websocket - enforcement: enforce - access: read-write - websocket_credential_rewrite: true - allowed_ips: - - "10.0.0.0/8" - - "172.0.0.0/8" - - "192.168.0.0/16" - - "fc00::/7" - binaries: - - path: /usr/bin/python* - - path: /usr/local/bin/python* - - path: /sandbox/.uv/python/*/bin/python* -"# - ); - file.write_all(policy.as_bytes()) - .map_err(|e| format!("write temp policy file: {e}"))?; - file.flush() - .map_err(|e| format!("flush temp policy file: {e}"))?; - Ok(file) -} - -fn websocket_client_script(host: &str, port: u16) -> String { - format!( - r#" -import base64 -import json -import os -import socket -import struct -import time - -HOST = {host:?} -PORT = {port} -TOKEN_ENV = {token_env:?} - -def recv_until(sock, marker): - data = b"" - while marker not in data: - chunk = sock.recv(4096) - if not chunk: - break - data += chunk - return data - -def read_exact(sock, size): - data = b"" - while len(data) < size: - chunk = sock.recv(size - len(data)) - if not chunk: - raise EOFError("unexpected end of websocket frame") - data += chunk - return data - -def masked_text_frame(payload): - data = payload.encode("utf-8") - mask = os.urandom(4) - if len(data) < 126: - header = bytes([0x81, 0x80 | len(data)]) - elif len(data) <= 0xFFFF: - header = bytes([0x81, 0x80 | 126]) + struct.pack("!H", len(data)) - else: - header = bytes([0x81, 0x80 | 127]) + struct.pack("!Q", len(data)) - masked = bytes(byte ^ mask[index % 4] for index, byte in enumerate(data)) - return header + mask + masked - -def read_frame(sock): - first, second = read_exact(sock, 2) - length = second & 0x7F - if length == 126: - length = struct.unpack("!H", read_exact(sock, 2))[0] - elif length == 127: - length = struct.unpack("!Q", read_exact(sock, 8))[0] - mask = read_exact(sock, 4) if second & 0x80 else b"" - payload = read_exact(sock, length) - if mask: - payload = bytes(byte ^ mask[index % 4] for index, byte in enumerate(payload)) - return first, payload - -def transparent_socket_with_retry(host, port, timeout_seconds=20): - deadline = time.monotonic() + timeout_seconds - last_error = None - while time.monotonic() < deadline: - sock = None - try: - sock = socket.create_connection((host, port), timeout=5) - return sock - except OSError as error: - if sock is not None: - sock.close() - last_error = error - time.sleep(0.25) - raise last_error - -token = os.environ[TOKEN_ENV] -payload = json.dumps({{"authorization": "Bearer " + token}}, sort_keys=True) -key = base64.b64encode(os.urandom(16)).decode("ascii") -with transparent_socket_with_retry(HOST, PORT) as sock: - request = ( - "GET /ws HTTP/1.1\r\n" - f"Host: {{HOST}}:{{PORT}}\r\n" - "Upgrade: websocket\r\n" - "Connection: Upgrade\r\n" - f"Sec-WebSocket-Key: {{key}}\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ) - sock.sendall(request.encode("ascii")) - response = recv_until(sock, b"\r\n\r\n").decode("iso-8859-1", "replace") - if not response.startswith("HTTP/1.1 101"): - raise RuntimeError(f"websocket upgrade failed: {{response!r}}") - sock.sendall(masked_text_frame(payload)) - _, response_payload = read_frame(sock) - result = json.loads(response_payload.decode("utf-8")) -results = {{"transparent": result}} -print(json.dumps(results, sort_keys=True)) -"#, - host = host, - port = port, - token_env = TOKEN_ENV, - ) -} - -#[tokio::test] -async fn websocket_text_placeholder_is_rewritten_transparently() { - let _provider_lock = PROVIDER_LOCK - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner); - - delete_provider(PROVIDER_NAME).await; - delete_provider_profile(PROVIDER_PROFILE_ID).await; - - let result = async { - let server = WebSocketProbeServer::start().await?; - let profile = write_credential_profile(server.port)?; - let profile_path = profile.path().to_string_lossy().into_owned(); - run_cli(&["profile", "import", "--file", &profile_path]).await?; - create_bound_provider(PROVIDER_NAME).await?; - let policy = write_websocket_policy(TEST_SERVER_HOST, server.port)?; - let policy_path = policy - .path() - .to_str() - .ok_or_else(|| "temp policy path should be utf-8".to_string())? - .to_string(); - let script = websocket_client_script(TEST_SERVER_HOST, server.port); - - SandboxGuard::create(&[ - "--policy", - &policy_path, - "--provider", - PROVIDER_NAME, - "--", - "python3", - "-c", - &script, - ]) - .await - } - .await; - - delete_provider(PROVIDER_NAME).await; - delete_provider_profile(PROVIDER_PROFILE_ID).await; - - let guard = result.expect("sandbox create"); - assert!( - guard - .create_output - .contains(r#""transparent": {"saw_placeholder": false, "saw_secret": true}"#), - "expected upstream to see only the resolved secret marker:\n{}", - guard.create_output - ); - assert!( - !guard.create_output.contains(TEST_SECRET), - "test output should not expose the raw WebSocket credential:\n{}", - guard.create_output - ); - assert!( - !guard.create_output.contains(PLACEHOLDER_PREFIX), - "test output should not expose unresolved credential placeholders:\n{}", - guard.create_output - ); -} diff --git a/tasks/rust.toml b/tasks/rust.toml index c995e74f8e..bf485db8cc 100644 --- a/tasks/rust.toml +++ b/tasks/rust.toml @@ -40,6 +40,7 @@ run = [ "cargo clippy --manifest-path tests/tmachine/Cargo.toml --all-targets -- -D warnings", "cargo clippy --manifest-path tests/runner/Cargo.toml --all-targets -- -D warnings", "cargo clippy --manifest-path tests/suites/conformance/Cargo.toml --workspace --all-targets -- -D warnings", + "cargo clippy --manifest-path tests/suites/drivers/docker/Cargo.toml --workspace --all-targets -- -D warnings", "cargo clippy --manifest-path tests/suites/drivers/podman/Cargo.toml --workspace --all-targets -- -D warnings", "cargo clippy --manifest-path tests/suites/features/Cargo.toml --workspace --all-targets -- -D warnings", "cargo clippy --manifest-path tests/support/Cargo.toml --all-targets -- -D warnings", @@ -59,6 +60,7 @@ run = [ "cargo fmt --manifest-path tests/tmachine/Cargo.toml --all", "cargo fmt --manifest-path tests/runner/Cargo.toml --all", "cargo fmt --manifest-path tests/suites/conformance/Cargo.toml --all", + "cargo fmt --manifest-path tests/suites/drivers/docker/Cargo.toml --all", "cargo fmt --manifest-path tests/suites/drivers/podman/Cargo.toml --all", "cargo fmt --manifest-path tests/suites/features/Cargo.toml --all", "cargo fmt --manifest-path tests/support/Cargo.toml --all", @@ -77,6 +79,7 @@ run = [ "cargo fmt --manifest-path tests/tmachine/Cargo.toml --all -- --check", "cargo fmt --manifest-path tests/runner/Cargo.toml --all -- --check", "cargo fmt --manifest-path tests/suites/conformance/Cargo.toml --all -- --check", + "cargo fmt --manifest-path tests/suites/drivers/docker/Cargo.toml --all -- --check", "cargo fmt --manifest-path tests/suites/drivers/podman/Cargo.toml --all -- --check", "cargo fmt --manifest-path tests/suites/features/Cargo.toml --all -- --check", "cargo fmt --manifest-path tests/support/Cargo.toml --all -- --check", diff --git a/tasks/scripts/check_cargo_lockfile_alignment.py b/tasks/scripts/check_cargo_lockfile_alignment.py index b442c3b5c1..dc0755af5a 100644 --- a/tasks/scripts/check_cargo_lockfile_alignment.py +++ b/tasks/scripts/check_cargo_lockfile_alignment.py @@ -38,6 +38,7 @@ "tests/support", "tests/testkit", "tests/suites/conformance", + "tests/suites/drivers/docker", "tests/suites/drivers/podman", "tests/suites/features", ) diff --git a/tasks/test.toml b/tasks/test.toml index da750c904f..233d78273b 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -199,7 +199,7 @@ run = "e2e/with-docker-gateway.sh cargo nextest run --locked --manifest-path tes ["e2e:rust:push"] description = "Run conformance and policy e2e tests against a Docker gateway that pushes configuration" -env = { OPENSHELL_CONFIG_DELIVERY_MODE = "push", OPENSHELL_E2E_DOCKER_FEATURES = "e2e-config-push", OPENSHELL_E2E_DOCKER_TEST = "config_push live_policy_update policy_activation" } +env = { OPENSHELL_CONFIG_DELIVERY_MODE = "push", OPENSHELL_E2E_DOCKER_FEATURES = "e2e-config-push", OPENSHELL_E2E_DOCKER_TEST = "config_push policy_activation" } run = "e2e/rust/e2e-docker.sh" ["e2e:workload:build"] @@ -222,13 +222,6 @@ exec e2e/with-docker-gateway.sh cargo test --manifest-path e2e/rust/Cargo.toml \ --features e2e-docker --test supervisor_middleware_http_hooks -- --nocapture """ -["e2e:websocket-conformance"] -description = "Run focused WebSocket conformance e2e tests against a Docker-backed gateway" -run = [ - "CONTAINER_ENGINE=docker bash tasks/scripts/e2e-build-workload.sh", - "e2e/with-docker-gateway.sh cargo test --manifest-path e2e/rust/Cargo.toml --features e2e-docker --test websocket_conformance", -] - ["e2e:mcp"] description = "Run MCP conformance e2e scenarios against one Docker-backed gateway (static defaults for spec 2025-11-25; set OPENSHELL_MCP_CONFORMANCE_SCENARIOS for a focused subset)" run = "bash e2e/mcp-conformance.sh" diff --git a/tests/suites/conformance/Cargo.lock b/tests/suites/conformance/Cargo.lock index 855f0ccac8..dbf9114e33 100644 --- a/tests/suites/conformance/Cargo.lock +++ b/tests/suites/conformance/Cargo.lock @@ -1207,6 +1207,7 @@ name = "host-server-support" version = "0.0.0" dependencies = [ "openshell-testkit", + "serde_json", "tokio", "tungstenite", ] @@ -2273,6 +2274,7 @@ dependencies = [ "openshell-policy", "openshell-sdk", "openshell-testkit-macros", + "prost-types", "quick-junit", "rand 0.9.4", "serde", diff --git a/tests/suites/conformance/README.md b/tests/suites/conformance/README.md index 0639d70d52..45d61eb60b 100644 --- a/tests/suites/conformance/README.md +++ b/tests/suites/conformance/README.md @@ -17,7 +17,12 @@ nextest run the tests as the library's unit tests. The crate also builds the | `persistent-workspace` | Files in `/sandbox` survive stop and start | | `policy-advisor` | `policy.local` accepts a proposed rule; a denied address or hostname yields one draft rule | | `file-transfer` | `sandbox upload` and `download`: round trips, file modes and symlinks outside the workspace, `.gitignore` filtering, workspace-escape and option-looking names, a large upload | -| `credential-gating` | Provider credentials: admission of credentialed endpoints, REST body placeholders and rewriting, WebSocket binary frames, live policy binding | +| `credential-gating` | Provider credentials: admission of credentialed endpoints, REST header and body placeholders and rewriting, WebSocket text and binary frames, live policy binding, static credentials bound to their profile endpoints | +| `network` | Direct connections that bypass the proxy are denied; reserved destinations fail with `EACCES`; localhost works without proxy settings; closed listeners release their ports | +| `network-l7` | REST, GraphQL, JSON-RPC, and MCP rules allow and deny requests; REST upgrades are refused | +| `network-egress` | Transparent egress: policy reloads close open connections, ambiguous updates are rejected, `tls: skip` relays raw bytes, middleware redacts or blocks traffic, pipelined requests are authorized one at a time | +| `policy-update` | `policy set` and `policy update`: revisions and versions, repeated updates, scoped endpoint changes, the revision for a sparse initial policy | +| `port-forward` | `forward start` reaches a server on the sandbox's loopback; `forward stop` closes the port | | `image` | A sandbox runs the default image or the one it is created from | | `labels` | Labels are stored and select sandboxes in `sandbox list` | | `templates` | A sandbox created from a template uses its workload; duplicate, deleted and missing templates return the right errors | @@ -31,8 +36,9 @@ tmachine environment on CI. The other suites are ports of the old (credited in each file). `file-transfer` runs `git` on the machine that runs the tests, so a test environment needs it installed (`tests/tmachine/ansible/playbooks/test-tools.yaml` does that for the tmachine -environments). `credential-gating`, ported from NVIDIA/OpenShell#5264, starts -servers (`tests/support/host-server`) on the machine that runs the tests and +environments). `credential-gating`, `network`, `network-l7`, and +`network-egress` start servers (`tests/support/host-server`) on the machine +that runs the tests and reaches them from sandboxes created from `testkit::python_image()` through `host.openshell.internal`. `ssh` runs `ssh` and `ssh-keygen` there and needs a named gateway, which `sandbox ssh-config` writes into its `ProxyCommand`. diff --git a/tests/suites/conformance/src/credential_gating.rs b/tests/suites/conformance/src/credential_gating.rs index 2d67926ef0..f6ff4a0c9d 100644 --- a/tests/suites/conformance/src/credential_gating.rs +++ b/tests/suites/conformance/src/credential_gating.rs @@ -4,20 +4,26 @@ //! Credential gating: which endpoints a provider credential may reach, and //! what the supervisor forwards upstream in REST bodies and WebSocket frames. //! -//! Ported from the e2e tests added in NVIDIA/OpenShell#5264. The upstream +//! Ported from the e2e tests added in NVIDIA/OpenShell#5264, the credential +//! test in `proxy_egress_pipeline`, and `websocket_conformance`. The upstream //! servers run on the test host ([`host_server_support`]), so the suite //! requires sandboxes to reach the test host as `host.openshell.internal`. use std::time::Duration; -use host_server_support::{HttpRecorder, Request, WebSocketRecorder}; +use host_server_support::{HttpRecorder, Request, Response, TEXT_REPLY, WebSocketRecorder}; +use serde_json::json; use testkit::policy::{self, Access, Endpoint as _}; use testkit::sdk::raw::proto; -use testkit::{ - Context, Error, GrpcCode, PYTHON_BINARIES, Result, ResultExt as _, Sandbox, YamlFile, -}; +use testkit::{Context, Error, GrpcCode, PYTHON_BINARIES, Result, ResultExt as _, Sandbox}; + +use crate::support::{self, TEST_HOST, python_binaries_yaml}; + +const CREDENTIAL_REWRITE_CLIENT: &str = include_str!("scripts/credential_rewrite_client.py"); +const WEBSOCKET_TEXT_CLIENT: &str = include_str!("scripts/websocket_text_client.py"); +const BOUND_CREDENTIAL_CLIENT: &str = include_str!("scripts/bound_credential_client.sh"); +const BASH: &str = "/usr/bin/bash"; -const TEST_HOST: &str = "host.openshell.internal"; const TOKEN_ENV: &str = "E2E_GATING_TOKEN"; const TEST_SECRET: &str = "e2e-gating-secret-value"; const PLACEHOLDER_PREFIX: &str = "openshell:resolve:env:"; @@ -208,17 +214,173 @@ async fn policy_binding_updates_provider_environment_live(cx: &mut Context) -> t let sandbox = create_sandbox(cx, "live", unbound.clone(), &[&provider]).await?; wait_for_token(&sandbox, "TOKEN_ABSENT").await?; - set_policy(cx, &sandbox, &bound) + policy::set(&sandbox, &bound) .await .context("bind the provider")?; wait_for_token(&sandbox, "TOKEN_PLACEHOLDER").await?; - set_policy(cx, &sandbox, &unbound) + policy::set(&sandbox, &unbound) .await .context("unbind the provider")?; wait_for_token(&sandbox, "TOKEN_ABSENT").await } +/// A provider whose profile declares a REST endpoint with body rewriting +/// gets its placeholder replaced with the secret in both the +/// `Authorization` header and the body of every request, with no +/// placeholder left upstream. +#[testkit::test] +async fn profile_rest_endpoint_rewrites_header_and_body(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::start("ok").await?; + let sandbox = profile_endpoint_sandbox( + cx, + "rwrt", + &format!( + "{{host: {TEST_HOST}, port: {}, path: /probe, protocol: rest, access: full, \ + enforcement: enforce, request_body_credential_rewrite: true}}", + server.port + ), + ) + .await?; + support::run_python( + &sandbox, + CREDENTIAL_REWRITE_CLIENT, + &[TEST_HOST, &server.port.to_string()], + ) + .await? + .expect_stdout("REWRITE_OK\n")?; + + let requests = server.wait_for_requests(2).await?; + let authorization = format!("Bearer {TEST_SECRET}"); + for request in &requests { + testkit::ensure!( + request.header("authorization").as_deref() == Some(authorization.as_str()) + && request.body.contains(TEST_SECRET) + && !request.head.contains(PLACEHOLDER_PREFIX) + && !request.body.contains(PLACEHOLDER_PREFIX), + "expected the secret in the header and body upstream; got {}", + redact(request) + ); + } + Ok(()) +} + +/// A provider whose profile declares a WebSocket endpoint with +/// `websocket_credential_rewrite` gets its placeholder replaced with the +/// secret in a text frame. +#[testkit::test] +async fn profile_websocket_endpoint_rewrites_text_frames(cx: &mut Context) -> testkit::Result { + let server = WebSocketRecorder::start().await?; + let sandbox = profile_endpoint_sandbox( + cx, + "wstxt", + &format!( + "{{host: {TEST_HOST}, port: {}, path: /ws, protocol: websocket, \ + enforcement: enforce, access: read-write, websocket_credential_rewrite: true}}", + server.port + ), + ) + .await?; + support::run_python( + &sandbox, + WEBSOCKET_TEXT_CLIENT, + &[TEST_HOST, &server.port.to_string()], + ) + .await? + .expect_stdout(&format!("{TEXT_REPLY}\n"))?; + + let texts = server.texts(); + testkit::ensure!( + texts.len() == 1 + && texts[0].contains(TEST_SECRET) + && !texts[0].contains(PLACEHOLDER_PREFIX), + "expected one text frame with the secret upstream; got {:?}", + texts + .iter() + .map(|text| text.replace(TEST_SECRET, "")) + .collect::>() + ); + Ok(()) +} + +/// A provider's credential resolves only at the endpoints its profile +/// declares: another provider's endpoint and an undeclared path on its own +/// endpoint get `403`, and the sandbox logs the mismatch without the secret +/// or its variable name. +#[testkit::test] +async fn profile_endpoints_bind_static_credentials(cx: &mut Context) -> testkit::Result { + const SECRET_A: &str = "e2e-bound-secret"; + const SECRET_B: &str = "e2e-provider-b-secret"; + let authorized = |request: &Request| { + let authorized = request.header("authorization").as_deref() + == Some(format!("Bearer {SECRET_A}").as_str()); + Response::json(&json!({ "authorized": authorized })) + }; + let server_a = HttpRecorder::serve(authorized).await?; + let server_b = HttpRecorder::serve(authorized).await?; + let provider_a = + install_bound_provider(cx, "binda", "BOUND_TOKEN_A", SECRET_A, server_a.port).await?; + let provider_b = + install_bound_provider(cx, "bindb", "BOUND_TOKEN_B", SECRET_B, server_b.port).await?; + + let endpoint = |port| { + format!( + "{{host: {TEST_HOST}, port: {port}, path: /**, protocol: rest, access: full, \ + enforcement: enforce}}" + ) + }; + let policy = policy::base_with(&format!( + "network_policies: + binding: + name: binding + endpoints: [{}, {}] + binaries: [{{path: {BASH}}}] +", + endpoint(server_a.port), + endpoint(server_b.port), + ))?; + let sandbox = cx + .sandbox("bind") + .image(testkit::python_image()) + .policy(policy) + .spec(|spec| spec.providers = vec![provider_a, provider_b]) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + let output = sandbox + .exec([ + BASH, + "-c", + BOUND_CREDENTIAL_CLIENT, + "bash", + TEST_HOST, + &server_a.port.to_string(), + &server_b.port.to_string(), + ]) + .await? + .success()?; + testkit::ensure!( + output.stdout.trim() + == r#"ALLOWED={"authorized":true} ENDPOINT_DENIED=403 PATH_DENIED=403"#, + "expected the credential only at its bound endpoint and path; got {}", + output.stdout.replace(SECRET_A, "") + ); + + let logs = sandbox + .logs_until("the endpoint mismatch", |logs| { + logs.contains("openshell.provider_credential.endpoint_mismatch") + && logs.contains("credential_endpoint_mismatch") + }) + .await?; + for leaked in [SECRET_A, SECRET_B, "BOUND_TOKEN_A", "BOUND_TOKEN_B"] { + testkit::ensure!( + !logs.contains(leaked), + "the sandbox logs contain a credential value or variable name" + ); + } + Ok(()) +} + /// Run [`WEBSOCKET_CLIENT`] against `server` in a sandbox with `providers`, /// and return whether its binary frame reached `server`. async fn send_binary_frame( @@ -253,21 +415,74 @@ fn allow(policy: &mut proto::SandboxPolicy, port: u16) -> &mut proto::NetworkEnd /// `endpoints`, its profile declares the REST and WebSocket ports as its /// endpoints; without, a policy must bind the provider explicitly. async fn install_gating_provider(cx: &Context, endpoints: Option<(u16, u16)>) -> Result { - let name = cx.name("cg"); - let endpoints = endpoints.map_or_else(String::new, |(rest, websocket)| { - format!( - "endpoints: - - host: {TEST_HOST} - port: {rest} - protocol: rest - access: full - - host: {TEST_HOST} - port: {websocket} - protocol: websocket - access: read-write -" - ) + let endpoints = endpoints.map_or_else(Vec::new, |(rest, websocket)| { + vec![ + format!("{{host: {TEST_HOST}, port: {rest}, protocol: rest, access: full}}"), + format!( + "{{host: {TEST_HOST}, port: {websocket}, protocol: websocket, access: read-write}}" + ), + ] }); + install_provider_with_endpoints(cx, &endpoints).await +} + +/// A long-running sandbox with a provider from +/// [`install_provider_with_endpoints`] whose profile declares `endpoint`, a +/// YAML flow mapping, and a policy that allows the same endpoint. +async fn profile_endpoint_sandbox(cx: &Context, suffix: &str, endpoint: &str) -> Result { + let provider = install_provider_with_endpoints(cx, &[endpoint.to_string()]).await?; + let policy = policy::base_with(&format!( + "network_policies: + credential_gating: + name: credential_gating + endpoints: [{endpoint}] + binaries: {binaries} +", + binaries = python_binaries_yaml(), + ))?; + create_sandbox(cx, suffix, policy, &[&provider]).await +} + +/// Install a provider named `cx.name(suffix)` holding `secret` in `env_var`, +/// whose profile binds it to `/allowed/**` on `TEST_HOST` at `port` for +/// [`BASH`]. +async fn install_bound_provider( + cx: &Context, + suffix: &str, + env_var: &str, + secret: &str, + port: u16, +) -> Result { + let name = cx.name(suffix); + let profile = format!( + "id: {name} +display_name: E2E static endpoint binding +category: other +credentials: + - name: bound_token + env_vars: [{env_var}] + required: true + auth_style: bearer + header_name: authorization +endpoints: + - {{host: {TEST_HOST}, port: {port}, path: /allowed/**, protocol: rest, access: full, enforcement: enforce}} +binaries: [{BASH}] +" + ); + cx.install_provider(&name, &profile, &[(env_var, secret)]) + .await?; + Ok(name) +} + +/// Install a run-unique provider holding `TEST_SECRET` in `TOKEN_ENV`, whose +/// profile declares `endpoints`, each a YAML flow mapping. +async fn install_provider_with_endpoints(cx: &Context, endpoints: &[String]) -> Result { + let name = cx.name("cg"); + let endpoints = if endpoints.is_empty() { + String::new() + } else { + format!("endpoints: [{}]\n", endpoints.join(", ")) + }; let binaries: String = PYTHON_BINARIES .iter() .map(|path| format!(" - path: {path}\n")) @@ -392,22 +607,3 @@ async fn wait_for_token(sandbox: &Sandbox, expected: &str) -> Result { .await?; Ok(()) } - -/// Replace `sandbox`'s policy with `policy` and wait until it is applied. -async fn set_policy(cx: &Context, sandbox: &Sandbox, policy: &proto::SandboxPolicy) -> Result { - let file = YamlFile::new(&policy::to_yaml(policy)?)?; - cx.cli([ - "policy", - "set", - sandbox.name(), - "--policy", - file.path()?, - "--wait", - "--timeout", - "120", - ]) - .await? - .success() - .context("policy set")?; - Ok(()) -} diff --git a/tests/suites/conformance/src/lib.rs b/tests/suites/conformance/src/lib.rs index f0a568679c..0a1ed08203 100644 --- a/tests/suites/conformance/src/lib.rs +++ b/tests/suites/conformance/src/lib.rs @@ -17,10 +17,16 @@ mod filesystem_policy; mod image; mod labels; mod lifecycle; +mod network; +mod network_egress; +mod network_l7; mod persistent_workspace; mod policy_advisor; +mod policy_update; +mod port_forward; mod process; mod settings; mod smoke; mod ssh; +mod support; mod templates; diff --git a/tests/suites/conformance/src/lifecycle.rs b/tests/suites/conformance/src/lifecycle.rs index 71854d2b52..9510c9365f 100644 --- a/tests/suites/conformance/src/lifecycle.rs +++ b/tests/suites/conformance/src/lifecycle.rs @@ -395,9 +395,11 @@ const EPHEMERAL_CLEANUP_TIMEOUT: Duration = Duration::from_secs(60); /// command exits, whether the command succeeds or fails. /// /// This checks only what the gateway shows: get and list stop returning the -/// sandbox. Conformance can't see driver resources, so the check that the -/// driver removed its containers, pods or VM state stays in the legacy -/// `e2e/rust/tests/ephemeral_cleanup.rs` until the driver suites replace it. +/// sandbox. Conformance can't see driver resources: the Docker and Podman +/// driver suites (`tests/suites/drivers/{docker,podman}`) check that the +/// driver removed its containers, and the legacy +/// `e2e/rust/tests/ephemeral_cleanup.rs` still checks Kubernetes pods and VM +/// state. #[testkit::test] async fn detached_no_keep_sandbox_is_removed_after_main_exits(cx: &mut Context) -> testkit::Result { let mut sandboxes = Vec::new(); diff --git a/tests/suites/conformance/src/network.rs b/tests/suites/conformance/src/network.rs new file mode 100644 index 0000000000..fdbc8c544f --- /dev/null +++ b/tests/suites/conformance/src/network.rs @@ -0,0 +1,133 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Sandbox networking: direct connections the sandbox refuses, loopback +//! traffic it leaves alone, and listening sockets whose lifetime it must not +//! extend. +//! +//! Ported from the `bypass_detection`, `listener_lifetime`, and `no_proxy` +//! e2e tests, and the destination denials in `proxy_egress_pipeline`. + +use std::time::Duration; + +use serde_json::json; +use testkit::{Context, ResultExt as _, policy}; + +use crate::support::{ + expect_values, json_result, python_binaries_yaml, python_sandbox, run_python, +}; + +const BYPASS_CLIENT: &str = include_str!("scripts/bypass_client.py"); +const DESTINATION_DENIALS_CLIENT: &str = include_str!("scripts/destination_denials_client.py"); +const LOCALHOST_CLIENT: &str = include_str!("scripts/localhost_client.py"); +const LISTENER_LIFETIME_PROBE: &str = include_str!("scripts/listener_lifetime_probe.py"); +const PRECONNECT_OWNER: &str = include_str!("scripts/preconnect_owner.py"); +const SOCKET_NOT_INHERITED: &str = include_str!("scripts/socket_not_inherited.py"); + +/// A direct TCP connection that bypasses the proxy is denied with a +/// permission error well before the socket's 10-second timeout. +#[testkit::test] +async fn direct_connect_bypass_is_denied_promptly(cx: &mut Context) -> testkit::Result { + let sandbox = python_sandbox(cx, "bypas", policy::base()).await?; + let output = run_python(&sandbox, BYPASS_CLIENT, &[]).await?; + let result = json_result(&output)?; + testkit::ensure!( + result["bypass_result"] == "denied", + "expected the direct connect to be denied; got {result}" + ); + let elapsed = result["elapsed_ms"].as_u64().unwrap_or(u64::MAX); + testkit::ensure!( + elapsed < 8000, + "the denial took {elapsed} ms; expected under 8000" + ); + Ok(()) +} + +/// Connections to cloud metadata, a Kubernetes API port, and an address +/// outside an endpoint's `allowed_ips` fail with `EACCES` even though the +/// policy names them. +#[testkit::test] +async fn reserved_destinations_fail_with_eacces_even_when_allowed( + cx: &mut Context, +) -> testkit::Result { + let policy = policy::base_with(&format!( + r#"network_policies: + destination_denials: + name: destination_denials + endpoints: + - {{ host: 169.254.169.254, port: 80 }} + - {{ host: 127.0.0.1, port: 80 }} + - {{ host: 203.0.113.10, port: 6443 }} + - host: 203.0.113.10 + port: 8080 + allowed_ips: ["198.51.100.0/24"] + binaries: {binaries} +"#, + binaries = python_binaries_yaml(), + ))?; + let sandbox = python_sandbox(cx, "deny", policy).await?; + let output = run_python(&sandbox, DESTINATION_DENIALS_CLIENT, &[]).await?; + expect_values( + &json_result(&output)?, + &[ + ("metadata", json!(13)), + ("control_plane", json!(13)), + ("outside_allowed_ips", json!(13)), + ], + ) +} + +/// A process can serve and fetch HTTP on 127.0.0.1 without proxy variables +/// in its environment. +#[testkit::test] +async fn localhost_is_reachable_without_proxy_environment(cx: &mut Context) -> testkit::Result { + let sandbox = python_sandbox(cx, "local", policy::base()).await?; + let output = run_python(&sandbox, LOCALHOST_CLIENT, &[]).await?; + expect_values( + &json_result(&output)?, + &[ + ("proxy_env_absent", json!(true)), + ("payload", json!({"message": "hello"})), + ], + ) +} + +/// Closing a listener, or exiting while holding one, frees its port: new +/// connections are refused and the port can be bound again. A later exec +/// doesn't inherit the exited child's listener. +#[testkit::test] +async fn closed_or_exited_listener_releases_its_port(cx: &mut Context) -> testkit::Result { + let sandbox = python_sandbox(cx, "lsten", policy::base()).await?; + let output = run_python(&sandbox, LISTENER_LIFETIME_PROBE, &[]).await?; + let inode = json_result(&output)?[1].to_string(); + run_python(&sandbox, SOCKET_NOT_INHERITED, &[&inode]) + .await + .context("a later exec inherited the closed listener")?; + Ok(()) +} + +/// An exec doesn't inherit a socket that the sandbox's main process opened +/// without close-on-exec. +#[testkit::test] +async fn exec_does_not_inherit_main_process_socket(cx: &mut Context) -> testkit::Result { + let sandbox = cx + .sandbox("prcon") + .policy(policy::base()) + .image(testkit::python_image()) + .command(["python3", "-c", PRECONNECT_OWNER]) + .create_ready() + .await?; + let inode = sandbox + .poll_exec( + "the main process to publish its socket inode", + Duration::from_secs(30), + ["cat", "/sandbox/preconnect-inode"], + |output| output.exit_code == 0 && output.stdout.trim().parse::().is_ok(), + ) + .await? + .stdout; + run_python(&sandbox, SOCKET_NOT_INHERITED, &[inode.trim()]) + .await + .context("the exec inherited the main process's socket")?; + Ok(()) +} diff --git a/tests/suites/conformance/src/network_egress.rs b/tests/suites/conformance/src/network_egress.rs new file mode 100644 index 0000000000..899e146eee --- /dev/null +++ b/tests/suites/conformance/src/network_egress.rs @@ -0,0 +1,432 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Transparent egress: what the supervisor does with connections a workload +//! makes straight to a destination, without proxy settings. Policy reloads +//! apply to open connections, `tls: skip` relays raw bytes, middleware +//! inspects or blocks traffic, and pipelined requests are authorized one at +//! a time. +//! +//! Ported from the `proxy_egress_pipeline` e2e tests. The upstream servers +//! run on the test host ([`host_server_support`]). + +use std::time::Duration; + +use host_server_support::{HttpRecorder, Request, Response, TcpServer}; +use serde_json::{Value, json}; +use testkit::policy::{self, Endpoint as _}; +use testkit::sdk::raw::proto; +use testkit::{Context, PYTHON_BINARIES, Result, ResultExt as _, Sandbox}; + +use crate::support::{ + TEST_HOST, expect_values, json_result, policy_revisions, python_binaries_yaml, python_sandbox, + run_python, +}; + +const STATUS_CLIENT: &str = include_str!("scripts/status_client.py"); +const RELOAD_KEEP_ALIVE_CLIENT: &str = include_str!("scripts/reload_keep_alive_client.py"); +const ECHO_CLIENT: &str = include_str!("scripts/echo_client.py"); +const UNINSPECTABLE_CLIENT: &str = include_str!("scripts/uninspectable_client.py"); +const REDACTION_CLIENT: &str = include_str!("scripts/redaction_client.py"); +const PIPELINE_CLIENT: &str = include_str!("scripts/pipeline_client.py"); + +/// Files [`RELOAD_KEEP_ALIVE_CLIENT`] signals through. +const RELOAD_READY: &str = "/tmp/proxy-reload-ready"; +const RELOAD_GO: &str = "/tmp/proxy-reload-go"; +const RELOAD_RESULT: &str = "/tmp/proxy-reload-result"; +const RELOAD_LOG: &str = "/tmp/proxy-reload-client.log"; + +/// The reply [`TcpServer::reply_when_idle`] gives a pipelined request, so the +/// connection stays usable for the next one. +const PIPELINE_REPLY: &[u8] = b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok"; + +/// A policy reload that removes access applies to new connections and to a +/// keep-alive connection opened before it: the next request on that +/// connection isn't forwarded. +#[testkit::test] +async fn policy_reload_denies_new_and_open_connections(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(|_| Response::text("ok").keep_alive()).await?; + let allowed = allow_server(server.port); + let sandbox = python_sandbox(cx, "reld", allowed.clone()).await?; + policy::set(&sandbox, &allowed).await?; + + let port = server.port.to_string(); + sandbox + .exec([ + "sh", + "-c", + &format!("nohup python3 -c \"$1\" {TEST_HOST} {port} >{RELOAD_LOG} 2>&1 &"), + "reload-client", + RELOAD_KEEP_ALIVE_CLIENT, + ]) + .await? + .success() + .context("start the keep-alive client")?; + wait_for_file(&sandbox, RELOAD_READY).await?; + expect_statuses(&sandbox, &port, |status| status == 200) + .await + .context("before the reload")?; + + policy::set(&sandbox, &policy::base()).await?; + sandbox + .exec(["touch", RELOAD_GO]) + .await? + .success() + .context("release the keep-alive client")?; + let result: Value = serde_json::from_str(wait_for_file(&sandbox, RELOAD_RESULT).await?.trim()) + .context("parse the keep-alive client's result")?; + testkit::ensure!( + result["failed_closed"] == true, + "the open connection forwarded a request after the reload: {result}" + ); + expect_statuses(&sandbox, &port, |status| status != 200) + .await + .context("after the reload") +} + +/// The gateway rejects a policy update with two endpoints for one host and +/// port, one of them `tls: skip`. The sandbox keeps its policy revisions and +/// still forwards requests under the active policy. +#[testkit::test] +async fn ambiguous_policy_update_is_rejected_and_active_policy_kept( + cx: &mut Context, +) -> testkit::Result { + let server = HttpRecorder::serve(|_| Response::text("ok").keep_alive()).await?; + let allowed = allow_server(server.port); + let sandbox = python_sandbox(cx, "ambig", allowed.clone()).await?; + policy::set(&sandbox, &allowed).await?; + let port = server.port.to_string(); + expect_statuses(&sandbox, &port, |status| status == 200) + .await + .context("before the rejected update")?; + let revisions = policy_revisions(cx, &sandbox).await?; + let connections = server.connections(); + + let mut ambiguous = policy::base(); + policy::allow( + &mut ambiguous, + "terminating", + TEST_HOST, + server.port, + PYTHON_BINARIES, + ); + policy::allow( + &mut ambiguous, + "passthrough", + TEST_HOST, + server.port, + PYTHON_BINARIES, + ) + .tls_skip(); + let file = testkit::YamlFile::new(&policy::to_yaml(&ambiguous)?)?; + let output = cx + .cli([ + "policy", + "set", + sandbox.name(), + "--policy", + file.path()?, + "--wait", + "--timeout", + "120", + ]) + .await? + .failure()?; + testkit::ensure!( + output.report_text().contains("ambiguity validation failed"), + "the rejection doesn't explain the ambiguity:\n{}", + output.report_text() + ); + + let after = policy_revisions(cx, &sandbox).await?; + testkit::ensure!( + after == revisions, + "the rejected policy changed the revisions:\nbefore: {revisions}\nafter: {after}" + ); + expect_statuses(&sandbox, &port, |status| status == 200) + .await + .context("after the rejected update")?; + testkit::ensure!( + server.connections() > connections, + "requests under the active policy didn't reach the server" + ); + Ok(()) +} + +/// An endpoint with `tls: skip` relays bytes that are neither HTTP nor TLS +/// unchanged in both directions. +#[testkit::test] +async fn tls_skip_relays_opaque_bytes(cx: &mut Context) -> testkit::Result { + let server = TcpServer::echo().await?; + let mut policy = policy::base(); + allow(&mut policy, server.port).tls_skip(); + let sandbox = python_sandbox(cx, "tlskp", policy).await?; + let mut payload = vec![0x00, 0xff, 0x13, 0x37, 0x80, 0x0a]; + payload.extend_from_slice(b"not-http-or-tls"); + payload.extend(0..64_u8); + run_python( + &sandbox, + ECHO_CLIENT, + &[TEST_HOST, &server.port.to_string(), &hex(&payload)], + ) + .await? + .expect_stdout("ECHO_OK\n")?; + Ok(()) +} + +/// A redacting middleware rewrites an API key in each request body before +/// it reaches upstream. +#[testkit::test] +async fn middleware_redacts_request_bodies(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(|request: &Request| { + Response::new(200) + .header("Content-Type", "application/json") + .body(request.body.clone()) + }) + .await?; + let policy = middleware_policy(server.port, "fail_closed", "")?; + let sandbox = python_sandbox(cx, "redct", policy).await?; + let output = run_python( + &sandbox, + REDACTION_CLIENT, + &[TEST_HOST, &server.port.to_string()], + ) + .await?; + let result = json_result(&output)?; + for request in ["first", "second"] { + expect_values(&result[request], &[("api_key", json!("[REDACTED]"))]) + .context(format!("the {request} request"))?; + } + Ok(()) +} + +/// A `fail_closed` middleware blocks traffic it can't inspect before any +/// byte reaches upstream, and the sandbox logs why. +#[testkit::test] +async fn fail_closed_middleware_blocks_uninspectable_traffic(cx: &mut Context) -> testkit::Result { + let server = TcpServer::echo().await?; + let policy = middleware_policy(server.port, "fail_closed", "")?; + let sandbox = python_sandbox(cx, "fclos", policy).await?; + run_python( + &sandbox, + UNINSPECTABLE_CLIENT, + &[TEST_HOST, &server.port.to_string()], + ) + .await? + .expect_stdout("BLOCKED\n")?; + // Give a forwarded payload time to arrive before checking it didn't. + tokio::time::sleep(Duration::from_millis(200)).await; + let received = server.received(); + testkit::ensure!( + received.is_empty(), + "the payload reached upstream: {:?}", + String::from_utf8_lossy(&received) + ); + sandbox + .logs_until("the middleware denial", |logs| { + logs.contains("openshell.middleware.traffic_uninspectable") + && logs.contains( + "Unsupported tunnel protocol cannot be inspected by required middleware", + ) + }) + .await?; + Ok(()) +} + +/// A `fail_open` middleware on a `tls: skip` endpoint lets traffic it can't +/// inspect through unchanged. +#[testkit::test] +async fn fail_open_middleware_relays_uninspectable_traffic(cx: &mut Context) -> testkit::Result { + let server = TcpServer::echo().await?; + let policy = middleware_policy(server.port, "fail_open", " tls: skip\n")?; + let sandbox = python_sandbox(cx, "fopen", policy).await?; + let mut payload = vec![0x00, 0xff, 0x13, 0x37, 0x80]; + payload.extend_from_slice(b"middleware-bypass"); + run_python( + &sandbox, + ECHO_CLIENT, + &[TEST_HOST, &server.port.to_string(), &hex(&payload)], + ) + .await? + .expect_stdout("ECHO_OK\n")?; + let received = server.received(); + testkit::ensure!( + received == payload, + "upstream received {:?}; expected the payload unchanged", + String::from_utf8_lossy(&received) + ); + Ok(()) +} + +/// A denied request pipelined behind an allowed one is answered with `403` +/// and never reaches upstream, not even as extra bytes after the first +/// request. The relay strips the hop-by-hop `Connection` header. +#[testkit::test] +async fn pipelined_request_is_authorized_separately(cx: &mut Context) -> testkit::Result { + let server = TcpServer::reply_when_idle(PIPELINE_REPLY).await?; + let sandbox = python_sandbox(cx, "pipe", rest_policy(server.port, "GET")?).await?; + let target = format!("{TEST_HOST}:{}", server.port); + let requests = format!( + "GET /allowed HTTP/1.1\r\nHost: {target}\r\nConnection: keep-alive\r\n\r\n\ + POST /blocked HTTP/1.1\r\nHost: {target}\r\nContent-Length: 0\r\n\r\n" + ); + run_pipeline(&sandbox, server.port, &requests).await?; + let received = String::from_utf8_lossy(&server.received()).into_owned(); + testkit::ensure!( + received.starts_with("GET /allowed HTTP/1.1\r\n") + && !received.to_ascii_lowercase().contains("\r\nconnection:") + && !received.contains("/blocked"), + "expected only the allowed request upstream, without Connection; got:\n{received}" + ); + Ok(()) +} + +/// A denied request pipelined behind an allowed chunked request is +/// authorized on its own: upstream sees the chunked request whole and +/// nothing after it. +#[testkit::test] +async fn chunked_pipelined_request_is_authorized_separately(cx: &mut Context) -> testkit::Result { + let server = TcpServer::reply_when_idle(PIPELINE_REPLY).await?; + let sandbox = python_sandbox(cx, "chunk", rest_policy(server.port, "POST")?).await?; + let target = format!("{TEST_HOST}:{}", server.port); + let requests = format!( + "POST /allowed HTTP/1.1\r\nHost: {target}\r\nTransfer-Encoding: chunked\r\n\ + Connection: keep-alive\r\n\r\n0\r\n\r\n\ + DELETE /blocked HTTP/1.1\r\nHost: {target}\r\nContent-Length: 0\r\n\r\n" + ); + run_pipeline(&sandbox, server.port, &requests).await?; + let received = String::from_utf8_lossy(&server.received()).into_owned(); + testkit::ensure!( + received.starts_with("POST /allowed HTTP/1.1\r\n") + && received.ends_with("0\r\n\r\n") + && !received.contains("/blocked"), + "expected only the allowed chunked request upstream; got:\n{received}" + ); + Ok(()) +} + +/// [`policy::base`] with the image's Python allowed to reach `TEST_HOST` on +/// `port`. +fn allow_server(port: u16) -> proto::SandboxPolicy { + let mut policy = policy::base(); + allow(&mut policy, port); + policy +} + +fn allow(policy: &mut proto::SandboxPolicy, port: u16) -> &mut proto::NetworkEndpoint { + policy::allow(policy, "egress", TEST_HOST, port, PYTHON_BINARIES) +} + +/// An endpoint on `port` with the `openshell/regex` redacting middleware, +/// `on_error`, and the extra endpoint YAML in `endpoint_options`. +fn middleware_policy( + port: u16, + on_error: &str, + endpoint_options: &str, +) -> Result { + policy::base_with(&format!( + r#"network_middlewares: + regex-redactor: + name: Redact API tokens + middleware: openshell/regex + order: 10 + config: + mode: redact + on_error: {on_error} + endpoints: + include: ["{TEST_HOST}"] + exclude: [] +network_policies: + egress: + name: egress + endpoints: + - host: {TEST_HOST} + port: {port} +{endpoint_options} binaries: {binaries} +"#, + binaries = python_binaries_yaml(), + )) +} + +/// A REST endpoint on `port` that allows only `method` on `/allowed`. +fn rest_policy(port: u16, method: &str) -> Result { + policy::base_with(&format!( + r"network_policies: + egress: + name: egress + endpoints: + - host: {TEST_HOST} + port: {port} + protocol: rest + enforcement: enforce + rules: + - allow: + method: {method} + path: /allowed + binaries: {binaries} +", + binaries = python_binaries_yaml(), + )) +} + +/// Send `requests` pipelined in one write, and fail unless the first gets +/// `200` and the second `403`. +async fn run_pipeline(sandbox: &Sandbox, port: u16, requests: &str) -> Result { + let output = run_python( + sandbox, + PIPELINE_CLIENT, + &[TEST_HOST, &port.to_string(), requests], + ) + .await?; + let result = json_result(&output)?; + let statuses: Vec<&str> = result["statuses"] + .as_array() + .into_iter() + .flatten() + .filter_map(Value::as_str) + .collect(); + testkit::ensure!( + statuses.len() == 2 + && statuses[0].starts_with("HTTP/1.1 200") + && statuses.contains(&"HTTP/1.1 403 Forbidden"), + "expected 200 then 403; got {statuses:?}" + ); + Ok(()) +} + +/// Run [`STATUS_CLIENT`] and fail unless both its requests got a status +/// `expected` accepts. A failed connection counts as status 0. +async fn expect_statuses(sandbox: &Sandbox, port: &str, expected: impl Fn(i64) -> bool) -> Result { + let output = run_python(sandbox, STATUS_CLIENT, &[TEST_HOST, port]).await?; + let result = json_result(&output)?; + for request in ["first", "second"] { + let status = result[request].as_i64().unwrap_or(0); + testkit::ensure!( + expected(status), + "unexpected {request} request outcome: {result}" + ); + } + Ok(()) +} + +/// The contents of `path` in the sandbox, once it exists. A timeout reports +/// the keep-alive client's log. +async fn wait_for_file(sandbox: &Sandbox, path: &str) -> Result { + Ok(sandbox + .poll_exec( + &format!("{path} to appear"), + Duration::from_secs(60), + [ + "sh", + "-c", + &format!("cat {path} || {{ cat {RELOAD_LOG}; exit 1; }}"), + ], + |output| output.exit_code == 0, + ) + .await? + .stdout) +} + +fn hex(bytes: &[u8]) -> String { + bytes.iter().map(|byte| format!("{byte:02x}")).collect() +} diff --git a/tests/suites/conformance/src/network_l7.rs b/tests/suites/conformance/src/network_l7.rs new file mode 100644 index 0000000000..bbf71fde51 --- /dev/null +++ b/tests/suites/conformance/src/network_l7.rs @@ -0,0 +1,273 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! L7 network policy: REST, GraphQL, and JSON-RPC rules the sandbox enforces +//! on requests a workload sends straight to a server, without a proxy. +//! +//! Ported from the `forward_proxy_l7_bypass`, `forward_proxy_graphql_l7`, +//! and `forward_proxy_jsonrpc_l7` e2e tests. The upstream servers run on the +//! test host ([`host_server_support`]) and implement none of the protocols: +//! the sandbox parses and enforces them before forwarding, so a server that +//! answers is enough to tell an allowed request from a denied one. + +mod mcp; + +use host_server_support::{HttpRecorder, Request, Response}; +use serde_json::json; +use testkit::{Context, Result, ResultExt as _, policy}; + +use crate::support::{ + TEST_HOST, expect_values, json_result, python_binaries_yaml, python_sandbox, run_python, +}; + +const REST_CLIENT: &str = include_str!("scripts/rest_client.py"); +const REST_UPGRADE_CLIENT: &str = include_str!("scripts/rest_upgrade_client.py"); +const GRAPHQL_CLIENT: &str = include_str!("scripts/graphql_client.py"); +const JSONRPC_CLIENT: &str = include_str!("scripts/jsonrpc_client.py"); +const JSONRPC_AUDIT_CLIENT: &str = include_str!("scripts/jsonrpc_audit_client.py"); + +/// A REST endpoint that allows only `GET /allowed` passes that request and +/// answers a `POST` to the same path with `403` before it reaches upstream. +#[testkit::test] +async fn rest_rules_allow_get_and_deny_post(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(rest_upstream).await?; + let sandbox = python_sandbox(cx, "rest", rest_policy(server.port, "enforce")?).await?; + let output = run_python(&sandbox, REST_CLIENT, &[TEST_HOST, &port(&server)]).await?; + expect_values( + &json_result(&output)?, + &[("get", json!(200)), ("post", json!(403))], + )?; + let methods: Vec = server + .requests() + .iter() + .map(|request| request.method().to_string()) + .collect(); + testkit::ensure!( + methods == ["GET"], + "expected only the GET upstream; got {methods:?}" + ); + Ok(()) +} + +/// A permitted `GET` can't switch a REST endpoint into an uninspected +/// WebSocket tunnel, in enforce or audit mode: the sandbox answers the +/// upgrade with `403` and `unsupported_l7_protocol`. +#[testkit::test] +async fn rest_upgrade_is_refused_in_enforce_and_audit_modes(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(rest_upstream).await?; + for (suffix, enforcement) in [("enfrc", "enforce"), ("audit", "audit")] { + let sandbox = python_sandbox(cx, suffix, rest_policy(server.port, enforcement)?).await?; + run_python(&sandbox, REST_UPGRADE_CLIENT, &[TEST_HOST, &port(&server)]) + .await + .context(format!("{enforcement} mode"))? + .expect_stdout("REST_UPGRADE_REFUSED\n")?; + } + Ok(()) +} + +/// GraphQL rules allow listed query and mutation fields and registered +/// persisted queries, and deny unlisted fields, deny-rule mutations, +/// unregistered persisted queries, and a GET with a second, denied query. +/// Bodies sent with Content-Length and chunked both work, through urllib +/// and raw sockets. +#[testkit::test] +async fn graphql_rules_allow_and_deny_operations(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(|request| match request.method() { + "GET" if request.path() == "/" || request.path().starts_with("/graphql?") => ok_json(), + "GET" => ok_json().status(418), + _ => ok_json(), + }) + .await?; + let policy = policy::base_with(&format!( + r"network_policies: + graphql: + name: graphql + endpoints: + - host: {TEST_HOST} + port: {port} + protocol: graphql + enforcement: enforce + persisted_queries: allow_registered + graphql_persisted_queries: + abc123: + operation_type: query + operation_name: Viewer + fields: [viewer] + rules: + - allow: + operation_type: query + fields: [viewer] + - allow: + operation_type: mutation + fields: [createIssue] + deny_rules: + - operation_type: mutation + fields: [deleteRepository] + binaries: {binaries} +", + port = server.port, + binaries = python_binaries_yaml(), + ))?; + let sandbox = python_sandbox(cx, "gql", policy).await?; + let output = run_python(&sandbox, GRAPHQL_CLIENT, &[TEST_HOST, &port(&server)]).await?; + let mut expected = Vec::new(); + for path in ["forward", "raw"] { + for (key, status) in [ + ("query_allowed", 200), + ("get_query_allowed", 200), + ("duplicate_get_denied", 403), + ("persisted_get_allowed", 200), + ("unregistered_persisted_get_denied", 403), + ("chunked_query_allowed", 200), + ("unlisted_field_denied", 403), + ("mutation_allowed", 200), + ("deny_rule_denied", 403), + ] { + expected.push((format!("{path}_{key}"), json!(status))); + } + } + expect_values(&json_result(&output)?, &expected) +} + +/// JSON-RPC rules allow listed methods whatever their params, deny a +/// deny-rule method, a batch with one denied call, and invalid JSON, through +/// urllib and raw sockets. +#[testkit::test] +async fn jsonrpc_rules_allow_and_deny_methods(cx: &mut Context) -> testkit::Result { + let server = HttpRecorder::serve(jsonrpc_upstream).await?; + let policy = policy::base_with(&format!( + r"network_policies: + jsonrpc: + name: jsonrpc + endpoints: + - host: {TEST_HOST} + port: {port} + path: /rpc + protocol: json-rpc + enforcement: enforce + json_rpc: + max_body_bytes: 65536 + rules: + - allow: + method: initialize + - allow: + method: tools/list + - allow: + method: tools/call + deny_rules: + - method: tools/delete + binaries: {binaries} +", + port = server.port, + binaries = python_binaries_yaml(), + ))?; + let sandbox = python_sandbox(cx, "jrpc", policy).await?; + let output = run_python(&sandbox, JSONRPC_CLIENT, &[TEST_HOST, &port(&server)]).await?; + let mut expected = Vec::new(); + for path in ["forward", "raw"] { + for (key, status) in [ + ("method_initialize_allowed", 200), + ("method_tools_list_allowed", 200), + ("method_tools_call_allowed", 200), + ("method_tools_call_with_unmatched_params_allowed", 200), + ("method_tools_delete_denied", 403), + ] { + expected.push((format!("{path}_{key}"), json!(status))); + } + } + for (key, status) in [ + ("forward_batch_all_allowed", 200), + ("forward_batch_one_denied", 403), + ("forward_invalid_json_denied", 403), + ] { + expected.push((key.to_string(), json!(status))); + } + expect_values(&json_result(&output)?, &expected) +} + +/// A JSON-RPC endpoint without `enforcement` audits an unlisted method and +/// passes it, but still denies a response frame sent as a request. +#[testkit::test] +async fn jsonrpc_default_audit_mode_still_denies_response_frames( + cx: &mut Context, +) -> testkit::Result { + let server = HttpRecorder::serve(jsonrpc_upstream).await?; + let policy = policy::base_with(&format!( + r"network_policies: + jsonrpc_audit: + name: jsonrpc_audit + endpoints: + - host: {TEST_HOST} + port: {port} + path: /rpc + protocol: json-rpc + json_rpc: + max_body_bytes: 65536 + rules: + - allow: + method: initialize + binaries: {binaries} +", + port = server.port, + binaries = python_binaries_yaml(), + ))?; + let sandbox = python_sandbox(cx, "jaud", policy).await?; + let output = run_python(&sandbox, JSONRPC_AUDIT_CLIENT, &[TEST_HOST, &port(&server)]).await?; + expect_values( + &json_result(&output)?, + &[ + ("forward_unknown_method_audited", json!(200)), + ("forward_response_frame_hard_denied", json!(403)), + ], + ) +} + +/// A REST endpoint on `port` in `enforcement` mode that allows only +/// `GET /allowed`. +fn rest_policy(port: u16, enforcement: &str) -> Result { + policy::base_with(&format!( + r"network_policies: + rest: + name: rest + endpoints: + - host: {TEST_HOST} + port: {port} + protocol: rest + enforcement: {enforcement} + rules: + - allow: + method: GET + path: /allowed + binaries: {binaries} +", + binaries = python_binaries_yaml(), + )) +} + +/// Answers a WebSocket upgrade with `101`, and `GET` or `DELETE` with +/// `200`, so that a refused upgrade shows the sandbox refused it. +fn rest_upstream(request: &Request) -> Response { + match request.method() { + "GET" if request.header("upgrade").is_some() => Response::new(101) + .header("Connection", "Upgrade") + .header("Upgrade", "websocket") + .header("Sec-WebSocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="), + "GET" | "DELETE" => ok_json(), + _ => Response::new(405), + } +} + +fn jsonrpc_upstream(request: &Request) -> Response { + match request.method() { + "POST" => Response::json(&json!({"jsonrpc": "2.0", "id": 1, "result": {}})), + _ => Response::new(200), + } +} + +fn ok_json() -> Response { + Response::json(&json!({"ok": true})) +} + +fn port(server: &HttpRecorder) -> String { + server.port.to_string() +} diff --git a/tests/suites/conformance/src/network_l7/mcp.rs b/tests/suites/conformance/src/network_l7/mcp.rs new file mode 100644 index 0000000000..c553516bb9 --- /dev/null +++ b/tests/suites/conformance/src/network_l7/mcp.rs @@ -0,0 +1,221 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! MCP request profiles: the sandbox authorizes tool calls by MCP revision, +//! for the sessionless revision, legacy initialization, and an endpoint that +//! accepts several revisions. +//! +//! Ported from the `mcp_sessionless` e2e test. The fixture on the test host +//! serves initialization, discovery, tools, and a bounded subscription +//! stream, and reports the requests it received in each tool result, so the +//! client can tell a policy denial from a request the fixture accepted. + +use std::sync::{Arc, Mutex, PoisonError}; + +use host_server_support::{HttpRecorder, Request, Response}; +use serde_json::{Value, json}; +use testkit::{Context, Result, ResultExt as _, policy}; + +use crate::support::{TEST_HOST, python_binaries_yaml, python_sandbox, run_python}; + +const MCP_CLIENT: &str = include_str!("../scripts/mcp_client.py"); +const SESSIONLESS: &str = "2026-07-28"; + +/// The sessionless revision: discovery, an allowed and a denied tool, and a +/// subscription stream, with the request metadata the revision requires. +#[testkit::test] +async fn mcp_sessionless_discovery_tools_and_subscription(cx: &mut Context) -> testkit::Result { + run_profile(cx, "mcpsl", &[SESSIONLESS]).await +} + +/// Each legacy revision: initialization, then an allowed and a denied tool. +#[testkit::test] +async fn mcp_legacy_revisions_authorize_tools(cx: &mut Context) -> testkit::Result { + for (suffix, version) in [("m0326", "2025-03-26"), ("m0618", "2025-06-18")] { + run_profile(cx, suffix, &[version]).await?; + } + Ok(()) +} + +/// An endpoint that accepts a legacy and the sessionless revision authorizes +/// tools under each, against one fixture. +#[testkit::test] +async fn mcp_multi_version_endpoint_authorizes_tools(cx: &mut Context) -> testkit::Result { + run_profile(cx, "mcpmv", &["2025-11-25", SESSIONLESS]).await +} + +/// Start a fresh fixture for `versions`, and run [`MCP_CLIENT`] for them in +/// a sandbox whose policy accepts them. +async fn run_profile(cx: &Context, suffix: &str, versions: &[&str]) -> Result { + let supported: Vec = versions.iter().map(ToString::to_string).collect(); + let received = Arc::new(Mutex::new(Vec::new())); + let server = + HttpRecorder::serve(move |request| fixture(request, &supported, &received)).await?; + + let legacy_rules = if versions.iter().any(|version| *version != SESSIONLESS) { + " - allow:\n method: initialize\n - allow:\n method: notifications/initialized\n" + } else { + "" + }; + let versions_json = serde_json::to_string(versions).context("encode the MCP revisions")?; + let policy = policy::base_with(&format!( + r"network_policies: + mcp: + name: mcp + endpoints: + - host: {TEST_HOST} + port: {port} + path: /mcp + protocol: mcp + enforcement: enforce + mcp: + versions: {versions_json} + max_body_bytes: 65536 + rules: +{legacy_rules} - allow: + method: server/discover + - allow: + method: tools/call + tool: read_status + - allow: + method: subscriptions/listen + deny_rules: + - method: tools/call + tool: read_details + binaries: {binaries} +", + port = server.port, + binaries = python_binaries_yaml(), + ))?; + let sandbox = python_sandbox(cx, suffix, policy).await?; + let output = run_python( + &sandbox, + MCP_CLIENT, + &[TEST_HOST, &server.port.to_string(), &versions_json], + ) + .await + .context(format!("MCP revisions {versions:?}"))?; + for version in versions { + let marker = format!("MCP_OK version={version}"); + testkit::ensure!( + output.stdout.lines().any(|line| line == marker), + "{versions:?}: the client didn't finish {version}:\n{}", + output.stdout + ); + } + Ok(()) +} + +/// The MCP fixture. It records each parsed request as `[version, method, +/// tool]` in `received` before checking it, so rejected requests stay +/// visible in later tool results. +fn fixture(request: &Request, supported: &[String], received: &Mutex>) -> Response { + if request.method() == "GET" { + return Response::new(if request.path() == "/" { 200 } else { 405 }); + } + let Ok(message) = serde_json::from_str::(&request.body) else { + return bad_request("the request body is not JSON"); + }; + let method = message["method"].as_str().unwrap_or_default(); + let params = &message["params"]; + let version = if method == "initialize" { + params["protocolVersion"].as_str().map(ToString::to_string) + } else { + request.header("mcp-protocol-version") + }; + let received_now = { + let mut received = received.lock().unwrap_or_else(PoisonError::into_inner); + received.push(json!([version, method, params.get("name")])); + received.clone() + }; + let Some(version) = version.filter(|version| supported.contains(version)) else { + return bad_request("request revision did not reach the fixture intact"); + }; + if request.path() != "/mcp" { + return bad_request("request revision did not reach the fixture intact"); + } + let sessionless = version == SESSIONLESS; + if sessionless { + let meta = ¶ms["_meta"]; + let intact = request.header("mcp-protocol-version").as_deref() == Some(&version) + && request.header("mcp-method").as_deref() == Some(method) + && meta["io.modelcontextprotocol/protocolVersion"] == version.as_str() + && meta["io.modelcontextprotocol/clientCapabilities"] == json!({}) + && (method != "tools/call" + || request.header("mcp-name").as_deref() == params["name"].as_str()); + if !intact { + return bad_request("request metadata did not reach the fixture intact"); + } + } + + let result = match method { + "initialize" if !sessionless => json!({ + "protocolVersion": version, + "capabilities": {"tools": {}}, + "serverInfo": {"name": "openshell-profile-fixture", "version": "1"}, + }), + "notifications/initialized" if !sessionless => return Response::new(202), + "server/discover" if sessionless => json!({ + "supportedVersions": [version], + "capabilities": {"tools": {"listChanged": true}}, + "ttlMs": 0, + "cacheScope": "private", + "_meta": { + "io.modelcontextprotocol/serverInfo": { + "name": "openshell-sessionless-fixture", "version": "1" + } + }, + }), + // Both tool names work upstream; the sandbox owns the policy denial. + "tools/call" => { + let mut result = json!({ + "content": [{"type": "text", "text": params["name"]}], + "isError": false, + "_meta": {"fixtureRequests": received_now}, + }); + if sessionless { + result["resultType"] = json!("complete"); + } + result + } + "subscriptions/listen" if sessionless => return subscription(&message), + _ => return bad_request("unexpected method for the selected fixture revision"), + }; + Response::json(&json!({"jsonrpc": "2.0", "id": message["id"], "result": result})) +} + +/// A subscription stream that acknowledges, sends one notification, and +/// completes. +fn subscription(message: &Value) -> Response { + let meta = json!({"io.modelcontextprotocol/subscriptionId": message["id"]}); + let events = [ + json!({ + "jsonrpc": "2.0", + "method": "notifications/subscriptions/acknowledged", + "params": {"notifications": message["params"]["notifications"], "_meta": meta}, + }), + json!({ + "jsonrpc": "2.0", + "method": "notifications/tools/list_changed", + "params": {"_meta": meta}, + }), + json!({ + "jsonrpc": "2.0", + "id": message["id"], + "result": {"resultType": "complete", "_meta": meta}, + }), + ]; + let body: String = events + .iter() + .map(|event| format!("event: message\ndata: {event}\n\n")) + .collect(); + Response::new(200) + .header("Content-Type", "text/event-stream") + .body(body) +} + +fn bad_request(reason: &str) -> Response { + Response::new(400) + .header("Content-Type", "text/plain") + .body(reason) +} diff --git a/tests/suites/conformance/src/policy_update.rs b/tests/suites/conformance/src/policy_update.rs new file mode 100644 index 0000000000..4fe50706fd --- /dev/null +++ b/tests/suites/conformance/src/policy_update.rs @@ -0,0 +1,364 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Live policy updates through `policy set` and `policy update`: revisions +//! and versions, idempotent updates, scoped rule changes, and the revision a +//! supervisor writes when it fills in a sparse initial policy. +//! +//! Ported from the `live_policy_update` e2e tests. Revisions are read from +//! `policy get` and `policy list` with `--output json`. + +use std::time::Duration; + +use serde_json::Value; +use testkit::policy; +use testkit::sdk::raw::proto; +use testkit::{Context, Result, Sandbox}; + +use crate::support::policy_revisions; + +/// A network-only policy the supervisor fills in with the filesystem paths it +/// needs at startup, which makes a second revision. +const SPARSE_POLICY: &str = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../examples/policy-advisor/sandbox-policy.yaml" +)); + +/// How long a revision may take to be loaded. +const LOAD_TIMEOUT: Duration = Duration::from_mins(2); + +/// Each new policy makes a newer version with a different hash, and setting +/// the same policy again makes no new version. Starts from a policy without +/// network rules, adds one rule, then a second. Every revision is listed, and +/// none is left pending. +#[testkit::test] +async fn policy_set_versions_and_ignores_repeats(cx: &mut Context) -> testkit::Result { + let sandbox = cx + .sandbox("pset") + .policy(policy::base()) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + let initial = settled(cx, &sandbox).await?; + + let mut one_rule = policy::base(); + policy::allow(&mut one_rule, "rule_0", "api.anthropic.com", 443, &["/**"]); + let mut two_rules = one_rule.clone(); + policy::allow(&mut two_rules, "rule_1", "example.com", 443, &["/**"]); + + let mut previous = initial.clone(); + let mut versions = vec![version(&initial)?]; + for (step, next) in [("one rule", &one_rule), ("two rules", &two_rules)] { + policy::set(&sandbox, next).await?; + let updated = settled(cx, &sandbox).await?; + testkit::ensure!( + version(&updated)? > version(&previous)?, + "setting {step} didn't make a newer version: before {previous}, after {updated}" + ); + testkit::ensure!( + updated["hash"] != previous["hash"], + "setting {step} didn't change the hash: {}", + updated["hash"] + ); + + policy::set(&sandbox, next).await?; + let repeated = settled(cx, &sandbox).await?; + for field in ["version", "hash"] { + testkit::ensure!( + repeated[field] == updated[field], + "setting {step} again changed the {field}: {} became {}", + updated[field], + repeated[field] + ); + } + versions.push(version(&updated)?); + previous = updated; + } + + let revisions = policy_revisions(cx, &sandbox).await?; + let listed: Vec = revisions["revisions"] + .as_array() + .into_iter() + .flatten() + .filter_map(|revision| revision["version"].as_u64()) + .collect(); + let missing: Vec<_> = versions.iter().filter(|v| !listed.contains(v)).collect(); + testkit::ensure!( + missing.is_empty(), + "policy list is missing versions {missing:?}: {revisions}" + ); + Ok(()) +} + +/// `policy update` with an explicit rule and binaries changes only the +/// endpoint they select, even when another rule has the same host and ports. +/// An update whose ports or binaries match the rule only in part is rejected +/// without a new revision. +#[testkit::test] +async fn policy_update_changes_only_the_selected_endpoint(cx: &mut Context) -> testkit::Result { + let sandbox = cx + .sandbox("pscop") + .policy(scoped_policy()?) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + let before = settled(cx, &sandbox).await?; + let rules_before = &before["policy"]["network_policies"]; + testkit::ensure!( + rules_before.is_object(), + "policy get has no network policies: {before}" + ); + + // Each partial update matches one of ports and binaries fully, so a check + // that needs both to mismatch can't pass. + for (target, binaries) in [ + ( + "api.example.com:443:POST:/admin", + &["/usr/bin/curl", "/usr/bin/python3"][..], + ), + ( + "api.example.com:443,8443:POST:/admin", + &["/usr/bin/curl"][..], + ), + ] { + let mut args = vec![ + "policy", + "update", + sandbox.name(), + "--rule-name", + "internal_api", + "--add-allow", + target, + ]; + for binary in binaries { + args.extend(["--binary", binary]); + } + cx.cli(args).await?.failure()?; + let unchanged = policy_get(cx, &sandbox).await?; + for field in ["version", "hash", "policy"] { + testkit::ensure!( + unchanged[field] == before[field], + "rejected update {target} with {binaries:?} changed the {field}" + ); + } + } + + update( + cx, + &sandbox, + "--add-allow", + "api.example.com:443,8443:POST:/admin", + ) + .await?; + let allowed = policy_get(cx, &sandbox).await?; + testkit::ensure!( + version(&allowed)? > version(&before)? && allowed["hash"] != before["hash"], + "the allow didn't make a new revision: before {before}, after {allowed}" + ); + let rules = &allowed["policy"]["network_policies"]; + testkit::ensure!( + rules["sibling"] == rules_before["sibling"], + "the allow changed the sibling rule: {}", + rules["sibling"] + ); + testkit::ensure!( + rules["internal_api"]["endpoints"][1] == rules_before["internal_api"]["endpoints"][1], + "the allow changed the other endpoint: {}", + rules["internal_api"]["endpoints"][1] + ); + testkit::ensure!( + has_rule(&rules["internal_api"]["endpoints"][0]["rules"], |rule| { + rule["allow"]["method"] == "POST" && rule["allow"]["path"] == "/admin" + }), + "the endpoint has no POST /admin allow rule: {}", + rules["internal_api"]["endpoints"][0] + ); + + update( + cx, + &sandbox, + "--add-deny", + "api.example.com:443,8443:POST:/admin/private", + ) + .await?; + let denied = policy_get(cx, &sandbox).await?; + testkit::ensure!( + version(&denied)? > version(&allowed)?, + "the deny didn't make a new revision: before {allowed}, after {denied}" + ); + let rules = &denied["policy"]["network_policies"]; + testkit::ensure!( + rules["sibling"] == rules_before["sibling"], + "the deny changed the sibling rule: {}", + rules["sibling"] + ); + testkit::ensure!( + has_rule( + &rules["internal_api"]["endpoints"][0]["deny_rules"], + |rule| { rule["method"] == "POST" && rule["path"] == "/admin/private" } + ), + "the endpoint has no POST /admin/private deny rule: {}", + rules["internal_api"]["endpoints"][0] + ); + Ok(()) +} + +/// A sandbox created with a sparse policy gets a second revision with the +/// paths the supervisor added, and the supervisor reports it loaded: the +/// first is superseded and neither stays pending. Regression for #2159. +#[testkit::test] +async fn sparse_initial_policy_revision_is_loaded(cx: &mut Context) -> testkit::Result { + let sandbox = cx + .cli_sandbox("spars") + .policy_yaml(SPARSE_POLICY) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + testkit::poll_until( + "the filled-in revision 2 to be loaded", + LOAD_TIMEOUT, + Duration::from_secs(2), + async || { + let active = policy_get(cx, &sandbox).await?; + let revisions = policy_revisions(cx, &sandbox).await?; + let statuses = statuses(&revisions); + let expected = [(1_u64, "superseded".to_string()), (2, "loaded".to_string())]; + Ok( + if active["version"] == 2 && statuses.as_slice() == expected { + testkit::Poll::Ready(()) + } else { + testkit::Poll::Pending(format!( + "active version {}, revisions {statuses:?}", + active["version"] + )) + }, + ) + }, + ) + .await +} + +/// [`policy::base`] with two rules that share a host and ports: `internal_api` +/// with a second endpoint, and `sibling` for other binaries. +fn scoped_policy() -> Result { + policy::base_with( + "network_policies: + internal_api: + name: internal_api + binaries: [{path: /usr/bin/curl}, {path: /usr/bin/python3}] + endpoints: + - {host: api.example.com, ports: [443, 8443], protocol: rest, access: read-only} + - {host: other.example.com, port: 443, protocol: rest, access: read-only} + sibling: + name: sibling + binaries: [{path: /usr/bin/wget}] + endpoints: + - {host: api.example.com, ports: [443, 8443], protocol: rest, access: read-only} +", + ) +} + +/// Add `rule` to the `internal_api` rule for curl and Python with +/// `policy update --wait`. +async fn update(cx: &Context, sandbox: &Sandbox, flag: &str, rule: &str) -> Result { + cx.cli([ + "policy", + "update", + sandbox.name(), + "--rule-name", + "internal_api", + "--binary", + "/usr/bin/curl", + "--binary", + "/usr/bin/python3", + flag, + rule, + "--wait", + ]) + .await? + .success()?; + Ok(()) +} + +/// The sandbox's active policy, from `policy get --full --output json`. +async fn policy_get(cx: &Context, sandbox: &Sandbox) -> Result { + let active: Value = cx + .cli([ + "policy", + "get", + sandbox.name(), + "--full", + "--output", + "json", + ]) + .await? + .success()? + .json()?; + version(&active)?; + testkit::ensure!( + active["hash"].as_str().is_some_and(|hash| !hash.is_empty()), + "policy get has no hash: {active}" + ); + Ok(active) +} + +/// The active policy once its revision is loaded and no revision is pending. +/// Fails if a revision failed to load. +async fn settled(cx: &Context, sandbox: &Sandbox) -> Result { + testkit::poll_until( + &format!("the policy of sandbox {} to be loaded", sandbox.name()), + LOAD_TIMEOUT, + Duration::from_secs(1), + async || { + let active = policy_get(cx, sandbox).await?; + let revisions = policy_revisions(cx, sandbox).await?; + let statuses = statuses(&revisions); + testkit::ensure!( + statuses.iter().all(|(_, status)| status != "failed"), + "a policy revision failed to load: {revisions}" + ); + let active_version = version(&active)?; + let loaded = statuses + .iter() + .any(|(version, status)| *version == active_version && status == "loaded"); + let pending = statuses.iter().any(|(_, status)| status == "pending"); + Ok(if loaded && !pending { + testkit::Poll::Ready(active) + } else { + testkit::Poll::Pending(format!( + "active version {active_version}, revisions {statuses:?}" + )) + }) + }, + ) + .await +} + +/// Each revision's version and status, oldest first. +fn statuses(revisions: &Value) -> Vec<(u64, String)> { + let mut statuses: Vec<_> = revisions["revisions"] + .as_array() + .into_iter() + .flatten() + .map(|revision| { + ( + revision["version"].as_u64().unwrap_or_default(), + revision["status"].as_str().unwrap_or_default().to_string(), + ) + }) + .collect(); + statuses.sort(); + statuses +} + +fn version(policy: &Value) -> Result { + policy["version"] + .as_u64() + .ok_or_else(|| testkit::Error::msg(format!("policy get has no version: {policy}"))) +} + +fn has_rule(rules: &Value, matches: impl Fn(&Value) -> bool) -> bool { + rules + .as_array() + .is_some_and(|rules| rules.iter().any(matches)) +} diff --git a/tests/suites/conformance/src/port_forward.rs b/tests/suites/conformance/src/port_forward.rs new file mode 100644 index 0000000000..999a7988a2 --- /dev/null +++ b/tests/suites/conformance/src/port_forward.rs @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Port forwarding with `openshell forward`. +//! +//! Ported from the `port_forward` e2e test. + +use std::time::Duration; + +use testkit::{Context, policy}; + +const ECHO_SERVER: &str = include_str!("scripts/echo_server.py"); + +/// How long `forward start` and the first echo through it may take. +const FORWARD_TIMEOUT: Duration = Duration::from_secs(60); + +/// `forward start -d` forwards a local port to a server on the sandbox's +/// loopback, and `forward stop` ends it. +#[testkit::test] +async fn forward_reaches_sandbox_loopback_server(cx: &mut Context) -> testkit::Result { + let local_port = host_server_support::free_port().await?; + let port = local_port.to_string(); + let sandbox = cx + .sandbox("fwd") + .policy(policy::base()) + .image(testkit::python_image()) + .command(["python3", "-c", ECHO_SERVER, &port]) + .create_ready() + .await?; + let name = sandbox.name().to_string(); + + // The forward's ssh keeps the CLI's stdout and stderr open, so wait for + // the CLI to exit rather than for its output to end. + let mut start = cx.cli_spawn(["forward", "start", "-d", &port, &name])?; + let code = start.wait(FORWARD_TIMEOUT).await?; + if code != 0 { + let output = start.output(FORWARD_TIMEOUT).await?; + return Err(testkit::Error::msg(format!( + "`{}` exited {code}:\n{}", + output.command, + output.report_text() + ))); + } + // Stops the forward if the test fails before it does. Its outcome is + // ignored, since the forward is already gone when the test passes. + let cli = cx.cli_handle(); + let (stop_port, stop_name) = (port.clone(), name.clone()); + cx.on_cleanup(format!("stop forward {port}"), async move || { + cli.run(["forward", "stop", &stop_port, &stop_name]).await?; + Ok(()) + }); + + testkit::poll_until( + &format!("an echo through forwarded port {port}"), + FORWARD_TIMEOUT, + Duration::from_secs(1), + async || { + Ok( + match host_server_support::exchange(local_port, b"hello-forward\n").await { + Ok(reply) if reply == b"echo:hello-forward\n" => testkit::Poll::Ready(()), + Ok(reply) => testkit::Poll::Pending(format!( + "reply {:?}", + String::from_utf8_lossy(&reply) + )), + Err(error) => testkit::Poll::Pending(error.to_string()), + }, + ) + }, + ) + .await?; + + cx.cli(["forward", "stop", &port, &name]).await?.success()?; + testkit::poll_until( + &format!("forwarded port {port} to close"), + FORWARD_TIMEOUT, + Duration::from_secs(1), + async || { + Ok( + match host_server_support::exchange(local_port, b"after-stop\n").await { + Err(_) => testkit::Poll::Ready(()), + Ok(reply) => testkit::Poll::Pending(format!( + "still forwarding; reply {:?}", + String::from_utf8_lossy(&reply) + )), + }, + ) + }, + ) + .await +} diff --git a/tests/suites/conformance/src/scripts/bound_credential_client.sh b/tests/suites/conformance/src/scripts/bound_credential_client.sh new file mode 100644 index 0000000000..8ec43ede27 --- /dev/null +++ b/tests/suites/conformance/src/scripts/bound_credential_client.sh @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends provider A's token from BOUND_TOKEN_A to host $1: on port $2 at a +# path its profile binds, on port $3, which provider B's profile binds, and on +# port $2 at a path outside the binding. Prints the first response body and +# the other two statuses. Never prints the token. +host="$1" port_a="$2" port_b="$3" + +http_request() { + local port="$1" path="$2" status_line line + HTTP_STATUS= HTTP_BODY= + if ! exec 3<>"/dev/tcp/$host/$port"; then + HTTP_STATUS=connect-denied + return 1 + fi + printf 'GET %s HTTP/1.1\r\nHost: %s:%s\r\nAuthorization: Bearer %s\r\nConnection: close\r\n\r\n' \ + "$path" "$host" "$port" "$BOUND_TOKEN_A" >&3 + IFS= read -r status_line <&3 || return 1 + status_line="${status_line%$'\r'}" + HTTP_STATUS="${status_line#* }" + HTTP_STATUS="${HTTP_STATUS%% *}" + while IFS= read -r line <&3; do + line="${line%$'\r'}" + [[ -z "$line" ]] && break + done + while IFS= read -r line <&3 || [[ -n "$line" ]]; do HTTP_BODY+="$line"; done + exec 3>&- 3<&- +} + +http_request "$port_a" /allowed/check; allowed="$HTTP_BODY" +http_request "$port_b" /allowed/check || true; endpoint_denied="$HTTP_STATUS" +http_request "$port_a" /other/check; path_denied="$HTTP_STATUS" +printf 'ALLOWED=%s ENDPOINT_DENIED=%s PATH_DENIED=%s\n' "$allowed" "$endpoint_denied" "$path_denied" diff --git a/tests/suites/conformance/src/scripts/bypass_client.py b/tests/suites/conformance/src/scripts/bypass_client.py new file mode 100644 index 0000000000..e3c1a75d51 --- /dev/null +++ b/tests/suites/conformance/src/scripts/bypass_client.py @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Connects straight to an unroutable address, bypassing any proxy, and +# prints the outcome and how long it took. +import json, socket, time + +start = time.monotonic() +result = "unknown" +try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(10) + s.connect(("198.51.100.1", 80)) + result = "connected" + s.close() +except ConnectionRefusedError: + result = "refused" +except PermissionError: + result = "denied" +except socket.timeout: + result = "timeout" +except OSError as e: + result = f"error:{e}" + +elapsed_ms = int((time.monotonic() - start) * 1000) +print(json.dumps({"bypass_result": result, "elapsed_ms": elapsed_ms}), flush=True) diff --git a/tests/suites/conformance/src/scripts/credential_rewrite_client.py b/tests/suites/conformance/src/scripts/credential_rewrite_client.py new file mode 100644 index 0000000000..b3d77a3ac0 --- /dev/null +++ b/tests/suites/conformance/src/scripts/credential_rewrite_client.py @@ -0,0 +1,46 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# POSTs the provider's token from E2E_GATING_TOKEN in an Authorization header +# and a JSON body to argv[1]:argv[2]/probe twice, each on its own +# connection, and fails unless both get 200. Never prints the token. +import json +import os +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +TOKEN = os.environ["E2E_GATING_TOKEN"] + + +def status(sock): + data = b"" + while b"\r\n\r\n" not in data: + chunk = sock.recv(4096) + if not chunk: + break + data += chunk + parts = data.split(None, 2) + return int(parts[1]) if len(parts) > 1 else 0 + + +def request_once(): + body = json.dumps({"credential": TOKEN}, separators=(",", ":")).encode() + request = ( + "POST /probe HTTP/1.1\r\n" + f"Host: {HOST}:{PORT}\r\n" + f"Authorization: Bearer {TOKEN}\r\n" + "Content-Type: application/json\r\n" + f"Content-Length: {len(body)}\r\n" + "Connection: close\r\n\r\n" + ).encode() + body + with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall(request) + return status(sock) + + +statuses = [request_once(), request_once()] +if statuses != [200, 200]: + raise SystemExit(f"expected two 200 responses; got {statuses}") +print("REWRITE_OK") diff --git a/tests/suites/conformance/src/scripts/destination_denials_client.py b/tests/suites/conformance/src/scripts/destination_denials_client.py new file mode 100644 index 0000000000..a4ddd6475e --- /dev/null +++ b/tests/suites/conformance/src/scripts/destination_denials_client.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Connects to addresses the policy names but the sandbox must still refuse, +# and prints each connect's errno as JSON, 0 for a connection. +import json +import socket + +targets = { + "metadata": ("169.254.169.254", 80), + "control_plane": ("203.0.113.10", 6443), + "outside_allowed_ips": ("203.0.113.10", 8080), +} +result = {} +for name, target in targets.items(): + try: + with socket.create_connection(target, timeout=10): + result[name] = 0 + except OSError as error: + result[name] = error.errno +print(json.dumps(result, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/echo_client.py b/tests/suites/conformance/src/scripts/echo_client.py new file mode 100644 index 0000000000..aea3b9da97 --- /dev/null +++ b/tests/suites/conformance/src/scripts/echo_client.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends the bytes hex-encoded in argv[3] to the echo server at +# argv[1]:argv[2] and fails unless it reads the same bytes back. +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +PAYLOAD = bytes.fromhex(sys.argv[3]) + +with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall(PAYLOAD) + echoed = b"" + while len(echoed) < len(PAYLOAD): + chunk = sock.recv(len(PAYLOAD) - len(echoed)) + if not chunk: + break + echoed += chunk +if echoed != PAYLOAD: + raise SystemExit(f"the payload changed in transit: {echoed!r}") +print("ECHO_OK") diff --git a/tests/suites/conformance/src/scripts/echo_server.py b/tests/suites/conformance/src/scripts/echo_server.py new file mode 100644 index 0000000000..9933a17333 --- /dev/null +++ b/tests/suites/conformance/src/scripts/echo_server.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# A TCP server on 127.0.0.1:argv[1] that answers each connection's first +# read with b"echo:" and the bytes read, then closes it. + +import socket +import sys + +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +server.bind(("127.0.0.1", int(sys.argv[1]))) +server.listen(8) +while True: + conn, _ = server.accept() + with conn: + data = conn.recv(4096) + if data: + conn.sendall(b"echo:" + data) diff --git a/tests/suites/conformance/src/scripts/graphql_client.py b/tests/suites/conformance/src/scripts/graphql_client.py new file mode 100644 index 0000000000..f8d4c07c6a --- /dev/null +++ b/tests/suites/conformance/src/scripts/graphql_client.py @@ -0,0 +1,242 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends GraphQL queries, mutations, and persisted queries to HOST:PORT with +# urllib (`forward_*`) and raw sockets (`raw_*`), and prints each status as +# JSON. +import json +import socket +import sys +import time +import urllib.error +import urllib.parse +import urllib.request + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +DETAILS = {} + +QUERY_VIEWER = "query Viewer { viewer { login } }" +QUERY_REPOSITORY = "query Repo { repository(owner:\"o\", name:\"r\") { id } }" +MUTATION_CREATE = "mutation Create { createIssue(input:{repositoryId:\"r\", title:\"t\", body:\"b\"}) { issue { id } } }" +MUTATION_DELETE = "mutation Delete { deleteRepository(input:{repositoryId:\"r\"}) { clientMutationId } }" + +def forward_status(query): + body = json.dumps({"query": query}).encode() + request = urllib.request.Request( + f"http://{HOST}:{PORT}/graphql", + data=body, + headers={"Content-Type": "application/json"}, + method="POST", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + +def forward_get_status(query): + encoded = urllib.parse.urlencode({"query": query}) + request = urllib.request.Request( + f"http://{HOST}:{PORT}/graphql?{encoded}", + method="GET", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + +def forward_duplicate_get_status(): + safe = urllib.parse.quote_plus(QUERY_VIEWER) + unsafe = urllib.parse.quote_plus(MUTATION_DELETE) + request = urllib.request.Request( + f"http://{HOST}:{PORT}/graphql?query={safe}&query={unsafe}", + method="GET", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + +def forward_persisted_get_status(hash_value): + extensions = json.dumps({"persistedQuery": {"version": 1, "sha256Hash": hash_value}}) + encoded = urllib.parse.urlencode({"operationName": "Viewer", "extensions": extensions}) + request = urllib.request.Request( + f"http://{HOST}:{PORT}/graphql?{encoded}", + method="GET", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + +def forward_chunked_status(query): + target = f"{HOST}:{PORT}" + body = json.dumps({"query": query}).encode() + chunk = f"{len(body):x}\r\n".encode() + body + b"\r\n0\r\n\r\n" + + with socket.create_connection((HOST, PORT), timeout=15) as sock: + request = ( + f"POST /graphql HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Content-Type: application/json\r\n" + f"Transfer-Encoding: chunked\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + chunk + sock.sendall(request) + response, body = read_response(sock) + DETAILS["forward_chunked_query_allowed_detail"] = body.decode(errors="replace") + return status_code(response, "forward_chunked_response") + +def read_until(sock, marker): + data = b"" + while marker not in data: + chunk = sock.recv(4096) + if not chunk: + break + data += chunk + return data + +def read_response(sock): + response = read_until(sock, b"\r\n\r\n") + headers, _, body = response.partition(b"\r\n\r\n") + content_length = 0 + for line in headers.split(b"\r\n")[1:]: + if line.lower().startswith(b"content-length:"): + content_length = int(line.split(b":", 1)[1].strip()) + break + while len(body) < content_length: + chunk = sock.recv(4096) + if not chunk: + break + body += chunk + return response, body + +def status_code(response, label): + parts = response.split() + if len(parts) < 2: + DETAILS[f"{label}_raw"] = response.decode(errors="replace") + raise RuntimeError(f"{label}: malformed HTTP response: {response!r}") + try: + return int(parts[1]) + except ValueError as error: + DETAILS[f"{label}_raw"] = response.decode(errors="replace") + raise RuntimeError(f"{label}: non-numeric HTTP status: {response!r}") from error + +def raw_http_status(label, request): + last_error = None + for attempt in range(5): + try: + with socket.create_connection((HOST, PORT), timeout=15) as sock: + sock.sendall(request) + sock.shutdown(socket.SHUT_WR) + response = read_until(sock, b"\r\n\r\n") + return status_code(response, f"{label}_response") + except (OSError, RuntimeError) as error: + last_error = error + DETAILS[f"{label}_attempt_{attempt + 1}_error"] = str(error) + time.sleep(0.2) + + raise RuntimeError(f"{label}: failed after 5 attempts: {last_error}") + +def raw_status(query, label): + target = f"{HOST}:{PORT}" + body = json.dumps({"query": query}).encode() + + request = ( + f"POST /graphql HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Content-Type: application/json\r\n" + f"Content-Length: {len(body)}\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + body + return raw_http_status(label, request) + +def raw_get_status(query, label): + target = f"{HOST}:{PORT}" + encoded = urllib.parse.urlencode({"query": query}) + + request = ( + f"GET /graphql?{encoded} HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + return raw_http_status(label, request) + +def raw_duplicate_get_status(): + target = f"{HOST}:{PORT}" + safe = urllib.parse.quote_plus(QUERY_VIEWER) + unsafe = urllib.parse.quote_plus(MUTATION_DELETE) + + request = ( + f"GET /graphql?query={safe}&query={unsafe} HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + return raw_http_status("raw_duplicate_get_denied", request) + +def raw_persisted_get_status(hash_value, label): + target = f"{HOST}:{PORT}" + extensions = json.dumps({"persistedQuery": {"version": 1, "sha256Hash": hash_value}}) + encoded = urllib.parse.urlencode({"operationName": "Viewer", "extensions": extensions}) + + request = ( + f"GET /graphql?{encoded} HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + return raw_http_status(label, request) + +def raw_chunked_status(query): + target = f"{HOST}:{PORT}" + body = json.dumps({"query": query}).encode() + chunk = f"{len(body):x}\r\n".encode() + body + b"\r\n0\r\n\r\n" + + request = ( + f"POST /graphql HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Content-Type: application/json\r\n" + f"Transfer-Encoding: chunked\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + chunk + return raw_http_status("raw_chunked_query_allowed", request) + +results = { + "forward_query_allowed": forward_status(QUERY_VIEWER), + "forward_get_query_allowed": forward_get_status(QUERY_VIEWER), + "forward_duplicate_get_denied": forward_duplicate_get_status(), + "forward_persisted_get_allowed": forward_persisted_get_status("abc123"), + "forward_unregistered_persisted_get_denied": forward_persisted_get_status("missing"), + "forward_chunked_query_allowed": forward_chunked_status(QUERY_VIEWER), + "forward_unlisted_field_denied": forward_status(QUERY_REPOSITORY), + "forward_mutation_allowed": forward_status(MUTATION_CREATE), + "forward_deny_rule_denied": forward_status(MUTATION_DELETE), + "raw_query_allowed": raw_status(QUERY_VIEWER, "raw_query_allowed"), + "raw_get_query_allowed": raw_get_status(QUERY_VIEWER, "raw_get_query_allowed"), + "raw_duplicate_get_denied": raw_duplicate_get_status(), + "raw_persisted_get_allowed": raw_persisted_get_status("abc123", "raw_persisted_get_allowed"), + "raw_unregistered_persisted_get_denied": raw_persisted_get_status("missing", "raw_unregistered_persisted_get_denied"), + "raw_chunked_query_allowed": raw_chunked_status(QUERY_VIEWER), + "raw_unlisted_field_denied": raw_status(QUERY_REPOSITORY, "raw_unlisted_field_denied"), + "raw_mutation_allowed": raw_status(MUTATION_CREATE, "raw_mutation_allowed"), + "raw_deny_rule_denied": raw_status(MUTATION_DELETE, "raw_deny_rule_denied"), +} +results.update(DETAILS) +print(json.dumps(results, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/jsonrpc_audit_client.py b/tests/suites/conformance/src/scripts/jsonrpc_audit_client.py new file mode 100644 index 0000000000..c1145be040 --- /dev/null +++ b/tests/suites/conformance/src/scripts/jsonrpc_audit_client.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends an unlisted JSON-RPC method and a response frame to HOST:PORT/rpc, +# and prints each status as JSON. +import json +import sys +import urllib.error +import urllib.request + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) + +def post_jsonrpc(body): + encoded = json.dumps(body).encode() + request = urllib.request.Request( + f"http://{HOST}:{PORT}/rpc", + data=encoded, + headers={"Content-Type": "application/json"}, + method="POST", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + +results = { + "forward_unknown_method_audited": post_jsonrpc({"jsonrpc": "2.0", "id": 1, "method": "unknown/method"}), + "forward_response_frame_hard_denied": post_jsonrpc({"jsonrpc": "2.0", "id": 1, "result": {}}), +} +print(json.dumps(results, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/jsonrpc_client.py b/tests/suites/conformance/src/scripts/jsonrpc_client.py new file mode 100644 index 0000000000..919009584f --- /dev/null +++ b/tests/suites/conformance/src/scripts/jsonrpc_client.py @@ -0,0 +1,197 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends JSON-RPC calls, batches, and invalid JSON to HOST:PORT/rpc with +# urllib (`forward_*`) and raw sockets (`raw_*`), and prints each status as +# JSON. +import json +import socket +import sys +import time +import urllib.error +import urllib.request + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +DETAILS = { + "debug_target": {"host": HOST, "port": PORT}, +} + +def text(data): + return data.decode(errors="replace") + +def selected_headers(headers): + return { + key.lower(): value + for key, value in headers.items() + if key.lower() in ("content-type", "content-length", "server") + } + +def record_http_error(label, error, request_body): + response_body = error.read() + DETAILS[f"{label}_request"] = request_body + DETAILS[f"{label}_response"] = { + "status": error.code, + "reason": str(error.reason), + "headers": selected_headers(error.headers), + "body": text(response_body), + } + return error.code + +def post_jsonrpc(label, method, params=None, req_id=1): + body = {"jsonrpc": "2.0", "id": req_id, "method": method} + if params is not None: + body["params"] = params + encoded = json.dumps(body).encode() + request = urllib.request.Request( + f"http://{HOST}:{PORT}/rpc", + data=encoded, + headers={"Content-Type": "application/json"}, + method="POST", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + return record_http_error(label, error, body) + +def post_jsonrpc_batch(label, requests): + encoded = json.dumps(requests).encode() + request = urllib.request.Request( + f"http://{HOST}:{PORT}/rpc", + data=encoded, + headers={"Content-Type": "application/json"}, + method="POST", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + return record_http_error(label, error, requests) + +def post_invalid_json(label): + encoded = b"not valid json {" + request = urllib.request.Request( + f"http://{HOST}:{PORT}/rpc", + data=encoded, + headers={"Content-Type": "application/json", "Content-Length": str(len(encoded))}, + method="POST", + ) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + return record_http_error(label, error, text(encoded)) + +def read_until(sock, marker): + data = b"" + while marker not in data: + chunk = sock.recv(4096) + if not chunk: + break + data += chunk + return data + +def read_response(sock): + response = read_until(sock, b"\r\n\r\n") + headers, _, body = response.partition(b"\r\n\r\n") + content_length = 0 + for line in headers.split(b"\r\n")[1:]: + if line.lower().startswith(b"content-length:"): + content_length = int(line.split(b":", 1)[1].strip()) + break + while len(body) < content_length: + chunk = sock.recv(4096) + if not chunk: + break + body += chunk + return response, body + +def status_code(response, label): + parts = response.split() + if len(parts) < 2: + DETAILS[f"{label}_raw"] = response.decode(errors="replace") + raise RuntimeError(f"{label}: malformed HTTP response: {response!r}") + try: + return int(parts[1]) + except ValueError as error: + DETAILS[f"{label}_raw"] = response.decode(errors="replace") + raise RuntimeError(f"{label}: non-numeric HTTP status: {response!r}") from error + +def record_raw_response(label, response, body=b""): + code = status_code(response, label) + if code != 200: + DETAILS[f"{label}_raw"] = text(response) + if body: + DETAILS[f"{label}_body"] = text(body) + return code + +def raw_http_status(label, request): + last_error = None + for attempt in range(5): + try: + with socket.create_connection((HOST, PORT), timeout=15) as sock: + sock.sendall(request) + sock.shutdown(socket.SHUT_WR) + response, body = read_response(sock) + return record_raw_response(f"{label}_response", response, body) + except (OSError, RuntimeError) as error: + last_error = error + DETAILS[f"{label}_attempt_{attempt + 1}_error"] = str(error) + time.sleep(0.2) + + raise RuntimeError(f"{label}: failed after 5 attempts: {last_error}") + +def raw_jsonrpc_status(method, params, label): + target = f"{HOST}:{PORT}" + body = {"jsonrpc": "2.0", "id": 1, "method": method} + if params is not None: + body["params"] = params + encoded = json.dumps(body).encode() + request = ( + f"POST /rpc HTTP/1.1\r\n" + f"Host: {target}\r\n" + f"Content-Type: application/json\r\n" + f"Content-Length: {len(encoded)}\r\n" + f"Connection: close\r\n" + f"\r\n" + ).encode() + encoded + return raw_http_status(label, request) + +results = { + # forward proxy — method-only allow rules + "forward_method_initialize_allowed": post_jsonrpc("forward_method_initialize_allowed", "initialize", {"protocolVersion": "2025-11-25", "capabilities": {}}), + "forward_method_tools_list_allowed": post_jsonrpc("forward_method_tools_list_allowed", "tools/list"), + + # forward proxy — method allow/deny rules + "forward_method_tools_call_allowed": post_jsonrpc("forward_method_tools_call_allowed", "tools/call", {"name": "read_status"}), + "forward_method_tools_call_with_unmatched_params_allowed": post_jsonrpc("forward_method_tools_call_with_unmatched_params_allowed", "tools/call", {"name": "blocked_action", "arguments": {"scope": "ignored"}}), + "forward_method_tools_delete_denied": post_jsonrpc("forward_method_tools_delete_denied", "tools/delete", {"name": "purge_cache"}), + + # forward proxy — batch: all requests allowed + "forward_batch_all_allowed": post_jsonrpc_batch("forward_batch_all_allowed", [ + {"jsonrpc": "2.0", "id": 1, "method": "tools/list"}, + {"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "read_status"}}, + ]), + + # forward proxy — batch: one denied request causes full batch denial + "forward_batch_one_denied": post_jsonrpc_batch("forward_batch_one_denied", [ + {"jsonrpc": "2.0", "id": 1, "method": "tools/list"}, + {"jsonrpc": "2.0", "id": 2, "method": "tools/delete", "params": {"name": "purge_cache"}}, + ]), + + # forward proxy — invalid JSON body fails closed before generic rules apply + "forward_invalid_json_denied": post_invalid_json("forward_invalid_json_denied"), + + # raw socket path — representative allowed and denied cases + "raw_method_initialize_allowed": raw_jsonrpc_status("initialize", {"protocolVersion": "2025-11-25", "capabilities": {}}, "raw_method_initialize_allowed"), + "raw_method_tools_list_allowed": raw_jsonrpc_status("tools/list", None, "raw_method_tools_list_allowed"), + "raw_method_tools_call_allowed": raw_jsonrpc_status("tools/call", {"name": "read_status"}, "raw_method_tools_call_allowed"), + "raw_method_tools_call_with_unmatched_params_allowed": raw_jsonrpc_status("tools/call", {"name": "blocked_action", "arguments": {"scope": "ignored"}}, "raw_method_tools_call_with_unmatched_params_allowed"), + "raw_method_tools_delete_denied": raw_jsonrpc_status("tools/delete", {"name": "purge_cache"}, "raw_method_tools_delete_denied"), +} +results.update(DETAILS) +print(json.dumps(results, sort_keys=True)) diff --git a/e2e/rust/tests/listener_lifetime.rs b/tests/suites/conformance/src/scripts/listener_lifetime_probe.py similarity index 54% rename from e2e/rust/tests/listener_lifetime.rs rename to tests/suites/conformance/src/scripts/listener_lifetime_probe.py index ec58a0dcd2..e53b2a6875 100644 --- a/e2e/rust/tests/listener_lifetime.rs +++ b/tests/suites/conformance/src/scripts/listener_lifetime_probe.py @@ -1,11 +1,9 @@ -// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 -#![cfg(feature = "e2e")] - -use openshell_e2e::harness::sandbox::SandboxGuard; - -const LIFETIME_PROBE: &str = r" +# Closes listeners and exits a child that owns one, and checks each time that +# the port refuses connections and can be bound again. Prints the child +# listener's address and socket inode as JSON. import errno, json, os, socket, subprocess, sys def assert_closed(address, inode): @@ -81,74 +79,3 @@ def inode(sock): address, identity = json.loads(result.stdout) assert_closed(address, identity) print(json.dumps([address, identity])) -"; - -#[tokio::test] -async fn closing_or_exiting_listener_refuses_connections_and_releases_port() { - let mut sandbox = SandboxGuard::create(&[]).await.expect("create sandbox"); - let output = sandbox - .exec(&["python3", "-c", LIFETIME_PROBE]) - .await - .expect("listener lifetime probe"); - let observer = r" -import json, os, sys -_, inode = json.loads(sys.argv[1]) -for fd in os.listdir('/proc/self/fd'): - try: - target = os.readlink('/proc/self/fd/' + fd) - except FileNotFoundError: - continue - assert target != 'socket:[' + str(inode) + ']', (fd, target) -"; - sandbox - .exec(&["python3", "-c", observer, output.trim()]) - .await - .expect("subsequent exec must not inherit closed listener"); - sandbox.cleanup().await; -} - -#[tokio::test] -async fn unrelated_exec_does_not_inherit_broker_preconnect_socket() { - // Request a non-CLOEXEC socket explicitly; Python's socket constructor - // otherwise masks broker inheritance bugs by requesting SOCK_CLOEXEC. - let owner = r" -import ctypes, json, os, socket, time -libc = ctypes.CDLL(None, use_errno=True) -fd = libc.socket(socket.AF_INET, socket.SOCK_STREAM, 0) -assert fd >= 0, ctypes.get_errno() -assert os.get_inheritable(fd) -inode = int(os.readlink('/proc/self/fd/' + str(fd))[8:-1]) -with open('/sandbox/preconnect-inode.json', 'w') as f: - json.dump(inode, f) -while True: - time.sleep(60) -"; - let mut sandbox = SandboxGuard::create_detached_main(&["python3", "-c", owner]) - .await - .expect("create socket owner"); - let observer = r" -import json, os, time -path = '/sandbox/preconnect-inode.json' -for _ in range(100): - try: - with open(path) as f: - inode = json.load(f) - break - except (FileNotFoundError, json.JSONDecodeError): - time.sleep(0.1) -else: - raise AssertionError('socket owner did not publish its inode') -for fd in os.listdir('/proc/self/fd'): - try: - target = os.readlink('/proc/self/fd/' + fd) - except FileNotFoundError: - continue - assert target != 'socket:[' + str(inode) + ']', (fd, target) -print('broker socket was not inherited') -"; - sandbox - .exec(&["python3", "-c", observer]) - .await - .expect("unrelated exec inherited broker descriptor"); - sandbox.cleanup().await; -} diff --git a/e2e/rust/tests/no_proxy.rs b/tests/suites/conformance/src/scripts/localhost_client.py similarity index 56% rename from e2e/rust/tests/no_proxy.rs rename to tests/suites/conformance/src/scripts/localhost_client.py index 447c408f8b..3621138742 100644 --- a/e2e/rust/tests/no_proxy.rs +++ b/tests/suites/conformance/src/scripts/localhost_client.py @@ -1,12 +1,8 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 -#![cfg(feature = "e2e")] - -use openshell_e2e::harness::sandbox::SandboxGuard; - -fn localhost_transparent_script() -> &'static str { - r#" +# Serves HTTP on 127.0.0.1 and fetches from it, with no proxy variables in +# the environment. import json import os import threading @@ -40,20 +36,3 @@ def do_GET(self): server.shutdown() thread.join(timeout=5) server.server_close() -"# -} - -#[tokio::test] -async fn sandbox_reaches_localhost_without_proxy_environment() { - let guard = SandboxGuard::create(&["--", "python3", "-c", localhost_transparent_script()]) - .await - .expect("sandbox create with transparent localhost check"); - - assert!( - guard - .create_output - .contains(r#"{"proxy_env_absent": true, "payload": {"message": "hello"}}"#), - "expected localhost HTTP request to stay local and succeed:\n{}", - guard.create_output - ); -} diff --git a/tests/suites/conformance/src/scripts/mcp_client.py b/tests/suites/conformance/src/scripts/mcp_client.py new file mode 100644 index 0000000000..7845555f19 --- /dev/null +++ b/tests/suites/conformance/src/scripts/mcp_client.py @@ -0,0 +1,113 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Runs an MCP client against the fixture at HOST:PORT for each revision in the +# JSON list VERSIONS: discovery or initialization, an allowed and a denied +# tool, and for the sessionless revision, a subscription. Prints +# `MCP_OK version=` after each revision's checks pass. +import json +import sys +import urllib.error +import urllib.request + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +VERSIONS = json.loads(sys.argv[3]) +SESSIONLESS = "2026-07-28" + +# Direct client connections pass through the sandbox's transparent interception. +opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + + +def post(request_id, method, params, version): + params = dict(params) + headers = { + "Content-Type": "application/json", + "Accept": "application/json, text/event-stream", + } + if method != "initialize": + headers["MCP-Protocol-Version"] = version + if version == SESSIONLESS: + params["_meta"] = { + "io.modelcontextprotocol/protocolVersion": version, + "io.modelcontextprotocol/clientCapabilities": {}, + "io.modelcontextprotocol/clientInfo": {"name": "openshell-e2e", "version": "1"}, + } + headers["Mcp-Method"] = method + if method == "tools/call": + headers["Mcp-Name"] = params["name"] + message = {"jsonrpc": "2.0", "method": method, "params": params} + if request_id is not None: + message["id"] = request_id + request = urllib.request.Request( + f"http://{HOST}:{PORT}/mcp", + data=json.dumps(message).encode(), + headers=headers, + method="POST", + ) + try: + with opener.open(request, timeout=15) as response: + return response.status, response.headers.get_content_type(), response.read() + except urllib.error.HTTPError as error: + return error.code, error.headers.get_content_type(), error.read() + + +expected_receipts = [] +for version in VERSIONS: + if version == SESSIONLESS: + status, content_type, body = post(1, "server/discover", {}, version) + assert status == 200, (version, "discovery", status, body) + assert content_type == "application/json", (version, content_type) + discovery = json.loads(body) + assert discovery["id"] == 1, discovery + assert discovery["result"]["supportedVersions"] == [version], discovery + expected_receipts.append([version, "server/discover", None]) + else: + status, _, body = post(1, "initialize", { + "protocolVersion": version, + "capabilities": {}, + "clientInfo": {"name": "openshell-e2e", "version": "1"}, + }, version) + assert status == 200, (version, "initialize", status, body) + assert json.loads(body)["result"]["protocolVersion"] == version, body + expected_receipts.append([version, "initialize", None]) + status, _, body = post(None, "notifications/initialized", {}, version) + assert status == 202, (version, "initialized", status, body) + expected_receipts.append([version, "notifications/initialized", None]) + + status, _, body = post(2, "tools/call", {"name": "read_status", "arguments": {}}, version) + assert status == 200, (version, "allowed tool", status, body) + tool = json.loads(body) + assert tool["id"] == 2, tool + assert tool["result"]["content"] == [{"type": "text", "text": "read_status"}], tool + expected_receipts.append([version, "tools/call", "read_status"]) + assert tool["result"]["_meta"]["fixtureRequests"] == expected_receipts, tool + + status, _, body = post(3, "tools/call", {"name": "read_details", "arguments": {}}, version) + assert status == 403, (version, "denied tool", status, body) + + # The fixture accepts both tools. A later allowed call proves the denial + # came from the proxy and no denied operation reached the upstream. + status, _, body = post(4, "tools/call", {"name": "read_status", "arguments": {}}, version) + assert status == 200, (version, "receipt tool", status, body) + receipt = json.loads(body) + assert receipt["id"] == 4, receipt + expected_receipts.append([version, "tools/call", "read_status"]) + assert receipt["result"]["_meta"]["fixtureRequests"] == expected_receipts, receipt + + if version == SESSIONLESS: + status, content_type, body = post( + 5, "subscriptions/listen", {"notifications": {"toolsListChanged": True}}, version + ) + assert status == 200, (version, "subscription", status, body) + assert content_type == "text/event-stream", (content_type, body) + events = [json.loads(line[6:]) for line in body.decode().splitlines() if line.startswith("data: ")] + assert len(events) == 3, events + assert events[0]["method"] == "notifications/subscriptions/acknowledged", events + assert events[0]["params"]["notifications"] == {"toolsListChanged": True}, events + assert events[1]["method"] == "notifications/tools/list_changed", events + assert events[1]["params"]["_meta"]["io.modelcontextprotocol/subscriptionId"] == 5, events + assert events[2]["id"] == 5 and events[2]["result"]["resultType"] == "complete", events + expected_receipts.append([version, "subscriptions/listen", None]) + + print(f"MCP_OK version={version}", flush=True) diff --git a/tests/suites/conformance/src/scripts/pipeline_client.py b/tests/suites/conformance/src/scripts/pipeline_client.py new file mode 100644 index 0000000000..2ed5521bd9 --- /dev/null +++ b/tests/suites/conformance/src/scripts/pipeline_client.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends the pipelined HTTP requests in argv[3] to argv[1]:argv[2] in one +# write, reads until the connection closes, and prints the status lines of +# the responses. +import json +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +REQUESTS = sys.argv[3].encode() + +with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall(REQUESTS) + response = b"" + while True: + chunk = sock.recv(4096) + if not chunk: + break + response += chunk +statuses = [ + line.decode(errors="replace") + for line in response.split(b"\r\n") + if line.startswith(b"HTTP/1.1 ") +] +print(json.dumps({"statuses": statuses})) diff --git a/tests/suites/conformance/src/scripts/preconnect_owner.py b/tests/suites/conformance/src/scripts/preconnect_owner.py new file mode 100644 index 0000000000..1b17222d69 --- /dev/null +++ b/tests/suites/conformance/src/scripts/preconnect_owner.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Opens an inheritable socket, writes its inode to /sandbox/preconnect-inode, +# and sleeps. It asks libc for the socket, since Python's socket constructor +# requests SOCK_CLOEXEC, which would hide an inheritance bug. +import ctypes +import os +import socket +import time + +libc = ctypes.CDLL(None, use_errno=True) +fd = libc.socket(socket.AF_INET, socket.SOCK_STREAM, 0) +assert fd >= 0, ctypes.get_errno() +assert os.get_inheritable(fd) +inode = int(os.readlink('/proc/self/fd/' + str(fd))[8:-1]) +with open('/sandbox/preconnect-inode.tmp', 'w') as f: + f.write(str(inode)) +os.rename('/sandbox/preconnect-inode.tmp', '/sandbox/preconnect-inode') +while True: + time.sleep(60) diff --git a/tests/suites/conformance/src/scripts/redaction_client.py b/tests/suites/conformance/src/scripts/redaction_client.py new file mode 100644 index 0000000000..6bb7bc9b99 --- /dev/null +++ b/tests/suites/conformance/src/scripts/redaction_client.py @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# POSTs a JSON body holding an API key to the body-echo server at +# argv[1]:argv[2] twice, each on its own connection, and prints the bodies +# the server echoed. +import json +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +SECRET = "sk-1234567890abcdef" + + +def read_response(sock): + data = b"" + while b"\r\n\r\n" not in data: + chunk = sock.recv(4096) + if not chunk: + raise RuntimeError("incomplete response headers") + data += chunk + headers, body = data.split(b"\r\n\r\n", 1) + length = 0 + for line in headers.split(b"\r\n")[1:]: + if line.lower().startswith(b"content-length:"): + length = int(line.split(b":", 1)[1].strip()) + while len(body) < length: + chunk = sock.recv(4096) + if not chunk: + break + body += chunk + status = int(headers.split(None, 2)[1]) + if status != 200: + raise RuntimeError(f"request failed with HTTP {status}: {body!r}") + return json.loads(body[:length]) + + +def request_once(): + body = json.dumps({"api_key": SECRET}, separators=(",", ":")).encode() + request = ( + "POST /middleware HTTP/1.1\r\n" + f"Host: {HOST}:{PORT}\r\n" + "Content-Type: application/json\r\n" + f"Content-Length: {len(body)}\r\n" + "Connection: close\r\n\r\n" + ).encode() + body + with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall(request) + return read_response(sock) + + +print(json.dumps({"first": request_once(), "second": request_once()}, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/reload_keep_alive_client.py b/tests/suites/conformance/src/scripts/reload_keep_alive_client.py new file mode 100644 index 0000000000..906cb95019 --- /dev/null +++ b/tests/suites/conformance/src/scripts/reload_keep_alive_client.py @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends a keep-alive GET to argv[1]:argv[2] and touches READY once it +# succeeds. When GO appears, sends a second request on the same connection +# and writes to RESULT whether it was refused. +import json +import os +import socket +import sys +import time + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +READY = "/tmp/proxy-reload-ready" +GO = "/tmp/proxy-reload-go" +RESULT = "/tmp/proxy-reload-result" + + +def read_response(sock): + data = b"" + while b"\r\n\r\n" not in data: + chunk = sock.recv(4096) + if not chunk: + return 0 + data += chunk + headers, body = data.split(b"\r\n\r\n", 1) + length = 0 + for line in headers.split(b"\r\n")[1:]: + if line.lower().startswith(b"content-length:"): + length = int(line.split(b":", 1)[1].strip()) + while len(body) < length: + chunk = sock.recv(4096) + if not chunk: + return 0 + body += chunk + return int(headers.split(None, 2)[1]) + + +target = f"{HOST}:{PORT}" +failed_closed = False +second_status = 0 +try: + with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall( + f"GET /before-reload HTTP/1.1\r\nHost: {target}\r\nConnection: keep-alive\r\n\r\n".encode() + ) + if read_response(sock) != 200: + raise RuntimeError("the first request was denied") + open(READY, "w").close() + deadline = time.monotonic() + 120 + while not os.path.exists(GO) and time.monotonic() < deadline: + time.sleep(0.1) + if not os.path.exists(GO): + raise RuntimeError("timed out waiting for the policy reload") + try: + sock.sendall( + f"GET /after-reload HTTP/1.1\r\nHost: {target}\r\nConnection: close\r\n\r\n".encode() + ) + second_status = read_response(sock) + except OSError: + second_status = 0 + failed_closed = second_status != 200 +finally: + with open(RESULT, "w") as result: + json.dump({"failed_closed": failed_closed, "second_status": second_status}, result, sort_keys=True) diff --git a/tests/suites/conformance/src/scripts/rest_client.py b/tests/suites/conformance/src/scripts/rest_client.py new file mode 100644 index 0000000000..d59543a760 --- /dev/null +++ b/tests/suites/conformance/src/scripts/rest_client.py @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Prints the status of GET and POST to /allowed as JSON. +import json +import sys +import urllib.error +import urllib.request + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) + + +def status(method, data=None): + request = urllib.request.Request(f"http://{HOST}:{PORT}/allowed", data=data, method=method) + try: + with urllib.request.urlopen(request, timeout=15) as response: + response.read() + return response.status + except urllib.error.HTTPError as error: + error.read() + return error.code + + +print(json.dumps({"get": status("GET"), "post": status("POST", b"test")}, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/rest_upgrade_client.py b/tests/suites/conformance/src/scripts/rest_upgrade_client.py new file mode 100644 index 0000000000..305742fe46 --- /dev/null +++ b/tests/suites/conformance/src/scripts/rest_upgrade_client.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Asks to upgrade a REST endpoint to WebSocket with an origin-form and an +# absolute-form target, and fails unless the sandbox refuses both. +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) + +for target in ["/allowed", f"http://{HOST}:{PORT}/allowed"]: + s = socket.create_connection((HOST, PORT), timeout=15) + request = ("GET " + target + f" HTTP/1.1\r\nHost: {HOST}:{PORT}\r\n" + "Connection: Upgrade\r\nUpgrade: websocket\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nSec-WebSocket-Version: 13\r\n\r\n") + s.sendall(request.encode()) + response = b"" + while True: + chunk = s.recv(4096) + if not chunk: + break + response += chunk + s.close() + assert response.startswith(b"HTTP/1.1 403"), response + assert b"unsupported_l7_protocol" in response, response + assert b"REST endpoints" in response, response +print("REST_UPGRADE_REFUSED") diff --git a/tests/suites/conformance/src/scripts/socket_not_inherited.py b/tests/suites/conformance/src/scripts/socket_not_inherited.py new file mode 100644 index 0000000000..488a0d2683 --- /dev/null +++ b/tests/suites/conformance/src/scripts/socket_not_inherited.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Fails if this process holds the socket whose inode is argv[1]. +import os +import sys + +inode = int(sys.argv[1]) +for fd in os.listdir('/proc/self/fd'): + try: + target = os.readlink('/proc/self/fd/' + fd) + except FileNotFoundError: + continue + assert target != 'socket:[' + str(inode) + ']', (fd, target) diff --git a/tests/suites/conformance/src/scripts/status_client.py b/tests/suites/conformance/src/scripts/status_client.py new file mode 100644 index 0000000000..1d059a9c37 --- /dev/null +++ b/tests/suites/conformance/src/scripts/status_client.py @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends two GET requests to argv[1]:argv[2], each on its own connection, and +# prints their statuses, or the error a connection failed with. +import json +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) + + +def read_headers(sock): + data = b"" + while b"\r\n\r\n" not in data: + chunk = sock.recv(4096) + if not chunk: + break + data += chunk + return data + + +def status(response): + parts = response.split(None, 2) + return int(parts[1]) if len(parts) > 1 else 0 + + +def request_status(path): + try: + with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall( + f"GET {path} HTTP/1.1\r\n" + f"Host: {HOST}:{PORT}\r\nConnection: close\r\n\r\n".encode() + ) + return status(read_headers(sock)) + except OSError as error: + return {"errno": error.errno, "error": repr(error)} + + +print(json.dumps({ + "first": request_status("/first"), + "second": request_status("/second"), +}, sort_keys=True)) diff --git a/tests/suites/conformance/src/scripts/uninspectable_client.py b/tests/suites/conformance/src/scripts/uninspectable_client.py new file mode 100644 index 0000000000..75fa7d65a7 --- /dev/null +++ b/tests/suites/conformance/src/scripts/uninspectable_client.py @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Sends bytes that are neither HTTP nor TLS to argv[1]:argv[2] and fails if +# the connection answers with anything but a 403 unsupported_l7_protocol +# denial. A reset or an empty close also counts as blocked. +import socket +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +PAYLOAD = bytes([0x00, 0xFF, 0x13, 0x37]) + b"not-http-or-tls" + +with socket.create_connection((HOST, PORT), timeout=10) as sock: + sock.sendall(PAYLOAD) + denial = b"" + while True: + try: + chunk = sock.recv(4096) + except ConnectionResetError: + break + if not chunk: + break + denial += chunk +if denial and ( + b"HTTP/1.1 403 Forbidden" not in denial + or b"unsupported_l7_protocol" not in denial +): + raise SystemExit(f"missing the middleware denial: {denial!r}") +print("BLOCKED") diff --git a/tests/suites/conformance/src/scripts/websocket_text_client.py b/tests/suites/conformance/src/scripts/websocket_text_client.py new file mode 100644 index 0000000000..a211a83f36 --- /dev/null +++ b/tests/suites/conformance/src/scripts/websocket_text_client.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Upgrades to WebSocket at argv[1]:argv[2], sends the provider's token from +# E2E_GATING_TOKEN in one text frame, and prints the server's text reply. +# Never prints the token. +import base64 +import json +import os +import socket +import struct +import sys + +HOST = sys.argv[1] +PORT = int(sys.argv[2]) +TOKEN = os.environ["E2E_GATING_TOKEN"] + + +def read_exact(sock, size): + data = b"" + while len(data) < size: + chunk = sock.recv(size - len(data)) + if not chunk: + raise EOFError("the connection closed mid-frame") + data += chunk + return data + + +def masked_text_frame(text): + data = text.encode() + mask = os.urandom(4) + if len(data) < 126: + header = bytes([0x81, 0x80 | len(data)]) + else: + header = bytes([0x81, 0x80 | 126]) + struct.pack("!H", len(data)) + return header + mask + bytes(byte ^ mask[i % 4] for i, byte in enumerate(data)) + + +def read_text_frame(sock): + _, second = read_exact(sock, 2) + length = second & 0x7F + if length == 126: + length = struct.unpack("!H", read_exact(sock, 2))[0] + elif length == 127: + length = struct.unpack("!Q", read_exact(sock, 8))[0] + mask = read_exact(sock, 4) if second & 0x80 else b"" + payload = read_exact(sock, length) + if mask: + payload = bytes(byte ^ mask[i % 4] for i, byte in enumerate(payload)) + return payload.decode() + + +with socket.create_connection((HOST, PORT), timeout=10) as sock: + key = base64.b64encode(os.urandom(16)).decode() + sock.sendall( + ( + "GET /ws HTTP/1.1\r\n" + f"Host: {HOST}:{PORT}\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + f"Sec-WebSocket-Key: {key}\r\n" + "Sec-WebSocket-Version: 13\r\n\r\n" + ).encode() + ) + response = b"" + while b"\r\n\r\n" not in response: + chunk = sock.recv(4096) + if not chunk: + break + response += chunk + if not response.startswith(b"HTTP/1.1 101"): + raise SystemExit(f"upgrade failed: {response!r}") + sock.sendall(masked_text_frame(json.dumps({"authorization": "Bearer " + TOKEN}))) + print(read_text_frame(sock)) diff --git a/tests/suites/conformance/src/support.rs b/tests/suites/conformance/src/support.rs new file mode 100644 index 0000000000..5b80d1e5a6 --- /dev/null +++ b/tests/suites/conformance/src/support.rs @@ -0,0 +1,87 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Helpers the network and policy suites share. Not a suite. +//! +//! Their clients are Python scripts in `src/scripts/` that take the server's +//! host and port as arguments, run in a long-running sandbox from +//! [`testkit::python_image`], and print their result as one JSON line. + +use serde_json::Value; +use testkit::sdk::raw::proto; +use testkit::{Context, ExecOutput, PYTHON_BINARIES, Result, ResultExt as _, Sandbox}; + +/// The name sandboxes reach the test host's servers by. +pub const TEST_HOST: &str = "host.openshell.internal"; + +/// A long-running sandbox from the Python image with `policy`, Ready. +pub async fn python_sandbox( + cx: &Context, + suffix: &str, + policy: proto::SandboxPolicy, +) -> Result { + cx.sandbox(suffix) + .policy(policy) + .image(testkit::python_image()) + .command(["sleep", "infinity"]) + .create_ready() + .await +} + +/// Run `script` with the image's Python and `args`, and fail unless it +/// exits 0. +pub async fn run_python(sandbox: &Sandbox, script: &str, args: &[&str]) -> Result { + let mut command = vec!["python3", "-c", script]; + command.extend_from_slice(args); + sandbox + .exec(command) + .await? + .success() + .context("run the client in the sandbox") +} + +/// The last line of `output`'s stdout that parses as JSON. +pub fn json_result(output: &ExecOutput) -> Result { + output + .stdout + .lines() + .rev() + .find_map(|line| serde_json::from_str(line.trim()).ok()) + .ok_or_else(|| { + testkit::Error::msg(format!( + "no JSON result in the client's output:\n{}\n{}", + output.stdout, output.stderr + )) + }) +} + +/// Fail unless each key in `expected` has its value in `result`. +pub fn expect_values>(result: &Value, expected: &[(K, Value)]) -> Result { + let wrong: Vec = expected + .iter() + .filter(|(key, value)| result[key.as_ref()] != *value) + .map(|(key, value)| { + let key = key.as_ref(); + format!("{key}: expected {value}, got {}", result[key]) + }) + .collect(); + testkit::ensure!(wrong.is_empty(), "{}\nresult: {result}", wrong.join("\n")); + Ok(()) +} + +/// The sandbox's policy revisions, from `policy list --output json`. +pub async fn policy_revisions(cx: &Context, sandbox: &Sandbox) -> Result { + cx.cli(["policy", "list", sandbox.name(), "--output", "json"]) + .await? + .success()? + .json() +} + +/// `binaries:` for policy YAML that lets the image's Python connect. +pub fn python_binaries_yaml() -> String { + let paths: Vec = PYTHON_BINARIES + .iter() + .map(|path| format!("{{path: \"{path}\"}}")) + .collect(); + format!("[{}]", paths.join(", ")) +} diff --git a/tests/suites/drivers/docker/Cargo.lock b/tests/suites/drivers/docker/Cargo.lock new file mode 100644 index 0000000000..115767c16f --- /dev/null +++ b/tests/suites/drivers/docker/Cargo.lock @@ -0,0 +1,4649 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "asn1-rs" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8" +dependencies = [ + "asn1-rs-derive", + "asn1-rs-impl", + "displaydoc", + "nom", + "num-traits", + "rusticata-macros", + "thiserror 2.0.20", + "time", +] + +[[package]] +name = "asn1-rs-derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", + "synstructure", +] + +[[package]] +name = "asn1-rs-impl" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "aws-lc-rs" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +dependencies = [ + "aws-lc-sys", + "untrusted 0.7.1", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", +] + +[[package]] +name = "backon" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cffb0e931875b666fc4fcb20fee52e9bbd1ef836fd9e9e04ec21555f9f85f7ef" +dependencies = [ + "fastrand", + "gloo-timers", + "tokio", +] + +[[package]] +name = "backtrace" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-link", +] + +[[package]] +name = "backtrace-ext" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" +dependencies = [ + "backtrace", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bit-vec" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.2.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43c5703da9466b66a946814e1adf53ea2c90f10063b86290cc9eb67ce3478a20" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "container-engine-support" +version = "0.0.0" +dependencies = [ + "openshell-testkit", + "tempfile", + "tokio", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "ctutils" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe3e9d21d39e6f39ff46e03d5b621424f88ee23d8a1672c6bfc9ccc7f2da4f6a" +dependencies = [ + "cmov", +] + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.117", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "data-encoding" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" + +[[package]] +name = "der-parser" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6" +dependencies = [ + "asn1-rs", + "displaydoc", + "nom", + "num-bigint", + "num-traits", + "rusticata-macros", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c" +dependencies = [ + "block-buffer 0.12.0", + "crypto-common 0.2.2", + "ctutils", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "docker" +version = "0.0.0" +dependencies = [ + "container-engine-support", + "openshell-testkit", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "enum-ordinalize" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89dd01549b09589510cf0647475075d12071456586d70f5c75c98ae2a5537677" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a65863d15a4ce2888bd2f0f543cc963d3879c3a022c8ee43f6141d479a3ac815" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "escape8259" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f0d310082fd5de539d4f41601182241147498444a7695c520288a0cdbead6" + +[[package]] +name = "etcetera" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de48cc4d1c1d97a20fd819def54b890cadde72ed3ad0c614822a0a433361be96" +dependencies = [ + "cfg-if", + "windows-sys 0.61.2", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "flume" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", + "wasip2", + "wasip3", +] + +[[package]] +name = "gimli" +version = "0.32.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.1.5", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] + +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + +[[package]] +name = "hashlink" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824e001ac4f3012dd16a264bec811403a67ca9deb6c102fc5049b32c4574b35f" +dependencies = [ + "hashbrown 0.16.1", +] + +[[package]] +name = "headers" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" +dependencies = [ + "base64 0.22.1", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1 0.10.6", +] + +[[package]] +name = "headers-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" +dependencies = [ + "http", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hickory-proto" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e2da0694c15b44c6f68a6b05e0233617008c54080e31d6eb848d858a9c5b38d" +dependencies = [ + "data-encoding", + "idna", + "ipnet", + "jni", + "once_cell", + "rand 0.10.2", + "ring", + "thiserror 2.0.20", + "tinyvec", + "tracing", + "url", +] + +[[package]] +name = "hkdf" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.2", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "hostname" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" +dependencies = [ + "cfg-if", + "libc", + "windows-link", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hybrid-array" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707114b52a152fa7bdb290cd7cd5912d9467273b6d74e21b8d81aca1f8533f6b" +dependencies = [ + "typenum", +] + +[[package]] +name = "hyper" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-http-proxy" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd1d471ea2f65ba45eddb1d6ab7d58ac2671d2d4ac14da5c6516ae1d97e1327a" +dependencies = [ + "bytes", + "futures-util", + "headers", + "http", + "hyper", + "hyper-rustls", + "hyper-util", + "pin-project-lite", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "log", + "rustls", + "rustls-native-certs", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.0", + "serde", + "serde_core", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "is_ci" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jni" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys", + "log", + "simd_cesu8", + "thiserror 2.0.20", + "walkdir", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn 2.0.117", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.117", +] + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "json-patch" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7421438de105a0827e44fadd05377727847d717c80ce29a229f85fd04c427b72" +dependencies = [ + "jsonptr", + "serde", + "serde_json", + "thiserror 2.0.20", +] + +[[package]] +name = "jsonpath-rust" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c00ae348f9f8fd2d09f82a98ca381c60df9e0820d8d79fce43e649b4dc3128b" +dependencies = [ + "pest", + "pest_derive", + "regex", + "serde_json", + "thiserror 2.0.20", +] + +[[package]] +name = "jsonptr" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a3cc660ba5d72bce0b3bb295bf20847ccbb40fd423f3f05b61273672e561fe" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "jsonwebtoken" +version = "10.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0529410abe238729a60b108898784df8984c87f6054c9c4fcacc47e4803c1ce1" +dependencies = [ + "aws-lc-rs", + "base64 0.22.1", + "getrandom 0.2.17", + "js-sys", + "pem 3.0.6", + "serde", + "serde_json", + "signature", + "simple_asn1", +] + +[[package]] +name = "k8s-openapi" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c75b990324f09bef15e791606b7b7a296d02fc88a344f6eba9390970a870ad5" +dependencies = [ + "base64 0.22.1", + "chrono", + "serde", + "serde-value", + "serde_json", +] + +[[package]] +name = "kube" +version = "0.99.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a4eb20010536b48abe97fec37d23d43069bcbe9686adcf9932202327bc5ca6e" +dependencies = [ + "k8s-openapi", + "kube-client", + "kube-core", + "kube-derive", + "kube-runtime", +] + +[[package]] +name = "kube-client" +version = "0.99.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc2ed952042df20d15ac2fe9614d0ec14b6118eab89633985d4b36e688dccf1" +dependencies = [ + "base64 0.22.1", + "bytes", + "chrono", + "either", + "futures", + "home", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-http-proxy", + "hyper-rustls", + "hyper-timeout", + "hyper-util", + "jsonpath-rust", + "k8s-openapi", + "kube-core", + "pem 3.0.6", + "rustls", + "secrecy", + "serde", + "serde_json", + "serde_yaml", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "tower", + "tower-http", + "tracing", +] + +[[package]] +name = "kube-core" +version = "0.99.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff0d0793db58e70ca6d689489183816cb3aa481673e7433dc618cf7e8007c675" +dependencies = [ + "chrono", + "form_urlencoded", + "http", + "json-patch", + "k8s-openapi", + "schemars", + "serde", + "serde-value", + "serde_json", + "thiserror 2.0.20", +] + +[[package]] +name = "kube-derive" +version = "0.99.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c562f58dc9f7ca5feac8a6ee5850ca221edd6f04ce0dd2ee873202a88cd494c9" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.117", +] + +[[package]] +name = "kube-runtime" +version = "0.99.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88f34cfab9b4bd8633062e0e85edb81df23cb09f159f2e31c60b069ae826ffdc" +dependencies = [ + "ahash", + "async-broadcast", + "async-stream", + "async-trait", + "backon", + "educe", + "futures", + "hashbrown 0.15.5", + "hostname", + "json-patch", + "k8s-openapi", + "kube-client", + "parking_lot", + "pin-project", + "serde", + "serde_json", + "thiserror 2.0.20", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libtest-mimic" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e6ba06f0ade6e504aff834d7c34298e5155c6baca353cc6a4aaff2f9fd7f33" +dependencies = [ + "anstream", + "anstyle", + "clap", + "escape8259", +] + +[[package]] +name = "linkme" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3045e122bd98aef8ec3ad58ce84f0791f64e70163d1a02710af4aa11a4d54cc5" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77060ebe535362c3da75682cd17b0431017b6e7c5661e714fc69a7ad017d1301" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "md-5" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" +dependencies = [ + "cfg-if", + "digest 0.11.2", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "miette" +version = "7.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" +dependencies = [ + "backtrace", + "backtrace-ext", + "cfg-if", + "miette-derive", + "owo-colors", + "supports-color", + "supports-hyperlinks", + "supports-unicode", + "terminal_size", + "textwrap", + "unicode-width 0.1.14", +] + +[[package]] +name = "miette-derive" +version = "7.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "multimap" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" + +[[package]] +name = "newtype-uuid" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa56da58097c7ae893c4097bb6d91bb5f7fa330053e07e033349db4d5f83ba8" +dependencies = [ + "uuid", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "noyalib" +version = "0.0.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "962838abbd8dd2cd3844d2208dc502458bba6985f8bf1dc21761b30260fcbd7f" +dependencies = [ + "hashbrown 0.17.0", + "indexmap", + "libm", + "memchr", + "rustc-hash", + "serde_core", + "smallvec", +] + +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "oauth2" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e219e79014df21a225b1860a479e2dcd7cbd9130f4defd4bd0e191ea31d67d" +dependencies = [ + "base64 0.22.1", + "chrono", + "getrandom 0.2.17", + "http", + "rand 0.8.6", + "reqwest", + "serde", + "serde_json", + "serde_path_to_error", + "sha2 0.10.9", + "thiserror 1.0.69", + "url", +] + +[[package]] +name = "object" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" +dependencies = [ + "memchr", +] + +[[package]] +name = "oid-registry" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7" +dependencies = [ + "asn1-rs", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +dependencies = [ + "critical-section", + "portable-atomic", +] + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openshell-bootstrap" +version = "0.0.0" +dependencies = [ + "bytes", + "miette", + "openshell-core", + "openshell-crypto", + "rcgen", + "serde", + "serde_json", + "tempfile", + "tokio", + "tracing", +] + +[[package]] +name = "openshell-core" +version = "0.0.0" +dependencies = [ + "async-trait", + "base64 0.22.1", + "chrono", + "glob", + "ipnet", + "libc", + "miette", + "nix", + "openshell-crypto", + "openshell-extension-core", + "openshell-policy-schema", + "prost", + "prost-types", + "protoc-bin-vendored", + "reqwest", + "rustix", + "rustls", + "serde", + "serde_json", + "sha2 0.10.9", + "thiserror 2.0.20", + "tokio", + "tokio-stream", + "tonic", + "tonic-prost", + "tonic-prost-build", + "tonic-types", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "openshell-crypto" +version = "0.0.0" +dependencies = [ + "aws-lc-rs", + "jsonwebtoken", + "kube", + "pem 3.0.6", + "rcgen", + "rustls", + "serde", + "sqlx", + "thiserror 2.0.20", + "tonic", + "x509-parser", +] + +[[package]] +name = "openshell-extension-core" +version = "0.0.0" +dependencies = [ + "hyper-util", + "serde", + "thiserror 2.0.20", + "tokio", + "tonic", + "tower", +] + +[[package]] +name = "openshell-policy" +version = "0.0.0" +dependencies = [ + "hickory-proto", + "miette", + "openshell-core", + "openshell-policy-schema", + "prost-types", + "serde", + "serde_json", +] + +[[package]] +name = "openshell-policy-schema" +version = "0.0.0" +dependencies = [ + "miette", + "noyalib", + "serde", + "serde_json", + "serde_path_to_error", + "thiserror 2.0.20", +] + +[[package]] +name = "openshell-sdk" +version = "0.0.0" +dependencies = [ + "async-stream", + "async-trait", + "futures", + "hyper", + "hyper-util", + "miette", + "oauth2", + "openshell-core", + "openshell-crypto", + "reqwest", + "rustls", + "serde", + "thiserror 2.0.20", + "tokio", + "tokio-rustls", + "tokio-tungstenite", + "tonic", + "tower", + "tracing", +] + +[[package]] +name = "openshell-testkit" +version = "0.0.0" +dependencies = [ + "clap", + "futures", + "libc", + "libtest-mimic", + "linkme", + "noyalib", + "openshell-bootstrap", + "openshell-core", + "openshell-policy", + "openshell-sdk", + "openshell-testkit-macros", + "prost-types", + "quick-junit", + "rand 0.9.4", + "serde", + "serde_json", + "tempfile", + "tokio", + "tonic", +] + +[[package]] +name = "openshell-testkit-macros" +version = "0.0.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + +[[package]] +name = "owo-colors" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pem" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" +dependencies = [ + "base64 0.22.1", + "serde_core", +] + +[[package]] +name = "pem" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d354a98a3d1251555de99e8fdd8afda05573c31b82f59063a7b0a29b5527f120" +dependencies = [ + "base64 0.23.1", + "serde_core", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pest" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0848c601009d37dfa3430c4666e147e49cdcf1b92ecd3e63657d8a5f19da662" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8040c4647b13b210a963c1ed407c1ff4fdfa01c31d6d2a098218702e6664f94f" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "pest_meta" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220" +dependencies = [ + "pest", + "sha2 0.10.9", +] + +[[package]] +name = "petgraph" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" +dependencies = [ + "fixedbitset", + "hashbrown 0.15.5", + "indexmap", +] + +[[package]] +name = "pin-project" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.117", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7" +dependencies = [ + "heck", + "itertools", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "regex", + "syn 2.0.117", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "prost-types" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8991c4cbdb8bc5b11f0b074ffe286c30e523de90fee5ba8132f1399f23cb3dd7" +dependencies = [ + "prost", +] + +[[package]] +name = "protoc-bin-vendored" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1c381df33c98266b5f08186583660090a4ffa0889e76c7e9a5e175f645a67fa" +dependencies = [ + "protoc-bin-vendored-linux-aarch_64", + "protoc-bin-vendored-linux-ppcle_64", + "protoc-bin-vendored-linux-s390_64", + "protoc-bin-vendored-linux-x86_32", + "protoc-bin-vendored-linux-x86_64", + "protoc-bin-vendored-macos-aarch_64", + "protoc-bin-vendored-macos-x86_64", + "protoc-bin-vendored-win32", +] + +[[package]] +name = "protoc-bin-vendored-linux-aarch_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c350df4d49b5b9e3ca79f7e646fde2377b199e13cfa87320308397e1f37e1a4c" + +[[package]] +name = "protoc-bin-vendored-linux-ppcle_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55a63e6c7244f19b5c6393f025017eb5d793fd5467823a099740a7a4222440c" + +[[package]] +name = "protoc-bin-vendored-linux-s390_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dba5565db4288e935d5330a07c264a4ee8e4a5b4a4e6f4e83fad824cc32f3b0" + +[[package]] +name = "protoc-bin-vendored-linux-x86_32" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8854774b24ee28b7868cd71dccaae8e02a2365e67a4a87a6cd11ee6cdbdf9cf5" + +[[package]] +name = "protoc-bin-vendored-linux-x86_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b38b07546580df720fa464ce124c4b03630a6fb83e05c336fea2a241df7e5d78" + +[[package]] +name = "protoc-bin-vendored-macos-aarch_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89278a9926ce312e51f1d999fee8825d324d603213344a9a706daa009f1d8092" + +[[package]] +name = "protoc-bin-vendored-macos-x86_64" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81745feda7ccfb9471d7a4de888f0652e806d5795b61480605d4943176299756" + +[[package]] +name = "protoc-bin-vendored-win32" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95067976aca6421a523e491fce939a3e65249bac4b977adee0ee9771568e8aa3" + +[[package]] +name = "pulldown-cmark" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db2be46835f013dd3f4fa7f5f7402c537787b54ebb6fe2b94bbdd7e2669bb7b" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50793def1b900256624a709439404384204a5dc3a6ec580281bfaac35e882e90" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quick-junit" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bae23b8e1a59a90f7bf98caa2f4c8c2eedf6df011c6c88ed633e85a87c84526e" +dependencies = [ + "chrono", + "indexmap", + "newtype-uuid", + "quick-xml", + "strip-ansi-escapes", + "thiserror 2.0.20", + "uuid", +] + +[[package]] +name = "quick-xml" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rcgen" +version = "0.14.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8774e05a7d0de114588e6a28fe7e71694b82614ed569d86d8b389dfbc98b8ad8" +dependencies = [ + "aws-lc-rs", + "pem 4.0.0", + "rustls-pki-types", + "time", + "x509-parser", + "yasna", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-native-certs", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rusticata-macros" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" +dependencies = [ + "nom", +] + +[[package]] +name = "rustix" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "aws-lc-rs", + "log", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted 0.9.0", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "schemars" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.117", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "secrecy" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e891af845473308773346dc847b2c23ee78fe442e0472ac50e22a18a93d3ae5a" +dependencies = [ + "zeroize", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.2", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.2", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "simple_asn1" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d585997b0ac10be3c5ee635f1bab02d512760d14b7c468801ac8a01d9ae5f1d" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror 2.0.20", + "time", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + +[[package]] +name = "sqlx" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "378620ccc25c62c89d8be1c819e76a88d59bdcc3304733330788948e619bfd71" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b44e85bf579a8eeb4ceaa77a3a523baf2bf0e9bac7e40f405d537b5d2d5ccb" +dependencies = [ + "base64 0.22.1", + "bytes", + "cfg-if", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.16.1", + "hashlink", + "indexmap", + "log", + "memchr", + "percent-encoding", + "rustls", + "serde", + "serde_json", + "sha2 0.10.9", + "smallvec", + "thiserror 2.0.20", + "tokio", + "tokio-stream", + "tracing", + "url", + "webpki-roots", +] + +[[package]] +name = "sqlx-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd2b84f2bc39a5705ef27ec785a11c934a41bbd4a24941e257927cddc26b60bf" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 2.0.117", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb8d96de5fdc85a5c4ec813432b523ec637e80ba98f046555f75f7908ddac7c3" +dependencies = [ + "cfg-if", + "dotenvy", + "either", + "heck", + "hex", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2 0.10.9", + "sqlx-core", + "sqlx-postgres", + "sqlx-sqlite", + "syn 2.0.117", + "thiserror 2.0.20", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b8020fe17c5f2c245bfa2505d7ef59c5604839527c740266ad2214acebea27" +dependencies = [ + "bitflags", + "byteorder", + "bytes", + "crc", + "digest 0.11.2", + "dotenvy", + "either", + "futures-core", + "futures-util", + "generic-array", + "log", + "percent-encoding", + "serde", + "sha1 0.11.0", + "sha2 0.11.0", + "sqlx-core", + "thiserror 2.0.20", + "tracing", +] + +[[package]] +name = "sqlx-postgres" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a2bdd6e83f6b3ea525ca9fee568030508b58355a43d0b2c1674d5f79dcd65e" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "rand 0.10.2", + "serde", + "serde_json", + "sha2 0.11.0", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.20", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488e99c397a62007e4229aec669a179816339afc6d2620ca6fa420dbee2e982c" +dependencies = [ + "atoi", + "flume", + "form_urlencoded", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "thiserror 2.0.20", + "tracing", + "url", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "strip-ansi-escapes" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8f8038e7e7969abb3f1b7c2a811225e9296da208539e0f79c5251d6cac0025" +dependencies = [ + "vte", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "supports-color" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6" +dependencies = [ + "is_ci", +] + +[[package]] +name = "supports-hyperlinks" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e396b6523b11ccb83120b115a0b7366de372751aa6edf19844dfb13a6af97e91" + +[[package]] +name = "supports-unicode" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12df2e0110f65b775f769bb17ef989067a1d931b2eb822bd4346631eeada89f9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "terminal_size" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874" +dependencies = [ + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "textwrap" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057" +dependencies = [ + "unicode-linebreak", + "unicode-width 0.2.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce3335fa71841cda333a58d7615b03901380ecf09d59b3296d21f8bbac0dde4e" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9daff607c6d2bf6c16fd681ccb7eecc83e4e2cdc1ca067ffaadfca5de7f084" +dependencies = [ + "futures-util", + "log", + "rustls", + "rustls-native-certs", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "slab", + "tokio", +] + +[[package]] +name = "tonic" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef" +dependencies = [ + "async-trait", + "axum", + "base64 0.22.1", + "bytes", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "rustls-native-certs", + "socket2", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322" +dependencies = [ + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tonic-prost" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0" +dependencies = [ + "bytes", + "prost", + "tonic", +] + +[[package]] +name = "tonic-prost-build" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "prost-types", + "quote", + "syn 2.0.117", + "tempfile", + "tonic-build", +] + +[[package]] +name = "tonic-types" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab1b02061f83d519bba3caa167f88f261ef05720ab8ebc954ade70de3348e8" +dependencies = [ + "prost", + "prost-types", + "tonic", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project-lite", + "slab", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "base64 0.22.1", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "mime", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand 0.9.4", + "rustls", + "rustls-pki-types", + "sha1 0.10.6", + "thiserror 2.0.20", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", + "serde_derive", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +dependencies = [ + "getrandom 0.4.2", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "vte" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" +dependencies = [ + "memchr", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.5", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "whoami" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626c4bac6755d76ffc12cb01b2eac751db1996b9e0041de9aa02c8c211ddc82c" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn 2.0.117", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.117", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "x509-parser" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202" +dependencies = [ + "asn1-rs", + "aws-lc-rs", + "data-encoding", + "der-parser", + "lazy_static", + "nom", + "oid-registry", + "rusticata-macros", + "thiserror 2.0.20", + "time", +] + +[[package]] +name = "yasna" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5f6765e852b9b4dc8e2a76843e4d64d1cea8e79bcde0b6901aea8e7c7f08282" +dependencies = [ + "bit-vec", + "time", +] + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/tests/suites/drivers/docker/Cargo.toml b/tests/suites/drivers/docker/Cargo.toml new file mode 100644 index 0000000000..ea987322ed --- /dev/null +++ b/tests/suites/drivers/docker/Cargo.toml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Each driver suite is its own workspace, with its own lockfile. +[package] +name = "docker" +description = "Drivers suite: Docker driver behavior, such as container lifecycle" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +container-engine-support = { path = "../../../support/container-engine" } +openshell-testkit = { path = "../../../testkit/testkit" } + +[workspace] diff --git a/tests/suites/drivers/docker/tests/lifecycle.rs b/tests/suites/drivers/docker/tests/lifecycle.rs new file mode 100644 index 0000000000..8df3eccf3d --- /dev/null +++ b/tests/suites/drivers/docker/tests/lifecycle.rs @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Docker driver sandbox lifecycle: what the driver does with its containers +//! when a sandbox's main process stops or an ephemeral sandbox finishes. + +use std::time::Duration; + +use container_engine_support::Engine; +use testkit::sdk::SandboxPhase; +use testkit::{Context, ResultExt as _}; + +/// Where the driver mounts the sandbox's bootstrap JWT. +const TOKEN_PATH: &str = "/etc/openshell/auth/sandbox.jwt"; +/// How long the gateway may take to report a stopped workload as Error. +const ERROR_TIMEOUT: Duration = Duration::from_secs(30); +/// How long the driver may take to remove an ephemeral sandbox's containers. +const CLEANUP_TIMEOUT: Duration = Duration::from_secs(90); + +/// Stopping a sandbox's workload container is terminal: the driver doesn't +/// relaunch the main process and the sandbox ends in Error. Before the stop, +/// the workload can't read its bootstrap JWT. +#[testkit::test] +async fn stopped_workload_container_is_terminal(cx: &mut Context) -> testkit::Result { + cx.expect_compute_driver("docker").await?; + let engine = Engine::from_env()?; + let sandbox = cx + .sandbox("st") + .command(["sleep", "infinity"]) + .create_ready() + .await?; + + let workload = engine.container_for_role(sandbox.name(), "sandbox").await?; + engine + .output([ + "exec", + &workload, + "/bin/sh", + "-c", + &format!("test ! -r {TOKEN_PATH}"), + ]) + .await + .context("the sandbox workload must not be able to read its bootstrap JWT")?; + + engine.output(["stop", &workload]).await?; + engine + .wait_running(&workload, false, Duration::from_mins(1)) + .await?; + sandbox + .wait_phase(SandboxPhase::Error, ERROR_TIMEOUT) + .await + .context("a stopped main process makes the sandbox terminal")?; + Ok(()) +} + +/// A detached `--no-keep` sandbox's containers are removed once its main +/// command exits, whether it succeeds or fails. Conformance checks that the +/// gateway forgets the sandbox; this checks the driver's containers. +#[testkit::test] +async fn ephemeral_sandbox_containers_are_removed_after_main_exits( + cx: &mut Context, +) -> testkit::Result { + cx.expect_compute_driver("docker").await?; + let engine = Engine::from_env()?; + let mut sandboxes = Vec::new(); + for (suffix, code) in [("ez", 0), ("ef", 17)] { + let builder = cx.cli_sandbox(suffix); + let release_path = format!("/sandbox/.ephemeral-release-{}", builder.name()); + let script = + format!("while [ ! -e '{release_path}' ]; do sleep 0.1; done; sleep 1; exit {code}"); + let sandbox = builder + .args(["--no-keep"]) + .command(["sh", "-c", &script]) + .create() + .await?; + sandboxes.push((sandbox, release_path, code)); + } + + for (sandbox, release_path, _) in &sandboxes { + sandbox.wait_ready().await?; + testkit::ensure!( + !engine + .containers_for_sandbox_id(sandbox.id()) + .await? + .is_empty(), + "no containers found for sandbox {} ({})", + sandbox.name(), + sandbox.id() + ); + sandbox + .exec(["touch", release_path.as_str()]) + .await? + .success()?; + } + for (sandbox, _, code) in &sandboxes { + testkit::poll_until( + &format!("containers of sandbox {} to be removed", sandbox.name()), + CLEANUP_TIMEOUT, + Duration::from_millis(500), + async || { + let left = engine.containers_for_sandbox_id(sandbox.id()).await?; + Ok(if left.is_empty() { + testkit::Poll::Ready(()) + } else { + testkit::Poll::Pending(format!("containers {left:?}")) + }) + }, + ) + .await + .context(format!("ephemeral sandbox exited {code}"))?; + } + Ok(()) +} diff --git a/tests/suites/drivers/podman/Cargo.lock b/tests/suites/drivers/podman/Cargo.lock index a4c8e1127a..9e4edf3a29 100644 --- a/tests/suites/drivers/podman/Cargo.lock +++ b/tests/suites/drivers/podman/Cargo.lock @@ -2261,6 +2261,7 @@ dependencies = [ "openshell-policy", "openshell-sdk", "openshell-testkit-macros", + "prost-types", "quick-junit", "rand 0.9.4", "serde", @@ -2445,9 +2446,11 @@ checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" name = "podman" version = "0.0.0" dependencies = [ + "base64 0.22.1", "container-engine-support", "openshell-testkit", "podman-support", + "serde_json", ] [[package]] diff --git a/tests/suites/drivers/podman/Cargo.toml b/tests/suites/drivers/podman/Cargo.toml index 02c0304a1c..cdf6c86639 100644 --- a/tests/suites/drivers/podman/Cargo.toml +++ b/tests/suites/drivers/podman/Cargo.toml @@ -4,7 +4,7 @@ # Each driver suite is its own workspace, with its own lockfile. [package] name = "podman" -description = "Drivers suite: Podman driver behavior, such as user namespaces" +description = "Drivers suite: Podman driver behavior, such as user namespaces and container lifecycle" version = "0.0.0" edition = "2024" rust-version = "1.94" @@ -13,8 +13,10 @@ repository = "https://github.com/NVIDIA/OpenShell" publish = false [dependencies] +base64 = "0.22" container-engine-support = { path = "../../../support/container-engine" } openshell-testkit = { path = "../../../testkit/testkit" } podman-support = { path = "../../../support/podman" } +serde_json = "1" [workspace] diff --git a/tests/suites/drivers/podman/tests/lifecycle.rs b/tests/suites/drivers/podman/tests/lifecycle.rs new file mode 100644 index 0000000000..89a21ddcb0 --- /dev/null +++ b/tests/suites/drivers/podman/tests/lifecycle.rs @@ -0,0 +1,148 @@ +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Podman driver sandbox lifecycle: what the driver does with its containers +//! when a sandbox's main process stops or an ephemeral sandbox finishes. + +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use base64::Engine as _; +use container_engine_support::Engine; +use testkit::sdk::SandboxPhase; +use testkit::{Context, Error, ResultExt as _}; + +/// Where the driver mounts the sandbox's bootstrap JWT. +const TOKEN_PATH: &str = "/etc/openshell/auth/sandbox.jwt"; +/// How long the gateway may take to report a stopped workload as Error. +const ERROR_TIMEOUT: Duration = Duration::from_secs(30); +/// How long the driver may take to remove an ephemeral sandbox's containers. +const CLEANUP_TIMEOUT: Duration = Duration::from_secs(90); + +/// Stopping a sandbox's workload container is terminal: the driver doesn't +/// relaunch the main process and the sandbox ends in Error. Before the stop, +/// the workload can't read its bootstrap JWT, and the supervisor's copy is +/// unexpired. +#[testkit::test] +async fn stopped_workload_container_is_terminal(cx: &mut Context) -> testkit::Result { + cx.expect_compute_driver("podman").await?; + let engine = Engine::from_env()?; + let sandbox = cx + .sandbox("st") + .command(["sleep", "infinity"]) + .create_ready() + .await?; + + let workload = engine.container_for_role(sandbox.name(), "sandbox").await?; + engine + .output([ + "exec", + &workload, + "/bin/sh", + "-c", + &format!("test ! -r {TOKEN_PATH}"), + ]) + .await + .context("the sandbox workload must not be able to read its bootstrap JWT")?; + + let supervisor = engine + .container_for_role(sandbox.name(), "supervisor") + .await?; + let token = engine.copy_from(&supervisor, TOKEN_PATH).await?; + require_unexpired(&String::from_utf8_lossy(&token))?; + + engine.output(["stop", &workload]).await?; + engine + .wait_running(&workload, false, Duration::from_mins(1)) + .await?; + sandbox + .wait_phase(SandboxPhase::Error, ERROR_TIMEOUT) + .await + .context("a stopped main process makes the sandbox terminal")?; + Ok(()) +} + +/// A detached `--no-keep` sandbox's containers are removed once its main +/// command exits, whether it succeeds or fails. Conformance checks that the +/// gateway forgets the sandbox; this checks the driver's containers. +#[testkit::test] +async fn ephemeral_sandbox_containers_are_removed_after_main_exits( + cx: &mut Context, +) -> testkit::Result { + cx.expect_compute_driver("podman").await?; + let engine = Engine::from_env()?; + let mut sandboxes = Vec::new(); + for (suffix, code) in [("ez", 0), ("ef", 17)] { + let builder = cx.cli_sandbox(suffix); + let release_path = format!("/sandbox/.ephemeral-release-{}", builder.name()); + let script = + format!("while [ ! -e '{release_path}' ]; do sleep 0.1; done; sleep 1; exit {code}"); + let sandbox = builder + .args(["--no-keep"]) + .command(["sh", "-c", &script]) + .create() + .await?; + sandboxes.push((sandbox, release_path, code)); + } + + for (sandbox, release_path, _) in &sandboxes { + sandbox.wait_ready().await?; + testkit::ensure!( + !engine + .containers_for_sandbox_id(sandbox.id()) + .await? + .is_empty(), + "no containers found for sandbox {} ({})", + sandbox.name(), + sandbox.id() + ); + sandbox + .exec(["touch", release_path.as_str()]) + .await? + .success()?; + } + for (sandbox, _, code) in &sandboxes { + testkit::poll_until( + &format!("containers of sandbox {} to be removed", sandbox.name()), + CLEANUP_TIMEOUT, + Duration::from_millis(500), + async || { + let left = engine.containers_for_sandbox_id(sandbox.id()).await?; + Ok(if left.is_empty() { + testkit::Poll::Ready(()) + } else { + testkit::Poll::Pending(format!("containers {left:?}")) + }) + }, + ) + .await + .context(format!("ephemeral sandbox exited {code}"))?; + } + Ok(()) +} + +/// Fail unless `token`'s `exp` claim is in the future. Sandbox tokens use +/// `exp = 0` when no TTL is configured. +fn require_unexpired(token: &str) -> testkit::Result { + let payload = token + .trim() + .split('.') + .nth(1) + .ok_or_else(|| Error::msg("the sandbox JWT has no payload segment"))?; + let payload = base64::engine::general_purpose::URL_SAFE_NO_PAD + .decode(payload) + .map_err(|err| Error::msg(format!("decode the sandbox JWT payload: {err}")))?; + let claims: serde_json::Value = + serde_json::from_slice(&payload).context("parse the sandbox JWT claims")?; + let exp = claims["exp"] + .as_u64() + .ok_or_else(|| Error::msg(format!("the sandbox JWT has no integer exp: {claims}")))?; + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_err(|err| Error::msg(format!("read the clock: {err}")))? + .as_secs(); + testkit::ensure!( + exp == 0 || exp > now, + "the supervisor's bootstrap JWT expired: exp={exp}, now={now}" + ); + Ok(()) +} diff --git a/tests/suites/features/Cargo.lock b/tests/suites/features/Cargo.lock index 0b9bd02a90..40c4e12843 100644 --- a/tests/suites/features/Cargo.lock +++ b/tests/suites/features/Cargo.lock @@ -26,6 +26,7 @@ dependencies = [ "cfg-if", "getrandom 0.3.4", "once_cell", + "serde", "version_check", "zerocopy", ] @@ -329,6 +330,21 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec 0.8.0", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + [[package]] name = "bit-vec" version = "0.9.1" @@ -365,12 +381,24 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "borrow-or-share" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0b364ead1874514c8c2855ab558056ebfeb775653e7ae45ff72f28f8f3166c" + [[package]] name = "bumpalo" version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +[[package]] +name = "bytecount" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" + [[package]] name = "byteorder" version = "1.5.0" @@ -738,6 +766,16 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "driver-config" +version = "0.0.0" +dependencies = [ + "container-engine-support", + "openshell-testkit", + "serde_json", + "tempfile", +] + [[package]] name = "dunce" version = "1.0.5" @@ -771,6 +809,15 @@ dependencies = [ "serde", ] +[[package]] +name = "email_address" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449" +dependencies = [ + "serde", +] + [[package]] name = "enum-ordinalize" version = "4.4.2" @@ -844,6 +891,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "fancy-regex" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d301f5bf187b3c295fce6468d3875037a0bccc5f6b151c63cac2f85babf21912" +dependencies = [ + "bit-set", + "regex-automata", + "regex-syntax", +] + [[package]] name = "fastrand" version = "2.4.1" @@ -862,6 +920,17 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" +[[package]] +name = "fluent-uri" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc74ac4d8359ae70623506d512209619e5cf8f347124910440dbc221714b328e" +dependencies = [ + "borrow-or-share", + "ref-cast", + "serde", +] + [[package]] name = "flume" version = "0.12.0" @@ -900,6 +969,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fraction" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e246562084dde8ebbcc943b261c406ce4f68e5032ec28029a251a47d6a295500" +dependencies = [ + "num", + "num-bigint", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -1035,9 +1114,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 5.3.0", "wasip2", + "wasm-bindgen", ] [[package]] @@ -1124,6 +1205,11 @@ name = "hashbrown" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] [[package]] name = "hashlink" @@ -1230,6 +1316,7 @@ name = "host-server-support" version = "0.0.0" dependencies = [ "openshell-testkit", + "serde_json", "tokio", "tungstenite", ] @@ -1692,6 +1779,59 @@ dependencies = [ "serde_json", ] +[[package]] +name = "jsonschema" +version = "0.58.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f622c574a29fb3034a0a90645afee194dfedc75fc124228801b6e77041075bd1" +dependencies = [ + "ahash", + "bytecount", + "data-encoding", + "email_address", + "fancy-regex", + "fraction", + "getrandom 0.3.4", + "itoa", + "jsonschema-regex", + "jsonschema-value", + "num-cmp", + "num-traits", + "percent-encoding", + "referencing", + "regex", + "serde", + "serde_json", + "strum", + "unicode-general-category", + "uuid-simd", +] + +[[package]] +name = "jsonschema-regex" +version = "0.58.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a968fffd387b2ab005bf00c1851f5d26e90df05b6f7ad609ed0d620033cca5e7" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "jsonschema-value" +version = "0.58.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39b7670345e5ce87371339d13705dbb9276b7e3e934bbe1efa2c6734a1f65a96" +dependencies = [ + "ahash", + "bytecount", + "fraction", + "getrandom 0.3.4", + "num-cmp", + "num-traits", + "serde_json", + "zmij", +] + [[package]] name = "jsonwebtoken" version = "10.3.0" @@ -1899,18 +2039,18 @@ dependencies = [ [[package]] name = "linkme" -version = "0.3.37" +version = "0.3.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3045e122bd98aef8ec3ad58ce84f0791f64e70163d1a02710af4aa11a4d54cc5" +checksum = "10a4e12fd3f6b22d5bc28beccac0f53bb35db4a897c6ddb709c4a0161f72eb6e" dependencies = [ "linkme-impl", ] [[package]] name = "linkme-impl" -version = "0.3.37" +version = "0.3.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77060ebe535362c3da75682cd17b0431017b6e7c5661e714fc69a7ad017d1301" +checksum = "22cd04c256b1cd686a45898c8fd150c79b801d96a3eb7bae1075f9eb3b4b85c1" dependencies = [ "proc-macro2", "quote", @@ -1966,6 +2106,12 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "micromap" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74" + [[package]] name = "miette" version = "7.6.0" @@ -2080,6 +2226,20 @@ dependencies = [ "smallvec", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.8" @@ -2090,6 +2250,21 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-cmp" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63335b2e2c34fae2fb0aa2cecfd9f0832a1e24b3b32ecec612c3426d46dc8aaa" + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-conv" version = "0.2.1" @@ -2105,6 +2280,28 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2152,6 +2349,18 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ocsf" +version = "0.0.0" +dependencies = [ + "container-engine-support", + "host-server-support", + "openshell-ocsf-validate", + "openshell-testkit", + "sandbox-clients-support", + "serde_json", +] + [[package]] name = "oid-registry" version = "0.8.1" @@ -2258,6 +2467,15 @@ dependencies = [ "tower", ] +[[package]] +name = "openshell-ocsf-validate" +version = "0.0.0" +dependencies = [ + "jsonschema", + "serde_json", + "thiserror 2.0.20", +] + [[package]] name = "openshell-policy" version = "0.0.0" @@ -2335,6 +2553,7 @@ dependencies = [ "openshell-policy", "openshell-sdk", "openshell-testkit-macros", + "prost-types", "quick-junit", "rand 0.9.4", "serde", @@ -2368,6 +2587,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "outref" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e" + [[package]] name = "owo-colors" version = "4.3.0" @@ -2845,6 +3070,43 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ref-cast" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "referencing" +version = "0.58.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "558f3855529c0a7e78a48e409fa653456e55f1b167eab4109c16a255b7727e3f" +dependencies = [ + "ahash", + "fluent-uri", + "getrandom 0.3.4", + "hashbrown 0.17.0", + "itoa", + "micromap", + "parking_lot", + "percent-encoding", + "serde_json", +] + [[package]] name = "regex" version = "1.12.3" @@ -2913,6 +3175,13 @@ dependencies = [ "web-sys", ] +[[package]] +name = "resource-limits" +version = "0.0.0" +dependencies = [ + "openshell-testkit", +] + [[package]] name = "ring" version = "0.17.14" @@ -2927,6 +3196,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "routable-host-ip" +version = "0.0.0" +dependencies = [ + "host-server-support", + "openshell-testkit", + "serde_json", +] + [[package]] name = "rustc-demangle" version = "0.1.27" @@ -3560,6 +3838,27 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "subtle" version = "2.6.1" @@ -4052,6 +4351,12 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" +[[package]] +name = "unicode-general-category" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f" + [[package]] name = "unicode-ident" version = "1.0.24" @@ -4157,6 +4462,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "uuid-simd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b082222b4f6619906941c17eb2297fff4c2fb96cb60164170522942a200bd8" +dependencies = [ + "outref", + "vsimd", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -4169,6 +4484,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vsimd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" + [[package]] name = "vte" version = "0.14.1" @@ -4609,7 +4930,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5f6765e852b9b4dc8e2a76843e4d64d1cea8e79bcde0b6901aea8e7c7f08282" dependencies = [ - "bit-vec", + "bit-vec 0.9.1", "time", ] diff --git a/tests/suites/features/Cargo.toml b/tests/suites/features/Cargo.toml index 78f4dd6277..7cac701180 100644 --- a/tests/suites/features/Cargo.toml +++ b/tests/suites/features/Cargo.toml @@ -3,4 +3,4 @@ [workspace] resolver = "2" -members = ["cdi", "connect-ssh-supervision", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image"] +members = ["cdi", "connect-ssh-supervision", "driver-config", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "ocsf", "resource-limits", "routable-host-ip"] diff --git a/tests/suites/features/driver-config/Cargo.toml b/tests/suites/features/driver-config/Cargo.toml new file mode 100644 index 0000000000..c6dcea67a4 --- /dev/null +++ b/tests/suites/features/driver-config/Cargo.toml @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "driver-config" +description = "Features suite: Docker and Podman sandboxes mount the volumes and bind mounts a caller's driver config names" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +container-engine-support = { path = "../../../support/container-engine" } +openshell-testkit = { path = "../../../testkit/testkit" } +serde_json = "1" +tempfile = "3" diff --git a/tests/suites/features/driver-config/tests/mounts.rs b/tests/suites/features/driver-config/tests/mounts.rs new file mode 100644 index 0000000000..37fc72b017 --- /dev/null +++ b/tests/suites/features/driver-config/tests/mounts.rs @@ -0,0 +1,294 @@ +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Docker and Podman sandboxes mount the engine volumes and host directories a +//! caller names in `--driver-config-json`. +//! +//! The gateway must allow caller driver config and bind mounts, and resource +//! admission must be off, because bind mounts can't carry approval labels. The +//! tmachine `-driver-config` environments configure that. The tests +//! still label their volumes for the sandbox's workspace, so the volume tests +//! also pass with admission on. + +use std::os::unix::fs::PermissionsExt as _; +use std::path::Path; + +use container_engine_support::Engine; +use testkit::{Context, Error, Result, ResultExt as _}; + +const VOLUME_TARGET: &str = "/sandbox/e2e-volume"; +const OCI_VOLUME_TARGET: &str = "/workspace/project/e2e-volume"; +const BIND_TARGET: &str = "/sandbox/e2e-bind"; + +/// An image whose `USER` has no passwd entry and owns its `WORKDIR`, so the +/// driver prepares a workspace with a volume nested inside it. +const OCI_USER_CONTAINERFILE: &str = "WORKDIR /workspace/project +RUN chown 2234:2235 . +USER 2234:2235 +CMD [\"sleep\", \"infinity\"] +"; + +/// The bind test checks the driver's mount wiring, not Landlock over host +/// bind mounts, so the sandbox user may write the mount and `/tmp`. It runs +/// as the `sandbox` user, which the Python image has. +const BIND_POLICY: &str = "version: 1 + +filesystem_policy: + include_workdir: false + read_only: [/bin, /dev, /etc, /lib, /proc, /usr] + read_write: [/sandbox/e2e-bind, /tmp] + +landlock: + compatibility: best_effort + +process: + run_as_user: sandbox + run_as_group: sandbox +"; + +/// A sandbox's main command reads a file seeded in an existing volume and +/// writes one the host then reads. +#[testkit::test] +async fn sandbox_mounts_existing_driver_config_volume(cx: &mut Context) -> testkit::Result { + let driver = container_driver(cx).await?; + let engine = Engine::from_env()?; + let volume = create_seeded_volume(cx, &engine, "dcv").await?; + + let builder = cx.cli_sandbox("dcv"); + let name = builder.name().to_string(); + let output = builder + .args([ + "--driver-config-json", + &mount_config(&driver, "volume", &volume, VOLUME_TARGET).to_string(), + ]) + .command([ + "sh", + "-lc", + &format!( + "set -eu; test \"$(cat {VOLUME_TARGET}/input.txt)\" = host-volume-ok; \ + printf sandbox-volume-ok > {VOLUME_TARGET}/output.txt; \ + cat {VOLUME_TARGET}/output.txt" + ), + ]) + .run() + .await? + .success() + .context("sandbox reads and writes the mounted volume")?; + testkit::ensure!( + output.stdout.contains("sandbox-volume-ok"), + "the sandbox did not print its write to the volume:\n{}", + output.stdout + ); + + cx.adopt(&name).await?.delete().await?; + run_on_volume( + &engine, + &volume, + "test \"$(cat /vol/input.txt)\" = host-volume-ok; \ + test \"$(cat /vol/output.txt)\" = sandbox-volume-ok", + ) + .await + .context("the volume keeps the sandbox's write") +} + +/// A volume mounted inside the workspace of an image with a numeric `USER` +/// keeps its ownership: the driver prepares the workspace for that user +/// without changing the ownership of the nested mount. The main process and +/// `sandbox exec` children both run as the image user in the workspace. +#[testkit::test] +async fn oci_workspace_preparation_skips_nested_volume_ownership( + cx: &mut Context, +) -> testkit::Result { + let driver = container_driver(cx).await?; + let engine = Engine::from_env()?; + let volume = create_seeded_volume(cx, &engine, "dco").await?; + let image = engine + .build_test_image( + cx, + "driver-config-oci-user", + &format!("FROM {}\n{OCI_USER_CONTAINERFILE}", testkit::base_image()), + ) + .await?; + + let checks = format!( + "test \"$(id -u):$(id -g)\" = 2234:2235; \ + test \"$(pwd -P)\" = /workspace/project; test \"$HOME\" = /workspace/project; \ + test \"$(stat -c %u:%g {OCI_VOLUME_TARGET}/input.txt)\" = 0:0;" + ); + let main = format!( + "(set -eu; {checks} touch direct-write) >/tmp/dc-main.log 2>&1; \ + echo $? >/tmp/dc-main.status; exec sleep infinity" + ); + let sandbox = cx + .cli_sandbox("dco") + .image(&image.tag) + .args([ + "--driver-config-json", + &mount_config(&driver, "volume", &volume, OCI_VOLUME_TARGET).to_string(), + ]) + .command(["sh", "-c", &main]) + .create() + .await + .context("sandbox starts from the OCI-user image with a nested volume")?; + + let script = format!( + "set -eu; i=0; \ + while [ ! -f /tmp/dc-main.status ]; do \ + i=$((i + 1)); [ \"$i\" -le 60 ] || {{ echo main process checks did not finish >&2; exit 1; }}; \ + sleep 1; \ + done; \ + if [ \"$(cat /tmp/dc-main.status)\" != 0 ]; then \ + echo main process checks failed: >&2; cat /tmp/dc-main.log >&2; exit 1; \ + fi; \ + test -f direct-write; {checks} touch exec-write" + ); + sandbox.wait_ready().await?; + sandbox + .exec(["sh", "-c", &script]) + .await? + .success() + .context("main process and exec children keep the nested volume's ownership")?; + + sandbox.delete().await?; + run_on_volume( + &engine, + &volume, + "test \"$(stat -c %u:%g /vol/input.txt)\" = 0:0", + ) + .await + .context("the nested volume's ownership is unchanged") +} + +/// With bind mounts enabled, a sandbox's main command reads a file in a host +/// directory and writes one the host then reads. +#[testkit::test] +async fn sandbox_mounts_enabled_driver_config_bind(cx: &mut Context) -> testkit::Result { + let driver = container_driver(cx).await?; + // Under the home directory, which the gateway's engine can reach: the + // test user runs a rootless gateway, and a rootful engine reads any path. + let home = std::env::var_os("HOME").ok_or_else(|| Error::msg("HOME is not set"))?; + let host_dir = tempfile::Builder::new() + .prefix("openshell-test-driver-config-bind-") + .tempdir_in(home) + .context("create the bind mount directory")?; + set_mode(host_dir.path(), 0o777)?; + let input = host_dir.path().join("input.txt"); + std::fs::write(&input, "host-bind-ok").context("seed the bind mount directory")?; + set_mode(&input, 0o666)?; + + let source = host_dir + .path() + .to_str() + .ok_or_else(|| Error::msg("the bind mount directory is not UTF-8"))?; + let mut config = mount_config(&driver, "bind", source, BIND_TARGET); + config[&driver]["mounts"][0]["selinux_label"] = "private".into(); + + let builder = cx.cli_sandbox("dcb"); + let name = builder.name().to_string(); + let output = builder + .image(testkit::python_image()) + .policy_yaml(BIND_POLICY) + .args(["--driver-config-json", &config.to_string()]) + .command([ + "sh", + "-lc", + &format!( + "set -eu; test \"$(cat {BIND_TARGET}/input.txt)\" = host-bind-ok; \ + printf sandbox-bind-ok > {BIND_TARGET}/output.txt; \ + cat {BIND_TARGET}/output.txt" + ), + ]) + .run() + .await? + .success() + .context("sandbox reads and writes the bind mount")?; + testkit::ensure!( + output.stdout.contains("sandbox-bind-ok"), + "the sandbox did not print its write to the bind mount:\n{}", + output.stdout + ); + + cx.adopt(&name).await?.delete().await?; + let written = std::fs::read_to_string(host_dir.path().join("output.txt")) + .context("read the sandbox's write from the bind mount directory")?; + testkit::ensure!( + written == "sandbox-bind-ok", + "the bind mount directory has output {written:?}; expected sandbox-bind-ok" + ); + Ok(()) +} + +/// The gateway's compute driver, which must be Docker or Podman. +async fn container_driver(cx: &Context) -> Result { + let driver = cx.compute_driver().await?; + testkit::ensure!( + matches!(driver.as_str(), "docker" | "podman"), + "this suite needs a Docker or Podman gateway; the gateway uses {driver}" + ); + Ok(driver) +} + +/// A driver config with one writable mount of `kind` from `source` at +/// `target`. +fn mount_config(driver: &str, kind: &str, source: &str, target: &str) -> serde_json::Value { + serde_json::json!({ + driver: { + "mounts": [{ + "type": kind, + "source": source, + "target": target, + "read_only": false, + }] + } + }) +} + +/// Create a volume the sandbox's workspace may attach, with a world-writable +/// root and `input.txt` owned by root. +async fn create_seeded_volume(cx: &Context, engine: &Engine, name: &str) -> Result { + let workspace = cx.cli_handle().gateway().workspace.clone(); + let volume = engine + .create_test_volume( + cx, + name, + &[ + ("openshell.ai/sandbox-attachable", "true"), + ("openshell.ai/sandbox-attachable-workspace", &workspace), + ], + ) + .await?; + run_on_volume( + engine, + &volume, + "chmod 0777 /vol; printf host-volume-ok > /vol/input.txt", + ) + .await + .context(format!("seed volume {volume}"))?; + Ok(volume) +} + +/// Run `script` as root in a container from the base image, with `volume` at +/// `/vol`. +async fn run_on_volume(engine: &Engine, volume: &str, script: &str) -> Result { + engine + .output([ + "run", + "--rm", + "--user", + "0:0", + "--volume", + &format!("{volume}:/vol"), + "--entrypoint", + "sh", + &testkit::base_image(), + "-c", + &format!("set -eu; {script}"), + ]) + .await + .map(drop) +} + +fn set_mode(path: &Path, mode: u32) -> Result { + std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode)) + .context(format!("set mode {mode:o} on {}", path.display())) +} diff --git a/tests/suites/features/host-gateway/tests/host_gateway.rs b/tests/suites/features/host-gateway/tests/host_gateway.rs index f77a3e378a..40d98e1bf6 100644 --- a/tests/suites/features/host-gateway/tests/host_gateway.rs +++ b/tests/suites/features/host-gateway/tests/host_gateway.rs @@ -9,11 +9,13 @@ //! with [`sandbox_clients_support::http`], from a sandbox created from the //! Python test image ([`testkit::python_image`]). +use std::time::Duration; + use host_server_support::{HttpRecorder, TEST_HOST}; use sandbox_clients_support::{Request, http}; use testkit::policy; use testkit::sdk::raw::proto; -use testkit::{Context, PYTHON_BINARIES, ResultExt as _}; +use testkit::{Context, PYTHON_BINARIES, Poll, ResultExt as _, Sandbox}; /// A sandbox from the Python test image resolves `host.openshell.internal` /// and gets a response from a server the test runs on the host. The default @@ -54,6 +56,57 @@ async fn python_sandbox_reaches_host_server(cx: &mut Context) -> testkit::Result Ok(()) } +/// `host.openshell.internal` still reaches the host after the sandbox is +/// stopped and started, when the driver recreates its containers or pod. +#[testkit::test] +async fn host_server_reachable_after_stop_start(cx: &mut Context) -> testkit::Result { + let marker = format!("host-gateway-restart-{}", cx.run_id()); + let server = HttpRecorder::start(marker.clone()).await?; + let sandbox = cx + .sandbox("hgss") + .image(testkit::python_image()) + .command(["sleep", "infinity"]) + .policy(policy(server.port)) + .create_ready() + .await?; + + expect_reachable(&sandbox, server.port, &marker) + .await + .context("before the restart")?; + sandbox.stop().await?; + sandbox.start().await?; + expect_reachable(&sandbox, server.port, &marker) + .await + .context("after the restart") +} + +/// Request a page from the host server until the reply has `marker`, for up +/// to 40 seconds, as the legacy test retried. +async fn expect_reachable(sandbox: &Sandbox, port: u16, marker: &str) -> testkit::Result { + testkit::poll_until( + &format!("the host server on port {port} from {}", sandbox.name()), + Duration::from_secs(40), + Duration::from_secs(1), + async || { + Ok( + match http(sandbox, TEST_HOST, port, &Request::get("/")).await { + Ok(reply) + if reply + .response + .as_ref() + .is_some_and(|response| response.body_text().contains(marker)) => + { + Poll::Ready(()) + } + Ok(reply) => Poll::Pending(format!("{reply:?}")), + Err(error) => Poll::Pending(format!("{error:#}")), + }, + ) + }, + ) + .await +} + /// A sandbox policy that allows the image's Python to connect to /// `host.openshell.internal` on `port`. It allows [`PYTHON_BINARIES`], the /// real paths behind `python3` in `testkit::python_image()` images, because a diff --git a/tests/suites/features/host-gateway/tests/response_eof.rs b/tests/suites/features/host-gateway/tests/response_eof.rs new file mode 100644 index 0000000000..3c35b2d4b8 --- /dev/null +++ b/tests/suites/features/host-gateway/tests/response_eof.rs @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! A sandbox client sees the connection close when a host server closes it +//! after an HTTP response, whatever framing the response uses. + +use host_server_support::{TEST_HOST, TcpServer}; +use sandbox_clients_support::{ReadEnd, http_raw}; +use testkit::policy; +use testkit::{Context, PYTHON_BINARIES, ResultExt as _}; + +/// Responses the server sends, then closes the connection. Each ends the +/// response a different way: an HTTP/1.0 body length, `Connection: close` +/// with a body length, and `Connection: close` with a chunked body. +const RESPONSES: [&str; 3] = [ + "HTTP/1.0 200 OK\r\nContent-Length: 3\r\n\r\nOK\n", + "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 3\r\n\r\nOK\n", + "HTTP/1.1 200 OK\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nOK\n\r\n0\r\n\r\n", +]; + +/// The client sends a request that doesn't ask the server to close, so only +/// the server's close ends the read. A client that goes idle instead got the +/// response but not the close. +#[testkit::test] +async fn sandbox_receives_eof_after_closing_http_response(cx: &mut Context) -> testkit::Result { + let mut servers = Vec::new(); + let mut allowed = policy::base(); + for response in RESPONSES { + let server = TcpServer::reply_when_idle(response).await?; + policy::allow( + &mut allowed, + "host_server", + TEST_HOST, + server.port, + PYTHON_BINARIES, + ); + servers.push((response, server)); + } + + let sandbox = cx + .sandbox("eof") + .image(testkit::python_image()) + .command(["sleep", "infinity"]) + .policy(allowed) + .create_ready() + .await?; + + for (response, server) in &servers { + let request = format!( + "GET / HTTP/1.1\r\nHost: {TEST_HOST}:{}\r\n\r\n", + server.port + ); + let reply = http_raw(&sandbox, TEST_HOST, server.port, request.as_bytes()) + .await + .context(format!("request {response:?} from the host server"))?; + testkit::ensure!( + reply.received_text().lines().any(|line| line == "OK"), + "the client did not get the body of {response:?}: {reply:?}" + ); + testkit::ensure!( + reply.read_end == Some(ReadEnd::Closed), + "the client did not see the server close after {response:?}: {reply:?}" + ); + } + Ok(()) +} diff --git a/tests/suites/features/ocsf/Cargo.toml b/tests/suites/features/ocsf/Cargo.toml new file mode 100644 index 0000000000..793e05c6de --- /dev/null +++ b/tests/suites/features/ocsf/Cargo.toml @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "ocsf" +description = "Features suite: a container supervisor writes opt-in OCSF JSON audit records to its stderr that conform to the OCSF schema and cover network, HTTP and SSH activity" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +container-engine-support = { path = "../../../support/container-engine" } +host-server-support = { path = "../../../support/host-server" } +openshell-ocsf-validate = { path = "../../../../crates/openshell-ocsf-validate" } +openshell-testkit = { path = "../../../testkit/testkit" } +sandbox-clients-support = { path = "../../../support/sandbox-clients" } +serde_json = "1" diff --git a/tests/suites/features/ocsf/tests/ocsf_stderr.rs b/tests/suites/features/ocsf/tests/ocsf_stderr.rs new file mode 100644 index 0000000000..4b0c1d33f6 --- /dev/null +++ b/tests/suites/features/ocsf/tests/ocsf_stderr.rs @@ -0,0 +1,216 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! A Docker or Podman supervisor writes OCSF audit records to its container's +//! stderr, so an operator can collect them without reading files in the +//! container. +//! +//! Conformance can't run this: it reads the supervisor container's own output +//! through the gateway's container engine, which only container drivers have. + +use std::time::Duration; + +use container_engine_support::Engine; +use host_server_support::{HttpRecorder, TEST_HOST}; +use sandbox_clients_support::{Request, connect, http}; +use testkit::policy::{self, Access, Endpoint as _}; +use testkit::sdk::raw::proto::setting_value::Value as SettingValue; +use testkit::{Context, Error, PYTHON_BINARIES, Poll, ResultExt as _}; + +const JSON_SETTING: &str = "ocsf_json_enabled"; +const JSON_MARKER: &str = " OCSF-JSON "; +/// An endpoint the policy doesn't allow, for a Network Activity denial. +const DENIED_HOST: &str = "1.1.1.1"; +const DENIED_PORT: u16 = 443; +/// Classes the traffic must produce: Network Activity for the denied +/// connect, HTTP Activity for the denied POST, and SSH Activity for the exec +/// sessions that run the clients. +const REQUIRED_CLASSES: [u64; 3] = [4001, 4002, 4007]; +/// How long the setting may take to reach the supervisor, which polls for it. +const JSON_TIMEOUT: Duration = Duration::from_secs(40); + +/// OCSF JSON is opt-in. With `ocsf_json_enabled`, the supervisor writes each +/// event as one ` OCSF-JSON ` line on stderr, never stdout, next to the +/// shorthand line. Denied TCP, a POST the L7 policy denies, and the exec +/// sessions produce Network, HTTP and SSH Activity records. Every record +/// conforms to the OCSF schema and names the sandbox's container and image. +/// The logs the gateway collects keep only the shorthand. +#[testkit::test] +async fn network_events_are_json_on_supervisor_stderr_only(cx: &mut Context) -> testkit::Result { + let driver = cx.compute_driver().await?; + testkit::ensure!( + matches!(driver.as_str(), "docker" | "podman"), + "this suite needs a Docker or Podman gateway; the gateway uses {driver}" + ); + let engine = Engine::from_env()?; + let server = HttpRecorder::start("ocsf").await?; + // Python reaches the server, but only to read: the POST is an L7 denial. + let mut allowed = policy::base(); + policy::allow( + &mut allowed, + "server", + TEST_HOST, + server.port, + PYTHON_BINARIES, + ) + .rest(Access::ReadOnly); + let image = testkit::python_image(); + let sandbox = cx + .sandbox("oc") + .image(&image) + .command(["sleep", "infinity"]) + .policy(allowed) + .create_ready() + .await?; + let supervisor = engine + .container_for_role(sandbox.name(), "supervisor") + .await?; + let workload = engine.container_for_role(sandbox.name(), "sandbox").await?; + let image_uid = engine.inspect_container(&workload, "{{.Image}}").await?; + + let before = engine.logs(&supervisor).await?; + testkit::ensure!( + json_records(&before.stderr)?.is_empty(), + "the supervisor wrote OCSF JSON before {JSON_SETTING} was set:\n{}", + before.stderr + ); + + sandbox + .set_setting(JSON_SETTING, SettingValue::BoolValue(true)) + .await?; + let post = Request::new("POST", "/allowed").body("x"); + let (logs, records) = testkit::poll_until( + "JSON Network, HTTP and SSH Activity on the supervisor's stderr", + JSON_TIMEOUT, + Duration::from_secs(1), + async || { + connect(&sandbox, DENIED_HOST, DENIED_PORT).await?; + let denied = http(&sandbox, TEST_HOST, server.port, &post).await?; + testkit::ensure!( + denied.status() == Some(403), + "the L7 policy did not deny the POST: {denied:?}" + ); + let logs = engine.logs(&supervisor).await?; + testkit::ensure!( + !logs.stdout.contains(JSON_MARKER), + "the supervisor wrote OCSF JSON to stdout:\n{}", + logs.stdout + ); + let records = json_records(&logs.stderr)?; + let missing: Vec = REQUIRED_CLASSES + .into_iter() + .filter(|class| !records.iter().any(|record| record["class_uid"] == *class)) + .collect(); + Ok( + if missing.is_empty() && records.iter().any(is_denied_connect) { + Poll::Ready((logs, records)) + } else { + Poll::Pending(format!( + "missing classes {missing:?}; stderr:\n{}", + logs.stderr + )) + }, + ) + }, + ) + .await?; + testkit::ensure!( + logs.stderr.contains(" OCSF NET:OPEN "), + "the shorthand NET:OPEN line is missing from the supervisor's stderr:\n{}", + logs.stderr + ); + + for record in &records { + check_record(record, sandbox.name(), &image, &image_uid) + .context(format!("OCSF record {record}"))?; + } + + let gateway_logs = sandbox + .logs_until("NET:OPEN", |logs| logs.contains("NET:OPEN")) + .await?; + testkit::ensure!( + !gateway_logs.contains("OCSF-JSON"), + "the logs the gateway collects contain OCSF JSON:\n{gateway_logs}" + ); + Ok(()) +} + +/// The JSON records in `stderr`, one per ` OCSF-JSON ` line. Each must be a +/// whole JSON object with no terminal escapes. +fn json_records(stderr: &str) -> testkit::Result> { + stderr + .lines() + .filter_map(|line| line.split_once(JSON_MARKER).map(|(_, payload)| payload)) + .map(|payload| { + testkit::ensure!( + !payload.contains('\x1b'), + "an OCSF JSON line has terminal escapes: {payload:?}" + ); + serde_json::from_str(payload).context(format!("parse OCSF JSON line {payload:?}")) + }) + .collect() +} + +fn is_denied_connect(record: &serde_json::Value) -> bool { + record["class_uid"] == 4001 + && record["dst_endpoint"]["port"] == DENIED_PORT + && record["action"] == "Denied" +} + +fn check_record( + record: &serde_json::Value, + sandbox: &str, + image: &str, + image_uid: &str, +) -> testkit::Result { + testkit::ensure!( + record["metadata"]["version"] == "1.8.0", + "metadata.version is not 1.8.0" + ); + testkit::ensure!( + record["metadata"]["uid"] + .as_str() + .is_some_and(|uid| !uid.is_empty()), + "metadata.uid is empty" + ); + testkit::ensure!( + record.get("container").is_none(), + "the container is at the top level, not under device" + ); + let container = &record["device"]["container"]; + testkit::ensure!( + container["name"] == sandbox, + "device.container.name is not {sandbox}" + ); + testkit::ensure!( + container["image"]["name"] == image, + "device.container.image.name is not {image}" + ); + let uid = container["image"]["uid"] + .as_str() + .ok_or_else(|| Error::msg("device.container.image.uid is missing"))?; + testkit::ensure!( + uid.trim_start_matches("sha256:") == image_uid.trim_start_matches("sha256:"), + "device.container.image.uid is not the workload image {image_uid}" + ); + openshell_ocsf_validate::validate_event(record) + .map_err(|reason| Error::msg(format!("does not conform to the OCSF schema: {reason}"))) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn json_records_reads_marked_lines_only() { + let stderr = "2026 INFO OCSF NET:OPEN [MED] DENIED\n\ + 2026 INFO OCSF-JSON {\"class_uid\":4001}\n"; + let records = json_records(stderr).unwrap(); + assert_eq!(records, vec![serde_json::json!({"class_uid": 4001})]); + } + + #[test] + fn json_records_rejects_escapes() { + assert!(json_records("x OCSF-JSON \x1b[1m{}\n").is_err()); + } +} diff --git a/tests/suites/features/resource-limits/Cargo.toml b/tests/suites/features/resource-limits/Cargo.toml new file mode 100644 index 0000000000..de5fc716cc --- /dev/null +++ b/tests/suites/features/resource-limits/Cargo.toml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "resource-limits" +description = "Features suite: a sandbox's CPU and memory limits are enforced by its cgroup" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +openshell-testkit = { path = "../../../testkit/testkit" } diff --git a/tests/suites/features/resource-limits/tests/limits.rs b/tests/suites/features/resource-limits/tests/limits.rs new file mode 100644 index 0000000000..6b27ea5b24 --- /dev/null +++ b/tests/suites/features/resource-limits/tests/limits.rs @@ -0,0 +1,77 @@ +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Declared sandbox CPU and memory limits are enforced by the workload's +//! cgroup, not just stored and returned by the API. +//! +//! Conformance checks that a template stores its resources. It can't check +//! enforcement: not every driver enforces limits, and those that do report it +//! in their gateway info capabilities. This test runs where the driver reports +//! both limits, and reads the cgroup v2 files from inside the sandbox. + +use testkit::{Context, Error}; + +const CGROUP_READ_POLICY: &str = "version: 1 +filesystem_policy: + include_workdir: true + read_only: [/usr, /lib, /lib64, /proc, /etc, /sys/fs/cgroup] + read_write: [/sandbox, /tmp, /dev/null] +landlock: + compatibility: best_effort +network_policies: {} +"; + +const CPU_REQUEST: &str = "500m"; +const MEMORY_REQUEST: &str = "512Mi"; +/// A 50000us quota over a 100000us CFS period, what `--cpus=0.5` gives a +/// container. +const EXPECTED_CPU_MAX: &str = "50000 100000"; +/// 512 * 1024 * 1024 bytes. +const EXPECTED_MEMORY_MAX: &str = "536870912"; + +/// A sandbox created with `--cpu 500m --memory 512Mi` reads those limits from +/// its own `cpu.max` and `memory.max`. +#[testkit::test] +async fn declared_limits_are_enforced_by_the_sandbox_cgroup(cx: &mut Context) -> testkit::Result { + let info = cx.gateway_info().await?; + let resources = info + .compute_drivers + .first() + .and_then(|driver| driver.capabilities.as_ref()) + .and_then(|capabilities| capabilities.resource_capabilities.as_ref()) + .ok_or_else(|| Error::msg("the gateway reports no compute driver resource capabilities"))?; + let cpu = resources + .cpu + .as_ref() + .is_some_and(|cpu| cpu.limit_supported); + let memory = resources + .memory + .as_ref() + .is_some_and(|memory| memory.limit_supported); + testkit::ensure!( + cpu && memory, + "this suite needs a driver that enforces CPU and memory limits; the gateway reports cpu={cpu}, memory={memory}" + ); + + let sandbox = cx + .cli_sandbox("rl") + .args(["--cpu", CPU_REQUEST, "--memory", MEMORY_REQUEST]) + .policy_yaml(CGROUP_READ_POLICY) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + + for (file, expected, request) in [ + ("memory.max", EXPECTED_MEMORY_MAX, MEMORY_REQUEST), + ("cpu.max", EXPECTED_CPU_MAX, CPU_REQUEST), + ] { + let path = format!("/sys/fs/cgroup/{file}"); + let output = sandbox.exec(["cat", path.as_str()]).await?.success()?; + let value = output.stdout.trim(); + testkit::ensure!( + value == expected, + "{path} reads {value:?}; expected {expected:?} for the declared {request} limit" + ); + } + Ok(()) +} diff --git a/tests/suites/features/routable-host-ip/Cargo.toml b/tests/suites/features/routable-host-ip/Cargo.toml new file mode 100644 index 0000000000..0645be32e8 --- /dev/null +++ b/tests/suites/features/routable-host-ip/Cargo.toml @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "routable-host-ip" +description = "Features suite: sandboxes reach the test host by an IP literal policy endpoint" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +host-server-support = { path = "../../../support/host-server" } +openshell-testkit = { path = "../../../testkit/testkit" } +serde_json = "1" diff --git a/tests/suites/features/routable-host-ip/tests/routable_host_ip.rs b/tests/suites/features/routable-host-ip/tests/routable_host_ip.rs new file mode 100644 index 0000000000..be414b0f0a --- /dev/null +++ b/tests/suites/features/routable-host-ip/tests/routable_host_ip.rs @@ -0,0 +1,96 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! A policy endpoint whose host is an IP literal reaches that address +//! transparently, whether `allowed_ips` names it or not. +//! +//! The servers run on the test host, and the sandbox reaches them by the +//! address `host.openshell.internal` resolves to. Not conformance, because +//! that address must be one the supervisor lets an IP literal reach: rootless +//! Podman's is link-local, which is always blocked. +//! +//! Ported from the `proxy_egress_pipeline` e2e test of IP literals, which +//! used two support containers on the e2e network instead. + +use host_server_support::HttpRecorder; +use serde_json::Value; +use testkit::policy; +use testkit::{Context, PYTHON_BINARIES, ResultExt as _}; + +/// Sends two GET requests to `argv[1]:argv[2]` and prints their statuses as +/// one JSON line. +const STATUS_CLIENT: &str = include_str!("../../../conformance/src/scripts/status_client.py"); + +const RESOLVE: &str = "import socket; print(socket.gethostbyname('host.openshell.internal'))"; + +/// Requests reach a server by an IP literal endpoint with `allowed_ips` for +/// that address, and another by an IP literal endpoint without it. +#[testkit::test] +async fn ip_literal_endpoints_reach_the_host(cx: &mut Context) -> testkit::Result { + let explicit = HttpRecorder::start("explicit").await?; + let implicit = HttpRecorder::start("implicit").await?; + let sandbox = cx + .sandbox("hstip") + .policy(policy::base()) + .image(testkit::python_image()) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + let ip = sandbox + .exec(["python3", "-c", RESOLVE]) + .await? + .success() + .context("resolve host.openshell.internal in the sandbox")? + .stdout + .trim() + .to_string(); + + let mut ip_policy = policy::base(); + policy::allow( + &mut ip_policy, + "explicit", + &ip, + explicit.port, + PYTHON_BINARIES, + ) + .allowed_ips = vec![format!("{ip}/32")]; + policy::allow( + &mut ip_policy, + "implicit", + &ip, + implicit.port, + PYTHON_BINARIES, + ); + policy::set(&sandbox, &ip_policy).await?; + + for (mode, server) in [("explicit allowed_ips", &explicit), ("implicit", &implicit)] { + let output = sandbox + .exec([ + "python3", + "-c", + STATUS_CLIENT, + &ip, + &server.port.to_string(), + ]) + .await? + .success() + .context(format!("run the {mode} client"))?; + let result: Value = output + .stdout + .lines() + .rev() + .find_map(|line| serde_json::from_str(line.trim()).ok()) + .ok_or_else(|| { + testkit::Error::msg(format!( + "no JSON result from the {mode} client:\n{}\n{}", + output.stdout, output.stderr + )) + })?; + testkit::ensure!( + result["first"] == 200 && result["second"] == 200, + "{mode} requests to {ip}:{} failed: {result}", + server.port + ); + } + Ok(()) +} diff --git a/tests/support/Cargo.lock b/tests/support/Cargo.lock index a27343f10e..187d80266e 100644 --- a/tests/support/Cargo.lock +++ b/tests/support/Cargo.lock @@ -1204,6 +1204,7 @@ name = "host-server-support" version = "0.0.0" dependencies = [ "openshell-testkit", + "serde_json", "tokio", "tungstenite", ] @@ -2279,6 +2280,7 @@ dependencies = [ "openshell-policy", "openshell-sdk", "openshell-testkit-macros", + "prost-types", "quick-junit", "rand 0.9.4", "serde", diff --git a/tests/support/container-engine/Cargo.toml b/tests/support/container-engine/Cargo.toml index 739e0986ca..30207dd07a 100644 --- a/tests/support/container-engine/Cargo.toml +++ b/tests/support/container-engine/Cargo.toml @@ -14,4 +14,4 @@ publish = false [dependencies] openshell-testkit = { path = "../../testkit/testkit" } tempfile = "3" -tokio = { version = "1.43", features = ["process"] } +tokio = { version = "1.43", features = ["process", "time"] } diff --git a/tests/support/container-engine/src/lib.rs b/tests/support/container-engine/src/lib.rs index 7d47f2d33f..e66d10ed8e 100644 --- a/tests/support/container-engine/src/lib.rs +++ b/tests/support/container-engine/src/lib.rs @@ -19,6 +19,7 @@ //! it. A missing variable fails the test; it never skips it. use std::path::Path; +use std::time::{Duration, Instant}; use testkit::{Context, Error, Result, ResultExt as _}; use tokio::process::Command; @@ -26,6 +27,8 @@ use tokio::process::Command; pub const ENGINE_ENV: &str = "OPENSHELL_TEST_CONTAINER_ENGINE"; /// The label the Docker and Podman drivers put on a sandbox's containers. pub const SANDBOX_NAME_LABEL: &str = "openshell.ai/sandbox-name"; +/// The label with the ID of the sandbox a container belongs to. +pub const SANDBOX_ID_LABEL: &str = "openshell.ai/sandbox-id"; /// The label that tells a sandbox's workload (`sandbox`) and `supervisor` /// containers apart. pub const ISOLATION_ROLE_LABEL: &str = "openshell.ai/isolation-role"; @@ -146,9 +149,110 @@ impl Engine { .await } + /// The IDs of every container, running or not, that the driver labeled + /// with sandbox ID `sandbox_id`. Sandbox IDs are unique, so this finds + /// only the containers of the sandbox the test created. + pub async fn containers_for_sandbox_id(&self, sandbox_id: &str) -> Result> { + let ids = self + .output([ + "ps", + "--all", + "--quiet", + "--filter", + &format!("label={SANDBOX_ID_LABEL}={sandbox_id}"), + ]) + .await?; + Ok(ids.split_whitespace().map(str::to_string).collect()) + } + + /// Whether container `id` is running. + pub async fn is_running(&self, id: &str) -> Result { + match self + .inspect_container(id, "{{.State.Running}}") + .await? + .as_str() + { + "true" => Ok(true), + "false" => Ok(false), + other => Err(Error::msg(format!( + "container {id} has running state {other:?}; expected true or false" + ))), + } + } + + /// Wait until container `id` is running (`running`) or stopped. + pub async fn wait_running(&self, id: &str, running: bool, timeout: Duration) -> Result { + let deadline = Instant::now() + timeout; + loop { + let last = match self.is_running(id).await { + Ok(now) if now == running => return Ok(()), + Ok(now) => format!("running={now}"), + Err(err) => err.to_string(), + }; + testkit::ensure!( + Instant::now() < deadline, + "container {id} did not reach running={running} within {timeout:?}; last state: {last}" + ); + tokio::time::sleep(Duration::from_millis(500)).await; + } + } + + /// Copy file `path` out of container `id` and return its contents. + pub async fn copy_from(&self, id: &str, path: &str) -> Result> { + let dir = tempfile::tempdir().context("create copy destination")?; + let destination = dir.path().join("copied"); + self.output(["cp", &format!("{id}:{path}"), utf8(&destination)?]) + .await?; + std::fs::read(&destination).context(format!("read {path} copied from container {id}")) + } + + /// The standard output and standard error container `id` has logged so + /// far, kept apart. + pub async fn logs(&self, id: &str) -> Result { + let output = self.run(["logs", id]).await?; + Ok(ContainerLogs { + stdout: String::from_utf8_lossy(&output.stdout).into_owned(), + stderr: String::from_utf8_lossy(&output.stderr).into_owned(), + }) + } + + /// Create volume `openshell-test--` with `labels` and + /// remove it when the test ends. Sandboxes created after it that mount it + /// are deleted first, because cleanup runs last registered first. + pub async fn create_test_volume( + &self, + cx: &Context, + name: &str, + labels: &[(&str, &str)], + ) -> Result { + let volume = format!("openshell-test-{name}-{}", cx.run_id()); + let mut args = vec!["volume".to_string(), "create".to_string()]; + for (key, value) in labels { + args.extend(["--label".to_string(), format!("{key}={value}")]); + } + args.push(volume.clone()); + self.output(args).await?; + let (engine, created) = (self.clone(), volume.clone()); + cx.on_cleanup(format!("remove volume {volume}"), async move || { + engine.output(["volume", "rm", &created]).await.map(drop) + }); + Ok(volume) + } + /// Run the engine with `args` and return its trimmed standard output. /// A non-zero exit is an error that includes the engine's output. pub async fn output(&self, args: I) -> Result + where + I: IntoIterator, + S: AsRef, + { + let output = self.run(args).await?; + Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) + } + + /// Run the engine with `args`. A non-zero exit is an error that includes + /// the engine's output. + async fn run(&self, args: I) -> Result where I: IntoIterator, S: AsRef, @@ -178,10 +282,17 @@ impl Engine { String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr) ); - Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) + Ok(output) } } +/// What a container logged, by stream. +#[derive(Clone, Debug, Default)] +pub struct ContainerLogs { + pub stdout: String, + pub stderr: String, +} + fn utf8(path: &Path) -> Result<&str> { path.to_str() .ok_or_else(|| Error::msg(format!("{} is not UTF-8", path.display()))) diff --git a/tests/support/host-server/Cargo.toml b/tests/support/host-server/Cargo.toml index e7db63f53d..cf51fd6a4c 100644 --- a/tests/support/host-server/Cargo.toml +++ b/tests/support/host-server/Cargo.toml @@ -13,6 +13,7 @@ publish = false [dependencies] openshell-testkit = { path = "../../testkit/testkit" } +serde_json = "1" tokio = { version = "1.43", features = ["io-util", "net", "rt", "time"] } tungstenite = "0.26" diff --git a/tests/support/host-server/src/http.rs b/tests/support/host-server/src/http.rs index 4d8ff8c812..5aec7932ff 100644 --- a/tests/support/host-server/src/http.rs +++ b/tests/support/host-server/src/http.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +use std::fmt::Write as _; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, PoisonError}; use testkit::{Poll, Result}; @@ -10,7 +12,7 @@ use tokio::task::JoinHandle; use crate::{MAX_REQUEST, READ_TIMEOUT, WAIT_INTERVAL, WAIT_TIMEOUT, bind, find, header}; -/// A request an [`HttpRecorder`] read. +/// A request an [`HttpRecorder`] read. A chunked body arrives decoded. #[derive(Clone, Debug)] pub struct Request { /// The request line and headers. @@ -18,26 +20,166 @@ pub struct Request { pub body: String, } -/// An HTTP server that answers every request with `200` and a fixed body, -/// and records each request it read. It reads a body by `Content-Length` -/// only, not a chunked one. +impl Request { + pub fn method(&self) -> &str { + self.request_line().0 + } + + /// The request target, such as `/path?query`. + pub fn path(&self) -> &str { + self.request_line().1 + } + + /// The value of the first header named `name`, in any case. + pub fn header(&self, name: &str) -> Option { + header(&self.head, name) + } + + fn request_line(&self) -> (&str, &str) { + let line = self.head.lines().next().unwrap_or_default(); + let mut parts = line.split(' '); + ( + parts.next().unwrap_or_default(), + parts.next().unwrap_or_default(), + ) + } +} + +/// A response an [`HttpRecorder`] handler returns. The server adds +/// `Content-Length`, except to an informational response, and `Connection`, +/// unless the handler set one. +#[derive(Clone, Debug)] +pub struct Response { + status: u16, + headers: Vec<(String, String)>, + body: Vec, + keep_alive: bool, +} + +impl Response { + /// A response with `status` and no body, that closes the connection. + pub fn new(status: u16) -> Self { + Self { + status, + headers: Vec::new(), + body: Vec::new(), + keep_alive: false, + } + } + + /// A `200` response with a `text/plain` body. + pub fn text(body: impl Into) -> Self { + Self::new(200) + .header("Content-Type", "text/plain") + .body(body.into()) + } + + /// A `200` response with an `application/json` body. + pub fn json(body: &serde_json::Value) -> Self { + Self::new(200) + .header("Content-Type", "application/json") + .body(body.to_string()) + } + + #[must_use] + pub fn status(mut self, status: u16) -> Self { + self.status = status; + self + } + + #[must_use] + pub fn header(mut self, name: impl Into, value: impl Into) -> Self { + self.headers.push((name.into(), value.into())); + self + } + + #[must_use] + pub fn body(mut self, body: impl Into>) -> Self { + self.body = body.into(); + self + } + + /// Keep the connection open for another request, unless the request + /// asked to close it. + #[must_use] + pub fn keep_alive(mut self) -> Self { + self.keep_alive = true; + self + } + + fn encode(&self, close: bool) -> Vec { + let mut head = format!("HTTP/1.1 {} {}\r\n", self.status, reason(self.status)); + for (name, value) in &self.headers { + let _ = write!(head, "{name}: {value}\r\n"); + } + if self.status >= 200 { + let _ = write!(head, "Content-Length: {}\r\n", self.body.len()); + } + if !self + .headers + .iter() + .any(|(name, _)| name.eq_ignore_ascii_case("connection")) + { + let connection = if close { "close" } else { "keep-alive" }; + let _ = write!(head, "Connection: {connection}\r\n"); + } + head.push_str("\r\n"); + let mut bytes = head.into_bytes(); + bytes.extend_from_slice(&self.body); + bytes + } +} + +fn reason(status: u16) -> &'static str { + match status { + 101 => "Switching Protocols", + 200 => "OK", + 202 => "Accepted", + 204 => "No Content", + 400 => "Bad Request", + 403 => "Forbidden", + 404 => "Not Found", + 405 => "Method Not Allowed", + 418 => "I'm a teapot", + _ => "Status", + } +} + +type Handler = dyn Fn(&Request) -> Response + Send + Sync; + +/// An HTTP server that records each request it read and answers it with a +/// handler's response. A connection stays open for another request while +/// the responses keep it alive and the requests don't close it. pub struct HttpRecorder { pub port: u16, requests: Arc>>, + connections: Arc, task: JoinHandle<()>, } impl HttpRecorder { + /// Answer every request with `200` and `body`. pub async fn start(body: impl Into) -> Result { + let body = body.into(); + Self::serve(move |_| Response::text(body.clone())).await + } + + /// Answer every request with `handler`'s response. + pub async fn serve( + handler: impl Fn(&Request) -> Response + Send + Sync + 'static, + ) -> Result { let (listener, port) = bind().await?; - let body: Arc = body.into().into(); + let handler: Arc = Arc::new(handler); let requests = Arc::new(Mutex::new(Vec::new())); + let connections = Arc::new(AtomicUsize::new(0)); let task_requests = Arc::clone(&requests); + let task_connections = Arc::clone(&connections); let task = tokio::spawn(async move { while let Ok((stream, _)) = listener.accept().await { + task_connections.fetch_add(1, Ordering::AcqRel); tokio::spawn(respond( stream, - Arc::clone(&body), + Arc::clone(&handler), Arc::clone(&task_requests), )); } @@ -45,10 +187,24 @@ impl HttpRecorder { Ok(Self { port, requests, + connections, task, }) } + /// The requests the server has read so far. + pub fn requests(&self) -> Vec { + self.requests + .lock() + .unwrap_or_else(PoisonError::into_inner) + .clone() + } + + /// The number of connections the server has accepted. + pub fn connections(&self) -> usize { + self.connections.load(Ordering::Acquire) + } + /// The requests the server has read, once there are at least `count`. pub async fn wait_for_requests(&self, count: usize) -> Result> { testkit::poll_until( @@ -59,11 +215,7 @@ impl HttpRecorder { WAIT_TIMEOUT, WAIT_INTERVAL, async || { - let requests = self - .requests - .lock() - .unwrap_or_else(PoisonError::into_inner) - .clone(); + let requests = self.requests(); Ok(if requests.len() >= count { Poll::Ready(requests) } else { @@ -81,45 +233,204 @@ impl Drop for HttpRecorder { } } -/// Read one request, headers and `Content-Length` body, record it, and -/// answer with `body`. -async fn respond(mut stream: TcpStream, body: Arc, requests: Arc>>) { +/// Read requests, record each, and answer with `handler` until a response +/// or request closes the connection. +async fn respond(mut stream: TcpStream, handler: Arc, requests: Arc>>) { let _ = stream.set_nodelay(true); - let Some(request) = read_request(&mut stream).await else { - return; - }; - requests - .lock() - .unwrap_or_else(PoisonError::into_inner) - .push(request); - let response = format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", - body.len() - ); - let _ = stream.write_all(response.as_bytes()).await; + let mut buffer = Vec::new(); + while let Some(request) = read_request(&mut stream, &mut buffer).await { + let response = handler(&request); + let close = !response.keep_alive + || request + .header("connection") + .is_some_and(|value| value.eq_ignore_ascii_case("close")); + requests + .lock() + .unwrap_or_else(PoisonError::into_inner) + .push(request); + if stream.write_all(&response.encode(close)).await.is_err() || close { + break; + } + } let _ = stream.shutdown().await; } -pub(crate) async fn read_request(stream: &mut TcpStream) -> Option { - let mut request = Vec::new(); - let mut buffer = [0_u8; 4096]; +/// Read one request from `stream`, starting with the bytes already in +/// `buffer`, and leave any bytes after it in `buffer`. +pub(crate) async fn read_request(stream: &mut TcpStream, buffer: &mut Vec) -> Option { + let mut chunk = [0_u8; 4096]; loop { - if let Some(end) = find(&request, b"\r\n\r\n") { - let head = String::from_utf8_lossy(&request[..end]).into_owned(); - let length = header(&head, "content-length") - .and_then(|value| value.parse::().ok()) - .unwrap_or(0); - if request.len() >= end + 4 + length { - let body = - String::from_utf8_lossy(&request[end + 4..end + 4 + length]).into_owned(); - return Some(Request { head, body }); - } + if let Some((request, length)) = parse_request(buffer) { + buffer.drain(..length); + return Some(request); } - match tokio::time::timeout(READ_TIMEOUT, stream.read(&mut buffer)).await { - Ok(Ok(read)) if read > 0 && request.len() < MAX_REQUEST => { - request.extend_from_slice(&buffer[..read]); + match tokio::time::timeout(READ_TIMEOUT, stream.read(&mut chunk)).await { + Ok(Ok(read)) if read > 0 && buffer.len() < MAX_REQUEST => { + buffer.extend_from_slice(&chunk[..read]); } _ => return None, } } } + +/// A complete request at the start of `bytes`, and its length. +fn parse_request(bytes: &[u8]) -> Option<(Request, usize)> { + let end = find(bytes, b"\r\n\r\n")?; + let head = String::from_utf8_lossy(&bytes[..end]).into_owned(); + let rest = &bytes[end + 4..]; + let chunked = header(&head, "transfer-encoding") + .is_some_and(|value| value.to_ascii_lowercase().contains("chunked")); + let (body, length) = if chunked { + decode_chunked(rest)? + } else { + let length = header(&head, "content-length") + .and_then(|value| value.parse::().ok()) + .unwrap_or(0); + (rest.get(..length)?.to_vec(), length) + }; + let body = String::from_utf8_lossy(&body).into_owned(); + Some((Request { head, body }, end + 4 + length)) +} + +/// A complete chunked body at the start of `bytes`, decoded, and its encoded +/// length. +fn decode_chunked(bytes: &[u8]) -> Option<(Vec, usize)> { + let mut body = Vec::new(); + let mut position = 0; + loop { + let line_end = position + find(&bytes[position..], b"\r\n")?; + let size = std::str::from_utf8(&bytes[position..line_end]).ok()?; + let size = size.split(';').next().unwrap_or_default().trim(); + let size = usize::from_str_radix(size, 16).ok()?; + position = line_end + 2; + if size == 0 { + // Skip trailers up to the blank line that ends the body. + loop { + let line_end = position + find(&bytes[position..], b"\r\n")?; + let blank = line_end == position; + position = line_end + 2; + if blank { + return Some((body, position)); + } + } + } + body.extend_from_slice(bytes.get(position..position + size)?); + position += size; + if bytes.get(position..position + 2)? != b"\r\n" { + return None; + } + position += 2; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + async fn connect(port: u16) -> TcpStream { + #[allow( + clippy::disallowed_methods, + reason = "standalone test support has no openshell-core dependency and enables TCP_NODELAY below" + )] + let stream = TcpStream::connect(("127.0.0.1", port)).await.unwrap(); + stream.set_nodelay(true).unwrap(); + stream + } + + async fn read_to_end(stream: &mut TcpStream) -> String { + let mut response = Vec::new(); + stream.read_to_end(&mut response).await.unwrap(); + String::from_utf8_lossy(&response).into_owned() + } + + #[test] + fn parse_request_decodes_a_chunked_body_and_leaves_the_next_request() { + let bytes = b"POST /a HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n\ + 3;ext=1\r\nabc\r\nA\r\n0123456789\r\n0\r\nTrailer: x\r\n\r\nGET /b"; + let (request, length) = parse_request(bytes).unwrap(); + assert_eq!(request.method(), "POST"); + assert_eq!(request.path(), "/a"); + assert_eq!(request.body, "abc0123456789"); + assert_eq!(&bytes[length..], b"GET /b"); + } + + #[test] + fn parse_request_waits_for_the_whole_body() { + assert!(parse_request(b"POST / HTTP/1.1\r\nContent-Length: 4\r\n\r\nabc").is_none()); + assert!( + parse_request(b"POST / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n3\r\nabc\r\n") + .is_none() + ); + let (request, _) = + parse_request(b"POST / HTTP/1.1\r\ncontent-length: 4\r\n\r\nabcd").unwrap(); + assert_eq!(request.body, "abcd"); + assert_eq!(request.header("Content-Length").as_deref(), Some("4")); + } + + #[test] + fn response_encodes_length_and_connection_unless_set() { + let encoded = String::from_utf8(Response::text("ok").encode(true)).unwrap(); + assert_eq!( + encoded, + "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok" + ); + let upgrade = Response::new(101) + .header("Connection", "Upgrade") + .header("Upgrade", "websocket") + .encode(true); + assert_eq!( + String::from_utf8(upgrade).unwrap(), + "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n\r\n" + ); + } + + #[tokio::test] + async fn http_recorder_keeps_a_connection_alive_until_the_request_closes_it() { + let recorder = + HttpRecorder::serve(|request| Response::text(request.path().to_string()).keep_alive()) + .await + .unwrap(); + let mut stream = connect(recorder.port).await; + stream + .write_all( + b"GET /one HTTP/1.1\r\nHost: test\r\n\r\n\ + GET /two HTTP/1.1\r\nHost: test\r\nConnection: close\r\n\r\n", + ) + .await + .unwrap(); + let response = read_to_end(&mut stream).await; + assert!( + response.contains("Connection: keep-alive\r\n\r\n/one"), + "{response}" + ); + assert!( + response.ends_with("Connection: close\r\n\r\n/two"), + "{response}" + ); + let paths: Vec<_> = recorder + .wait_for_requests(2) + .await + .unwrap() + .iter() + .map(|request| request.path().to_string()) + .collect(); + assert_eq!(paths, ["/one", "/two"]); + assert_eq!(recorder.connections(), 1); + } + + #[tokio::test] + async fn http_recorder_closes_after_a_response_that_is_not_kept_alive() { + let recorder = HttpRecorder::start("body").await.unwrap(); + let mut stream = connect(recorder.port).await; + stream + .write_all(b"GET / HTTP/1.1\r\nHost: test\r\n\r\nGET /ignored HTTP/1.1\r\n\r\n") + .await + .unwrap(); + let response = read_to_end(&mut stream).await; + assert!( + response.ends_with("Connection: close\r\n\r\nbody"), + "{response}" + ); + assert_eq!(recorder.requests().len(), 1); + } +} diff --git a/tests/support/host-server/src/lib.rs b/tests/support/host-server/src/lib.rs index f10a0e0632..e9781bf502 100644 --- a/tests/support/host-server/src/lib.rs +++ b/tests/support/host-server/src/lib.rs @@ -9,8 +9,18 @@ //! `host.openshell.internal` to different ones, and stop when dropped. They //! run where the tests run, so a gateway whose sandboxes can't reach the test //! host, such as one on a remote cluster, can't run tests that use them. +//! +//! - [`HttpRecorder`] answers HTTP requests with a fixed body or a handler's +//! [`Response`], and records each parsed [`Request`]. +//! - [`WebSocketRecorder`] completes the WebSocket handshake and records the +//! frames that arrive. +//! - [`TcpServer`] records raw bytes, and echoes them or answers once the +//! client goes idle. +//! - [`free_port`] finds a port nothing listens on, and [`exchange`] sends +//! bytes to a loopback port and reads the reply. mod http; +mod tcp; mod websocket; use std::time::Duration; @@ -18,8 +28,9 @@ use std::time::Duration; use testkit::{Result, ResultExt as _}; use tokio::net::TcpListener; -pub use http::{HttpRecorder, Request}; -pub use websocket::WebSocketRecorder; +pub use http::{HttpRecorder, Request, Response}; +pub use tcp::{TcpServer, exchange}; +pub use websocket::{TEXT_REPLY, WebSocketRecorder}; /// The name a sandbox reaches these servers by. pub const TEST_HOST: &str = "host.openshell.internal"; @@ -40,6 +51,12 @@ async fn bind() -> Result<(TcpListener, u16)> { Ok((listener, port)) } +/// A port that nothing on the test host listened on when this returned. +pub async fn free_port() -> Result { + let (_listener, port) = bind().await?; + Ok(port) +} + fn find(haystack: &[u8], needle: &[u8]) -> Option { haystack .windows(needle.len()) diff --git a/tests/support/host-server/src/tcp.rs b/tests/support/host-server/src/tcp.rs new file mode 100644 index 0000000000..1b6d566895 --- /dev/null +++ b/tests/support/host-server/src/tcp.rs @@ -0,0 +1,210 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::{Arc, Mutex, PoisonError}; +use std::time::Duration; + +use testkit::{Poll, Result, ResultExt as _}; +use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; +use tokio::net::TcpStream; +use tokio::task::JoinHandle; + +use crate::{MAX_REQUEST, READ_TIMEOUT, WAIT_INTERVAL, WAIT_TIMEOUT, bind, find}; + +/// How long a [`TcpServer::reply_when_idle`] connection waits for more bytes +/// before it answers. +const IDLE: Duration = Duration::from_millis(200); + +/// A TCP server that records the bytes every connection sent, in arrival +/// order, for a test that checks raw bytes rather than parsed requests. +pub struct TcpServer { + pub port: u16, + received: Arc>>, + connections: Arc, + task: JoinHandle<()>, +} + +#[derive(Clone)] +enum Mode { + Echo, + ReplyWhenIdle(Arc<[u8]>), +} + +impl TcpServer { + /// Write back every byte a connection sends until it closes. + pub async fn echo() -> Result { + Self::start(Mode::Echo).await + } + + /// Read until a connection is idle for 200 ms or closes, then write + /// `reply` and close it. A test can send several requests at once and + /// see all of them, since the server answers none before the last. + pub async fn reply_when_idle(reply: impl Into>) -> Result { + Self::start(Mode::ReplyWhenIdle(reply.into().into())).await + } + + async fn start(mode: Mode) -> Result { + let (listener, port) = bind().await?; + let received = Arc::new(Mutex::new(Vec::new())); + let connections = Arc::new(AtomicUsize::new(0)); + let task_received = Arc::clone(&received); + let task_connections = Arc::clone(&connections); + let task = tokio::spawn(async move { + while let Ok((stream, _)) = listener.accept().await { + task_connections.fetch_add(1, Ordering::AcqRel); + tokio::spawn(serve(stream, mode.clone(), Arc::clone(&task_received))); + } + }); + Ok(Self { + port, + received, + connections, + task, + }) + } + + /// The bytes the server has read so far. + pub fn received(&self) -> Vec { + self.received + .lock() + .unwrap_or_else(PoisonError::into_inner) + .clone() + } + + /// The number of connections the server has accepted. + pub fn connections(&self) -> usize { + self.connections.load(Ordering::Acquire) + } + + /// The bytes the server has read, once they contain `needle`. + pub async fn wait_for(&self, needle: &[u8]) -> Result> { + testkit::poll_until( + &format!( + "{:?} at the host server on port {}", + String::from_utf8_lossy(needle), + self.port + ), + WAIT_TIMEOUT, + WAIT_INTERVAL, + async || { + let received = self.received(); + Ok(if find(&received, needle).is_some() { + Poll::Ready(received) + } else { + Poll::Pending(format!("{} byte(s)", received.len())) + }) + }, + ) + .await + } +} + +/// Connect to `port` on the test host's loopback, send `request`, and return +/// what arrives until the other end closes. For a port the test reaches from +/// the host, such as one `openshell forward` listens on. +pub async fn exchange(port: u16, request: &[u8]) -> Result> { + #[allow( + clippy::disallowed_methods, + reason = "standalone test support has no openshell-core dependency and enables TCP_NODELAY below" + )] + let mut stream = TcpStream::connect(("127.0.0.1", port)) + .await + .context(format!("connect to 127.0.0.1:{port}"))?; + stream.set_nodelay(true).context("enable TCP_NODELAY")?; + stream + .write_all(request) + .await + .context(format!("send to 127.0.0.1:{port}"))?; + let mut reply = Vec::new(); + tokio::time::timeout(READ_TIMEOUT, stream.read_to_end(&mut reply)) + .await + .map_err(|_| { + testkit::Error::msg(format!( + "127.0.0.1:{port} didn't close within {READ_TIMEOUT:?}; read {} byte(s)", + reply.len() + )) + })? + .context(format!("read from 127.0.0.1:{port}"))?; + Ok(reply) +} + +impl Drop for TcpServer { + fn drop(&mut self) { + self.task.abort(); + } +} + +async fn serve(mut stream: TcpStream, mode: Mode, received: Arc>>) { + let _ = stream.set_nodelay(true); + let idle = match mode { + Mode::Echo => READ_TIMEOUT, + Mode::ReplyWhenIdle(_) => IDLE, + }; + let mut buffer = [0_u8; 4096]; + let mut total = 0; + loop { + let read = match tokio::time::timeout(idle, stream.read(&mut buffer)).await { + Ok(Ok(read)) if read > 0 && total < MAX_REQUEST => read, + _ => break, + }; + total += read; + received + .lock() + .unwrap_or_else(PoisonError::into_inner) + .extend_from_slice(&buffer[..read]); + if matches!(mode, Mode::Echo) && stream.write_all(&buffer[..read]).await.is_err() { + return; + } + } + if let Mode::ReplyWhenIdle(reply) = mode { + let _ = stream.write_all(&reply).await; + } + let _ = stream.shutdown().await; +} + +#[cfg(test)] +mod tests { + use super::*; + + async fn connect(port: u16) -> TcpStream { + #[allow( + clippy::disallowed_methods, + reason = "standalone test support has no openshell-core dependency and enables TCP_NODELAY below" + )] + let stream = TcpStream::connect(("127.0.0.1", port)).await.unwrap(); + stream.set_nodelay(true).unwrap(); + stream + } + + #[tokio::test] + async fn echo_writes_back_and_records_bytes() { + let server = TcpServer::echo().await.unwrap(); + let mut stream = connect(server.port).await; + stream.write_all(&[0x00, 0xff, b'x']).await.unwrap(); + let mut echoed = [0_u8; 3]; + stream.read_exact(&mut echoed).await.unwrap(); + assert_eq!(echoed, [0x00, 0xff, b'x']); + assert_eq!(server.wait_for(b"x").await.unwrap(), [0x00, 0xff, b'x']); + assert_eq!(server.connections(), 1); + } + + #[tokio::test] + async fn reply_when_idle_records_everything_before_replying() { + let server = TcpServer::reply_when_idle(b"reply".to_vec()).await.unwrap(); + let mut stream = connect(server.port).await; + stream.write_all(b"first ").await.unwrap(); + stream.write_all(b"second").await.unwrap(); + let mut reply = Vec::new(); + stream.read_to_end(&mut reply).await.unwrap(); + assert_eq!(reply, b"reply"); + assert_eq!(server.received(), b"first second"); + } + + #[tokio::test] + async fn exchange_returns_the_reply_until_close() { + let server = TcpServer::reply_when_idle(b"reply".to_vec()).await.unwrap(); + assert_eq!(exchange(server.port, b"hello").await.unwrap(), b"reply"); + assert_eq!(server.received(), b"hello"); + } +} diff --git a/tests/support/host-server/src/websocket.rs b/tests/support/host-server/src/websocket.rs index 264dd4b5d3..4f38bdb8f3 100644 --- a/tests/support/host-server/src/websocket.rs +++ b/tests/support/host-server/src/websocket.rs @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex, PoisonError}; use testkit::{Poll, Result}; use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; @@ -10,21 +10,26 @@ use tokio::net::TcpStream; use tokio::task::JoinHandle; use crate::http::read_request; -use crate::{READ_TIMEOUT, WAIT_INTERVAL, WAIT_TIMEOUT, bind, header}; +use crate::{MAX_REQUEST, READ_TIMEOUT, WAIT_INTERVAL, WAIT_TIMEOUT, bind, header}; /// A WebSocket server that completes the handshake, then reads frames until -/// the connection closes, and records whether any was a binary frame. +/// the connection closes. It records whether any was a binary frame, records +/// each text frame, and answers each text frame with [`TEXT_REPLY`]. pub struct WebSocketRecorder { pub port: u16, state: Arc, task: JoinHandle<()>, } +/// The text frame a [`WebSocketRecorder`] sends after each text frame. +pub const TEXT_REPLY: &str = "received"; + #[derive(Default)] struct WebSocketState { handshake_seen: AtomicBool, binary_seen: AtomicBool, finished: AtomicBool, + texts: Mutex>, } impl WebSocketRecorder { @@ -81,6 +86,15 @@ impl WebSocketRecorder { ) .await } + + /// The text frames the server has read so far. + pub fn texts(&self) -> Vec { + self.state + .texts + .lock() + .unwrap_or_else(PoisonError::into_inner) + .clone() + } } impl Drop for WebSocketRecorder { @@ -91,7 +105,7 @@ impl Drop for WebSocketRecorder { async fn accept_websocket(mut stream: TcpStream, state: Arc) { let _ = stream.set_nodelay(true); - let Some(request) = read_request(&mut stream).await else { + let Some(request) = read_request(&mut stream, &mut Vec::new()).await else { return; }; let Some(key) = header(&request.head, "sec-websocket-key") else { @@ -111,8 +125,8 @@ async fn accept_websocket(mut stream: TcpStream, state: Arc) { state.finished.store(true, Ordering::Release); } -/// Read frames until a close frame or the end of the stream, and record a -/// binary frame. +/// Read frames until a close frame or the end of the stream, record a +/// binary frame and each text frame, and answer each text frame. async fn read_frames(stream: &mut TcpStream, state: &WebSocketState) -> std::io::Result<()> { loop { let mut frame_header = [0_u8; 2]; @@ -123,31 +137,77 @@ async fn read_frames(stream: &mut TcpStream, state: &WebSocketState) -> std::io: 127 => stream.read_u64().await?, length => u64::from(length), }; - if opcode == 0x02 { - state.binary_seen.store(true, Ordering::Release); - } - if opcode == 0x08 { - return Ok(()); + match opcode { + 0x01 => { + let text = read_payload(stream, frame_header[1], length).await?; + state + .texts + .lock() + .unwrap_or_else(PoisonError::into_inner) + .push(String::from_utf8_lossy(&text).into_owned()); + stream.write_all(&server_text_frame(TEXT_REPLY)).await?; + continue; + } + 0x02 => state.binary_seen.store(true, Ordering::Release), + _ => {} } let mask = if frame_header[1] & 0x80 == 0 { 0 } else { 4 }; + // Read a close frame's payload too, since closing with unread bytes + // resets the connection. let skipped = tokio::io::copy( &mut (&mut *stream).take(mask + length), &mut tokio::io::sink(), ) .await?; - if skipped < mask + length { + if opcode == 0x08 || skipped < mask + length { return Ok(()); } } } +/// Read a text frame's payload, unmasked, up to [`MAX_REQUEST`] bytes. +async fn read_payload( + stream: &mut TcpStream, + second_byte: u8, + length: u64, +) -> std::io::Result> { + let length = usize::try_from(length) + .ok() + .filter(|length| *length <= MAX_REQUEST) + .ok_or_else(|| std::io::Error::other("text frame too large"))?; + let mut mask = [0_u8; 4]; + if second_byte & 0x80 != 0 { + stream.read_exact(&mut mask).await?; + } + let mut payload = vec![0_u8; length]; + stream.read_exact(&mut payload).await?; + for (index, byte) in payload.iter_mut().enumerate() { + *byte ^= mask[index % 4]; + } + Ok(payload) +} + +/// A final, unmasked server text frame. +fn server_text_frame(text: &str) -> Vec { + let mut frame = vec![0x81]; + match text.len() { + length @ 0..=125 => frame.push(u8::try_from(length).unwrap_or_default()), + length => { + frame.push(126); + frame.extend_from_slice(&u16::try_from(length).unwrap_or(u16::MAX).to_be_bytes()); + } + } + frame.extend_from_slice(text.as_bytes()); + frame +} + #[cfg(test)] mod tests { use super::*; use crate::find; /// Complete a handshake with `recorder`, send `frames`, and close. - async fn send_frames(recorder: &WebSocketRecorder, frames: &[(u8, Vec)]) { + async fn send_frames(recorder: &WebSocketRecorder, frames: &[(u8, Vec)]) -> TcpStream { #[allow( clippy::disallowed_methods, reason = "standalone test support has no openshell-core dependency and enables TCP_NODELAY below" @@ -181,6 +241,7 @@ mod tests { stream.write_all(&frame(*opcode, payload)).await.unwrap(); } stream.write_all(&frame(0x08, &[])).await.unwrap(); + stream } /// A final, masked client frame. @@ -202,22 +263,43 @@ mod tests { #[tokio::test] async fn websocket_recorder_sees_a_binary_frame_after_a_long_text_frame() { let recorder = WebSocketRecorder::start().await.unwrap(); - send_frames( + // Hold the connection so the replies to text frames don't reset it. + let _stream = send_frames( &recorder, &[(0x01, vec![b'x'; 300]), (0x02, b"binary".to_vec())], ) .await; assert!(recorder.wait_until_finished().await.unwrap()); + assert_eq!(recorder.texts(), ["x".repeat(300)]); } #[tokio::test] async fn websocket_recorder_sees_no_binary_frame_in_text_frames() { let recorder = WebSocketRecorder::start().await.unwrap(); - send_frames( + // Hold the connection so the replies to text frames don't reset it. + let _stream = send_frames( &recorder, &[(0x01, vec![b'x'; 300]), (0x01, b"text".to_vec())], ) .await; assert!(!recorder.wait_until_finished().await.unwrap()); } + + #[tokio::test] + async fn websocket_recorder_answers_each_text_frame() { + let recorder = WebSocketRecorder::start().await.unwrap(); + let mut stream = send_frames( + &recorder, + &[(0x01, b"one".to_vec()), (0x01, b"two".to_vec())], + ) + .await; + let mut replies = Vec::new(); + stream.read_to_end(&mut replies).await.unwrap(); + assert_eq!( + replies, + [server_text_frame(TEXT_REPLY), server_text_frame(TEXT_REPLY)].concat() + ); + recorder.wait_until_finished().await.unwrap(); + assert_eq!(recorder.texts(), ["one", "two"]); + } } diff --git a/tests/testkit/Cargo.lock b/tests/testkit/Cargo.lock index ccc512b2d5..77f16bea16 100644 --- a/tests/testkit/Cargo.lock +++ b/tests/testkit/Cargo.lock @@ -2252,6 +2252,7 @@ dependencies = [ "openshell-policy", "openshell-sdk", "openshell-testkit-macros", + "prost-types", "quick-junit", "rand 0.9.4", "serde", diff --git a/tests/testkit/README.md b/tests/testkit/README.md index f3f1f3c66e..12a94611b9 100644 --- a/tests/testkit/README.md +++ b/tests/testkit/README.md @@ -66,13 +66,15 @@ fails. A killed test process skips cleanup, so names are unique to the run. - `cx.sandbox(suffix)` to build a sandbox with a run-unique name (`test--`), then `create()` it or `create_ready()` to also wait for Ready. Set its image - with `image(..)`, its policy with `policy(..)` and its providers with - `providers(..)`. A long-running sandbox is - `.command(["sleep", "infinity"])`; add `.image(testkit::python_image())` - when a test runs Python clients in it. The returned + with `image(..)`, its policy with `policy(..)`, its providers with + `providers(..)`, and the template's driver-keyed `driver_config(json)`. A + long-running sandbox is `.command(["sleep", "infinity"])`; add + `.image(testkit::python_image())` when a test runs Python clients in it. The + returned `Sandbox` can wait for ready or finished, stop, start, exec or `poll_exec` until the output matches, read its config and draft policy, set - a setting, read `sandbox get` JSON with `get_json()`, read its policy + a setting, read `sandbox get` JSON with `get_json()`, read its supervisor + logs with `logs()` or wait for a line with `logs_until(..)`, read its policy revisions and active policy with `policy_revisions()` and `active_policy()`, and delete. Its `expect_listed`, `expect_absent` and `wait_absent` check list and get. `run_python(script, args)` runs a script @@ -91,7 +93,10 @@ fails. A killed test process skips cleanup, so names are unique to the run. create, so a create that fails after the gateway accepted it is still cleaned up. `cx.adopt(name)` returns a `Sandbox` handle for one the CLI created. - `cx.expect_compute_driver(name)` to fail unless the gateway runs only that - compute driver. Driver suites call it first. + compute driver. Driver suites call it first. `cx.compute_driver()` returns + the driver's name, for setup that depends on it, such as a driver config. + `cx.gateway_info()` returns the whole gateway info, such as the resource + capabilities the driver reports. - `testkit::base_image()` for the image to create sandboxes from or build on: `OPENSHELL_TEST_BASE_IMAGE`, or OpenShell's default sandbox image. - `testkit::python_image()` for sandboxes that run `python3`, curl, git, or @@ -119,8 +124,11 @@ fails. A killed test process skips cleanup, so names are unique to the run. (binaries apply to every endpoint under `name`) that `policy::Endpoint` configures (`.rest(Access::Full)`, `.credential_binding(provider)`, ...). Pass the result to `cx.sandbox(..).policy(policy)`, or `policy::to_yaml` - for the CLI. `policy::binaries_yaml(binaries)` writes a `binaries:` list - into policy YAML a test writes by hand. + for the CLI. `policy::base_with(yaml)` adds YAML sections, such as L7 + rules, to the base policy. `policy::from_yaml` reads a policy file, and + `policy::set(&sandbox, &policy)` replaces a running sandbox's policy and + waits until it is loaded. `policy::binaries_yaml(binaries)` writes a + `binaries:` list into policy YAML a test writes by hand. `testkit::PYTHON_BINARIES` names `python3` in `python_image()` images. - `cx.import_profile(profile)` to import a provider profile and return its `id`, and `cx.create_provider(name, type, credentials)` to create a diff --git a/tests/testkit/testkit/Cargo.toml b/tests/testkit/testkit/Cargo.toml index 7b8ebd90ab..d216c7b824 100644 --- a/tests/testkit/testkit/Cargo.toml +++ b/tests/testkit/testkit/Cargo.toml @@ -24,6 +24,7 @@ clap = { version = "4", features = ["derive"] } futures = "0.3" libtest-mimic = "0.8" linkme = "0.3" +prost-types = "0.14" quick-junit = "0.8" rand = "0.9" serde = { version = "1", features = ["derive"] } diff --git a/tests/testkit/testkit/src/context.rs b/tests/testkit/testkit/src/context.rs index a937ed069d..6ac64bff8c 100644 --- a/tests/testkit/testkit/src/context.rs +++ b/tests/testkit/testkit/src/context.rs @@ -121,6 +121,9 @@ impl Context { } /// A resource name unique to this run: `test--`. + /// + /// The gateway limits sandbox names to 19 characters, so a sandbox + /// suffix can have at most 5. pub fn name(&self, suffix: &str) -> String { format!("test-{}-{suffix}", self.run_id) } @@ -136,6 +139,7 @@ impl Context { SandboxBuilder { handles: self.handles.clone(), policy: None, + driver_config: None, spec: SandboxSpec { name: Some(self.sandbox_name(suffix)), ..SandboxSpec::default() @@ -227,7 +231,25 @@ impl Context { /// gateway info reports it. Driver suites check this first, so a suite /// pointed at another driver's gateway fails instead of testing it. pub async fn expect_compute_driver(&self, name: &str) -> Result { - let info = self + let driver = self.compute_driver().await?; + crate::ensure!( + driver == name, + "the gateway runs compute driver {driver}; expected {name}" + ); + Ok(()) + } + + /// The gateway's compute driver, such as `docker` or `kubernetes`, for + /// tests whose setup depends on it. Fails unless gateway info reports + /// exactly one driver, under the same configured and driver name. + pub async fn compute_driver(&self) -> Result { + single_compute_driver(&self.gateway_info().await?) + } + + /// The gateway's info: its version, compute drivers and their reported + /// capabilities, and negotiated extensions. + pub async fn gateway_info(&self) -> Result { + Ok(self .handles .grpc .client() @@ -235,23 +257,7 @@ impl Context { .get_gateway_info(proto::GetGatewayInfoRequest {}) .await .context("get gateway info")? - .into_inner(); - let drivers: Vec<(&str, &str)> = info - .compute_drivers - .iter() - .map(|driver| { - let reported = driver - .capabilities - .as_ref() - .map_or("", |capabilities| capabilities.driver_name.as_str()); - (driver.name.as_str(), reported) - }) - .collect(); - crate::ensure!( - matches!(drivers.as_slice(), [(configured, reported)] if *configured == name && *reported == name), - "the gateway reports compute drivers (name, driver name) {drivers:?}; expected only {name}" - ); - Ok(()) + .into_inner()) } /// Run the cleanup hooks, including deleting the sandboxes the test @@ -262,6 +268,30 @@ impl Context { } } +/// The one compute driver `info` reports, when its configured name and the +/// name the driver reports agree. +fn single_compute_driver(info: &proto::GetGatewayInfoResponse) -> Result { + let drivers: Vec<(&str, &str)> = info + .compute_drivers + .iter() + .map(|driver| { + let reported = driver + .capabilities + .as_ref() + .map_or("", |capabilities| capabilities.driver_name.as_str()); + (driver.name.as_str(), reported) + }) + .collect(); + match drivers.as_slice() { + [(configured, reported)] if configured == reported && !configured.is_empty() => { + Ok((*configured).to_string()) + } + _ => Err(Error::msg(format!( + "the gateway reports compute drivers (name, driver name) {drivers:?}; expected exactly one" + ))), + } +} + /// Register the cleanup hook that deletes sandbox `name`, unless it is /// already tracked. fn track_sandbox(cleanup: &Cleanup, client: &WorkspaceScopedClient, name: &str) { @@ -289,17 +319,19 @@ fn track_sandbox(cleanup: &Cleanup, client: &WorkspaceScopedClient, name: &str) /// The generated gRPC client, for public API the SDK does not wrap yet. #[derive(Clone)] -struct Grpc { +pub(crate) struct Grpc { client: OpenShellClient, workspace: String, } impl Grpc { - async fn client(&self) -> Result { + pub(crate) async fn client(&self) -> Result { Ok(self.client.raw_grpc_fresh().await?) } - fn scope(&self) -> Option { + pub(crate) fn scope( + &self, + ) -> Option { Some(proto::workspace_selector(&self.workspace)) } } @@ -319,6 +351,10 @@ impl Handles { &self.cli } + pub(crate) fn grpc(&self) -> &Grpc { + &self.grpc + } + pub(crate) fn track(&self, name: &str) { track_sandbox(&self.cleanup, &self.client, name); } @@ -343,6 +379,7 @@ impl Handles { pub struct SandboxBuilder { handles: Handles, policy: Option, + driver_config: Option, spec: SandboxSpec, } @@ -386,6 +423,20 @@ impl SandboxBuilder { self } + /// Set the template's `driver_config`, a JSON object keyed by driver + /// name, as `sandbox create --driver-config-json` does. The gateway + /// passes the block for its driver to the driver. + /// + /// ```ignore + /// let driver = cx.compute_driver().await?; + /// cx.sandbox("mount") + /// .driver_config(serde_json::json!({ driver: { "mounts": [] } })) + /// ``` + pub fn driver_config(mut self, config: serde_json::Value) -> Self { + self.driver_config = Some(config); + self + } + /// Full access to the spec for fields without a builder method. pub fn spec(mut self, update: impl FnOnce(&mut SandboxSpec)) -> Self { update(&mut self.spec); @@ -405,36 +456,40 @@ impl SandboxBuilder { pub async fn create(self) -> Result { let name = self.spec.name.clone().unwrap_or_default(); self.handles.track(&name); - let id = match self.policy { - None => { - self.handles - .client - .create_sandbox(self.spec) - .await - .context(format!("create sandbox {name}"))? - .id - } - // The SDK's spec has no policy field, so create through gRPC. - Some(policy) => { - crate::ensure!( - !self.spec.gpu && self.spec.service_exposures.is_empty(), - "testkit doesn't create a sandbox with a policy and a GPU or service exposures" - ); - let request = policy_create_request(self.spec, policy, self.handles.grpc.scope()); - self.handles - .grpc - .client() - .await? - .create_sandbox(request) - .await - .context(format!("create sandbox {name}"))?; - self.handles - .client - .get_sandbox(&name) - .await - .context(format!("get sandbox {name}"))? - .id - } + let id = if self.policy.is_none() && self.driver_config.is_none() { + self.handles + .client + .create_sandbox(self.spec) + .await + .context(format!("create sandbox {name}"))? + .id + } else { + // The SDK's spec has no policy or driver config, so create + // through gRPC. + crate::ensure!( + !self.spec.gpu && self.spec.service_exposures.is_empty(), + "testkit doesn't create a sandbox with a policy or driver config and a GPU or service exposures" + ); + let driver_config = self.driver_config.map(driver_config_struct).transpose()?; + let request = grpc_create_request( + self.spec, + self.policy, + driver_config, + self.handles.grpc.scope(), + ); + self.handles + .grpc + .client() + .await? + .create_sandbox(request) + .await + .context(format!("create sandbox {name}"))?; + self.handles + .client + .get_sandbox(&name) + .await + .context(format!("get sandbox {name}"))? + .id }; Ok(Sandbox { handles: self.handles, @@ -444,15 +499,28 @@ impl SandboxBuilder { } } -/// The gRPC request for a sandbox created from `spec` with `policy`, built -/// as the SDK builds one from `spec` alone. The spec is destructured without -/// `..`, so a field added to the SDK's spec fails to compile here instead of -/// being dropped. [`SandboxBuilder::create`] rejects a GPU or service -/// exposures before calling this. A policy field on the SDK's spec would -/// replace this (#5410). -fn policy_create_request( +/// `config` as the protobuf `Struct` the template carries. It must be a JSON +/// object, keyed by driver name. +fn driver_config_struct(config: serde_json::Value) -> Result { + let serde_json::Value::Object(fields) = config else { + return Err(Error::msg(format!( + "driver config must be a JSON object keyed by driver name; got {config}" + ))); + }; + openshell_core::proto_struct::json_object_to_struct(fields) + .map_err(|error| Error::msg(format!("driver config can't be represented: {error}"))) +} + +/// The gRPC request for a sandbox created from `spec` with `policy` and +/// `driver_config`, built as the SDK builds one from `spec` alone. The spec +/// is destructured without `..`, so a field added to the SDK's spec fails to +/// compile here instead of being dropped. [`SandboxBuilder::create`] rejects +/// a GPU or service exposures before calling this. Policy and driver config +/// fields on the SDK's spec would replace this (#5410). +fn grpc_create_request( spec: SandboxSpec, - policy: proto::SandboxPolicy, + policy: Option, + driver_config: Option, workspace_scope: Option, ) -> proto::CreateSandboxRequest { let SandboxSpec { @@ -473,14 +541,17 @@ fn policy_create_request( workspace_scope, spec: Some(proto::SandboxSpec { environment, - template: image.map(|image| proto::SandboxTemplate { - image, - ..proto::SandboxTemplate::default() + template: (image.is_some() || driver_config.is_some()).then(|| { + proto::SandboxTemplate { + image: image.unwrap_or_default(), + driver_config, + ..proto::SandboxTemplate::default() + } }), providers, command, tty, - policy: Some(policy), + policy, restart_policy: proto::SandboxRestartPolicy::from(restart_policy) as i32, ..proto::SandboxSpec::default() }), @@ -573,6 +644,10 @@ impl Sandbox { &self.name } + pub(crate) fn handles(&self) -> &Handles { + &self.handles + } + pub fn id(&self) -> &str { &self.id } @@ -948,12 +1023,83 @@ mod tests { }; let policy = crate::policy::base(); - let spec = policy_create_request(spec, policy.clone(), None) + let spec = grpc_create_request(spec, Some(policy.clone()), None, None) .spec .expect("spec"); - assert_eq!(spec.template.expect("template").image, "python:3"); + let template = spec.template.expect("template"); + assert_eq!(template.image, "python:3"); + assert_eq!(template.driver_config, None); assert_eq!(spec.providers, ["provider"]); assert_eq!(spec.policy, Some(policy)); } + + #[test] + fn grpc_create_request_carries_driver_config_without_an_image() { + let config = driver_config_struct(serde_json::json!({ + "docker": { "mounts": [{ "type": "volume", "source": "data" }] } + })) + .expect("an object converts"); + + let spec = grpc_create_request(SandboxSpec::default(), None, Some(config.clone()), None) + .spec + .expect("spec"); + + let template = spec.template.expect("a template for the driver config"); + assert_eq!(template.image, "", "an empty image selects the default"); + assert_eq!(template.driver_config, Some(config)); + assert_eq!(spec.policy, None); + } + + #[test] + fn grpc_create_request_omits_an_empty_template() { + let spec = grpc_create_request(SandboxSpec::default(), None, None, None) + .spec + .expect("spec"); + assert_eq!(spec.template, None); + } + + #[test] + fn driver_config_must_be_an_object() { + let error = driver_config_struct(serde_json::json!(["docker"])).expect_err("an array"); + assert!( + error.to_string().contains("keyed by driver name"), + "{error}" + ); + } + + fn gateway_info(drivers: &[(&str, &str)]) -> proto::GetGatewayInfoResponse { + proto::GetGatewayInfoResponse { + compute_drivers: drivers + .iter() + .map(|(name, reported)| proto::ComputeDriverInfo { + name: (*name).to_string(), + capabilities: Some(proto::ComputeDriverCapabilities { + driver_name: (*reported).to_string(), + ..proto::ComputeDriverCapabilities::default() + }), + }) + .collect(), + ..proto::GetGatewayInfoResponse::default() + } + } + + #[test] + fn compute_driver_is_the_single_agreeing_driver() { + assert_eq!( + single_compute_driver(&gateway_info(&[("docker", "docker")])).expect("one driver"), + "docker" + ); + for drivers in [ + &[][..], + &[("docker", "podman")][..], + &[("", "")][..], + &[("docker", "docker"), ("podman", "podman")][..], + ] { + assert!( + single_compute_driver(&gateway_info(drivers)).is_err(), + "{drivers:?} should fail" + ); + } + } } diff --git a/tests/testkit/testkit/src/lib.rs b/tests/testkit/testkit/src/lib.rs index e86b7c3b14..e24a9e6c60 100644 --- a/tests/testkit/testkit/src/lib.rs +++ b/tests/testkit/testkit/src/lib.rs @@ -34,6 +34,7 @@ mod context; mod error; pub mod gateway; mod image; +mod logs; mod output; pub mod policy; mod poll; @@ -55,6 +56,7 @@ pub use context::{ pub use error::{Error, Result, ResultExt}; pub use gateway::Gateway; pub use image::{PYTHON_BINARIES, base_image, python_image}; +pub use logs::{LOGS_TIMEOUT, Logs}; pub use openshell_sdk as sdk; pub use poll::{Poll, poll_until, with_deadline}; pub use program::main; diff --git a/tests/testkit/testkit/src/logs.rs b/tests/testkit/testkit/src/logs.rs new file mode 100644 index 0000000000..ce486fcc5b --- /dev/null +++ b/tests/testkit/testkit/src/logs.rs @@ -0,0 +1,175 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! A sandbox's supervisor logs, as `openshell logs --source sandbox` shows +//! them. + +use std::fmt; +use std::time::Duration; + +use openshell_sdk::raw::proto; + +use crate::context::Sandbox; +use crate::error::{Result, ResultExt as _}; +use crate::poll::{Poll, poll_until}; + +/// The most lines [`Sandbox::logs`] returns, as `openshell logs -n 500`. +const LINES: u32 = 500; +/// How long [`Sandbox::logs_until`] waits. The supervisor pushes its logs to +/// the gateway in batches, so a line can appear a few seconds after the event. +pub const LOGS_TIMEOUT: Duration = Duration::from_secs(10); + +/// Log lines from a sandbox's supervisor, oldest first. +#[derive(Debug, Clone, Default)] +pub struct Logs { + lines: Vec, +} + +impl Logs { + pub fn new(lines: Vec) -> Self { + Self { lines } + } + + pub fn lines(&self) -> &[proto::SandboxLogLine] { + &self.lines + } + + /// Whether a line contains `needle` in its level, target, message, or a + /// field name or value, as `openshell logs` prints the line. + pub fn contains(&self, needle: &str) -> bool { + self.lines + .iter() + .any(|line| Line(line).to_string().contains(needle)) + } +} + +/// One line per log line, as `openshell logs` prints them. +impl fmt::Display for Logs { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for line in &self.lines { + writeln!(f, "{}", Line(line))?; + } + Ok(()) + } +} + +/// `[.] [] [] [] `, +/// with fields sorted by name. +struct Line<'a>(&'a proto::SandboxLogLine); + +impl fmt::Display for Line<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let line = self.0; + let source = if line.source.is_empty() { + "gateway" + } else { + &line.source + }; + let (secs, millis) = line.event_time.as_ref().map_or((0, 0), |time| { + (time.seconds, time.nanos.clamp(0, 999_999_999) / 1_000_000) + }); + write!( + f, + "[{secs}.{millis:03}] [{source:<7}] [{:<5}] [{}] {}", + line.level, line.target, line.message + )?; + let mut fields: Vec<_> = line.fields.iter().collect(); + fields.sort_by_key(|(key, _)| key.as_str()); + for (key, value) in fields { + write!(f, " {key}={value}")?; + } + Ok(()) + } +} + +impl Sandbox { + /// The last 500 lines the sandbox's supervisor logged, as `openshell logs + /// -n 500 --source sandbox` returns them. + pub async fn logs(&self) -> Result { + let grpc = self.handles().grpc(); + let request = proto::GetSandboxLogsRequest { + sandbox: self.name().to_string(), + workspace_scope: grpc.scope(), + lines: LINES, + sources: vec!["sandbox".to_string()], + ..proto::GetSandboxLogsRequest::default() + }; + let response = grpc + .client() + .await? + .get_sandbox_logs(request) + .await + .context(format!("get logs of sandbox {}", self.name()))? + .into_inner(); + Ok(Logs::new(response.logs)) + } + + /// Read [`Sandbox::logs`] every 250 ms until `ready` accepts them, for up + /// to [`LOGS_TIMEOUT`]. A timeout reports the last logs read. + pub async fn logs_until(&self, what: &str, ready: impl Fn(&Logs) -> bool) -> Result { + poll_until( + &format!("sandbox {} to log {what}", self.name()), + LOGS_TIMEOUT, + Duration::from_millis(250), + async || { + let logs = self.logs().await?; + Ok(if ready(&logs) { + Poll::Ready(logs) + } else { + Poll::Pending(format!("logs:\n{logs}")) + }) + }, + ) + .await + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn line(message: &str, source: &str, fields: &[(&str, &str)]) -> proto::SandboxLogLine { + proto::SandboxLogLine { + event_time: Some(prost_types::Timestamp { + seconds: 1234, + nanos: 567_000_000, + }), + level: "INFO".to_string(), + target: "openshell_supervisor".to_string(), + message: message.to_string(), + source: source.to_string(), + fields: fields + .iter() + .map(|(key, value)| ((*key).to_string(), (*value).to_string())) + .collect(), + ..proto::SandboxLogLine::default() + } + } + + #[test] + fn renders_lines_like_the_cli() { + let logs = Logs::new(vec![ + line("hello world", "sandbox", &[]), + line("denied", "", &[("dst_port", "443"), ("action", "deny")]), + ]); + assert_eq!( + logs.to_string(), + "[1234.567] [sandbox] [INFO ] [openshell_supervisor] hello world\n\ + [1234.567] [gateway] [INFO ] [openshell_supervisor] denied action=deny dst_port=443\n" + ); + } + + #[test] + fn contains_searches_message_target_and_fields_per_line() { + let logs = Logs::new(vec![ + line("first", "sandbox", &[("event", "endpoint_mismatch")]), + line("second", "sandbox", &[]), + ]); + assert!(logs.contains("first")); + assert!(logs.contains("openshell_supervisor")); + assert!(logs.contains("event=endpoint_mismatch")); + assert!(logs.contains("endpoint_mismatch")); + assert!(!logs.contains("first\n"), "a needle doesn't span lines"); + assert!(!logs.contains("absent")); + } +} diff --git a/tests/testkit/testkit/src/policy.rs b/tests/testkit/testkit/src/policy.rs index c62c930528..41e7e45a4a 100644 --- a/tests/testkit/testkit/src/policy.rs +++ b/tests/testkit/testkit/src/policy.rs @@ -3,7 +3,7 @@ //! Sandbox policies for tests: [`base`], read from `base-policy.yaml`, plus //! [`allow`] and the [`Endpoint`] settings for the network access a test -//! needs. +//! needs. [`set`] applies a policy to a running sandbox. //! //! ```ignore //! let mut policy = testkit::policy::base(); @@ -14,7 +14,9 @@ use openshell_sdk::raw::proto; +use crate::context::Sandbox; use crate::error::{Error, Result, ResultExt as _}; +use crate::yaml_file::YamlFile; pub use proto::NetworkAccessPreset as Access; @@ -75,6 +77,45 @@ pub fn to_yaml(policy: &proto::SandboxPolicy) -> Result { .context("serialize the policy") } +/// The policy `yaml` describes, as `sandbox create --policy` reads a file. +/// Use it for a policy kept as a YAML file, such as an example; build one +/// with [`base`] and [`allow`] otherwise. +pub fn from_yaml(yaml: &str) -> Result { + openshell_policy::parse_sandbox_policy(yaml) + .map_err(|error| Error::msg(format!("{error:?}"))) + .context("parse the policy") +} + +/// [`base`] with the top-level sections in `yaml`, such as +/// `network_policies` or `network_middlewares`, added. Use it for policy +/// settings [`Endpoint`] doesn't cover, such as L7 rules. +pub fn base_with(yaml: &str) -> Result { + from_yaml(&format!("{BASE}{yaml}")) +} + +/// Replace `sandbox`'s policy with `policy` through `policy set --wait`, and +/// wait up to two minutes until the sandbox has loaded it. +pub async fn set(sandbox: &Sandbox, policy: &proto::SandboxPolicy) -> Result { + let file = YamlFile::new(&to_yaml(policy)?)?; + sandbox + .handles() + .cli() + .run([ + "policy", + "set", + sandbox.name(), + "--policy", + file.path()?, + "--wait", + "--timeout", + "120", + ]) + .await? + .success() + .context(format!("set the policy of sandbox {}", sandbox.name()))?; + Ok(()) +} + /// `binaries` as the flow-style list a network policy's `binaries:` key /// takes in YAML, such as `[{path: "/usr/bin/python*"}]`. Use it in policy /// YAML a test writes by hand, for example with @@ -196,5 +237,17 @@ mod tests { openshell_policy::parse_sandbox_policy(&to_yaml(&policy).expect("serializes")) .expect("the serialized policy parses"); assert_eq!(round_trip, expected); + assert_eq!(from_yaml(&yaml).expect("the YAML parses"), expected); + assert_eq!( + base_with(yaml.strip_prefix(BASE).expect("starts with the base")) + .expect("the YAML parses"), + expected + ); + } + + #[test] + fn from_yaml_reports_an_invalid_policy() { + let error = from_yaml("network_policies: [").expect_err("invalid YAML"); + assert!(error.to_string().contains("parse the policy"), "{error}"); } } diff --git a/tests/tmachine/ansible/playbooks/driver-config.yaml b/tests/tmachine/ansible/playbooks/driver-config.yaml new file mode 100644 index 0000000000..59d29cc416 --- /dev/null +++ b/tests/tmachine/ansible/playbooks/driver-config.yaml @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Let callers pass driver config with volume and bind mounts. Resource admission +# blocks bind mounts, which can't carry approval labels, so this disables it, as +# the legacy e2e gateways did. Every installer merges +# /etc/openshell-test/gateway-overrides.toml into the gateway's configuration +# (see openshell_gateway/tasks/merge-settings.yaml). +--- +- name: Caller driver config for tests + hosts: all + gather_facts: false + tasks: + - name: Wait for SSH + ansible.builtin.wait_for_connection: + + - name: Create the test settings directory + become: true + ansible.builtin.file: + path: /etc/openshell-test + state: directory + owner: root + group: root + mode: "0755" + + - name: Allow caller driver config and bind mounts + become: true + ansible.builtin.copy: + dest: /etc/openshell-test/gateway-overrides.toml + content: | + [openshell.drivers.{{ environment_driver }}] + allow_driver_config = true + enable_bind_mounts = true + + [openshell.drivers.{{ environment_driver }}.resource_admission] + enabled = false + owner: root + group: root + mode: "0644" diff --git a/tests/tmachine/artifacts.nix b/tests/tmachine/artifacts.nix index 5b605169b3..50f8f8a74e 100644 --- a/tests/tmachine/artifacts.nix +++ b/tests/tmachine/artifacts.nix @@ -87,10 +87,6 @@ let # wrapper-based Podman lane (`mise run e2e:podman:ci`), so they are covered # there until tmachine provides what they need. podmanE2eFollowUpBinaries = [ - # Needs the caller driver-config settings (`allow_driver_config`, - # `enable_bind_mounts`), which the tmachine gateway does not enable. Wrapper - # lane. - "driver_config_volume" # The next three self-skip without wrapper-owned gateway metadata (restart # and configuration control), so exclude them rather than report false # passes. Wrapper lane. @@ -102,10 +98,6 @@ let "provider_auto_create" # Needs the SPIFFE fixtures that the wrapper sets up. Wrapper lane. "provider_token_exchange" - # One test times out reaching support-container IPs from the sandbox in the - # rootless guest; the other tests in the binary pass. Nextest archive - # filters cannot select individual tests, so keep the complete binary here. - "proxy_egress_pipeline" # Holds only the on-failure restart test until #5507; the rest moved to # testkit. Nextest archive filters cannot select individual tests, so keep # the complete binary in the follow-up bucket. diff --git a/tests/tmachine/config.nix b/tests/tmachine/config.nix index 5a41618bf4..90221385ab 100644 --- a/tests/tmachine/config.nix +++ b/tests/tmachine/config.nix @@ -112,6 +112,12 @@ let bases = dockerBases ++ podmanBases; setup.playbooks = [ "ansible/playbooks/cdi.yaml" ]; }; + # Caller driver config with volume and bind mounts, for the driver-config + # suite. + driver-config = { + bases = dockerBases ++ podmanBases; + setup.playbooks = [ "ansible/playbooks/driver-config.yaml" ]; + }; }; featureEnvironments = pkgs.lib.concatMap ( feature: map (base: withSetup base feature features.${feature}.setup) features.${feature}.bases