From b2d44041e3455035d5bcec2ba9b70a94fd829348 Mon Sep 17 00:00:00 2001 From: "sec-check[bot]" Date: Wed, 23 Sep 2026 17:44:12 -0400 Subject: [PATCH] fix: generate console JWT secret at first boot, not in git The kubestellar-console-github-oauth Secret committed a usable jwt-secret (default-jwt-secret-123456789012345678901234). JWT_SECRET signs console session tokens, so a value published in git lets anyone forge valid sessions on every default install. Mirror the kubeflex-postgres pattern (#98): the committed 01- manifest now creates only the namespace, and a first-boot generator writes 02-kubestellar-console-secret.yaml with a random 256-bit jwt-secret and empty OAuth credentials (consumed with optional: true). Idempotent, 0600, runs from k0s-first-boot.service before k0scontroller starts. Existing installs rotate on upgrade: tmpfiles C+ replaces the stale 01- copy (dropping the published Secret) and the generator creates the 02- file fresh, invalidating any tokens forged with the public value. Closes #72 Assisted-by: Claude Fable 5 via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: sec-check[bot] --- elements/oci/k0s-sysext.bst | 1 + files/k0s/kubeflex/generate-console-secret.sh | 40 +++++++++++++++ .../01-kubestellar-console-github-oauth.yaml | 20 ++++---- .../os/systemd/system/k0s-first-boot.service | 1 + tests/unit/test_k0s_manifests.py | 50 +++++++++++++++++++ 5 files changed, 101 insertions(+), 11 deletions(-) create mode 100755 files/k0s/kubeflex/generate-console-secret.sh diff --git a/elements/oci/k0s-sysext.bst b/elements/oci/k0s-sysext.bst index dc5bcdbc..658f7f93 100644 --- a/elements/oci/k0s-sysext.bst +++ b/elements/oci/k0s-sysext.bst @@ -89,6 +89,7 @@ config: mkdir -p sysext/usr/share/k0s/kubeflex cp -a kubeflex-src/. sysext/usr/share/k0s/kubeflex/ chmod 0755 sysext/usr/share/k0s/kubeflex/generate-postgres-secret.sh + chmod 0755 sysext/usr/share/k0s/kubeflex/generate-console-secret.sh # Generate self-signed TLS certificate for local kiosk proxy openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ diff --git a/files/k0s/kubeflex/generate-console-secret.sh b/files/k0s/kubeflex/generate-console-secret.sh new file mode 100755 index 00000000..9798a4fa --- /dev/null +++ b/files/k0s/kubeflex/generate-console-secret.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# First-boot generator for the KubeStellar console session-signing secret. +# +# The console Deployment (40-kubestellar-console.yaml) reads JWT_SECRET from +# the kubestellar-console-github-oauth Secret via secretKeyRef. This script +# creates that Secret once, with a random jwt-secret, so no usable signing key +# is committed to git (see projectbluefin/server#72). The GitHub OAuth keys +# are created empty: the console consumes them with `optional: true`, and an +# operator enabling OAuth edits the generated file with real credentials. +# +# Idempotent: the secret is generated only if the file does not already exist, +# so operator-supplied OAuth credentials and issued sessions survive re-boots. +# Run once per boot by k0s-first-boot.service, before k0s applies the +# manifests (its 02- name sorts before 40-kubestellar-console.yaml). +set -euo pipefail + +manifest_dir="${KUBESTELLAR_MANIFEST_DIR:-/var/lib/k0s/manifests/kubestellar}" +secret_file="$manifest_dir/02-kubestellar-console-secret.yaml" + +if [ -e "$secret_file" ]; then + exit 0 +fi + +mkdir -p "$manifest_dir" +jwt_secret="$(od -An -tx1 -N32 /dev/urandom | tr -d ' \n')" + +cat > "$secret_file" <