KKIMS on-site docs
Deploy KIMS (UAT and production)

Kubernetes Secrets

Create the four Kubernetes Secrets the chart reads (kims-database, kims-keycloak, kims-app, kims-jenkins) on Linux, macOS or Windows without leaving secrets in shell history, generate SESSION_SECRET and SECRETS_KEY, check them, back up the one that must never change, and rotate the others.

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
Warning

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.

Warning

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

bash
kubectl --context <KUBE_CONTEXT> get namespace <NAMESPACE>
kubectl --context <KUBE_CONTEXT> auth can-i create secrets -n <NAMESPACE>
bash
kubectl --context <KUBE_CONTEXT> get namespace <NAMESPACE>
kubectl --context <KUBE_CONTEXT> auth can-i create secrets -n <NAMESPACE>
powershell
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.

bash
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KUBE_CONTEXT> --namespace <NAMESPACE>
bash
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KUBE_CONTEXT> --namespace <NAMESPACE>
powershell
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:

  1. read with a hidden prompt into a shell variable,
  2. written with no trailing newline into a file in a private temporary folder,
  3. given to kubectl with --from-file=<key>=<file>,
  4. 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

bash
umask 077
SECDIR=$(mktemp -d)
echo "$SECDIR"
bash
umask 077
SECDIR=$(mktemp -d)
echo "$SECDIR"
powershell
$SecDir = Join-Path $env:TEMP ("kims-secrets-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $SecDir | Out-Null
$SecDir

Expected: 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.

Note

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

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

bash
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"
bash
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"
powershell
$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.

bash
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"
bash
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"
powershell
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:

bash
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

bash
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"
bash
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"
powershell
$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

bash
shred -u "$SECDIR"/* 2>/dev/null; rm -rf "$SECDIR"; unset SECDIR
bash
rm -P "$SECDIR"/* 2>/dev/null; rm -rf "$SECDIR"; unset SECDIR
powershell
Remove-Item -Recurse -Force $SecDir; Remove-Variable SecDir

Expected: 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

bash
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-app
bash
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-app
powershell
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-app

Expected from get:

text
NAME            TYPE     DATA   AGE
kims-database   Opaque   1      2m
kims-keycloak   Opaque   1      2m
kims-app        Opaque   2      1m
kims-jenkins    Opaque   1      30s

Expected from describe (sizes only, never the values):

text
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:

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o jsonpath='{.data.secrets-key}' | base64 --decode | base64 --decode | wc -c
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o jsonpath='{.data.secrets-key}' | base64 --decode | base64 --decode | wc -c
powershell
kubectl --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

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-database -o jsonpath='{.data.url}' | base64 --decode | grep -cE 'sslmode=require(&uselibpqcompat=true)?
    
Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-database -o jsonpath='{.data.url}' | base64 --decode | grep -cE 'sslmode=require(&uselibpqcompat=true)?
    
    {{pager}}
    
Built {{built}}. Commands are shown for the system picked at the top; every block has all three.
powershell
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-database -o jsonpath="{.data.url}" | node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log(/sslmode=require(&uselibpqcompat=true)?$/.test(Buffer.from(s.trim(),'base64').toString())?1:0))"

Expected: 1 (the URL ends sslmode=require, or sslmode=require&uselibpqcompat=true if you needed the workaround in aws/rds-postgresql). 0 means the string lacks it or has a trailing newline: replace it (Rotate the others).

#Why the secrets key must never change

SECRETS_KEY (kims-app, key secrets-key) encrypts, with AES-256-GCM, the rows of the PostgreSQL secrets table: the Google translation API key, the Google OAuth client, and the Google Business sign-in. If it changes, those rows can no longer be read, and an Admin must enter the translation key again, the OAuth client must be saved again, and Connect Google pressed again. Nothing else is lost.

So:

#Keep a copy in KIMS's vault

Agree with KIMS where the copy lives (their password vault, or AWS Secrets Manager). Then export it once, straight into the vault, and delete the file:

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o yaml > kims-app-<ENVIRONMENT>.yaml
# upload kims-app-<ENVIRONMENT>.yaml to the vault, then:
shred -u kims-app-<ENVIRONMENT>.yaml
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o yaml > kims-app-<ENVIRONMENT>.yaml
# upload kims-app-<ENVIRONMENT>.yaml to the vault, then:
rm -P kims-app-<ENVIRONMENT>.yaml
powershell
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> get secret kims-app -o yaml | Out-File -Encoding ascii kims-app-<ENVIRONMENT>.yaml
# upload kims-app-<ENVIRONMENT>.yaml to the vault, then:
Remove-Item kims-app-<ENVIRONMENT>.yaml

To restore it after an accident: kubectl -n <NAMESPACE> apply -f kims-app-<ENVIRONMENT>.yaml, then restart the CMS and worker.

#Rotate the others

#Replace one Secret

create ... --dry-run=client -o yaml | kubectl apply -f - replaces a Secret in place. Write the new value to a file as in By hand, without leaving secrets behind, then:

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SECDIR/url" --dry-run=client -o yaml | kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> apply -f -
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms deployment/kims-worker
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout status deployment/kims-cms --timeout=5m
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SECDIR/url" --dry-run=client -o yaml | kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> apply -f -
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms deployment/kims-worker
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout status deployment/kims-cms --timeout=5m
powershell
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> create secret generic kims-database --from-file=url="$SecDir\url" --dry-run=client -o yaml | kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> apply -f -
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms deployment/kims-worker
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout status deployment/kims-cms --timeout=5m

Expected: secret/kims-database configured, two ... restarted lines, then deployment "kims-cms" successfully rolled out. CronJobs pick up the new value at their next run. Or with the helper: kims secrets create --replace kims-database (also kims-keycloak, kims-jenkins; never kims-app).

#What each change does

Secret When to change Effect Also update
kims-database RDS password changed Restart CMS and worker The Jenkins folder credential kims-database-url
kims-keycloak Client secret regenerated in Keycloak Restart CMS. Sign-in fails between the Keycloak change and the restart
kims-jenkins Token revoked or the user changed Restart CMS and worker JENKINS_USER in the values, if the user changed
kims-app session-secret Suspected leak Signs everybody out (it signs the session cookie and encrypts the stored Keycloak refresh tokens)
kims-app secrets-key Never Google secrets become unreadable

#Change only session-secret

Generate a new value into $SECDIR/session-secret (step 4's first line), then patch just that key, keeping secrets-key:

bash
NEW=$(base64 < "$SECDIR/session-secret" | tr -d '\n')
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> patch secret kims-app --type merge -p "{\"data\":{\"session-secret\":\"$NEW\"}}"; unset NEW
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms
bash
NEW=$(base64 < "$SECDIR/session-secret" | tr -d '\n')
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> patch secret kims-app --type merge -p "{\"data\":{\"session-secret\":\"$NEW\"}}"; unset NEW
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms
powershell
Set-Content -Path "$SecDir\patch.json" -NoNewline -Encoding ascii -Value ('{"data":{"session-secret":"' + [Convert]::ToBase64String([IO.File]::ReadAllBytes("$SecDir\session-secret")) + '"}}')
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> patch secret kims-app --type merge --patch-file "$SecDir\patch.json"
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> rollout restart deployment/kims-cms

Expected: secret/kims-app patched, then deployment.apps/kims-cms restarted. Run the 32-byte check again to be sure secrets-key is untouched. (On Linux and macOS the value briefly appears in the process list as a kubectl argument; it is already base64 and only you can read your processes on a single-user laptop.)

#If it goes wrong

What you see Cause Fix
error: failed to create secret secrets "kims-app" already exists Created before Leave kims-app alone. For the others, use Replace one Secret
Pods CreateContainerConfigError A Secret or key is missing or misnamed kubectl -n <NAMESPACE> describe pod <POD> names it, for example couldn't find key secrets-key in Secret
CMS logs SESSION_SECRET is N characters. It must be at least 32. Short value Regenerate with 48 bytes
CMS or worker logs SECRETS_KEY must be 32 bytes, base64 Wrong length, or a newline was base64-encoded with it Only on a brand new environment with nothing saved yet: recreate kims-app. Otherwise restore the vault copy
Health check says database: unreachable Wrong URL, missing sslmode=require, newline, or network Check the Secrets, then aws/networking
forbidden: User ... cannot create resource "secrets" No rights in the namespace KIMS runs the commands, or grants you edit in the namespace

#Sources

{{pager}}