From f5fa547c770684461d37b732f0b509ff0919ada7 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Thu, 3 Dec 2026 17:13:17 -0800 Subject: [PATCH 1/3] test(conformance): port the policy DNS IPv6 egress decision check Signed-off-by: Matthew Grossman --- e2e/rust/tests/policy_dns_ipv6_egress.rs | 128 ------------------ tests/suites/conformance/README.md | 2 + tests/suites/conformance/src/lib.rs | 1 + .../suites/conformance/src/policy_dns_ipv6.rs | 81 +++++++++++ tests/suites/unsupported.yaml | 5 + 5 files changed, 89 insertions(+), 128 deletions(-) delete mode 100644 e2e/rust/tests/policy_dns_ipv6_egress.rs create mode 100644 tests/suites/conformance/src/policy_dns_ipv6.rs diff --git a/e2e/rust/tests/policy_dns_ipv6_egress.rs b/e2e/rust/tests/policy_dns_ipv6_egress.rs deleted file mode 100644 index 10526f8ee0..0000000000 --- a/e2e/rust/tests/policy_dns_ipv6_egress.rs +++ /dev/null @@ -1,128 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(feature = "e2e")] - -//! Policy DNS IPv6 egress selection in each driver's supervisor network -//! namespace. -//! -//! The supervisor reports its decision in an OCSF configuration event. Every -//! driver lane checks that `auto` read the routing tables and enabled IPv6 -//! answers exactly when the namespace is IPv6-only. Lanes with a known -//! network layout pin it with `OPENSHELL_E2E_EXPECT_ROUTE_STATE` -//! (`ipv6_only`, `dual_stack`, `ipv4_only`), and lanes that configure the -//! driver's `policy_dns_ipv6_egress` set `OPENSHELL_E2E_POLICY_DNS_IPV6_EGRESS`. - -use std::process::Stdio; - -use openshell_e2e::harness::binary::openshell_cmd; -use openshell_e2e::harness::sandbox::SandboxGuard; - -const DECISION_PREFIX: &str = "Policy DNS IPv6 egress "; -const NAT64_MESSAGE: &str = "NAT64 prefixes for SSRF classification"; - -#[derive(Debug, PartialEq, Eq)] -struct Decision { - enabled: bool, - requested: String, - route_state: String, -} - -/// Parse `Policy DNS IPv6 egress (requested , route -/// state )` from the sandbox log. -fn parse_decision(logs: &str) -> Option { - let line = logs.lines().find(|line| line.contains(DECISION_PREFIX))?; - let rest = &line[line.find(DECISION_PREFIX)? + DECISION_PREFIX.len()..]; - let (state, rest) = rest.split_once(" (requested ")?; - let (requested, rest) = rest.split_once(", route state ")?; - let route_state = rest.split(')').next()?; - Some(Decision { - enabled: match state { - "enabled" => true, - "disabled" => false, - _ => return None, - }, - requested: requested.to_string(), - route_state: route_state.to_string(), - }) -} - -async fn sandbox_logs(name: &str) -> Result { - let output = openshell_cmd() - .args([ - "logs", name, "-n", "500", "--since", "5m", "--source", "sandbox", - ]) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .await - .map_err(|e| format!("failed to spawn openshell logs: {e}"))?; - let combined = format!( - "{}{}", - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ); - if output.status.success() { - Ok(combined) - } else { - Err(format!("openshell logs failed:\n{combined}")) - } -} - -#[tokio::test] -async fn supervisor_reports_policy_dns_ipv6_egress_decision() { - let mut guard = SandboxGuard::create(&["--", "sh", "-c", "echo ipv6-egress-ready"]) - .await - .expect("create sandbox"); - - let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(20); - let logs = loop { - let logs = sandbox_logs(&guard.name).await.expect("fetch sandbox logs"); - if parse_decision(&logs).is_some() && logs.contains(NAT64_MESSAGE) { - break logs; - } - assert!( - tokio::time::Instant::now() < deadline, - "timed out waiting for the IPv6 egress and NAT64 events:\n{logs}" - ); - tokio::time::sleep(std::time::Duration::from_millis(250)).await; - }; - let decision = parse_decision(&logs).expect("decision event"); - - let requested = std::env::var("OPENSHELL_E2E_POLICY_DNS_IPV6_EGRESS") - .unwrap_or_else(|_| "auto".to_string()); - assert_eq!(decision.requested, requested, "{logs}"); - assert_ne!( - decision.route_state, "route_table_unavailable", - "supervisor could not read its routing tables:\n{logs}" - ); - match decision.requested.as_str() { - "auto" => assert_eq!( - decision.enabled, - decision.route_state == "ipv6_only", - "auto must enable IPv6 egress only on IPv6-only namespaces: {decision:?}" - ), - "enabled" => assert!(decision.enabled, "{decision:?}"), - "disabled" => assert!(!decision.enabled, "{decision:?}"), - other => panic!("unexpected requested mode {other}"), - } - if let Ok(expected) = std::env::var("OPENSHELL_E2E_EXPECT_ROUTE_STATE") { - assert_eq!(decision.route_state, expected, "{logs}"); - } - - guard.cleanup().await; -} - -#[test] -fn parses_the_decision_message() { - let line = "OCSF CONFIG:ENABLED [INFO] Policy DNS IPv6 egress disabled (requested auto, route state dual_stack)"; - assert_eq!( - parse_decision(line), - Some(Decision { - enabled: false, - requested: "auto".to_string(), - route_state: "dual_stack".to_string(), - }) - ); - assert_eq!(parse_decision("unrelated"), None); -} diff --git a/tests/suites/conformance/README.md b/tests/suites/conformance/README.md index ec7111d27d..d7821494ae 100644 --- a/tests/suites/conformance/README.md +++ b/tests/suites/conformance/README.md @@ -33,6 +33,8 @@ target (`harness = false`), so `openshell-conformance run`, | `settings` | Sandbox-scoped settings | | `workspaces` | Workspace create, get, list and delete; a template is scoped to its workspace; a workspace holding a resource goes Terminating, rejects creates and deletes once empty | | `process` | Core dumps are disabled for sandbox processes | +| `signals-scheduling` | Scheduling, priority, resource-limit and signal calls succeed on the workload's own thread group and fail with `EPERM` on any other process | +| `policy-dns-ipv6` | The supervisor reads its routing tables and reports the policy DNS IPv6 egress decision; `auto` turns it on only on an IPv6-only network | | `filesystem-policy` | Landlock: a hard requirement accepts added device paths; a replaced policy path rejects the next launch | | `policy-validation` | Create refuses a root workload user, `..` in a filesystem path, a writable `/`, and endpoints pinned to different addresses; an MCP endpoint without a version is stored and served with the default | | `policy-enforcement` | Landlock allows and refuses reads, writes and cross-directory renames per the policy; connections no rule allows fail with `EPERM` or `EACCES` | diff --git a/tests/suites/conformance/src/lib.rs b/tests/suites/conformance/src/lib.rs index 9897c5334c..9cf44bb56c 100644 --- a/tests/suites/conformance/src/lib.rs +++ b/tests/suites/conformance/src/lib.rs @@ -23,6 +23,7 @@ mod network_egress; mod network_l7; mod persistent_workspace; mod policy_advisor; +mod policy_dns_ipv6; mod policy_enforcement; mod policy_update; mod policy_validation; diff --git a/tests/suites/conformance/src/policy_dns_ipv6.rs b/tests/suites/conformance/src/policy_dns_ipv6.rs new file mode 100644 index 0000000000..c6ab66b23a --- /dev/null +++ b/tests/suites/conformance/src/policy_dns_ipv6.rs @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: Apache-2.0 + +//! Policy DNS IPv6 egress: the supervisor reads its namespace's routing tables +//! and reports, in an OCSF configuration event, whether policy DNS answers +//! AAAA queries. +//! +//! Ported from the `policy_dns_ipv6_egress` e2e test. The +//! `features/policy-dns-ipv6` suite checks the answers on an IPv6-only network. + +use testkit::{Context, Logs}; + +const DECISION_PREFIX: &str = "Policy DNS IPv6 egress "; +const NAT64_MESSAGE: &str = "NAT64 prefixes for SSRF classification"; + +#[derive(Debug)] +struct Decision { + enabled: bool, + requested: String, + route_state: String, +} + +/// Parse `Policy DNS IPv6 egress (requested , route +/// state )` from the first line that reports it. +fn decision(logs: &Logs) -> Option { + let message = logs + .lines() + .iter() + .find_map(|line| line.message.split_once(DECISION_PREFIX))? + .1; + let (state, rest) = message.split_once(" (requested ")?; + let (requested, rest) = rest.split_once(", route state ")?; + Some(Decision { + enabled: match state { + "enabled" => true, + "disabled" => false, + _ => return None, + }, + requested: requested.to_string(), + route_state: rest.split(')').next()?.to_string(), + }) +} + +/// The supervisor reads its routing tables and honors the requested mode: +/// `auto` turns IPv6 answers on exactly when the namespace is IPv6-only. It +/// also reports the NAT64 prefixes it classifies for SSRF checks. +#[testkit::test] +async fn supervisor_reports_ipv6_egress_decision(cx: &mut Context) -> testkit::Result { + let sandbox = cx + .sandbox("dns6e") + .command(["sleep", "infinity"]) + .create_ready() + .await?; + let logs = sandbox + .logs_until("the IPv6 egress and NAT64 events", |logs| { + decision(logs).is_some() && logs.contains(NAT64_MESSAGE) + }) + .await?; + let decision = decision(&logs) + .ok_or_else(|| testkit::Error::msg(format!("no IPv6 egress decision:\n{logs}")))?; + + testkit::ensure!( + decision.route_state != "route_table_unavailable", + "the supervisor couldn't read its routing tables:\n{logs}" + ); + let expected = match decision.requested.as_str() { + "auto" => decision.route_state == "ipv6_only", + "enabled" => true, + "disabled" => false, + other => { + return Err(testkit::Error::msg(format!( + "unexpected requested mode {other}:\n{logs}" + ))); + } + }; + testkit::ensure!( + decision.enabled == expected, + "IPv6 egress should be {} for {decision:?}:\n{logs}", + if expected { "enabled" } else { "disabled" }, + ); + Ok(()) +} diff --git a/tests/suites/unsupported.yaml b/tests/suites/unsupported.yaml index 360d783dea..71031b4908 100644 --- a/tests/suites/unsupported.yaml +++ b/tests/suites/unsupported.yaml @@ -28,6 +28,11 @@ environments: - ubuntu-k3s/k3s-ha - ubuntu-k3s-ipv6/k3s-ha +- test: conformance::policy_dns_ipv6::supervisor_reports_ipv6_egress_decision + issue: https://github.com/ai-openshell/openshell/issues/5752 + environments: + - ubuntu-k3s/k3s-ha + - ubuntu-k3s-ipv6/k3s-ha # The VM driver can't recover the preserved overlay disk on restart. - test: conformance::lifecycle::on_failure_policy_restarts_main_and_keeps_workspace From f03fba950addc6a5a1560531c435167d9a6d7e6e Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Thu, 3 Dec 2026 17:13:17 -0800 Subject: [PATCH 2/3] test(e2e): delete oidc_pkce and its Keycloak gateway mode features/oidc-auth covers its remaining checks. Signed-off-by: Matthew Grossman --- .github/workflows/e2e-docker-test.yml | 2 +- e2e/rust/Cargo.toml | 6 - e2e/rust/tests/oidc_pkce.rs | 703 -------------------------- e2e/support/gateway-common.sh | 88 ---- e2e/support/podman-gateway-config.sh | 11 +- e2e/with-docker-gateway.sh | 70 +-- e2e/with-keycloak.sh | 57 --- e2e/with-podman-gateway.sh | 66 +-- tasks/scripts/test-gateway-config.sh | 4 +- tasks/test.toml | 12 - 10 files changed, 31 insertions(+), 988 deletions(-) delete mode 100644 e2e/rust/tests/oidc_pkce.rs delete mode 100755 e2e/with-keycloak.sh diff --git a/.github/workflows/e2e-docker-test.yml b/.github/workflows/e2e-docker-test.yml index d7ba6761d3..90ef004862 100644 --- a/.github/workflows/e2e-docker-test.yml +++ b/.github/workflows/e2e-docker-test.yml @@ -33,7 +33,7 @@ on: required: false type: string default: >- - [{"suite":"oidc-pkce-docker","cmd":"mise run --no-deps --skip-deps e2e:oidc-pkce:docker","apt_packages":"openssh-client","mcp":false},{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","mcp":false},{"suite":"oci-image","cmd":"mise run --no-deps --skip-deps e2e:oci-image","apt_packages":"openssh-client","mcp":false},{"suite":"additional-ca","cmd":"OPENSHELL_E2E_DOCKER_TEST=additional_ca mise run --no-deps --skip-deps e2e:docker","apt_packages":"openssh-client","mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","mcp":true}] + [{"suite":"rust-docker","cmd":"mise run --no-deps --skip-deps e2e:rust","apt_packages":"openssh-client","mcp":false},{"suite":"oci-image","cmd":"mise run --no-deps --skip-deps e2e:oci-image","apt_packages":"openssh-client","mcp":false},{"suite":"additional-ca","cmd":"OPENSHELL_E2E_DOCKER_TEST=additional_ca mise run --no-deps --skip-deps e2e:docker","apt_packages":"openssh-client","mcp":false},{"suite":"mcp","cmd":"mise run --no-deps --skip-deps e2e:mcp","apt_packages":"","mcp":true}] permissions: actions: read diff --git a/e2e/rust/Cargo.toml b/e2e/rust/Cargo.toml index 33464ed903..56b2e2ad89 100644 --- a/e2e/rust/Cargo.toml +++ b/e2e/rust/Cargo.toml @@ -48,7 +48,6 @@ e2e-kubernetes-shared-supervisor-ha = ["e2e-kubernetes", "e2e-host-gateway"] e2e-kubernetes-shared-supervisor-scaling = ["e2e-kubernetes", "e2e-host-gateway"] e2e-podman = ["e2e", "e2e-host-gateway", "e2e-local-container-driver"] e2e-podman-gpu = ["e2e-podman", "e2e-gpu"] -e2e-oidc-pkce = [] e2e-vm = ["e2e", "e2e-host-gateway"] [[test]] @@ -56,11 +55,6 @@ name = "policy_activation" path = "tests/policy_activation.rs" required-features = ["e2e-docker"] -[[test]] -name = "oidc_pkce" -path = "tests/oidc_pkce.rs" -required-features = ["e2e-oidc-pkce"] - [[test]] name = "vm_overlay" path = "tests/vm_overlay.rs" diff --git a/e2e/rust/tests/oidc_pkce.rs b/e2e/rust/tests/oidc_pkce.rs deleted file mode 100644 index 461db3b287..0000000000 --- a/e2e/rust/tests/oidc_pkce.rs +++ /dev/null @@ -1,703 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -#![cfg(target_os = "linux")] - -//! End-to-end coverage for interactive OIDC PKCE login and gateway RBAC. -//! -//! The test replaces Linux's `xdg-open` with a recorder, then drives the -//! captured Keycloak login URL with curl. This exercises the same loopback -//! callback and token exchange used by a real browser without requiring a GUI. -//! It logs in as the fixture identities and verifies standard-user and admin-only -//! actions against a live Docker- or Podman-backed gateway. -//! -//! The rest of this coverage lives in the `oidc-auth` testkit suite. These -//! four checks duplicate it and are not ported. - -use std::collections::HashMap; -use std::ffi::OsString; -use std::fs::Permissions; -use std::os::unix::fs::PermissionsExt; -use std::path::Path; -use std::process::{Output, Stdio}; -use std::time::{Duration, Instant}; - -use base64::Engine as _; -use openshell_e2e::harness::binary::openshell_cmd; -use serde_json::Value; -use serial_test::serial; -use tokio::process::Command; -use tokio::sync::Mutex; -use url::Url; - -static SANDBOX_LIFECYCLE_LOCK: Mutex<()> = Mutex::const_new(()); - -#[derive(Clone, Copy)] -struct IdentityScenario { - gateway_name: &'static str, - username: &'static str, - password: &'static str, - expected_role: &'static str, -} - -const ADMIN: IdentityScenario = IdentityScenario { - gateway_name: "oidc-pkce-admin", - username: "admin@test", - password: "admin", - expected_role: "openshell-admin", -}; - -const USER: IdentityScenario = IdentityScenario { - gateway_name: "oidc-pkce-user", - username: "user@test", - password: "user", - expected_role: "openshell-user", -}; - -const USER_B: IdentityScenario = IdentityScenario { - gateway_name: "oidc-pkce-user-b", - username: "user-b@test", - password: "user-b", - expected_role: "openshell-user", -}; - -struct LoginSession { - config_home: tempfile::TempDir, - identity: IdentityScenario, - subject: String, -} - -#[tokio::test] -#[serial(oidc_pkce)] -async fn admin_can_delete_workspace() { - const WORKSPACE: &str = "oidc-admin-delete"; - let admin = login_identity(ADMIN).await; - let _ = run_session_cli(&admin, &["workspace", "delete", WORKSPACE]).await; - assert_allowed( - &admin, - &["workspace", "create", "--name", WORKSPACE], - "create a workspace deletion target", - ) - .await; - delete_workspace(&admin, WORKSPACE).await; -} - -#[tokio::test] -#[serial(oidc_pkce)] -async fn workspace_admin_can_create_sandbox() { - const WORKSPACE: &str = "oidc-wsa-create-sb"; - let user = login_identity(USER).await; - let admin = login_identity(ADMIN).await; - prepare_workspace(&admin, &user, WORKSPACE, "admin").await; - let _lifecycle = SANDBOX_LIFECYCLE_LOCK.lock().await; - assert_can_create_sandbox(&user, WORKSPACE, "oidc-wsa-create").await; - delete_workspace(&admin, WORKSPACE).await; -} - -#[tokio::test] -#[serial(oidc_pkce)] -async fn workspace_admin_can_delete_sandbox() { - const WORKSPACE: &str = "oidc-wsa-delete-sb"; - let user = login_identity(USER).await; - let admin = login_identity(ADMIN).await; - prepare_workspace(&admin, &user, WORKSPACE, "admin").await; - let _lifecycle = SANDBOX_LIFECYCLE_LOCK.lock().await; - assert_can_delete_sandbox(&user, WORKSPACE, "oidc-wsa-delete").await; - delete_workspace(&admin, WORKSPACE).await; -} - -#[tokio::test] -#[serial(oidc_pkce)] -async fn second_workspace_user_cannot_read_first_users_workspace() { - const WORKSPACE_A: &str = "oidc-xread2-a"; - const WORKSPACE_B: &str = "oidc-xread2-b"; - let (admin, _user_a, user_b) = prepare_isolated_workspaces(WORKSPACE_A, WORKSPACE_B).await; - - let denied = run_session_cli(&user_b, &["workspace", "get", WORKSPACE_A]).await; - assert_non_member_denial(&denied, "read another user's workspace"); - - delete_workspace(&admin, WORKSPACE_B).await; - delete_workspace(&admin, WORKSPACE_A).await; -} - -async fn login_identity(identity: IdentityScenario) -> LoginSession { - let issuer = std::env::var("OPENSHELL_E2E_OIDC_ISSUER") - .unwrap_or_else(|_| "http://localhost:8180/realms/openshell".to_string()); - let gateway_endpoint = std::env::var("OPENSHELL_E2E_OIDC_GATEWAY_ENDPOINT") - .expect("OIDC E2E requires a live gateway endpoint"); - let temp = tempfile::tempdir().expect("create isolated test directory"); - let fake_bin = temp.path().join("bin"); - std::fs::create_dir(&fake_bin).expect("create fake bin directory"); - let browser_url_file = temp.path().join("browser-url"); - install_xdg_open_recorder(&fake_bin); - - let path = prepend_path(&fake_bin); - let mut cli = openshell_cmd(); - cli.args([ - "gateway", - "add", - &gateway_endpoint, - "--name", - identity.gateway_name, - "--local", - "--oidc-issuer", - &issuer, - "--oidc-scopes", - "profile email openshell:all", - ]) - .env("XDG_CONFIG_HOME", temp.path()) - .env("HOME", temp.path()) - .env("PATH", path) - .env("OPENSHELL_E2E_BROWSER_URL_FILE", &browser_url_file) - .env_remove("OPENSHELL_GATEWAY") - .env_remove("OPENSHELL_GATEWAY_ENDPOINT") - .env_remove("OPENSHELL_NO_BROWSER") - .env_remove("OPENSHELL_OIDC_CLIENT_SECRET") - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - - let child = cli.spawn().expect("start openshell PKCE login"); - let authorization_url = wait_for_browser_url(&browser_url_file).await; - let redirect_uri = assert_pkce_authorization_url(&authorization_url, &issuer); - - let cookie_jar = temp.path().join("keycloak-cookies"); - let login_page = curl_get(&authorization_url, &cookie_jar).await; - let login_action = extract_login_action(&login_page); - let callback_page = curl_login( - &login_action, - &cookie_jar, - identity.username, - identity.password, - ) - .await; - assert!( - callback_page.contains("Authentication successful"), - "loopback callback did not return its success page:\n{callback_page}" - ); - - let output = tokio::time::timeout(Duration::from_secs(30), child.wait_with_output()) - .await - .expect("openshell did not finish after receiving the OIDC callback") - .expect("wait for openshell PKCE login"); - let combined = format!( - "{}{}", - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ); - assert!( - output.status.success(), - "openshell PKCE login failed:\n{combined}" - ); - assert!( - combined.contains("Authenticated successfully"), - "missing successful authentication message:\n{combined}" - ); - - let subject = assert_persisted_login( - temp.path(), - &issuer, - &redirect_uri, - identity.gateway_name, - identity.username, - identity.expected_role, - ); - - LoginSession { - config_home: temp, - identity, - subject, - } -} - -fn install_xdg_open_recorder(bin_dir: &Path) { - let script = bin_dir.join("xdg-open"); - std::fs::write( - &script, - "#!/bin/sh\nset -eu\nprintf '%s\\n' \"$1\" > \"$OPENSHELL_E2E_BROWSER_URL_FILE\"\n", - ) - .expect("write xdg-open recorder"); - std::fs::set_permissions(&script, Permissions::from_mode(0o755)) - .expect("make xdg-open recorder executable"); -} - -fn prepend_path(bin_dir: &Path) -> OsString { - let current = std::env::var_os("PATH").unwrap_or_default(); - std::env::join_paths( - std::iter::once(bin_dir.to_path_buf()).chain(std::env::split_paths(¤t)), - ) - .expect("construct PATH with xdg-open recorder") -} - -async fn wait_for_browser_url(path: &Path) -> String { - for _ in 0..200 { - if let Ok(contents) = tokio::fs::read_to_string(path).await { - let url = contents.trim(); - if !url.is_empty() { - return url.to_string(); - } - } - tokio::time::sleep(Duration::from_millis(50)).await; - } - panic!( - "xdg-open did not receive an authorization URL within 10 seconds ({})", - path.display() - ); -} - -fn assert_pkce_authorization_url(authorization_url: &str, issuer: &str) -> String { - let url = Url::parse(authorization_url).expect("authorization URL is valid"); - let expected_path = format!( - "{}/protocol/openid-connect/auth", - Url::parse(issuer) - .expect("issuer URL is valid") - .path() - .trim_end_matches('/') - ); - assert_eq!(url.path(), expected_path); - - let params: HashMap<_, _> = url.query_pairs().into_owned().collect(); - assert_eq!( - params.get("response_type").map(String::as_str), - Some("code") - ); - assert_eq!( - params.get("client_id").map(String::as_str), - Some("openshell-cli") - ); - assert_eq!( - params.get("code_challenge_method").map(String::as_str), - Some("S256") - ); - let challenge = params - .get("code_challenge") - .expect("authorization URL has a PKCE challenge"); - assert_eq!(challenge.len(), 43, "S256 challenge is base64url encoded"); - assert!( - challenge - .bytes() - .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_')), - "PKCE challenge must use unpadded base64url" - ); - assert!( - params.get("state").is_some_and(|state| !state.is_empty()), - "authorization URL must contain CSRF state" - ); - - let scopes: Vec<_> = params - .get("scope") - .expect("authorization URL has scopes") - .split_whitespace() - .collect(); - for expected in ["openid", "profile", "email", "openshell:all"] { - assert!(scopes.contains(&expected), "missing OIDC scope {expected}"); - } - - let redirect_uri = params - .get("redirect_uri") - .expect("authorization URL has a redirect URI"); - let redirect = Url::parse(redirect_uri).expect("redirect URI is valid"); - assert_eq!(redirect.scheme(), "http"); - assert_eq!(redirect.host_str(), Some("127.0.0.1")); - assert!( - redirect.port().is_some(), - "redirect URI has a callback port" - ); - assert_eq!(redirect.path(), "/callback"); - redirect_uri.clone() -} - -async fn curl_get(url: &str, cookie_jar: &Path) -> String { - let output = Command::new("curl") - .args(["--fail", "--silent", "--show-error", "--cookie-jar"]) - .arg(cookie_jar) - .arg(url) - .output() - .await - .expect("run curl for Keycloak login page"); - assert!( - output.status.success(), - "failed to load Keycloak login page: {}", - String::from_utf8_lossy(&output.stderr) - ); - String::from_utf8(output.stdout).expect("Keycloak login page is UTF-8") -} - -async fn curl_login(action: &str, cookie_jar: &Path, username: &str, password: &str) -> String { - let output = Command::new("curl") - .args([ - "--fail", - "--silent", - "--show-error", - "--location", - "--cookie", - ]) - .arg(cookie_jar) - .arg("--cookie-jar") - .arg(cookie_jar) - .arg("--data-urlencode") - .arg(format!("username={username}")) - .arg("--data-urlencode") - .arg(format!("password={password}")) - .arg("--data-urlencode") - .arg("credentialId=") - .arg(action) - .output() - .await - .expect("run curl for Keycloak credentials submission"); - assert!( - output.status.success(), - "Keycloak login submission failed: {}", - String::from_utf8_lossy(&output.stderr) - ); - String::from_utf8(output.stdout).expect("OIDC callback page is UTF-8") -} - -fn extract_login_action(html: &str) -> String { - let form_id = html - .find("id=\"kc-form-login\"") - .expect("Keycloak page has the login form"); - let form_start = html[..form_id] - .rfind("') - .expect("Keycloak login form start tag is closed"); - let form = &html[form_start..form_end]; - let action_start = form - .find("action=\"") - .map(|index| index + "action=\"".len()) - .expect("Keycloak login form has an action"); - let action_end = action_start - + form[action_start..] - .find('"') - .expect("Keycloak login action is quoted"); - form[action_start..action_end] - .replace("&", "&") - .replace("&", "&") -} - -fn assert_persisted_login( - config_home: &Path, - issuer: &str, - redirect_uri: &str, - gateway_name: &str, - username: &str, - expected_role: &str, -) -> String { - let gateway_dir = config_home - .join("openshell") - .join("gateways") - .join(gateway_name); - let metadata: Value = read_json(&gateway_dir.join("metadata.json")); - assert_eq!(metadata["auth_mode"], "oidc"); - assert_eq!(metadata["oidc_issuer"], issuer); - assert_eq!(metadata["oidc_client_id"], "openshell-cli"); - assert_eq!(metadata["oidc_scopes"], "profile email openshell:all"); - - let token: Value = read_json(&gateway_dir.join("oidc_token.json")); - let access_token = token["access_token"] - .as_str() - .expect("stored access token is a string"); - assert!(!access_token.is_empty()); - assert!( - token["refresh_token"] - .as_str() - .is_some_and(|refresh| !refresh.is_empty()), - "browser flow should persist a refresh token" - ); - assert_eq!(token["issuer"], issuer); - assert_eq!(token["client_id"], "openshell-cli"); - - let claims = decode_jwt_claims(access_token); - assert!(jwt_audience_contains(&claims["aud"], "openshell-cli")); - assert_eq!(claims["azp"], "openshell-cli"); - assert_eq!(claims["preferred_username"], username); - let subject = claims["sub"] - .as_str() - .filter(|subject| !subject.is_empty()) - .expect("access token should contain a non-empty subject") - .to_string(); - assert!( - claims["realm_access"]["roles"] - .as_array() - .is_some_and(|roles| roles.iter().any(|role| role == expected_role)), - "access token should contain the {expected_role} realm role" - ); - - let redirect = Url::parse(redirect_uri).expect("saved redirect URI remains valid"); - assert_eq!(redirect.host_str(), Some("127.0.0.1")); - subject -} - -async fn assert_allowed(session: &LoginSession, args: &[&str], action: &str) -> Output { - let output = run_session_cli(session, args).await; - assert!( - output.status.success(), - "{} should be allowed to {action}:\n{}", - session.identity.username, - combined_output(&output) - ); - output -} - -async fn prepare_workspace( - admin: &LoginSession, - member: &LoginSession, - workspace: &str, - role: &str, -) { - let _ = run_session_cli(admin, &["workspace", "delete", workspace]).await; - assert_allowed( - admin, - &["workspace", "create", "--name", workspace], - "create a workspace fixture", - ) - .await; - assert_allowed( - admin, - &[ - "workspace", - "member", - "add", - "--workspace", - workspace, - "--subject", - &member.subject, - "--role", - role, - ], - "add a workspace member", - ) - .await; -} - -async fn prepare_isolated_workspaces( - workspace_a: &str, - workspace_b: &str, -) -> (LoginSession, LoginSession, LoginSession) { - let admin = login_identity(ADMIN).await; - let user_a = login_identity(USER).await; - let user_b = login_identity(USER_B).await; - prepare_workspace(&admin, &user_a, workspace_a, "user").await; - prepare_workspace(&admin, &user_b, workspace_b, "user").await; - (admin, user_a, user_b) -} - -async fn delete_workspace(admin: &LoginSession, workspace: &str) { - for attempt in 0..30 { - let output = run_session_cli(admin, &["workspace", "delete", workspace]).await; - if output.status.success() { - return; - } - let stderr = combined_output(&output); - if !stderr.contains("still contains") { - panic!( - "{} should be allowed to delete workspace {workspace}:\n{stderr}", - admin.identity.username - ); - } - if attempt == 29 { - panic!("workspace {workspace} still contains resources after 30 retries:\n{stderr}"); - } - tokio::time::sleep(std::time::Duration::from_secs(2)).await; - } -} - -// Keep RBAC fixtures running until cleanup so authorization checks do not also -// exercise fast canonical-process completion. The conformance `lifecycle` -// suite covers that. -async fn assert_can_create_sandbox(session: &LoginSession, workspace: &str, sandbox_name: &str) { - let create = run_workspace_cli( - session, - workspace, - &[ - "sandbox", - "create", - "--name", - sandbox_name, - "--no-tty", - "--detach", - "--", - "sleep", - "infinity", - ], - ) - .await; - let create_output = combined_output(&create); - - if !create.status.success() { - let _ = run_workspace_cli(session, workspace, &["sandbox", "delete", sandbox_name]).await; - panic!( - "{} should be allowed to create sandbox {sandbox_name}:\n{create_output}", - session.identity.username - ); - } - - let list = - run_workspace_cli(session, workspace, &["sandbox", "list", "--output", "json"]).await; - let list_output = combined_output(&list); - let cleanup = run_workspace_cli(session, workspace, &["sandbox", "delete", sandbox_name]).await; - - assert!( - list.status.success() && list_output.contains(sandbox_name), - "created sandbox {sandbox_name} should appear in the sandbox list:\n{list_output}" - ); - assert!( - cleanup.status.success(), - "failed to clean up created sandbox {sandbox_name}:\n{}", - combined_output(&cleanup) - ); -} - -async fn assert_can_delete_sandbox(session: &LoginSession, workspace: &str, sandbox_name: &str) { - let create = run_workspace_cli( - session, - workspace, - &[ - "sandbox", - "create", - "--name", - sandbox_name, - "--no-tty", - "--detach", - "--", - "sleep", - "infinity", - ], - ) - .await; - let create_output = combined_output(&create); - if !create.status.success() { - let _ = run_workspace_cli(session, workspace, &["sandbox", "delete", sandbox_name]).await; - panic!("failed to create sandbox deletion target {sandbox_name}:\n{create_output}"); - } - - let delete = run_workspace_cli(session, workspace, &["sandbox", "delete", sandbox_name]).await; - let delete_output = combined_output(&delete); - if !delete.status.success() { - let _ = run_workspace_cli(session, workspace, &["sandbox", "delete", sandbox_name]).await; - panic!( - "{} should be allowed to delete sandbox {sandbox_name}:\n{delete_output}", - session.identity.username - ); - } - - if let Err(last_list) = wait_for_sandbox_absence(session, workspace, sandbox_name).await { - panic!( - "deleted sandbox {sandbox_name} should disappear from the sandbox list:\n{last_list}" - ); - } -} - -async fn wait_for_sandbox_absence( - session: &LoginSession, - workspace: &str, - sandbox_name: &str, -) -> Result<(), String> { - const TIMEOUT: Duration = Duration::from_secs(30); - const POLL_INTERVAL: Duration = Duration::from_millis(250); - - let deadline = Instant::now() + TIMEOUT; - loop { - let list = - run_workspace_cli(session, workspace, &["sandbox", "list", "--output", "json"]).await; - let list_output = combined_output(&list); - if !list.status.success() { - return Err(list_output); - } - - let present = list_output.contains(sandbox_name); - if !present { - return Ok(()); - } - if Instant::now() >= deadline { - return Err(list_output); - } - - tokio::time::sleep(POLL_INTERVAL).await; - } -} - -async fn run_session_cli(session: &LoginSession, args: &[&str]) -> Output { - let mut command_args = Vec::with_capacity(args.len() + 2); - command_args.extend(["--gateway", session.identity.gateway_name]); - command_args.extend_from_slice(args); - run_cli(session.config_home.path(), &command_args).await -} - -async fn run_workspace_cli(session: &LoginSession, workspace: &str, args: &[&str]) -> Output { - let mut command_args = Vec::with_capacity(args.len() + 4); - command_args.extend([ - "--gateway", - session.identity.gateway_name, - "--workspace", - workspace, - ]); - command_args.extend_from_slice(args); - run_cli(session.config_home.path(), &command_args).await -} - -fn assert_non_member_denial(output: &Output, action: &str) { - let denied = combined_output(output); - let compact_denial: String = denied - .chars() - .filter(|character| !character.is_whitespace() && *character != '│') - .collect(); - assert!( - !output.status.success() - && compact_denial - .to_ascii_lowercase() - .contains("notamemberofworkspace"), - "non-member unexpectedly authorized to {action}, or denial omitted membership context:\n{denied}" - ); -} - -async fn run_cli(config_home: &Path, args: &[&str]) -> Output { - openshell_cmd() - .arg("--gateway-insecure") - .args(args) - .env("XDG_CONFIG_HOME", config_home) - .env("HOME", config_home) - .env("OPENSHELL_GATEWAY_INSECURE", "true") - .env_remove("OPENSHELL_GATEWAY") - .env_remove("OPENSHELL_GATEWAY_ENDPOINT") - .env_remove("OPENSHELL_OIDC_CLIENT_SECRET") - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .await - .expect("run openshell authorization action") -} - -fn combined_output(output: &Output) -> String { - format!( - "{}{}", - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) - ) -} - -fn read_json(path: &Path) -> Value { - let contents = std::fs::read_to_string(path) - .unwrap_or_else(|error| panic!("read {}: {error}", path.display())); - serde_json::from_str(&contents) - .unwrap_or_else(|error| panic!("parse {} as JSON: {error}", path.display())) -} - -fn decode_jwt_claims(token: &str) -> Value { - let payload = token.split('.').nth(1).expect("access token is a JWT"); - let bytes = base64::engine::general_purpose::URL_SAFE_NO_PAD - .decode(payload) - .expect("decode JWT claims"); - serde_json::from_slice(&bytes).expect("parse JWT claims") -} - -fn jwt_audience_contains(audience: &Value, expected: &str) -> bool { - audience.as_str() == Some(expected) - || audience - .as_array() - .is_some_and(|values| values.iter().any(|value| value == expected)) -} diff --git a/e2e/support/gateway-common.sh b/e2e/support/gateway-common.sh index f69518f0bc..02f6c8561c 100644 --- a/e2e/support/gateway-common.sh +++ b/e2e/support/gateway-common.sh @@ -337,94 +337,6 @@ e2e_import_example_provider_profiles() { fi } -# Register an administrator OIDC session for a gateway, non-interactively. -# -# The browser PKCE flow the CLI normally uses cannot run unattended, so mint an -# admin access token with Keycloak's password grant and write the same token -# bundle `openshell gateway login` would have stored. Used only to establish a -# setup identity; the tests themselves still authenticate however they choose. -e2e_register_oidc_admin_session() { - local config_home=$1 - local name=$2 - local endpoint=$3 - local port=$4 - local issuer=$5 - local username=$6 - local password=$7 - local pki_dir=$8 - local cli_bin=$9 - local client_id="${10:-openshell-cli}" - local gateway_config_dir="${config_home}/openshell/gateways/${name}" - - # The OpenShell scopes are optional client scopes on openshell-cli, so - # Keycloak mints them only when they are asked for. Without an explicit - # scope the token carries the realm defaults alone and every authorized RPC - # fails with "scope '' required". - local token - token=$(curl -sf -X POST "${issuer}/protocol/openid-connect/token" \ - -d "grant_type=password" \ - -d "client_id=${client_id}" \ - -d "username=${username}" \ - -d "password=${password}" \ - --data-urlencode "scope=openid openshell:all" \ - | python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])' 2>/dev/null) || true - - if [ -z "${token}" ]; then - echo "ERROR: could not obtain an admin OIDC token from ${issuer}" >&2 - return 1 - fi - - mkdir -p "${gateway_config_dir}" - - # Trust the gateway's self-signed serving certificate. Only the CA is - # installed: these lanes start the gateway without --tls-client-ca, and with - # no client cert/key on disk the CLI falls back to CA-only server - # verification and authenticates with the bearer token instead of an mTLS - # identity. - mkdir -p "${gateway_config_dir}/mtls" - cp "${pki_dir}/ca.crt" "${gateway_config_dir}/mtls/ca.crt" - - # auth_mode must be "oidc": the CLI dispatches on this field alone when - # deciding to load a stored bearer token, so omitting it leaves - # oidc_token.json on disk and unread, and the request goes unauthenticated. - cat >"${gateway_config_dir}/metadata.json" <"${gateway_config_dir}/oidc_token.json" <"${config_home}/openshell/active_gateway" - - # Assert the CLI reaches the gateway as an authenticated administrator before - # anything depends on it. ListProviderProfiles is annotated - # auth_mode: "bearer", so it cannot succeed unless the stored token was - # loaded and accepted -- this fails here, with the cause named, rather than - # surfacing later as an opaque profile import error. - if ! "${cli_bin}" provider list-profiles --global --output json >/dev/null 2>&1; then - echo "ERROR: the CLI could not make an authenticated call as the OIDC administrator" >&2 - echo " gateway config: ${gateway_config_dir}" >&2 - echo " CLI output follows:" >&2 - "${cli_bin}" provider list-profiles --global --output json >&2 || true - return 1 - fi - - echo "Established an authenticated OIDC administrator session for '${name}'." -} - e2e_toml_string() { local value="$1" value="${value//\\/\\\\}" diff --git a/e2e/support/podman-gateway-config.sh b/e2e/support/podman-gateway-config.sh index 0be7ab7576..7a5144703e 100755 --- a/e2e/support/podman-gateway-config.sh +++ b/e2e/support/podman-gateway-config.sh @@ -31,8 +31,7 @@ e2e_write_podman_gateway_config() { local supervisor_image=${12} local sandbox_runtime_image=${13} local podman_socket=${14} - local oidc_mode=${15} - local oidc_issuer=${16} + local oidc_issuer=${15} local configured_with_tls cp "${root}/deploy/rpm/gateway.toml.default" "${output}" @@ -73,11 +72,9 @@ e2e_write_podman_gateway_config() { printf 'enabled = false\n' fi e2e_write_gateway_jwt_config "${jwt_dir}" "${gateway_id}" - if [ "${oidc_mode}" != "1" ]; then - e2e_write_gateway_mtls_auth_config - if [ -n "${oidc_issuer}" ]; then - e2e_write_gateway_oidc_config "${oidc_issuer}" - fi + e2e_write_gateway_mtls_auth_config + if [ -n "${oidc_issuer}" ]; then + e2e_write_gateway_oidc_config "${oidc_issuer}" fi } >>"${output}" } diff --git a/e2e/with-docker-gateway.sh b/e2e/with-docker-gateway.sh index 57d49632f4..b689f3aaeb 100755 --- a/e2e/with-docker-gateway.sh +++ b/e2e/with-docker-gateway.sh @@ -119,8 +119,6 @@ DOCKER_NETWORK_NAME="" DOCKER_NETWORK_CONNECTED_CONTAINER="" DOCKER_NETWORK_MANAGED=0 GPU_MODE="${OPENSHELL_E2E_DOCKER_GPU:-0}" -OIDC_MODE="${OPENSHELL_E2E_OIDC_GATEWAY:-0}" -OIDC_ISSUER="${OPENSHELL_E2E_OIDC_ISSUER:-}" ADDITIONAL_CA_MODE="${OPENSHELL_E2E_ADDITIONAL_CA:-0}" ADDITIONAL_CA_SERVER_PID="" ADDITIONAL_CA_SERVER_LOG="${WORKDIR}/additional-ca-server.log" @@ -138,11 +136,6 @@ if [ "${IMAGE_UPDATES_MODE}" = "1" ] && [ -n "${OPENSHELL_GATEWAY_ENDPOINT:-}" ] exit 2 fi -if [ "${OIDC_MODE}" = "1" ] && [ -z "${OIDC_ISSUER}" ]; then - echo "ERROR: OPENSHELL_E2E_OIDC_ISSUER is required when OPENSHELL_E2E_OIDC_GATEWAY=1" >&2 - exit 2 -fi - # Isolate CLI/SDK gateway metadata from the developer's real config. export XDG_CONFIG_HOME="${WORKDIR}/config" export XDG_DATA_HOME="${WORKDIR}/data" @@ -639,11 +632,9 @@ GATEWAY_CONFIG="${STATE_DIR}/gateway.toml" fi printf 'guest_tls_ca = %s\n' "$(toml_string "${PKI_DIR}/ca.crt")" e2e_write_gateway_jwt_config "${JWT_DIR}" "openshell-e2e-docker-${HOST_PORT}" - if [ "${OIDC_MODE}" != "1" ]; then - e2e_write_gateway_mtls_auth_config - if [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then - e2e_write_gateway_oidc_config "${OPENSHELL_OIDC_ISSUER}" - fi + e2e_write_gateway_mtls_auth_config + if [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then + e2e_write_gateway_oidc_config "${OPENSHELL_OIDC_ISSUER}" fi if [ "${ADDITIONAL_CA_MODE}" = "1" ]; then printf '[openshell.supervisor.network]\n' @@ -683,25 +674,9 @@ GATEWAY_ARGS=( # edge_tunnel_e2e exercises the opt-in WebSocket tunnel. --enable-websocket-tunnel true --db-url "sqlite:${STATE_DIR}/gateway.db?mode=rwc" + --tls-client-ca "${PKI_DIR}/ca.crt" ) -if [ "${OIDC_MODE}" = "1" ]; then - GATEWAY_ARGS+=( - --oidc-issuer "${OIDC_ISSUER}" - --oidc-audience openshell-cli - --oidc-scopes-claim scope - ) - case "${OIDC_ISSUER}" in - http://127.*|http://\[::1\]*) - GATEWAY_ARGS+=(--oidc-dangerously-allow-insecure-http true) - ;; - esac -else - GATEWAY_ARGS+=( - --tls-client-ca "${PKI_DIR}/ca.crt" - ) -fi - e2e_write_gateway_args_file "${GATEWAY_ARGS_FILE}" "${GATEWAY_ARGS[@]}" e2e_export_gateway_restart_metadata \ "${GATEWAY_BIN}" \ @@ -715,22 +690,18 @@ printf '%s\n' "${GATEWAY_PID}" >"${GATEWAY_PID_FILE}" GATEWAY_NAME="openshell-e2e-docker-${HOST_PORT}" CLI_GATEWAY_ENDPOINT="https://127.0.0.1:${HOST_PORT}" -if [ "${OIDC_MODE}" = "1" ]; then - export OPENSHELL_E2E_OIDC_GATEWAY_ENDPOINT="${CLI_GATEWAY_ENDPOINT}" -else - e2e_register_mtls_gateway \ - "${XDG_CONFIG_HOME}" \ - "${GATEWAY_NAME}" \ - "${CLI_GATEWAY_ENDPOINT}" \ - "${HOST_PORT}" \ - "${PKI_DIR}" \ - "${OPENSHELL_OIDC_ISSUER:-}" -fi +e2e_register_mtls_gateway \ + "${XDG_CONFIG_HOME}" \ + "${GATEWAY_NAME}" \ + "${CLI_GATEWAY_ENDPOINT}" \ + "${HOST_PORT}" \ + "${PKI_DIR}" \ + "${OPENSHELL_OIDC_ISSUER:-}" export OPENSHELL_GATEWAY="${GATEWAY_NAME}" export OPENSHELL_PROVISION_TIMEOUT="${OPENSHELL_PROVISION_TIMEOUT:-180}" -if [ "${OIDC_MODE}" = "1" ] || [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then +if [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then export OPENSHELL_E2E_OIDC=1 export OPENSHELL_E2E_OIDC_SCOPES=1 fi @@ -755,22 +726,7 @@ if [ "${elapsed}" -ge "${timeout}" ]; then exit 1 fi -# Seed the example profiles the provider tests rely on. The mTLS lanes already -# have a registered gateway identity; the OIDC lanes deliberately skip -# registration and have no token yet, so establish an administrator session -# first rather than importing unauthenticated. -if [ "${OIDC_MODE}" = "1" ]; then - e2e_register_oidc_admin_session \ - "${XDG_CONFIG_HOME}" \ - "${GATEWAY_NAME}" \ - "${CLI_GATEWAY_ENDPOINT}" \ - "${HOST_PORT}" \ - "${OIDC_ISSUER}" \ - "${OPENSHELL_E2E_OIDC_USERNAME:-admin@test}" \ - "${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" \ - "${PKI_DIR}" \ - "${CLI_BIN}" || exit 1 -fi +# Seed the example profiles the provider tests rely on. e2e_import_example_provider_profiles "${CLI_BIN}" "${ROOT}" || exit 1 echo "Running e2e command against ${CLI_GATEWAY_ENDPOINT}: $*" diff --git a/e2e/with-keycloak.sh b/e2e/with-keycloak.sh deleted file mode 100755 index 5c29491f38..0000000000 --- a/e2e/with-keycloak.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -# Run a command against the local Keycloak OIDC fixture. An already-running -# fixture is preserved; a fixture started by this wrapper is removed on exit. - -set -euo pipefail - -if [ "$#" -eq 0 ]; then - echo "Usage: $0 [args...]" >&2 - exit 2 -fi - -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -KEYCLOAK_PORT="${KEYCLOAK_PORT:-8180}" - -if [ -n "${CONTAINER_RUNTIME:-}" ]; then - RUNTIME="$CONTAINER_RUNTIME" -elif command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then - RUNTIME=docker -elif command -v podman >/dev/null 2>&1 && podman info >/dev/null 2>&1; then - RUNTIME=podman -else - echo "Error: no usable Docker or Podman runtime found" >&2 - exit 1 -fi - -STARTED_KEYCLOAK=0 -cleanup() { - local status=$? - trap - EXIT - if [ "$status" -ne 0 ]; then - echo "Keycloak logs from failed OIDC E2E run:" >&2 - "$RUNTIME" logs --tail 80 openshell-keycloak >&2 2>/dev/null || true - fi - if [ "$STARTED_KEYCLOAK" -eq 1 ]; then - CONTAINER_RUNTIME="$RUNTIME" KEYCLOAK_PORT="$KEYCLOAK_PORT" \ - "$ROOT_DIR/scripts/keycloak-dev.sh" stop - fi - exit "$status" -} -trap cleanup EXIT - -if ! CONTAINER_RUNTIME="$RUNTIME" KEYCLOAK_PORT="$KEYCLOAK_PORT" \ - "$ROOT_DIR/scripts/keycloak-dev.sh" status >/dev/null 2>&1; then - STARTED_KEYCLOAK=1 - CONTAINER_RUNTIME="$RUNTIME" KEYCLOAK_PORT="$KEYCLOAK_PORT" \ - "$ROOT_DIR/scripts/keycloak-dev.sh" start -fi - -export OPENSHELL_E2E_OIDC_ISSUER="${OPENSHELL_E2E_OIDC_ISSUER:-http://127.0.0.1:${KEYCLOAK_PORT}/realms/openshell}" -export OPENSHELL_E2E_OIDC_USERNAME="${OPENSHELL_E2E_OIDC_USERNAME:-admin@test}" -export OPENSHELL_E2E_OIDC_PASSWORD="${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" -export OPENSHELL_E2E_OIDC_ROLE="${OPENSHELL_E2E_OIDC_ROLE:-openshell-admin}" - -"$@" diff --git a/e2e/with-podman-gateway.sh b/e2e/with-podman-gateway.sh index c489fb678e..c1ccaf8b55 100755 --- a/e2e/with-podman-gateway.sh +++ b/e2e/with-podman-gateway.sh @@ -117,19 +117,12 @@ PODMAN_SERVICE_PID="" PODMAN_SERVICE_LOG="${WORKDIR}/podman-service.log" PODMAN_SOCKET="" GPU_MODE="${OPENSHELL_E2E_PODMAN_GPU:-0}" -OIDC_MODE="${OPENSHELL_E2E_OIDC_GATEWAY:-0}" -OIDC_ISSUER="${OPENSHELL_E2E_OIDC_ISSUER:-}" ADDITIONAL_CA_MODE="${OPENSHELL_E2E_ADDITIONAL_CA:-0}" ADDITIONAL_CA_SERVER_PID="" ADDITIONAL_CA_SERVER_LOG="${WORKDIR}/additional-ca-server.log" ADDITIONAL_CA_DIR="${WORKDIR}/additional-ca" ADDITIONAL_CA_PORT="" -if [ "${OIDC_MODE}" = "1" ] && [ -z "${OIDC_ISSUER}" ]; then - echo "ERROR: OPENSHELL_E2E_OIDC_ISSUER is required when OPENSHELL_E2E_OIDC_GATEWAY=1" >&2 - exit 2 -fi - # Isolate CLI/SDK gateway metadata from the developer's real config. export XDG_CONFIG_HOME="${WORKDIR}/config" @@ -572,7 +565,6 @@ e2e_write_podman_gateway_config \ "${SUPERVISOR_IMAGE}" \ "${SANDBOX_BOUNDARY_IMAGE}" \ "${OPENSHELL_PODMAN_SOCKET:-}" \ - "${OIDC_MODE}" \ "${OPENSHELL_OIDC_ISSUER:-}" if [ "${ADDITIONAL_CA_MODE}" = "1" ]; then CONFIG_WITH_ADDITIONAL_CA="${GATEWAY_CONFIG}.additional-ca" @@ -642,25 +634,9 @@ GATEWAY_ARGS=( --enable-websocket-tunnel true --db-url "sqlite:${STATE_DIR}/gateway.db?mode=rwc" --log-level info + --tls-client-ca "${PKI_DIR}/ca.crt" ) -if [ "${OIDC_MODE}" = "1" ]; then - GATEWAY_ARGS+=( - --oidc-issuer "${OIDC_ISSUER}" - --oidc-audience openshell-cli - --oidc-scopes-claim scope - ) - case "${OIDC_ISSUER}" in - http://127.*|http://\[::1\]*) - GATEWAY_ARGS+=(--oidc-dangerously-allow-insecure-http true) - ;; - esac -else - GATEWAY_ARGS+=( - --tls-client-ca "${PKI_DIR}/ca.crt" - ) -fi - e2e_write_gateway_args_file "${GATEWAY_ARGS_FILE}" "${GATEWAY_ARGS[@]}" e2e_export_gateway_restart_metadata \ "${GATEWAY_BIN}" \ @@ -676,24 +652,19 @@ GATEWAY_PID=$! printf '%s\n' "${GATEWAY_PID}" >"${GATEWAY_PID_FILE}" GATEWAY_NAME="openshell-e2e-podman-${HOST_PORT}" -if [ "${OIDC_MODE}" = "1" ]; then - CLI_GATEWAY_ENDPOINT="https://${CLI_ENDPOINT_HOST}:${HOST_PORT}" - export OPENSHELL_E2E_OIDC_GATEWAY_ENDPOINT="${CLI_GATEWAY_ENDPOINT}" -else - CLI_GATEWAY_ENDPOINT="https://${CLI_ENDPOINT_HOST}:${HOST_PORT}" - e2e_register_mtls_gateway \ - "${XDG_CONFIG_HOME}" \ - "${GATEWAY_NAME}" \ - "${CLI_GATEWAY_ENDPOINT}" \ - "${HOST_PORT}" \ - "${PKI_DIR}" \ - "${OPENSHELL_OIDC_ISSUER:-}" -fi +CLI_GATEWAY_ENDPOINT="https://${CLI_ENDPOINT_HOST}:${HOST_PORT}" +e2e_register_mtls_gateway \ + "${XDG_CONFIG_HOME}" \ + "${GATEWAY_NAME}" \ + "${CLI_GATEWAY_ENDPOINT}" \ + "${HOST_PORT}" \ + "${PKI_DIR}" \ + "${OPENSHELL_OIDC_ISSUER:-}" export OPENSHELL_GATEWAY="${GATEWAY_NAME}" export OPENSHELL_PROVISION_TIMEOUT="${OPENSHELL_PROVISION_TIMEOUT:-300}" -if [ "${OIDC_MODE}" = "1" ] || [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then +if [ -n "${OPENSHELL_OIDC_ISSUER:-}" ]; then export OPENSHELL_E2E_OIDC=1 export OPENSHELL_E2E_OIDC_SCOPES=1 fi @@ -719,22 +690,7 @@ if [ "${elapsed}" -ge "${timeout}" ]; then exit 1 fi -# Seed the example profiles the provider tests rely on. The mTLS lanes already -# have a registered gateway identity; the OIDC lanes deliberately skip -# registration and have no token yet, so establish an administrator session -# first rather than importing unauthenticated. -if [ "${OIDC_MODE}" = "1" ]; then - e2e_register_oidc_admin_session \ - "${XDG_CONFIG_HOME}" \ - "${GATEWAY_NAME}" \ - "${CLI_GATEWAY_ENDPOINT}" \ - "${HOST_PORT}" \ - "${OIDC_ISSUER}" \ - "${OPENSHELL_E2E_OIDC_USERNAME:-admin@test}" \ - "${OPENSHELL_E2E_OIDC_PASSWORD:-admin}" \ - "${PKI_DIR}" \ - "${CLI_BIN}" || exit 1 -fi +# Seed the example profiles the provider tests rely on. e2e_import_example_provider_profiles "${CLI_BIN}" "${ROOT}" || exit 1 echo "Running e2e command against ${CLI_GATEWAY_ENDPOINT}: $*" diff --git a/tasks/scripts/test-gateway-config.sh b/tasks/scripts/test-gateway-config.sh index 109fed8a76..dd2a9f5771 100755 --- a/tasks/scripts/test-gateway-config.sh +++ b/tasks/scripts/test-gateway-config.sh @@ -44,12 +44,12 @@ e2e_write_podman_gateway_config \ "${WORK}/podman.toml" "${ROOT}" "${WORK}/pki" "${WORK}/jwt" \ test-gateway 0 "${WORK}/driver.sock" test-network 18181 \ workload:test 15 supervisor:test sandbox:test \ - "${WORK}/podman.sock" 0 "" + "${WORK}/podman.sock" "" e2e_write_podman_gateway_config \ "${WORK}/podman-external.toml" "${ROOT}" "${WORK}/pki" "${WORK}/jwt" \ test-gateway 1 "${WORK}/driver.sock" test-network 18181 \ workload:test 15 supervisor:test sandbox:test \ - "${WORK}/podman.sock" 0 "" + "${WORK}/podman.sock" "" printf '%s\n' \ 'import sys, tomllib' \ diff --git a/tasks/test.toml b/tasks/test.toml index ca254eec4d..21e4751fa0 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -235,18 +235,6 @@ run = "e2e/rust/e2e-podman.sh" description = "Run the Podman Rust e2e targets enabled in required branch CI" run = "OPENSHELL_E2E_PODMAN_TEST_SET=ci e2e/rust/e2e-podman.sh" -["e2e:oidc-pkce"] -description = "Run Linux browser PKCE and RBAC e2e tests against Keycloak and a Podman gateway" -run = [ - "CONTAINER_RUNTIME=podman e2e/with-keycloak.sh env OPENSHELL_E2E_OIDC_GATEWAY=1 e2e/with-podman-gateway.sh cargo test --manifest-path e2e/rust/Cargo.toml --features e2e-oidc-pkce --test oidc_pkce", -] - -["e2e:oidc-pkce:docker"] -description = "Run Linux browser PKCE and RBAC e2e tests against Keycloak and a Docker gateway" -run = [ - "CONTAINER_RUNTIME=docker e2e/with-keycloak.sh env OPENSHELL_E2E_OIDC_GATEWAY=1 e2e/with-docker-gateway.sh cargo test --manifest-path e2e/rust/Cargo.toml --features e2e-oidc-pkce --test oidc_pkce", -] - ["e2e:podman:gpu"] description = "Run GPU e2e against a standalone gateway with the Podman compute driver" env = { OPENSHELL_E2E_PODMAN_GPU = "1", OPENSHELL_E2E_PODMAN_TEST = "gpu", OPENSHELL_E2E_PODMAN_FEATURES = "e2e-podman-gpu" } From 6a31bce4cc1f04b5e37ca397aa5d757f4816a25c Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Fri, 4 Dec 2026 10:33:43 -0800 Subject: [PATCH 3/3] test(conformance): require the default DNS IPv6 mode and skip conformance in the HA smoke job Signed-off-by: Matthew Grossman --- .github/workflows/branch-e2e.yml | 5 +++-- .github/workflows/e2e-kubernetes-test.yml | 6 ++++++ .../suites/conformance/src/policy_dns_ipv6.rs | 21 +++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/branch-e2e.yml b/.github/workflows/branch-e2e.yml index 87d9a38db7..1dbaf348c3 100644 --- a/.github/workflows/branch-e2e.yml +++ b/.github/workflows/branch-e2e.yml @@ -781,7 +781,7 @@ jobs: e2e-task: e2e:kubernetes:tracing kubernetes-ha-e2e: - needs: [pr_metadata, build-binaries-linux, build-conformance, build-images] + needs: [pr_metadata, build-binaries-linux, build-images] if: needs.pr_metadata.outputs.should_run == 'true' && needs.pr_metadata.outputs.run_kubernetes_ha_e2e == 'true' permissions: actions: read @@ -790,9 +790,10 @@ jobs: uses: ./.github/workflows/e2e-kubernetes-test.yml with: checkout-ref: ${{ needs.pr_metadata.outputs.sha }} - prebuilt-conformance: true image-tag: ${{ needs.pr_metadata.outputs.sha }} job-name: Kubernetes HA E2E (Rust smoke) + # The ubuntu-k3s/k3s-ha suite row runs conformance on an HA gateway. + conformance: false extra-helm-values: deploy/helm/openshell/ci/values-high-availability.yaml external-postgres-secret: openshell-ha-pg test-name: kubernetes_ha_rebalancing diff --git a/.github/workflows/e2e-kubernetes-test.yml b/.github/workflows/e2e-kubernetes-test.yml index 340beb81f7..90f0bcac13 100644 --- a/.github/workflows/e2e-kubernetes-test.yml +++ b/.github/workflows/e2e-kubernetes-test.yml @@ -67,6 +67,11 @@ on: required: false type: string default: "" + conformance: + description: "Run the conformance suite before the Rust e2e tests" + required: false + type: boolean + default: true prebuilt-conformance: description: "Run conformance with the openshell-conformance artifact instead of building it" required: false @@ -169,6 +174,7 @@ jobs: OPENSHELL_E2E_KUBE_EXTRA_VALUES: ${{ inputs.extra-helm-values }} OPENSHELL_E2E_KUBE_EXTERNAL_POSTGRES_SECRET: ${{ inputs.external-postgres-secret }} OPENSHELL_E2E_KUBE_TEST: ${{ inputs.test-name }} + OPENSHELL_E2E_KUBE_CONFORMANCE: ${{ !inputs.conformance && '0' || '' }} OPENSHELL_E2E_KUBERNETES_FEATURES: ${{ inputs.kubernetes-features }} OPENSHELL_E2E_KUBE_USE_ENVOY: ${{ inputs.use-envoy-gateway && '1' || '0' }} IMAGE_TAG: ${{ inputs.image-tag }} diff --git a/tests/suites/conformance/src/policy_dns_ipv6.rs b/tests/suites/conformance/src/policy_dns_ipv6.rs index c6ab66b23a..e60cc5afe5 100644 --- a/tests/suites/conformance/src/policy_dns_ipv6.rs +++ b/tests/suites/conformance/src/policy_dns_ipv6.rs @@ -40,9 +40,9 @@ fn decision(logs: &Logs) -> Option { }) } -/// The supervisor reads its routing tables and honors the requested mode: -/// `auto` turns IPv6 answers on exactly when the namespace is IPv6-only. It -/// also reports the NAT64 prefixes it classifies for SSRF checks. +/// The supervisor reads its routing tables, and the default `auto` mode turns +/// IPv6 answers on exactly when the namespace is IPv6-only. It also reports +/// the NAT64 prefixes it classifies for SSRF checks. #[testkit::test] async fn supervisor_reports_ipv6_egress_decision(cx: &mut Context) -> testkit::Result { let sandbox = cx @@ -62,16 +62,11 @@ async fn supervisor_reports_ipv6_egress_decision(cx: &mut Context) -> testkit::R decision.route_state != "route_table_unavailable", "the supervisor couldn't read its routing tables:\n{logs}" ); - let expected = match decision.requested.as_str() { - "auto" => decision.route_state == "ipv6_only", - "enabled" => true, - "disabled" => false, - other => { - return Err(testkit::Error::msg(format!( - "unexpected requested mode {other}:\n{logs}" - ))); - } - }; + testkit::ensure!( + decision.requested == "auto", + "the supervisor should run the default auto mode: {decision:?}\n{logs}" + ); + let expected = decision.route_state == "ipv6_only"; testkit::ensure!( decision.enabled == expected, "IPv6 egress should be {} for {decision:?}:\n{logs}",