The chart reads every secret from four Kubernetes Secrets that must exist in the environment's namespace before the first deploy. Nothing secret is ever in the Helm values file.
#The four Secrets
#Names, keys and contents
| Secret | Key | Becomes | Contents | Where it comes from |
|---|---|---|---|---|
kims-database |
url |
DATABASE_URL |
postgres://kims:<PASSWORD>@<RDS_ENDPOINT>:5432/kims?sslmode=require |
aws/rds-postgresql |
kims-keycloak |
client-secret |
KEYCLOAK_CLIENT_SECRET |
The CMS client's secret (Keycloak: the client > Credentials tab) | keycloak/client |
kims-app |
session-secret |
SESSION_SECRET |
48 random bytes, base64 (64 characters). At least 32 characters | Generated below |
kims-app |
secrets-key |
SECRETS_KEY |
32 random bytes, base64 (44 characters) | Generated below |
kims-jenkins |
token |
JENKINS_TOKEN |
The API token of the CMS's Jenkins user | jenkins/api-token |
The pinned Node driver may treat sslmode=require as full certificate verification, and the RDS certificate authorities are not in Node's trust store. If the migrate Job, the readiness check or the site build fails with self-signed certificate in certificate chain, end the URL with ?sslmode=require&uselibpqcompat=true instead, in both the kims-database Secret and the folder's kims-database-url credential: aws/rds-postgresql.
They are named under secretEnv in the values file; change the names there only if KIMS insists on its own.
All four must exist before the first deploy, kims-jenkins included. None is optional in the chart, so a missing one stops every pod (the migrate Job too) with CreateContainerConfigError. Create the Jenkins user and its API token first (jenkins/api-token). The deploy helper's kims secrets create refuses to create anything if the Jenkins token is left empty.
#Per environment
| Production | UAT | |
|---|---|---|
| Namespace | kims |
kims-uat |
kims-database |
Production RDS | UAT RDS |
kims-keycloak |
Production CMS client | UAT CMS client |
kims-app |
Generated for production | Generated separately. Never copy production's to UAT or back |
kims-jenkins |
Token of the user allowed on kims-production/kims-site-build |
That user's token, or a UAT user's |
#Before you start
#Check you may create Secrets
kubectl --context <KUBE_CONTEXT> get namespace <NAMESPACE>
kubectl --context <KUBE_CONTEXT> auth can-i create secrets -n <NAMESPACE>kubectl --context <KUBE_CONTEXT> get namespace <NAMESPACE>
kubectl --context <KUBE_CONTEXT> auth can-i create secrets -n <NAMESPACE>kubectl --context <KUBE_CONTEXT> get namespace <NAMESPACE>
kubectl --context <KUBE_CONTEXT> auth can-i create secrets -n <NAMESPACE>Expected: <NAMESPACE> Active ..., then yes. no means KIMS's team must run the commands on this page, or grant you the right (aws/eks).
#Have the three values ready
- The RDS master (or app) password and endpoint.
- The Keycloak client secret.
- The Jenkins API token.
Keep them in KIMS's password vault, not in a text file.
#Quick way: the deploy helper
kims secrets create asks for the database URL, the Keycloak client secret and the Jenkins token without showing them (or reads KIMS_DATABASE_URL, KIMS_KEYCLOAK_CLIENT_SECRET, KIMS_JENKINS_TOKEN), checks the URL is RDS-like and ends ?sslmode=require, generates kims-app itself, leaves existing Secrets alone, and never replaces kims-app. It works in a locked-down PowerShell, because it is Node.
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KUBE_CONTEXT> --namespace <NAMESPACE>node deployment-steps/scripts/deploy.mjs kims secrets create --context <KUBE_CONTEXT> --namespace <NAMESPACE>node deployment-steps/scripts/deploy.mjs kims secrets create --context <KUBE_CONTEXT> --namespace <NAMESPACE>Then go to Check the Secrets. See operate/deploy-cli for its options.
#By hand, without leaving secrets behind
#The method
Typed into a command (--from-literal=url='...'), a secret lands in shell history and, briefly, in the process list. Instead, each value is:
- read with a hidden prompt into a shell variable,
- written with no trailing newline into a file in a private temporary folder,
- given to kubectl with
--from-file=<key>=<file>, - deleted with the folder.
A trailing newline matters: DATABASE_URL would end with a newline after its last parameter and fail to parse.
#Step 1: make a private temporary folder
umask 077
SECDIR=$(mktemp -d)
echo "$SECDIR"umask 077
SECDIR=$(mktemp -d)
echo "$SECDIR"$SecDir = Join-Path $env:TEMP ("kims-secrets-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $SecDir | Out-Null
$SecDirExpected: a path such as /tmp/tmp.Xa12bc (Linux), /var/folders/.../T/tmp.Xa12bc (macOS) or C:\Users\<USER>\AppData\Local\Temp\kims-secrets-... (Windows). On Windows the folder is inside your own profile, readable only by you and administrators.
If PowerShell on the engineer's machine runs in Constrained Language Mode ($ExecutionContext.SessionState.LanguageMode prints ConstrainedLanguage), the [guid] and [Runtime.InteropServices.Marshal] calls on this page are blocked. Use the Quick way, or run the Linux commands in Git Bash (it has openssl and read -s).
#Step 2: kims-database
read -rs -p "RDS connection string (postgres://...?sslmode=require): " V; echo
printf '%s' "$V" > "$SECDIR/url"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SECDIR/url"read -rs "V?RDS connection string (postgres://...?sslmode=require): "; echo # zsh; in bash: read -rs -p "..." V
printf '%s' "$V" > "$SECDIR/url"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SECDIR/url"# PowerShell 7.1 or later:
$v = Read-Host "RDS connection string (postgres://...?sslmode=require)" -MaskInput
# Windows PowerShell 5.1 instead:
# $s = Read-Host "RDS connection string" -AsSecureString
# $v = [Runtime.InteropServices.Marshal]::PtrToStringBSTR([Runtime.InteropServices.Marshal]::SecureStringToBSTR($s))
Set-Content -Path "$SecDir\url" -Value $v -NoNewline -Encoding ascii; Remove-Variable v
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SecDir\url"Expected: secret/kims-database created.
If the password has characters that are special in a URL (@, :, /, ?, #, %), they must be percent-encoded in the string (@ becomes %40). Simpler: ask KIMS for a password of letters and digits only.
#Step 3: kims-keycloak
read -rs -p "Keycloak client secret: " V; echo
printf '%s' "$V" > "$SECDIR/client-secret"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-keycloak --from-file=client-secret="$SECDIR/client-secret"read -rs "V?Keycloak client secret: "; echo
printf '%s' "$V" > "$SECDIR/client-secret"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-keycloak --from-file=client-secret="$SECDIR/client-secret"$v = Read-Host "Keycloak client secret" -MaskInput # 5.1: use the SecureString lines from step 2
Set-Content -Path "$SecDir\client-secret" -Value $v -NoNewline -Encoding ascii; Remove-Variable v
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-keycloak --from-file=client-secret="$SecDir\client-secret"Expected: secret/kims-keycloak created.
#Step 4: generate SESSION_SECRET and SECRETS_KEY, create kims-app
Nobody needs to know these values; they are generated straight into files.
openssl rand -base64 48 | tr -d '\n' > "$SECDIR/session-secret"
openssl rand -base64 32 | tr -d '\n' > "$SECDIR/secrets-key"
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-app \
--from-file=session-secret="$SECDIR/session-secret" \
--from-file=secrets-key="$SECDIR/secrets-key"openssl rand -base64 48 | tr -d '\n' > "$SECDIR/session-secret"
openssl rand -base64 32 | tr -d '\n' > "$SECDIR/secrets-key"
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-app \
--from-file=session-secret="$SECDIR/session-secret" \
--from-file=secrets-key="$SECDIR/secrets-key"function New-RandomBase64([int]$Bytes) {
$b = New-Object byte[] $Bytes
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($b); $rng.Dispose()
[Convert]::ToBase64String($b)
}
Set-Content -Path "$SecDir\session-secret" -Value (New-RandomBase64 48) -NoNewline -Encoding ascii
Set-Content -Path "$SecDir\secrets-key" -Value (New-RandomBase64 32) -NoNewline -Encoding ascii
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-app --from-file=session-secret="$SecDir\session-secret" --from-file=secrets-key="$SecDir\secrets-key"Expected: secret/kims-app created.
Without openssl (or in Constrained Language Mode), Node 24 generates the same, on any system. It writes the files itself, so PowerShell's encoding never touches them:
node -e "const c=require('crypto'),f=require('fs'),p=require('path'),d=process.argv[1];f.writeFileSync(p.join(d,'session-secret'),c.randomBytes(48).toString('base64'));f.writeFileSync(p.join(d,'secrets-key'),c.randomBytes(32).toString('base64'))" "<SECRETS_FOLDER>"Replace <SECRETS_FOLDER> with the folder from step 1, then run the kubectl ... create secret generic kims-app line above.
#Step 5: kims-jenkins
read -rs -p "Jenkins API token: " V; echo
printf '%s' "$V" > "$SECDIR/token"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-jenkins --from-file=token="$SECDIR/token"read -rs "V?Jenkins API token: "; echo
printf '%s' "$V" > "$SECDIR/token"; unset V
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-jenkins --from-file=token="$SECDIR/token"$v = Read-Host "Jenkins API token" -MaskInput # 5.1: use the SecureString lines from step 2
Set-Content -Path "$SecDir\token" -Value $v -NoNewline -Encoding ascii; Remove-Variable v
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-jenkins --from-file=token="$SecDir\token"Expected: secret/kims-jenkins created.
#Step 6: delete the temporary folder
shred -u "$SECDIR"/* 2>/dev/null; rm -rf "$SECDIR"; unset SECDIRrm -P "$SECDIR"/* 2>/dev/null; rm -rf "$SECDIR"; unset SECDIRRemove-Item -Recurse -Force $SecDir; Remove-Variable SecDirExpected: no output. Check the folder is gone with ls "$SECDIR" before the unset if in doubt.
#Check the Secrets
#All four exist, with the right keys
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secrets kims-database kims-keycloak kims-app kims-jenkins
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> describe secret kims-appkubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secrets kims-database kims-keycloak kims-app kims-jenkins
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> describe secret kims-appkubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secrets kims-database kims-keycloak kims-app kims-jenkins
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> describe secret kims-appExpected from get:
NAME TYPE DATA AGE
kims-database Opaque 1 2m
kims-keycloak Opaque 1 2m
kims-app Opaque 2 1m
kims-jenkins Opaque 1 30sExpected from describe (sizes only, never the values):
Data
====
secrets-key: 44 bytes
session-secret: 64 bytes#SECRETS_KEY decodes to 32 bytes
The CMS and worker refuse to start with SECRETS_KEY must be 32 bytes, base64; it decodes to N. otherwise. Check it without printing it:
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o jsonpath='{.data.secrets-key}' | base64 --decode | base64 --decode | wc -ckubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o jsonpath='{.data.secrets-key}' | base64 --decode | base64 --decode | wc -ckubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o jsonpath="{.data.secrets-key}" | node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log(Buffer.from(Buffer.from(s.trim(),'base64').toString(),'base64').length))"Expected: 32.
#The database URL asks for TLS
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-database -o jsonpath='{.data.url}' | base64 --decode | grep -cE 'sslmode=require(&uselibpqcompat=true)?