From 8d19308c083b794928fb94d00274b337a07c14f7 Mon Sep 17 00:00:00 2001 From: Max Dubrinsky Date: Mon, 14 Sep 2026 16:49:44 +0000 Subject: [PATCH 1/2] fix(bootstrap): emit RFC 5280 extensions on generated gateway PKI (#3286) generate_pki minted a CA with no key usage and server and client leaves with no Authority Key Identifier. RFC 5280 requires both, and verifiers that enforce it reject the chain: OpenSSL X509_STRICT fails with "Missing Authority Key Identifier", and Python 3.13 turned that flag on by default in ssl.create_default_context(). rustls and BoringSSL do not enforce it, so gRPC clients kept working while an HTTPS client built on Python 3.13 (for example a platform proxying to an exposed sandbox service) could not complete a handshake with a pkiInitJob-provisioned gateway at all. cert-manager PKI was unaffected. Set keyCertSign and cRLSign on the CA and use_authority_key_identifier on both leaves, matching what the sandbox L7 CA already does. Add a test that parses the bundle and asserts the extensions, including that each leaf AKI matches the CA SKI. Verified: openssl verify -x509_strict accepts both leaves, and a strict Python 3.13 client completes an mTLS handshake against a server using the new bundle where the previous bundle reproduces the failure. Signed-off-by: Max Dubrinsky --- Cargo.lock | 1 + crates/openshell-bootstrap/Cargo.toml | 1 + crates/openshell-bootstrap/src/pki.rs | 59 ++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c633b7f26c..e34d588c3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3949,6 +3949,7 @@ dependencies = [ "tempfile", "tokio", "tracing", + "x509-parser", ] [[package]] diff --git a/crates/openshell-bootstrap/Cargo.toml b/crates/openshell-bootstrap/Cargo.toml index 435024e302..3705bdced2 100644 --- a/crates/openshell-bootstrap/Cargo.toml +++ b/crates/openshell-bootstrap/Cargo.toml @@ -22,6 +22,7 @@ tokio = { workspace = true } tracing = { workspace = true } [dev-dependencies] +x509-parser = "0.16" [lints] workspace = true diff --git a/crates/openshell-bootstrap/src/pki.rs b/crates/openshell-bootstrap/src/pki.rs index ed6e839bf6..5e5839a11a 100644 --- a/crates/openshell-bootstrap/src/pki.rs +++ b/crates/openshell-bootstrap/src/pki.rs @@ -3,7 +3,9 @@ use crate::jwt::{JwtKeyMaterial, generate_jwt_key}; use miette::{IntoDiagnostic, Result, WrapErr}; -use rcgen::{BasicConstraints, CertificateParams, DnType, Ia5String, IsCa, KeyPair, SanType}; +use rcgen::{ + BasicConstraints, CertificateParams, DnType, Ia5String, IsCa, KeyPair, KeyUsagePurpose, SanType, +}; use std::net::IpAddr; /// All PEM-encoded materials produced by [`generate_pki`]. @@ -59,6 +61,7 @@ pub fn generate_pki(extra_sans: &[String]) -> Result { .into_diagnostic() .wrap_err("failed to create CA params")?; ca_params.is_ca = IsCa::Ca(BasicConstraints::Unconstrained); + ca_params.key_usages = vec![KeyUsagePurpose::KeyCertSign, KeyUsagePurpose::CrlSign]; ca_params .distinguished_name .push(DnType::OrganizationName, "openshell"); @@ -80,6 +83,7 @@ pub fn generate_pki(extra_sans: &[String]) -> Result { .into_diagnostic() .wrap_err("failed to create server cert params")?; server_params.subject_alt_names = server_sans; + server_params.use_authority_key_identifier_extension = true; server_params .distinguished_name .push(DnType::CommonName, "openshell-server"); @@ -96,6 +100,7 @@ pub fn generate_pki(extra_sans: &[String]) -> Result { let mut client_params = CertificateParams::new(Vec::::new()) .into_diagnostic() .wrap_err("failed to create client cert params")?; + client_params.use_authority_key_identifier_extension = true; client_params .distinguished_name .push(DnType::CommonName, "openshell-client"); @@ -178,6 +183,58 @@ mod tests { assert!(bundle.server_cert_pem.contains("BEGIN CERTIFICATE")); } + #[test] + fn generate_pki_emits_strict_verifier_extensions() { + use x509_parser::pem::parse_x509_pem; + use x509_parser::prelude::{FromDer, ParsedExtension, X509Certificate}; + + let bundle = generate_pki(&[]).expect("generate_pki failed"); + let parse = |pem: &str| -> Vec { + parse_x509_pem(pem.as_bytes()) + .expect("valid PEM") + .1 + .contents + }; + let ca_der = parse(&bundle.ca_cert_pem); + let ca = X509Certificate::from_der(&ca_der).expect("valid CA cert").1; + let ca_key_usage = ca + .key_usage() + .expect("readable key usage") + .expect("CA has a key usage extension"); + assert!(ca_key_usage.value.key_cert_sign()); + assert!(ca_key_usage.value.crl_sign()); + let ca_ski = ca + .get_extension_unique(&x509_parser::oid_registry::OID_X509_EXT_SUBJECT_KEY_IDENTIFIER) + .expect("readable SKI") + .expect("CA has a Subject Key Identifier"); + + for (name, pem) in [ + ("server", &bundle.server_cert_pem), + ("client", &bundle.client_cert_pem), + ] { + let der = parse(pem); + let cert = X509Certificate::from_der(&der).expect("valid leaf cert").1; + let aki = cert + .get_extension_unique( + &x509_parser::oid_registry::OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER, + ) + .expect("readable AKI") + .unwrap_or_else(|| panic!("{name} cert has no Authority Key Identifier")); + let ( + ParsedExtension::AuthorityKeyIdentifier(aki), + ParsedExtension::SubjectKeyIdentifier(ski), + ) = (aki.parsed_extension(), ca_ski.parsed_extension()) + else { + panic!("{name}: unexpected extension shapes"); + }; + let key_id = aki + .key_identifier + .as_ref() + .unwrap_or_else(|| panic!("{name} AKI has no key identifier")); + assert_eq!(key_id.0, ski.0, "{name} AKI must match the CA SKI"); + } + } + #[test] fn build_server_sans_includes_defaults_and_extras() { let extras = vec!["192.168.1.100".to_string(), "remote.host".to_string()]; From cc780d4e17512e8f804f68c153c033fe6584ae3a Mon Sep 17 00:00:00 2001 From: Brandon Squizzato <35474886+bsquizz@users.noreply.github.com> Date: Mon, 14 Sep 2026 17:39:15 +0000 Subject: [PATCH 2/2] feat(helm): add BackendTLSPolicy support (#2728) * feat(helm): add optional BackendTLSPolicy for e2e TLS Add grpcRoute.backendTLSPolicy values to optionally create a BackendTLSPolicy resource that enables end-to-end TLS between the Gateway proxy and the OpenShell gateway pod. The Gateway proxy terminates client-facing TLS and re-encrypts when connecting to the backend, validating the pod's certificate against a user-supplied CA ConfigMap. This removes the requirement to set server.disableTls=true when using HTTPS at the Gateway listener. Supported on OpenShift 4.22+ and other platforms with BackendTLSPolicy support in the Gateway API implementation. Update OpenShift and ingress documentation with e2e TLS instructions. Signed-off-by: Brandon Squizzato * feat(helm,server): auto-create backend CA ConfigMap in certgen hook Extend the generate-certs command with --backend-ca-configmap-name and --backend-ca-source-secret flags. When BackendTLSPolicy is enabled, the certgen pre-install hook creates the CA ConfigMap automatically: - pkiInitJob mode (default): uses the CA from the generated PKI bundle. Fully automatic on first install. - cert-manager mode: reads ca.crt from the server TLS Secret. On first install the Secret does not exist yet (cert-manager reconciles after templates are applied), so the ConfigMap is created on the first helm upgrade. Logs a warning on the initial skip. The caCertificateConfigMapName value now defaults to -backend-ca when empty, so users only need to set backendTLSPolicy.enabled=true. Update certgen RBAC to include configmaps get/create when the feature is enabled. Add CLI arg parsing tests for the new flags. Signed-off-by: Brandon Squizzato * refactor(helm): add server.tls.enableMtls flag for mTLS control Replace automatic mTLS disabling based on BackendTLSPolicy with an explicit server.tls.enableMtls flag that defaults to true. The user is now responsible for setting this to false when using BackendTLSPolicy, as ingress proxies cannot present client certificates to backends. Updated: - values.yaml: Added server.tls.enableMtls (default true) - gateway-config.yaml: Check enableMtls instead of backendTLSPolicy - _gateway-workload.tpl: Check enableMtls for client CA mount - Tests: Updated to use enableMtls flag - Docs: Added enableMtls=false to BackendTLSPolicy examples - README: Document new flag and BackendTLSPolicy requirement Signed-off-by: Brandon Squizzato * docs(helm): clarify cert-manager backend CA ConfigMap workflow Update documentation to explain the two-step install process required when using cert-manager with BackendTLSPolicy: 1. helm install - cert-manager issues the server certificate, but the certgen hook can't create the backend CA ConfigMap yet (cert-manager reconciles after templates are applied) 2. helm upgrade - certgen hook reads the CA from the cert-manager-issued certificate and creates the ConfigMap Previously, the docs said "created on first upgrade" without explaining why or that the feature won't work until then. The updated docs now: - Explain the timing issue (cert-manager reconciles after chart install) - Provide clear steps for the cert-manager workflow - Note that pkiInitJob (default) creates it immediately on install - Clarify that users must wait for the Certificate to be Ready before running the second upgrade Signed-off-by: Brandon Squizzato * fix(docs): remove incorrect external hostname requirement for BackendTLSPolicy BackendTLSPolicy validates the backend certificate against the service FQDN (e.g., openshell.openshell.svc.cluster.local), not the external hostname. The external hostname only needs to be on the Gateway listener certificate for client-facing TLS. The default certManager.serverDnsNames already includes all required service FQDN variants, so no configuration is needed for BackendTLSPolicy to work. Fixed incorrect documentation that claimed: - "The server certificate SAN list must include the external hostname" - Users need to "configure certManager.serverDnsNames with the external hostname" Removed the unnecessary pkiInitJob.serverDnsNames override from the example and clarified that: - Gateway listener certificate needs the external hostname (for clients) - Backend certificate needs the service FQDN (for Gateway proxy) - The service FQDN is already in the defaults Signed-off-by: Brandon Squizzato * docs: clarify ACME with LetsEncrypt reference Change all references from "ACME issuer" to "LetsEncrypt/ACME issuer" to help users understand that LetsEncrypt is the most common ACME provider and what ACME means in practice. Updated: - docs/kubernetes/managing-certificates.mdx - docs/kubernetes/openshift.mdx - deploy/helm/openshell/values.yaml - deploy/helm/openshell/README.md - deploy/helm/openshell/ci/values-openshift-route-cert-manager.yaml Signed-off-by: Brandon Squizzato * docs(openshift): restructure end-to-end TLS options and clarify Gateway hostname Reorganize the OpenShift production deployment documentation: 1. Changed main section from "Production Deployments" to "Options for end-to-end TLS" for better clarity 2. Renamed subsections for consistency and clarity: - "End-to-end TLS using Gateway API and BackendTLSPolicy (OpenShift 4.22+)" - "End-to-end TLS using pass-through Route (all OpenShift versions)" 3. Clarified that the Gateway hostname is typically a wildcard: "typically a wildcard like *.openshell-ingress-gw.example.com" 4. Removed the recommendation to copy the cluster's wildcard certificate from openshift-ingress namespace, as this is not a recommended security best practice These changes make it clearer that users have two end-to-end TLS options and help them understand the typical naming pattern for Gateway hostnames. Signed-off-by: Brandon Squizzato * feat(helm): eliminate two-stage install for BackendTLSPolicy with cert-manager When using BackendTLSPolicy with cert-manager, the certgen hook now polls for up to 90 seconds waiting for cert-manager to issue the TLS certificate before creating the backend CA ConfigMap. This eliminates the need for a second `helm upgrade` in most cases. The hook polls every 2 seconds with progress logging every 10 seconds. If cert-manager takes longer than 90 seconds, the hook times out gracefully and logs a warning, preserving the fallback to manual ConfigMap creation or a second upgrade. The Job's activeDeadlineSeconds is 120s, so the 90s timeout leaves 30s margin for ConfigMap creation and hook completion. Signed-off-by: Brandon Squizzato * feat(helm): add configurable timeout for certgen hook Add `pkiInitJob.timeoutSeconds` Helm value (default 120) to control how long the certgen hook Job can run. When using cert-manager with BackendTLSPolicy, the hook polls for (timeoutSeconds - 30) seconds to leave margin for ConfigMap creation and cleanup. This allows users to increase the timeout for environments where cert-manager takes longer than 90 seconds to issue certificates, without requiring code changes. Example usage: ```yaml pkiInitJob: timeoutSeconds: 180 # Hook polls for 150 seconds ``` Signed-off-by: Brandon Squizzato * docs(helm): document configurable certgen timeout Update documentation to mention the pkiInitJob.timeoutSeconds value and how it affects the cert-manager polling behavior when using BackendTLSPolicy. Signed-off-by: Brandon Squizzato * feat(helm): add configurable failure behavior for certgen timeout Add `pkiInitJob.failOnTimeout` Helm value (default false) to control whether the certgen hook fails or succeeds when cert-manager does not issue a certificate within the polling timeout. When false (default), the hook succeeds with a warning and users can run `helm upgrade` after cert-manager issues the certificate to create the backend CA ConfigMap. This provides backwards-compatible behavior. When true, the hook fails immediately if the timeout is reached, providing clear feedback that BackendTLSPolicy is non-functional. This is useful for strict validation requirements where incomplete installs should fail fast. Example usage: ```yaml pkiInitJob: timeoutSeconds: 180 failOnTimeout: true # Fail install if cert-manager takes >150s ``` Signed-off-by: Brandon Squizzato * feat(helm): change failOnTimeout default to true and add troubleshooting docs Change `pkiInitJob.failOnTimeout` default from false to true to provide immediate feedback when cert-manager does not issue certificates within the polling timeout. This prevents silent failures where BackendTLSPolicy is non-functional but the install appears to succeed. Add comprehensive troubleshooting section to docs/kubernetes/ingress.mdx documenting the specific error "TLS error: Secret is not supplied by SDS" that occurs when the backend CA ConfigMap is missing, with step-by-step resolution instructions. Updated comments in values.yaml to clearly document the default behavior and explain when administrators might see connectivity errors if they override the default to failOnTimeout=false. BREAKING CHANGE: pkiInitJob.failOnTimeout now defaults to true. Helm installs will fail if cert-manager takes longer than (timeoutSeconds - 30) seconds to issue certificates. To restore the old behavior of allowing installs to succeed with a warning, set `pkiInitJob.failOnTimeout=false`. Signed-off-by: Brandon Squizzato * fix(helm): make cert-manager resources pre-install hooks to fix ordering Make Certificate and Issuer resources run as pre-install/pre-upgrade hooks with weight -30, before the certgen hook (weight -20). This fixes the chicken-and-egg problem where the certgen hook was waiting for Secrets created by Certificates that hadn't been created yet. **Hook ordering:** 1. Certificate and Issuer resources created (weight -30) 2. cert-manager issues certificates and creates Secrets 3. certgen hook runs (weight -20), finds Secrets, creates ConfigMap 4. Main resources (StatefulSet, Service, etc.) created Previously, the certgen pre-install hook would run before any resources were created, poll for a non-existent Secret, timeout, and fail. The Certificate resources would never get created because Helm waits for all pre-install hooks to succeed before creating main resources. This fix allows single-stage installs to work reliably as long as cert-manager can issue certificates within the polling timeout. Signed-off-by: Brandon Squizzato * feat(helm): add validation to prevent enableMtls with BackendTLSPolicy Add Helm chart validation that fails the install if both server.tls.enableMtls=true and grpcRoute.backendTLSPolicy.enabled=true are set, since this is an invalid configuration. BackendTLSPolicy requires mTLS to be disabled because the Gateway proxy cannot present client certificates to the backend. This validation provides immediate, clear feedback at install time rather than allowing the misconfiguration to be discovered through runtime errors. Example error message: ``` Error: grpcRoute.backendTLSPolicy requires mTLS to be disabled because the Gateway proxy cannot present client certificates to the backend; set server.tls.enableMtls=false ``` Also updated documentation to mention this validation check. Signed-off-by: Brandon Squizzato * docs(helm): clarify pkiInitJob.timeoutSeconds polling behavior Improve documentation to clearly explain that pkiInitJob.timeoutSeconds controls the Job deadline, but the actual polling timeout is (timeoutSeconds - 30) to reserve 30 seconds for ConfigMap creation and cleanup. Added concrete example: "timeoutSeconds=180 allows 150 seconds of polling" to make the relationship explicit and avoid confusion where users might expect the hook to poll for the full timeout value. Updated both values.yaml inline comments and ingress.mdx documentation for consistency. Signed-off-by: Brandon Squizzato * docs(openshift): remove outdated two-stage install instructions Update OpenShift documentation to reflect that single-stage installs now work with cert-manager and BackendTLSPolicy. The Certificate resources run as pre-install hooks (weight -30) before certgen (weight -20), allowing the hook to poll for and find the issued certificates. Removed the outdated two-step process: 1. helm install (cert-manager issues cert, hook logs warning) 2. helm upgrade (hook creates ConfigMap) Replaced with current single-stage behavior: - Certificate resources created as pre-install hooks - certgen hook polls for up to 90 seconds (configurable) - Single helm install succeeds in most cases - Fails fast by default if timeout reached This brings openshift.mdx in line with the already-updated ingress.mdx documentation. Signed-off-by: Brandon Squizzato * fix(helm): make pkiInitJob.timeoutSeconds the actual polling duration The timeout value now represents the actual polling time that users experience when waiting for cert-manager to issue certificates. The Job activeDeadlineSeconds is set to (timeoutSeconds + 30) to allow buffer time for ConfigMap creation and cleanup. Previously, the hook polled for (timeoutSeconds - 30) seconds, which was confusing when users set timeoutSeconds=180 and only got 150 seconds of actual polling. Updated documentation in values.yaml, ingress.mdx, and openshift.mdx to reflect the clearer behavior. Signed-off-by: Brandon Squizzato * docs(helm): update values.yaml and README with correct polling duration Updated the caCertificateConfigMapName description to reflect that the hook polls for exactly pkiInitJob.timeoutSeconds seconds, not (timeoutSeconds - 30) seconds. Regenerated README.md with helm-docs. Signed-off-by: Brandon Squizzato * docs(kubernetes): add OIDC configuration to helm install and CLI examples Updated all helm install and openshell gateway add examples in ingress.mdx and openshift.mdx to include OIDC issuer and audience configuration. Examples now use concrete placeholder values: - OIDC issuer: https://keycloak.example.com/realms/openshell - OIDC audience: openshell-cli - Hostname: gateway.example.com - ClusterIssuer: letsencrypt-prod This makes it clearer how to configure OIDC authentication, which is required when using BackendTLSPolicy or HTTPS termination since the Gateway proxy cannot present client certificates to the backend. Signed-off-by: Brandon Squizzato * docs(kubernetes): explicitly list OIDC client ID in gateway add examples Added --oidc-client-id openshell-cli to all openshell gateway add commands in ingress.mdx and openshift.mdx, making the default client ID explicit in the examples even though it's the CLI default. This improves clarity and helps users understand the complete OIDC configuration needed for gateway registration. Signed-off-by: Brandon Squizzato * fix(helm): address PR review feedback for BackendTLSPolicy - Read backend CA from the authoritative server Secret instead of the in-memory PKI bundle so enabling BackendTLSPolicy on an existing release uses the CA that actually signed the server certificate. - Reconcile the backend CA ConfigMap on every hook run (compare and update) instead of skipping when it already exists, so CA rotations propagate automatically. - Remove hook annotations from cert-manager Issuer/Certificate resources so they remain regular release objects managed by Helm lifecycle. Split the cert-manager backend CA ConfigMap creation into a separate post-install/post-upgrade hook Job that polls after cert-manager Certificate resources are applied. - Update architecture/gateway.md, docs/reference/gateway-config.mdx, debug-openshell-cluster skill, and helm-dev-environment skill with BackendTLSPolicy, backend CA ConfigMap, enableMtls, and timeout documentation. Signed-off-by: Brandon Squizzato Signed-off-by: Brandon Squizzato * fix(docs): resolve markdown lint errors in helm README and kubernetes docs Escape inline HTML angle brackets in README.md template placeholders, remove trailing spaces, and add blank lines around fenced code blocks in numbered lists. Signed-off-by: Brandon Squizzato * Update docs * fix(helm): escape inline HTML in values.yaml descriptions and sync mise lockfile Wrap `` and `` template placeholders in backticks so markdownlint does not flag them as inline HTML (MD033). Regenerate mise.lock to match current mise.toml after rebase onto main. Signed-off-by: Brandon Squizzato * Run 'mise lock' * fix: align mise.lock with CI mise version output The lockfile was regenerated locally with mise 2026.8.10 which resolves uv Linux artifacts to gnu variants and adds provenance_verified fields, but CI uses v2026.4.25 which produces musl variants without those fields. Signed-off-by: Brandon Squizzato * fix(docs): correct cert-manager hook ordering and clientCaSecretName comment Update ingress.mdx and openshift.mdx to describe Certificate resources as regular release objects with a post-install/post-upgrade Job, matching the current implementation and architecture/gateway.md. Fix values.yaml clientCaSecretName comment to state that "" disables client certificate verification, matching the helper and access-control docs. Signed-off-by: Brandon Squizzato --------- Signed-off-by: Brandon Squizzato Signed-off-by: Brandon Squizzato Signed-off-by: Brandon Squizzato --- .agents/skills/helm-dev-environment/SKILL.md | 29 +++ architecture/gateway.md | 19 ++ crates/openshell-server/src/certgen.rs | 196 +++++++++++++++++- crates/openshell-server/src/cli.rs | 53 +++++ deploy/helm/openshell/README.md | 13 +- deploy/helm/openshell/README.md.gotmpl | 3 + .../values-openshift-route-cert-manager.yaml | 2 +- deploy/helm/openshell/templates/_helpers.tpl | 8 + .../templates/backend-tls-policy.yaml | 29 +++ deploy/helm/openshell/templates/certgen.yaml | 68 +++++- deploy/helm/openshell/templates/gateway.yaml | 4 +- .../openshell/tests/gateway_config_test.yaml | 18 ++ .../tests/statefulset_client_ca_test.yaml | 19 ++ deploy/helm/openshell/values.yaml | 58 +++++- docs/kubernetes/ingress.mdx | 77 ++++++- docs/kubernetes/managing-certificates.mdx | 2 +- docs/kubernetes/openshift.mdx | 137 ++++++++++-- docs/reference/gateway-config.mdx | 3 + mise.lock | 8 - skills/debug-openshell-cluster/SKILL.md | 25 +++ 20 files changed, 735 insertions(+), 36 deletions(-) create mode 100644 deploy/helm/openshell/templates/backend-tls-policy.yaml diff --git a/.agents/skills/helm-dev-environment/SKILL.md b/.agents/skills/helm-dev-environment/SKILL.md index 780cf8b9c6..15198a891f 100644 --- a/.agents/skills/helm-dev-environment/SKILL.md +++ b/.agents/skills/helm-dev-environment/SKILL.md @@ -225,6 +225,35 @@ Envoy Gateway is already installed by Skaffold (the `envoy-gateway` Helm release service for the proxy; klipper-lb binds it to hostPort 80, reachable via the `8080:80` load balancer port mapping. +### BackendTLSPolicy (end-to-end TLS) + +To enable end-to-end TLS between the Gateway proxy and the gateway pod, add +BackendTLSPolicy values to the Helm install: + +```bash +helm upgrade --install openshell deploy/helm/openshell \ + --set grpcRoute.enabled=true \ + --set grpcRoute.backendTLSPolicy.enabled=true \ + --set server.tls.enableMtls=false \ + ... +``` + +This requires `server.tls.enableMtls=false` because ingress proxies cannot +present client certificates to the backend. The certgen hook creates a backend +CA ConfigMap from the server Secret's `ca.crt` key. With cert-manager, a +separate post-install Job polls for the cert-manager-issued certificate (up to +`pkiInitJob.timeoutSeconds`); with built-in PKI the ConfigMap is created in the +same pre-install hook. The ConfigMap is reconciled on every upgrade so CA +rotations propagate automatically. + +Key Helm values: +- `grpcRoute.backendTLSPolicy.enabled`: create the BackendTLSPolicy resource +- `grpcRoute.backendTLSPolicy.caCertificateConfigMapName`: override ConfigMap name +- `grpcRoute.backendTLSPolicy.hostname`: override backend validation hostname +- `server.tls.enableMtls`: must be `false` for BackendTLSPolicy +- `pkiInitJob.timeoutSeconds`: polling duration for cert-manager mode +- `pkiInitJob.failOnTimeout`: fail install if cert-manager times out + ### Keycloak OIDC One-time setup — only needed once per cluster lifetime: diff --git a/architecture/gateway.md b/architecture/gateway.md index 113eb5603c..3881618db1 100644 --- a/architecture/gateway.md +++ b/architecture/gateway.md @@ -762,6 +762,25 @@ requested present -> generate and write. This guards continuity across restarts and upgrades while still recovering cleanly if an operator deletes everything and starts over. +When `grpcRoute.backendTLSPolicy.enabled=true`, the certgen hook also creates a +`ConfigMap` containing the CA certificate (`ca.crt`) used by the Gateway proxy +to validate the backend pod's TLS certificate. The CA is always read from the +authoritative server Secret (not the in-memory bundle) so that enabling +BackendTLSPolicy on an existing release uses the CA that actually signed the +server certificate. The ConfigMap is reconciled on every hook run: if the CA +changes (rotation, re-issue), the ConfigMap is updated in place. In built-in PKI +mode the ConfigMap is created in the same pre-install hook. In cert-manager +mode, a separate post-install/post-upgrade hook Job polls for the cert-manager- +issued server Secret and then creates or updates the ConfigMap, because +cert-manager Certificate resources are regular release objects applied after +pre-install hooks. + +The `server.tls.enableMtls` value controls whether the gateway requires client +certificates. When `enableMtls` is `false`, the gateway runs HTTPS-only without +client certificate verification (use OIDC for identity instead). BackendTLSPolicy +requires `enableMtls=false` because the ingress proxy cannot present client +certificates to the backend. + Operators who manage TLS PKI with cert-manager enable `certManager.enabled`; cert-manager takes precedence over built-in TLS generation and the chart still renders the JWT-only hook. Operators who pre-create all TLS and JWT Secrets can diff --git a/crates/openshell-server/src/certgen.rs b/crates/openshell-server/src/certgen.rs index 1f3ffca02d..764ceba98c 100644 --- a/crates/openshell-server/src/certgen.rs +++ b/crates/openshell-server/src/certgen.rs @@ -24,7 +24,7 @@ use clap::Args; use k8s_openapi::ByteString; -use k8s_openapi::api::core::v1::Secret; +use k8s_openapi::api::core::v1::{ConfigMap, Secret}; use kube::Client; use kube::api::{Api, ObjectMeta, PostParams}; use miette::{IntoDiagnostic, Result, WrapErr}; @@ -78,6 +78,33 @@ pub struct CertgenArgs { /// For local debugging. #[arg(long)] dry_run: bool, + + /// Name of a `ConfigMap` to create containing the CA certificate (key: ca.crt) + /// for `BackendTLSPolicy` backend validation. The CA is always read from the + /// authoritative server Secret: --server-secret-name in full PKI mode, + /// --backend-ca-source-secret in --jwt-only mode. + #[arg(long, value_name = "NAME")] + backend_ca_configmap_name: Option, + + /// Name of an existing `Secret` containing a ca.crt key to populate the + /// backend CA `ConfigMap` from. Required with --jwt-only when + /// --backend-ca-configmap-name is set (typically the server TLS `Secret` + /// created by cert-manager). + #[arg(long, value_name = "NAME", requires = "backend_ca_configmap_name")] + backend_ca_source_secret: Option, + + /// Maximum time in seconds to poll for the backend CA source `Secret` when + /// using cert-manager. Defaults to 90 seconds. The Helm chart sets this to + /// (Job activeDeadlineSeconds - 30) to leave margin for `ConfigMap` creation. + #[arg(long, value_name = "SECONDS", default_value = "90")] + backend_ca_poll_timeout_seconds: u64, + + /// Fail with an error if the backend CA source `Secret` is not found within + /// the polling timeout. When false (default), the hook succeeds with a warning + /// and the `ConfigMap` is not created. The Helm chart sets this based on + /// pkiInitJob.failOnTimeout. + #[arg(long)] + backend_ca_fail_on_timeout: bool, } pub async fn run(args: CertgenArgs) -> Result<()> { @@ -97,7 +124,13 @@ pub async fn run(args: CertgenArgs) -> Result<()> { run_local(dir, &args.server_sans) } else { let bundle = generate_pki(&args.server_sans)?; - run_kubernetes(&args, &bundle).await + run_kubernetes(&args, &bundle).await?; + + if let Some(ref cm_name) = args.backend_ca_configmap_name { + create_backend_ca_configmap_if_needed(&args, cm_name).await?; + } + + Ok(()) } } @@ -293,6 +326,165 @@ async fn create_tls_secrets( Ok(()) } +fn extract_ca_from_secret(secret: &Secret, name: &str) -> Result { + let data = secret + .data + .as_ref() + .ok_or_else(|| miette::miette!("secret {name} has no data"))?; + let ca = data + .get("ca.crt") + .ok_or_else(|| miette::miette!("secret {name} has no ca.crt key"))?; + String::from_utf8(ca.0.clone()) + .into_diagnostic() + .wrap_err("ca.crt is not valid UTF-8") +} + +async fn create_backend_ca_configmap_if_needed( + args: &CertgenArgs, + configmap_name: &str, +) -> Result<()> { + let namespace = args + .namespace + .as_deref() + .ok_or_else(|| miette::miette!("--namespace is required (or set POD_NAMESPACE)"))?; + + let client = Client::try_default() + .await + .into_diagnostic() + .wrap_err("failed to construct Kubernetes client for backend CA ConfigMap")?; + let secret_api: Api = Api::namespaced(client.clone(), namespace); + let cm_api: Api = Api::namespaced(client, namespace); + + // Resolve the CA from the authoritative server Secret rather than the + // in-memory bundle so upgrades that enable BackendTLSPolicy on an + // existing release use the CA that actually signed the server cert. + let ca_pem = if let Some(source_secret) = &args.backend_ca_source_secret { + let poll_timeout = std::time::Duration::from_secs(args.backend_ca_poll_timeout_seconds); + let poll_interval = std::time::Duration::from_secs(2); + let start = std::time::Instant::now(); + + let secret = loop { + match secret_api + .get_opt(source_secret) + .await + .into_diagnostic() + .wrap_err_with(|| format!("failed to read secret {source_secret}"))? + { + Some(secret) => break secret, + None if start.elapsed() >= poll_timeout => { + let msg = format!( + "Backend CA source secret {source_secret} not found after {timeout_secs}s; \ + ConfigMap {configmap_name} not created. This is expected if cert-manager \ + is still issuing the certificate.", + timeout_secs = poll_timeout.as_secs() + ); + if args.backend_ca_fail_on_timeout { + return Err(miette::miette!( + "{msg} Install failed due to --backend-ca-fail-on-timeout." + )); + } + warn!( + secret = %source_secret, + configmap = %configmap_name, + timeout_secs = poll_timeout.as_secs(), + "{msg} Run helm upgrade after the TLS secret exists or the BackendTLSPolicy \ + will remain non-functional until the ConfigMap is created manually." + ); + return Ok(()); + } + None => { + if start.elapsed().as_secs().is_multiple_of(10) { + info!( + secret = %source_secret, + elapsed_secs = start.elapsed().as_secs(), + "Waiting for cert-manager to issue TLS certificate..." + ); + } + tokio::time::sleep(poll_interval).await; + } + } + }; + + info!( + secret = %source_secret, + elapsed_secs = start.elapsed().as_secs(), + "cert-manager TLS certificate found." + ); + extract_ca_from_secret(&secret, source_secret)? + } else if let Some(server_secret) = &args.server_secret_name { + let secret = secret_api + .get(server_secret) + .await + .into_diagnostic() + .wrap_err_with(|| format!("failed to read server secret {server_secret}"))?; + extract_ca_from_secret(&secret, server_secret)? + } else { + return Err(miette::miette!( + "--backend-ca-source-secret or --server-secret-name is required \ + with --backend-ca-configmap-name" + )); + }; + + // Reconcile: create or update so the backend CA stays current across + // CA rotations and upgrades. + if let Some(existing) = cm_api + .get_opt(configmap_name) + .await + .into_diagnostic() + .wrap_err_with(|| format!("failed to read configmap {configmap_name}"))? + { + let up_to_date = existing + .data + .as_ref() + .and_then(|d| d.get("ca.crt")) + .map(String::as_str) + == Some(&ca_pem); + if up_to_date { + info!( + namespace = %namespace, + configmap = %configmap_name, + "Backend CA ConfigMap is up-to-date, skipping." + ); + return Ok(()); + } + let mut updated = existing; + updated.data = Some(BTreeMap::from([("ca.crt".to_string(), ca_pem)])); + cm_api + .replace(configmap_name, &PostParams::default(), &updated) + .await + .into_diagnostic() + .wrap_err_with(|| format!("failed to update configmap {configmap_name}"))?; + info!( + namespace = %namespace, + configmap = %configmap_name, + "Backend CA ConfigMap updated with current CA." + ); + return Ok(()); + } + + let configmap = ConfigMap { + metadata: ObjectMeta { + name: Some(configmap_name.to_string()), + ..Default::default() + }, + data: Some(BTreeMap::from([("ca.crt".to_string(), ca_pem)])), + ..Default::default() + }; + + cm_api + .create(&PostParams::default(), &configmap) + .await + .into_diagnostic() + .wrap_err_with(|| format!("failed to create configmap {configmap_name}"))?; + + info!( + namespace = %namespace, + configmap = %configmap_name, + "Backend CA ConfigMap created." + ); + Ok(()) +} + fn tls_secret(name: &str, crt_pem: &str, key_pem: &str, ca_pem: &str) -> Secret { let mut data = BTreeMap::new(); data.insert( diff --git a/crates/openshell-server/src/cli.rs b/crates/openshell-server/src/cli.rs index c11d895618..9b01b749a4 100644 --- a/crates/openshell-server/src/cli.rs +++ b/crates/openshell-server/src/cli.rs @@ -2314,6 +2314,59 @@ mod tests { .expect("complete package-generated TLS paths may not exist before certificate generation"); } + #[test] + fn generate_certs_backend_ca_configmap_flags_parse() { + let _lock = ENV_LOCK + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + let _g1 = EnvVarGuard::remove("OPENSHELL_DB_URL"); + let _g2 = EnvVarGuard::remove("POD_NAMESPACE"); + + let cli = Cli::try_parse_from([ + "openshell-gateway", + "generate-certs", + "--namespace", + "openshell", + "--jwt-only", + "--jwt-secret-name", + "openshell-jwt-keys", + "--backend-ca-configmap-name", + "openshell-backend-ca", + "--backend-ca-source-secret", + "openshell-server-tls", + ]) + .expect("backend CA ConfigMap flags should parse with --jwt-only"); + + assert!(matches!( + cli.command, + Some(super::Commands::GenerateCerts(_)) + )); + } + + #[test] + fn generate_certs_backend_ca_source_secret_requires_configmap_name() { + let _lock = ENV_LOCK + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + let _g1 = EnvVarGuard::remove("OPENSHELL_DB_URL"); + let _g2 = EnvVarGuard::remove("POD_NAMESPACE"); + + let err = Cli::try_parse_from([ + "openshell-gateway", + "generate-certs", + "--namespace", + "openshell", + "--jwt-only", + "--jwt-secret-name", + "openshell-jwt-keys", + "--backend-ca-source-secret", + "openshell-server-tls", + ]) + .expect_err("--backend-ca-source-secret should require --backend-ca-configmap-name"); + + assert_eq!(err.kind(), clap::error::ErrorKind::MissingRequiredArgument); + } + #[test] fn bare_invocation_with_no_db_url_parses_for_runtime_defaults() { // db_url is Option at the clap level so subcommand parsing diff --git a/deploy/helm/openshell/README.md b/deploy/helm/openshell/README.md index 92bd2a9db8..3c32e24b67 100644 --- a/deploy/helm/openshell/README.md +++ b/deploy/helm/openshell/README.md @@ -56,6 +56,9 @@ helm install openshell oci://ghcr.io/nvidia/openshell/helm-chart --version -backend-ca` when empty. The certgen hook auto-creates this: with pkiInitJob (default), immediately on install/upgrade; with cert-manager, the hook polls for pkiInitJob.timeoutSeconds seconds waiting for cert-manager to issue the server certificate, then creates the ConfigMap. A single install usually succeeds; if cert-manager takes longer, increase pkiInitJob.timeoutSeconds. By default (pkiInitJob.failOnTimeout=true), the install fails if the timeout is reached; set failOnTimeout=false to allow the install to succeed and run `helm upgrade` after the certificate is issued. | +| grpcRoute.backendTLSPolicy.enabled | bool | `false` | Create a BackendTLSPolicy resource for end-to-end TLS between the Gateway proxy and the OpenShell gateway pod. The traffic flow is: client → HTTPS → Gateway (terminate) → TLS (re-encrypt) → gateway pod. Requires server.disableTls=false and server.tls.enableMtls=false. The certgen hook auto-creates the backend CA ConfigMap. | +| grpcRoute.backendTLSPolicy.hostname | string | `""` | Hostname the Gateway proxy validates against the backend's TLS certificate SAN. Defaults to the service FQDN (`..svc.cluster.local`) when empty, which matches the SAN included by both cert-manager and the pkiInitJob. | | grpcRoute.enabled | bool | `false` | Create a Gateway API GRPCRoute for the gateway service. | | grpcRoute.gateway.className | string | `"eg"` | GatewayClass to reference. Envoy Gateway installs one named "eg". | | grpcRoute.gateway.create | bool | `false` | When true, a Gateway resource is created in the release namespace. Set to false and provide name/namespace to attach to a pre-existing Gateway. | @@ -204,8 +210,10 @@ discovery endpoint or its TLS CA. | openshiftRoute.enabled | bool | `false` | Create an OpenShift Route with TLS passthrough. | | openshiftRoute.host | string | `""` | Hostname for the Route. Must match a SAN on the gateway's server cert. | | pkiInitJob.enabled | bool | `true` | Run a pre-install/pre-upgrade Job that creates gateway and client mTLS Secrets. When certManager.enabled=true, cert-manager owns TLS and this same hook runs in JWT-only mode even if pkiInitJob.enabled remains true. | +| pkiInitJob.failOnTimeout | bool | `true` | Fail the helm install/upgrade if cert-manager does not issue the certificate within the polling timeout. When true (default), the install fails immediately if the timeout is reached, providing clear feedback that BackendTLSPolicy is non-functional. When false, the hook succeeds with a warning and you can run `helm upgrade` after cert-manager issues the certificate to create the backend CA ConfigMap. If you set this to false and see "TLS error: Secret is not supplied by SDS" when connecting to the gateway, check if the TLS secret exists and run `helm upgrade` to create the ConfigMap. | | pkiInitJob.serverDnsNames | list | `[]` | Extra DNS SANs to append to the server certificate. | | pkiInitJob.serverIpAddresses | list | `[]` | Extra IP SANs to append to the server certificate. | +| pkiInitJob.timeoutSeconds | int | `120` | Maximum time in seconds for the certgen hook to poll for cert-manager certificates. When using cert-manager with BackendTLSPolicy, the hook polls for this many seconds waiting for the certificate to be issued, then creates the backend CA ConfigMap. The Job deadline is set to (timeoutSeconds + 30) to allow time for ConfigMap creation and cleanup. Increase this if cert-manager takes longer than 120 seconds to issue certificates. | | podAnnotations | object | `{}` | Extra annotations to add to the gateway pod. | | podLabels | object | `{}` | Extra labels to add to the gateway pod. | | podLifecycle.terminationGracePeriodSeconds | int | `5` | Grace period, in seconds, before Kubernetes terminates the gateway pod. | @@ -286,8 +294,9 @@ discovery endpoint or its TLS CA. | server.sandboxNamespace | string | `""` | Namespace where sandbox pods are created. Defaults to the Helm release namespace (.Release.Namespace) when left empty. | | server.telemetryEnabled | bool | `true` | Enable anonymous OpenShell telemetry from the gateway and the sandbox supervisors it launches. | | server.tls.certSecretName | string | `"openshell-server-tls"` | K8s secret (type kubernetes.io/tls) with tls.crt and tls.key for the server. | -| server.tls.clientCaSecretName | string | `"openshell-server-client-ca"` | K8s secret with ca.crt for client certificate verification (mTLS). Set to "" to disable mTLS and run HTTPS-only (use OIDC for auth instead). Do not set to null; omit the key to use the default secret name above. | +| server.tls.clientCaSecretName | string | `"openshell-server-client-ca"` | K8s secret with ca.crt for client certificate verification (mTLS). Only used when enableMtls is true. Set to "" to disable client certificate verification for HTTPS-only mode. | | server.tls.clientTlsSecretName | string | `"openshell-client-tls"` | K8s secret mounted into sandbox pods for mTLS to the server. | +| server.tls.enableMtls | bool | `true` | Enable mTLS client certificate authentication. When false, the gateway runs HTTPS-only without requiring client certificates (use OIDC for auth instead). Must be false when using BackendTLSPolicy because ingress proxies cannot present client certificates to the backend. | | server.workspaceDefaultStorageSize | string | `""` | Default storage size for the workspace PVC in sandbox pods. Uses Kubernetes quantity syntax (e.g. "2Gi", "10Gi", "500Mi"). Empty = built-in default (2Gi). | | server.workspaceStorageClass | string | `""` | Kubernetes StorageClass for the workspace PVC in sandbox pods. Empty (default) = omit storageClassName, using the cluster's default StorageClass. Set this on clusters with no default StorageClass, otherwise the workspace PVC stays Pending and the sandbox never starts. | | service.healthPort | int | `8081` | Gateway health service port. | diff --git a/deploy/helm/openshell/README.md.gotmpl b/deploy/helm/openshell/README.md.gotmpl index cf8677741e..6e6f2012fc 100644 --- a/deploy/helm/openshell/README.md.gotmpl +++ b/deploy/helm/openshell/README.md.gotmpl @@ -56,6 +56,9 @@ helm install openshell oci://ghcr.io/nvidia/openshell/helm-chart --version -backend-ca` when empty. The certgen hook auto-creates this: + # with pkiInitJob (default), immediately on install/upgrade; with + # cert-manager, the hook polls for pkiInitJob.timeoutSeconds seconds + # waiting for cert-manager to issue the server certificate, then creates the + # ConfigMap. A single install usually succeeds; if cert-manager takes longer, + # increase pkiInitJob.timeoutSeconds. By default (pkiInitJob.failOnTimeout=true), + # the install fails if the timeout is reached; set failOnTimeout=false to allow + # the install to succeed and run `helm upgrade` after the certificate is issued. + caCertificateConfigMapName: "" + # -- Hostname the Gateway proxy validates against the backend's TLS + # certificate SAN. Defaults to the service FQDN + # (`..svc.cluster.local`) when empty, which matches + # the SAN included by both cert-manager and the pkiInitJob. + hostname: "" # OpenShift Route with TLS passthrough. The gateway terminates its own # TLS/mTLS; the router only forwards based on SNI, so it never sees plaintext diff --git a/docs/kubernetes/ingress.mdx b/docs/kubernetes/ingress.mdx index 51284465d9..85d12fc8d9 100644 --- a/docs/kubernetes/ingress.mdx +++ b/docs/kubernetes/ingress.mdx @@ -120,8 +120,9 @@ helm upgrade --install openshell \ --set grpcRoute.gateway.listener.port=443 \ --set 'grpcRoute.gateway.listener.tls.certificateRefs[0].name=openshell-ingress-tls' \ --set server.disableTls=true \ - --set server.oidc.issuer=https:// \ - --set 'grpcRoute.hostnames[0]=' + --set server.oidc.issuer=https://keycloak.example.com/realms/openshell \ + --set server.oidc.audience=openshell-cli \ + --set 'grpcRoute.hostnames[0]=gateway.example.com' ``` Keep the certificate Secret in the release namespace. Referencing a Secret in another namespace requires a `ReferenceGrant`. @@ -129,12 +130,82 @@ Keep the certificate Secret in the release namespace. Referencing a Secret in an ### Register over HTTPS ```shell -openshell gateway add https:// --name production --oidc-issuer https:// +openshell gateway add https://gateway.example.com \ + --name production \ + --oidc-issuer https://keycloak.example.com/realms/openshell \ + --oidc-client-id openshell-cli openshell status ``` See [Authentication](/kubernetes/setup) for OIDC issuer, audience, and roles configuration. +## End-to-end TLS (BackendTLSPolicy) + +As an alternative to the plaintext backend path above, the chart can create a `BackendTLSPolicy` that tells the Gateway proxy to re-encrypt traffic when connecting to the OpenShell gateway pod: + +```text +client → HTTPS → Gateway (terminate TLS) → TLS (re-encrypt) → openshell gateway pod +``` + +This keeps TLS on the gateway pod rather than disabling it with `server.disableTls=true`. The Gateway proxy validates the backend's certificate against a CA ConfigMap that the certgen hook auto-creates. + +BackendTLSPolicy is a standard Gateway API resource. It is supported on OpenShift 4.22+ (via the OpenShift gateway controller) and on other platforms where the Gateway API implementation supports it (check your controller's documentation). + +### Install with e2e TLS + +The certgen hook automatically creates the backend CA ConfigMap when `backendTLSPolicy` is enabled: + +```shell +helm upgrade --install openshell \ + oci://ghcr.io/nvidia/openshell/helm-chart \ + --version \ + --namespace openshell \ + --set server.tls.enableMtls=false \ + --set grpcRoute.enabled=true \ + --set grpcRoute.gateway.create=true \ + --set grpcRoute.gateway.className=eg \ + --set grpcRoute.gateway.listener.protocol=HTTPS \ + --set grpcRoute.gateway.listener.port=443 \ + --set 'grpcRoute.gateway.listener.tls.certificateRefs[0].name=openshell-ingress-tls' \ + --set grpcRoute.backendTLSPolicy.enabled=true \ + --set server.oidc.issuer=https://keycloak.example.com/realms/openshell \ + --set server.oidc.audience=openshell-cli \ + --set 'grpcRoute.hostnames[0]=gateway.example.com' +``` + +Note that `server.disableTls` is **not** set — the gateway pod continues to serve TLS — but `server.tls.enableMtls=false` disables mTLS client certificate authentication because the Gateway proxy cannot present a client certificate to the backend. The chart will fail the install if you try to enable both `grpcRoute.backendTLSPolicy.enabled=true` and `server.tls.enableMtls=true` simultaneously. The BackendTLSPolicy hostname defaults to the service FQDN, which matches the SAN on the server certificate. Use OIDC for authentication (configured via `server.oidc.issuer`). + +The example above uses the default `pkiInitJob` for TLS, which creates the backend CA ConfigMap immediately. If using cert-manager instead (`--set certManager.enabled=true`), the Certificate resources are regular release objects, and a separate post-install/post-upgrade Job (`-certgen-backend-ca`) polls for up to 120 seconds waiting for cert-manager to issue the server certificate, then creates the backend CA ConfigMap. This means a single `helm install` is sufficient in most cases. + +If cert-manager takes longer than 120 seconds to issue certificates, increase the polling timeout with `--set pkiInitJob.timeoutSeconds=`. The hook polls for exactly this many seconds. For example, `timeoutSeconds=180` polls for 180 seconds. By default (`pkiInitJob.failOnTimeout=true`), the install fails if the timeout is reached, providing clear feedback that the BackendTLSPolicy is non-functional. + +### Troubleshooting + +If you see the error `remote connection failure, transport failure reason: TLS error: Secret is not supplied by SDS` when connecting through the Gateway: + +1. Check if the backend CA ConfigMap exists: + + ```shell + kubectl get configmap -backend-ca -n + ``` + +2. If the ConfigMap is missing, verify the TLS secret exists: + + ```shell + kubectl get secret -server-tls -n + ``` + +3. If the secret exists but the ConfigMap doesn't, run `helm upgrade` to create it: + + ```shell + helm upgrade oci://ghcr.io/nvidia/openshell/helm-chart \ + --reuse-values --namespace + ``` + +This situation can occur if you set `pkiInitJob.failOnTimeout=false` and cert-manager issued the certificate after the hook timed out. + +For OpenShift 4.22+, see [OpenShift](/kubernetes/openshift#end-to-end-tls-openshift-422) for platform-specific instructions including Gateway and GatewayClass setup. + ## SSH Relay Sandbox SSH uses the gateway endpoint registered with the CLI. No separate Helm SSH host or port values are required. diff --git a/docs/kubernetes/managing-certificates.mdx b/docs/kubernetes/managing-certificates.mdx index c4cb07f57e..d97c1e24be 100644 --- a/docs/kubernetes/managing-certificates.mdx +++ b/docs/kubernetes/managing-certificates.mdx @@ -66,7 +66,7 @@ By default, cert-manager issues both the server and client certificates from a self-signed CA the chart creates — this rotates automatically, but the server certificate is still not publicly trusted. `certManager.serverIssuerRef` overrides the `issuerRef` on the server `Certificate` resource to point at a -real `Issuer` or `ClusterIssuer` instead, for example an ACME issuer: +real `Issuer` or `ClusterIssuer` instead, for example a LetsEncrypt/ACME issuer: ```shell helm upgrade --install openshell \ diff --git a/docs/kubernetes/openshift.mdx b/docs/kubernetes/openshift.mdx index 43e7d0338b..cfae001a38 100644 --- a/docs/kubernetes/openshift.mdx +++ b/docs/kubernetes/openshift.mdx @@ -87,13 +87,123 @@ openshell gateway add http://127.0.0.1:8080 --local --name openshift openshell status ``` -## Production: expose externally with a real certificate +## Options for end-to-end TLS -The steps above run the gateway over plaintext HTTP for quick evaluation. For -a real deployment, cert-manager can issue the gateway's server certificate -from a real Issuer or ClusterIssuer (for example, an ACME issuer), and an -OpenShift Route with TLS passthrough exposes it externally while the gateway -keeps terminating its own TLS and mTLS. +The steps above run the gateway over plaintext HTTP for quick evaluation. For production deployments, choose one of the approaches below based on your OpenShift version and preferences. + +### End-to-end TLS using Gateway API and BackendTLSPolicy (OpenShift 4.22+) + +OpenShift 4.22 and later support `BackendTLSPolicy` in the Gateway API, enabling end-to-end TLS between the OpenShift router and the OpenShell gateway pod. The traffic flow is: + +```text +client → HTTPS → OpenShift Gateway (terminate TLS) → TLS (re-encrypt) → openshell gateway pod +``` + +This removes the requirement to run the gateway with `server.disableTls=true`. The OpenShift router terminates client-facing TLS at the listener and re-encrypts when connecting to the backend service, validating the backend's certificate against a CA you provide. + +#### Prerequisites + +- OpenShift 4.22+ cluster with the Gateway API enabled +- cert-manager installed (recommended) or the built-in pkiInitJob for server certificates +- A `GatewayClass` registered for the OpenShift gateway controller + +#### Create the GatewayClass + +If your cluster does not already have an OpenShift GatewayClass, create one: + +```shell +oc apply -f - <<'EOF' +apiVersion: gateway.networking.k8s.io/v1 +kind: GatewayClass +metadata: + name: openshift-default +spec: + controllerName: openshift.io/gateway-controller/v1 +EOF +``` + +#### Create the Gateway + +Create a Gateway resource in the `openshift-ingress` namespace. Replace `` with your cluster's route hostname (typically a wildcard like `*.openshell-ingress-gw.example.com`): + +```shell +oc apply -f - <<'EOF' +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: openshell-gateway + namespace: openshift-ingress +spec: + gatewayClassName: openshift-default + listeners: + - name: grpc + hostname: "" + port: 443 + protocol: HTTPS + tls: + mode: Terminate + certificateRefs: + - name: + kind: Secret + allowedRoutes: + namespaces: + from: Selector + selector: + matchLabels: + kubernetes.io/metadata.name: openshell +EOF +``` + +The listener TLS Secret should contain the certificate for the external hostname. + +#### Install with e2e TLS + +Install the chart with the GRPCRoute and BackendTLSPolicy enabled. The certgen hook automatically creates the backend CA ConfigMap from the generated PKI bundle: + +```shell +helm install openshell oci://ghcr.io/nvidia/openshell/helm-chart \ + --version \ + --namespace openshell \ + --set podSecurityContext.fsGroup=null \ + --set securityContext.runAsUser=null \ + --set server.tls.enableMtls=false \ + --set grpcRoute.enabled=true \ + --set grpcRoute.gateway.name=openshell-gateway \ + --set grpcRoute.gateway.namespace=openshift-ingress \ + --set 'grpcRoute.hostnames[0]=gateway.example.com' \ + --set grpcRoute.backendTLSPolicy.enabled=true \ + --set server.oidc.issuer=https://keycloak.example.com/realms/openshell \ + --set server.oidc.audience=openshell-cli +``` + +| Override | Reason | +|---|---| +| `podSecurityContext.fsGroup=null` / `securityContext.runAsUser=null` | Let OpenShift's SCC admission assign UIDs. | +| `server.tls.enableMtls=false` | Disable mTLS client certificate authentication. BackendTLSPolicy only validates the server certificate; the ingress proxy cannot present a client certificate to the backend. Use OIDC for authentication instead. | +| `grpcRoute.enabled=true` | Create a GRPCRoute pointing at the external Gateway. | +| `grpcRoute.gateway.name` / `namespace` | Reference the Gateway created above in `openshift-ingress`. | +| `grpcRoute.backendTLSPolicy.enabled=true` | Create a BackendTLSPolicy for TLS re-encryption to the gateway pod. The certgen hook auto-creates the backend CA ConfigMap. The Gateway proxy validates the backend certificate against the service FQDN, which is already in the default server certificate SANs. | +| `grpcRoute.hostnames` | External hostname for the GRPCRoute. This goes on the Gateway listener certificate, not the backend certificate. | + +Note that `server.disableTls` is **not** set — the gateway pod serves TLS over HTTPS without requiring client certificates. Use OIDC for authentication (see [Access Control](/kubernetes/access-control)). + +**Using cert-manager instead of pkiInitJob:** Add `--set certManager.enabled=true` to the install command. The default `certManager.serverDnsNames` already includes the service FQDN needed for BackendTLSPolicy validation. The Certificate resources are regular release objects, and a separate post-install/post-upgrade Job (`-certgen-backend-ca`) polls for up to 120 seconds waiting for cert-manager to issue the server certificate, then creates the backend CA ConfigMap. A single `helm install` is sufficient in most cases. + +If cert-manager takes longer than 120 seconds to issue certificates, increase the polling timeout with `--set pkiInitJob.timeoutSeconds=`. The hook polls for exactly this many seconds. For example, `timeoutSeconds=180` polls for 180 seconds. By default (`pkiInitJob.failOnTimeout=true`), the install fails if the timeout is reached, providing clear feedback that the BackendTLSPolicy is non-functional. + +#### Register over HTTPS + +```shell +openshell gateway add https://gateway.example.com \ + --name openshift \ + --oidc-issuer https://keycloak.example.com/realms/openshell \ + --oidc-client-id openshell-cli +openshell status +``` + +### End-to-end TLS using pass-through Route (all OpenShift versions) + +For OpenShift versions prior to 4.22, or when you prefer Route-based ingress, cert-manager can issue the gateway's server certificate from a real Issuer or ClusterIssuer (for example, a LetsEncrypt/ACME issuer), and an OpenShift Route with TLS passthrough exposes it externally while the gateway keeps terminating its own TLS and mTLS. Install cert-manager and configure a working `ClusterIssuer` first — see [Managing Certificates](/kubernetes/managing-certificates) for the @@ -110,13 +220,13 @@ helm install openshell oci://ghcr.io/nvidia/openshell/helm-chart \ --set securityContext.runAsUser=null \ --set server.disableTls=false \ --set certManager.enabled=true \ - --set certManager.serverIssuerRef.name= \ + --set certManager.serverIssuerRef.name=letsencrypt-prod \ --set certManager.serverIssuerRef.kind=ClusterIssuer \ - --set certManager.serverDnsNames[0]= \ + --set certManager.serverDnsNames[0]=gateway.example.com \ --set openshiftRoute.enabled=true \ - --set openshiftRoute.host= \ - --set server.oidc.issuer= \ - --set server.oidc.audience= + --set openshiftRoute.host=gateway.example.com \ + --set server.oidc.issuer=https://keycloak.example.com/realms/openshell \ + --set server.oidc.audience=openshell-cli ``` | Override | Reason | @@ -129,9 +239,10 @@ Register the gateway with the CLI over OIDC. Remote gateways authenticate CLI users via OIDC, not mTLS — see [Access Control](/kubernetes/access-control): ```shell -openshell gateway add https:// \ +openshell gateway add https://gateway.example.com \ --name openshift \ - --oidc-issuer + --oidc-issuer https://keycloak.example.com/realms/openshell \ + --oidc-client-id openshell-cli openshell gateway login openshift ``` diff --git a/docs/reference/gateway-config.mdx b/docs/reference/gateway-config.mdx index e2d48087cd..f9a3f00321 100644 --- a/docs/reference/gateway-config.mdx +++ b/docs/reference/gateway-config.mdx @@ -522,6 +522,9 @@ compute_driver = "kubernetes" [openshell.gateway.tls] cert_path = "/etc/openshell-tls/server/tls.crt" key_path = "/etc/openshell-tls/server/tls.key" +# client_ca_path is only rendered when server.tls.enableMtls is true (the +# default). When enableMtls is false — required for BackendTLSPolicy — the +# gateway runs HTTPS-only and this line is omitted by Helm. client_ca_path = "/etc/openshell-tls/client-ca/ca.crt" # When cert-manager serverIssuerRef is configured, these are populated by Helm: # external_cert_path = "/etc/openshell-tls/server-external/tls.crt" diff --git a/mise.lock b/mise.lock index 6e0d6d4efc..a5e38be2c2 100644 --- a/mise.lock +++ b/mise.lock @@ -168,12 +168,6 @@ url = "https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-0.9 url_api = "https://api.github.com/repos/nextest-rs/nextest/releases/assets/501885637" provenance = "github-attestations" -[tools."github:nextest-rs/nextest"."platforms.windows-arm64"] -checksum = "sha256:58c1637ba2396e6c556aa0092f9aa4388695594b8ddda5a4b8b39212574678ce" -url = "https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-0.9.143/cargo-nextest-0.9.143-aarch64-pc-windows-msvc.zip" -url_api = "https://api.github.com/repos/nextest-rs/nextest/releases/assets/501886128" -provenance = "github-attestations" - [tools."github:nextest-rs/nextest"."platforms.windows-x64"] checksum = "sha256:c670ba18e8731fd2eff33a47af33a0fa53d1afa6d0678344e82dc6f8fc7344ac" url = "https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-0.9.143/cargo-nextest-0.9.143-x86_64-pc-windows-msvc.zip" @@ -463,13 +457,11 @@ backend = "aqua:astral-sh/uv" [tools.uv."platforms.linux-arm64"] checksum = "sha256:55bd1c1c10ec8b95a8c184f5e18b566703c6ab105f0fc118aaa4d748aabf28e4" url = "https://github.com/astral-sh/uv/releases/download/0.10.12/uv-aarch64-unknown-linux-musl.tar.gz" -url_api = "https://api.github.com/repos/astral-sh/uv/releases/assets/377491942" provenance = "github-attestations" [tools.uv."platforms.linux-x64"] checksum = "sha256:adccf40b5d1939a5e0093081ec2307ea24235adf7c2d96b122c561fa37711c46" url = "https://github.com/astral-sh/uv/releases/download/0.10.12/uv-x86_64-unknown-linux-musl.tar.gz" -url_api = "https://api.github.com/repos/astral-sh/uv/releases/assets/377491998" provenance = "github-attestations" [tools.uv."platforms.macos-arm64"] diff --git a/skills/debug-openshell-cluster/SKILL.md b/skills/debug-openshell-cluster/SKILL.md index 360bf28ee4..577b801a83 100644 --- a/skills/debug-openshell-cluster/SKILL.md +++ b/skills/debug-openshell-cluster/SKILL.md @@ -446,6 +446,31 @@ label, supervisor env vars `OPENSHELL_K8S_SA_TOKEN_FILE` and `OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET`, plus both the projected `openshell-sa-token` volume and the `spiffe-workload-api` CSI volume. +If `grpcRoute.backendTLSPolicy.enabled=true`, the Gateway proxy validates the +backend pod's TLS certificate against a CA in a ConfigMap. Check that the +ConfigMap exists and contains the correct CA, that `enableMtls` is disabled, +and that the BackendTLSPolicy resource is present: + +```bash +kubectl -n openshell get backendtlspolicy +kubectl -n openshell get configmap openshell-backend-ca -o yaml +helm -n openshell get values openshell | grep -E 'backendTLSPolicy|enableMtls|failOnTimeout|timeoutSeconds|caCertificateConfigMapName' +``` + +If the ConfigMap is missing after a cert-manager install, the post-install +certgen hook may have timed out waiting for cert-manager to issue the server +certificate. Check the certgen Job logs: + +```bash +kubectl -n openshell get jobs | grep certgen +kubectl -n openshell logs job/openshell-certgen-backend-ca +``` + +Increase `pkiInitJob.timeoutSeconds` and run `helm upgrade` to retry. If the +Gateway proxy reports `TLS error: Secret is not supplied by SDS` or similar +backend TLS errors, the ConfigMap CA likely does not match the server +certificate CA — verify both are from the same issuer. + Check the image references currently used by the gateway deployment: ```bash