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" <