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-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/.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/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("