diff --git a/docs/skills/k0s-sysext-ops.md b/docs/skills/k0s-sysext-ops.md index 7b806f80..e6a01276 100644 --- a/docs/skills/k0s-sysext-ops.md +++ b/docs/skills/k0s-sysext-ops.md @@ -46,6 +46,33 @@ k0s automatically applies all `.yaml` files under `/var/lib/k0s/manifests/argocd k0s kubectl get pods -A ``` +## Configuring KubeStellar Console OAuth and JWT Secret + +By default, the KubeStellar console runs in local development mode without requiring OAuth credentials or a static JWT secret. + +To configure production GitHub OAuth credentials and a persistent JWT signing key, apply an operator-provided Secret to the `kubestellar-console` namespace: + +```bash +cat <<'EOF' | k0s kubectl apply -f - +apiVersion: v1 +kind: Secret +metadata: + name: kubestellar-console-github-oauth + namespace: kubestellar-console +type: Opaque +stringData: + client-id: "" + client-secret: "" + jwt-secret: "" +EOF +``` + +Restart the console deployment to pick up the configured credentials: + +```bash +k0s kubectl rollout restart deployment/kubestellar-console -n kubestellar-console +``` + ## Troubleshooting - **Extension not merged**: Check `systemd-sysext status`. Verify the persistent image is `/var/lib/k0s/k0s.raw`; the boot activation unit copies it into `/run/extensions/k0s.raw`. diff --git a/files/k0s/manifests/kubestellar/01-kubestellar-console-github-oauth.yaml b/files/k0s/manifests/kubestellar/01-kubestellar-console-github-oauth.yaml deleted file mode 100644 index 3e58dc31..00000000 --- a/files/k0s/manifests/kubestellar/01-kubestellar-console-github-oauth.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: kubestellar-console ---- -apiVersion: v1 -kind: Secret -metadata: - name: kubestellar-console-github-oauth - namespace: kubestellar-console -type: Opaque -stringData: - client-id: "" - client-secret: "" - jwt-secret: default-jwt-secret-123456789012345678901234 diff --git a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml index fc502bdf..3c61ba12 100644 --- a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml +++ b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml @@ -40,7 +40,9 @@ spec: spec: containers: - name: console - image: ghcr.io/kubestellar/console:v0.3.34 + # v0.3.34, pinned by digest for supply-chain integrity (same pattern + # as the kiosk proxy's nginx image in 41-kubestellar-kiosk-proxy.yaml). + image: ghcr.io/kubestellar/console@sha256:f27adaf8d097a5403f60041615525497e0970151fcd10b90b7b6e903b395be32 env: - name: DEV_MODE value: "true" @@ -60,12 +62,23 @@ spec: name: kubestellar-console-github-oauth key: client-secret optional: true + # When unset, the server itself generates a random secret because + # DEV_MODE=true above: pkg/api/server.go calls loadOrCreateDevSecret, + # which persists it as .jwt-secret under os.UserConfigDir() inside + # the container (survives a plain container restart, lost on pod + # recreation since no volume is mounted here). Without DEV_MODE an + # unset JWT_SECRET is a fatal exit, not a weak default, so removing + # DEV_MODE requires setting jwt-secret in the Secret. Verified + # against the pinned v0.3.34 tag (the image entrypoint is + # entrypoint.sh, not start.sh): + # https://github.com/kubestellar/console/blob/v0.3.34/pkg/api/server.go#L78-L89 + # https://github.com/kubestellar/console/blob/v0.3.34/pkg/api/startup.go#L350-L388 - name: JWT_SECRET valueFrom: secretKeyRef: name: kubestellar-console-github-oauth key: jwt-secret - optional: false + optional: true ports: - containerPort: 8080 name: http diff --git a/tests/unit/test_k0s_manifests.py b/tests/unit/test_k0s_manifests.py index 149ca421..76104f41 100644 --- a/tests/unit/test_k0s_manifests.py +++ b/tests/unit/test_k0s_manifests.py @@ -38,6 +38,7 @@ def test_k0s_manifest_files(): assert (ks_dir / "30-kubestellar-core.yaml").is_file() assert (ks_dir / "40-kubestellar-console.yaml").is_file() assert (ks_dir / "41-kubestellar-kiosk-proxy.yaml").is_file() + assert not (ks_dir / "01-kubestellar-console-github-oauth.yaml").exists() def test_postgres_password_not_hardcoded(): diff --git a/tests/unit/test_kubestellar_kiosk.py b/tests/unit/test_kubestellar_kiosk.py index ec608c72..7d4682c2 100644 --- a/tests/unit/test_kubestellar_kiosk.py +++ b/tests/unit/test_kubestellar_kiosk.py @@ -2,6 +2,8 @@ from pathlib import Path +import yaml + ROOT = Path(__file__).resolve().parents[2] KIOSK = ROOT / "files" / "k0s" / "kiosk" KIOSK_CONF = KIOSK / "nginx.conf" @@ -89,10 +91,23 @@ def test_console_provides_local_and_oauth_login_options() -> None: assert "hostPort:" not in console assert "name: GITHUB_CLIENT_ID" in console assert "name: GITHUB_CLIENT_SECRET" in console + assert "name: JWT_SECRET" in console assert "name: kubestellar-console-github-oauth" in console assert "key: client-id" in console assert "key: client-secret" in console + assert "key: jwt-secret" in console assert "optional: true" in console + deployment = next( + doc + for doc in yaml.safe_load_all(CONSOLE_MANIFEST.read_text(encoding="utf-8")) + if doc and doc.get("kind") == "Deployment" + ) + jwt_secret = next( + env + for env in deployment["spec"]["template"]["spec"]["containers"][0]["env"] + if env["name"] == "JWT_SECRET" + ) + assert jwt_secret["valueFrom"]["secretKeyRef"]["optional"] is True def test_proxy_is_the_only_public_console_endpoint() -> None: