diff --git a/elements/oci/k0s-sysext.bst b/elements/oci/k0s-sysext.bst index b980c9d3..dc5bcdbc 100644 --- a/elements/oci/k0s-sysext.bst +++ b/elements/oci/k0s-sysext.bst @@ -30,6 +30,9 @@ sources: - kind: local path: files/k0s/kiosk directory: kiosk-src + - kind: local + path: files/k0s/kubeflex + directory: kubeflex-src - kind: local path: files/os/issue.d/40-kubestellar.issue directory: issue-src @@ -82,6 +85,11 @@ config: # Stage Console kiosk proxy assets. cp -a kiosk-src/. sysext/usr/share/k0s/kiosk/ + # Stage KubeStellar first-boot credential helper. + 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 + # Generate self-signed TLS certificate for local kiosk proxy openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ -keyout sysext/usr/share/k0s/kiosk/key.pem \ diff --git a/files/k0s/kubeflex/generate-postgres-secret.sh b/files/k0s/kubeflex/generate-postgres-secret.sh new file mode 100755 index 00000000..7e7ea1b8 --- /dev/null +++ b/files/k0s/kubeflex/generate-postgres-secret.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# First-boot generator for the KubeStellar postgres superuser password. +# +# The postgres StatefulSet (20-postgres.yaml) reads its superuser password from +# the kubeflex-postgres Secret via secretKeyRef. This script creates that Secret +# once, with a random password, so no usable credential is committed to git or +# exposed in the pod spec (see projectbluefin/server#98). +# +# Idempotent: the password is generated only if the Secret already exists, so +# the initialized database stays accessible across re-boots. Run once per boot +# by k0s-first-boot.service, before k0s applies the manifests (its 15- name +# sorts before 20-postgres.yaml, so the Secret exists first). +set -euo pipefail + +manifest_dir="${KUBEFLEX_MANIFEST_DIR:-/var/lib/k0s/manifests/kubestellar}" +secret_file="$manifest_dir/15-kubeflex-postgres-secret.yaml" + +if [ -e "$secret_file" ]; then + exit 0 +fi + +mkdir -p "$manifest_dir" +password="$(head -c 32 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' | cut -c1-30)" + +cat > "$secret_file" <