mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
Any stored KEK that did not decode to exactly 44 characters was overwritten. The proxy skips CR and LF when it decodes KKP_KEK, so a key restored from a file ending in a newline works, and the chart replaced it silently. A 44-character value that is not base64 of 32 bytes was kept, and the proxy could not start with it. Only the 32-character alphanumeric form earlier chart versions wrote is replaced now. A key the proxy accepts is kept, and anything else fails the render, so key material is never overwritten. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1138 lines
37 KiB
YAML
1138 lines
37 KiB
YAML
suite: keycloak optional KMS-encrypting DB proxy
|
|
templates:
|
|
- templates/proxy.yaml
|
|
- templates/sts.yaml
|
|
|
|
release:
|
|
name: keycloak
|
|
namespace: cozy-keycloak
|
|
|
|
tests:
|
|
- it: does not render the proxy when encryption is disabled (default)
|
|
template: templates/proxy.yaml
|
|
set:
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 0
|
|
|
|
- it: keeps Keycloak pointed at the CNPG secret when encryption is disabled
|
|
template: templates/sts.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: StatefulSet
|
|
set:
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KC_DB_URL_HOST
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: keycloak-db-app
|
|
key: "host"
|
|
|
|
- it: renders four documents (KEK Secret + ServiceAccount + Deployment + Service) when enabled
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 4
|
|
|
|
- it: deploys the proxy wired to the static KEK and the CNPG backend
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: keycloak-kms-proxy
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_KEK
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: keycloak-kms-proxy-kek
|
|
key: kek
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_BACKEND_ADDR
|
|
value: keycloak-db-rw.cozy-keycloak.svc.cozy.local:5432
|
|
|
|
- it: generates the static KEK Secret
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: keycloak-kms-proxy-kek
|
|
|
|
- it: generates a static KEK the proxy can decode (base64 of 32 bytes)
|
|
# data.kek is the Secret encoding of KKP_KEK, which must itself be base64
|
|
# of 32 bytes (44 characters), so data.kek is 60 characters long.
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- matchRegex:
|
|
path: data.kek
|
|
pattern: ^[A-Za-z0-9+/]{59}=$
|
|
|
|
- it: keeps an existing static KEK the proxy can decode
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: "v1"
|
|
resource: "secrets"
|
|
namespaced: true
|
|
objects:
|
|
- kind: Secret
|
|
apiVersion: v1
|
|
metadata:
|
|
name: keycloak-kms-proxy-kek
|
|
namespace: cozy-keycloak
|
|
data:
|
|
kek: QUFFQ0F3UUZCZ2NJQ1FvTERBME9EeEFSRWhNVUZSWVhHQmthR3h3ZEhoOD0=
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: data.kek
|
|
value: QUFFQ0F3UUZCZ2NJQ1FvTERBME9EeEFSRWhNVUZSWVhHQmthR3h3ZEhoOD0=
|
|
|
|
- it: replaces a static KEK from earlier chart versions that the proxy rejects
|
|
# Earlier versions stored 32 alphanumeric characters, which decode to 24
|
|
# bytes; the proxy never started with them, so nothing was encrypted.
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: "v1"
|
|
resource: "secrets"
|
|
namespaced: true
|
|
objects:
|
|
- kind: Secret
|
|
apiVersion: v1
|
|
metadata:
|
|
name: keycloak-kms-proxy-kek
|
|
namespace: cozy-keycloak
|
|
data:
|
|
kek: YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- matchRegex:
|
|
path: data.kek
|
|
pattern: ^[A-Za-z0-9+/]{59}=$
|
|
|
|
- it: keeps the static KEK Secret when the release drops it
|
|
# The DEK set is wrapped with this KEK; deleting it with the release
|
|
# would make the data undecryptable on the next enable.
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/resource-policy"]
|
|
value: keep
|
|
|
|
- it: keeps a restored static KEK with a trailing newline
|
|
# The proxy decodes KKP_KEK with base64.StdEncoding, which skips CR and
|
|
# LF, so a key restored from a file ending in a newline still works.
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Secret
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: "v1"
|
|
resource: "secrets"
|
|
namespaced: true
|
|
objects:
|
|
- kind: Secret
|
|
apiVersion: v1
|
|
metadata:
|
|
name: keycloak-kms-proxy-kek
|
|
namespace: cozy-keycloak
|
|
data:
|
|
kek: QUFFQ0F3UUZCZ2NJQ1FvTERBME9EeEFSRWhNVUZSWVhHQmthR3h3ZEhoOD0K
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: data.kek
|
|
value: QUFFQ0F3UUZCZ2NJQ1FvTERBME9EeEFSRWhNVUZSWVhHQmthR3h3ZEhoOD0K
|
|
|
|
- it: refuses a stored static KEK the proxy cannot decode instead of replacing it
|
|
# 44 characters of valid base64 that decode to 33 bytes.
|
|
template: templates/proxy.yaml
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: "v1"
|
|
resource: "secrets"
|
|
namespaced: true
|
|
objects:
|
|
- kind: Secret
|
|
apiVersion: v1
|
|
metadata:
|
|
name: keycloak-kms-proxy-kek
|
|
namespace: cozy-keycloak
|
|
data:
|
|
kek: QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE=
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "is not base64 of 32 bytes"
|
|
|
|
- it: exposes the proxy on a postgres Service
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Service
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: keycloak-kms-proxy
|
|
- equal:
|
|
path: spec.ports[0].port
|
|
value: 5432
|
|
|
|
- it: repoints Keycloak at the proxy Service when encryption is enabled
|
|
template: templates/sts.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: StatefulSet
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KC_DB_URL_HOST
|
|
value: keycloak-kms-proxy.cozy-keycloak.svc.cozy.local
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KC_DB_URL_PORT
|
|
value: "5432"
|
|
|
|
- it: uses the Vault Transit backend when selected
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.tokenSecretName: keycloak-vault-token
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_ADDR
|
|
value: https://vault.vault.svc:8200
|
|
# Token auth must not leak AppRole env vars. any:true matches on the
|
|
# element name alone (helm-unittest otherwise deep-equals whole elements).
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: KKP_VAULT_ROLE_ID
|
|
|
|
- it: does not generate a static KEK Secret for the Vault backend
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.tokenSecretName: keycloak-vault-token
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
# ServiceAccount + Deployment + Service (no KEK Secret for Vault).
|
|
- hasDocuments:
|
|
count: 3
|
|
|
|
- it: rejects an unsupported kms backend at render time
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.backend must be 'static' or 'vault-transit'"
|
|
|
|
- it: requires vault.address for the vault-transit backend
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.tokenSecretName: keycloak-vault-token
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.address is required"
|
|
|
|
- it: requires vault.keyName for the vault-transit backend
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.tokenSecretName: keycloak-vault-token
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.keyName is required"
|
|
|
|
- it: requires vault.tokenSecretName for the vault-transit backend
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.tokenSecretName is required"
|
|
|
|
- it: authenticates via AppRole when vault.auth=approle
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_APPROLE_MOUNT
|
|
value: approle
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_ROLE_ID
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: keycloak-vault-approle
|
|
key: role-id
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_SECRET_ID
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: keycloak-vault-approle
|
|
key: secret-id
|
|
# AppRole must not store a long-lived token. any:true matches on the
|
|
# element name alone (helm-unittest otherwise deep-equals whole elements,
|
|
# so a name-only content would never match the valueFrom entry).
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: KKP_VAULT_TOKEN
|
|
|
|
- it: requires appRole.secretName when vault.auth=approle
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.appRole.secretName is required"
|
|
|
|
- it: authenticates via Kubernetes when vault.auth=kubernetes
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: kubernetes
|
|
encryption.kms.vault.kubernetes.role: keycloak-proxy
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_KUBERNETES_ROLE
|
|
value: keycloak-proxy
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_VAULT_KUBERNETES_MOUNT
|
|
value: kubernetes
|
|
# No credential env vars for the other modes must leak in.
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: KKP_VAULT_TOKEN
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: KKP_VAULT_ROLE_ID
|
|
|
|
- it: requires kubernetes.role when vault.auth=kubernetes
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: kubernetes
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.kubernetes.role is required"
|
|
|
|
- it: rejects an unsupported vault auth method
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: bogus
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.kms.vault.auth must be 'token', 'approle', or 'kubernetes'"
|
|
|
|
- it: creates a dedicated proxy ServiceAccount with the token off by default
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: ServiceAccount
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: keycloak-kms-proxy
|
|
- equal:
|
|
path: automountServiceAccountToken
|
|
value: false
|
|
|
|
- it: enables the ServiceAccount token on the SA object for Kubernetes auth
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: ServiceAccount
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: kubernetes
|
|
encryption.kms.vault.kubernetes.role: keycloak-proxy
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: automountServiceAccountToken
|
|
value: true
|
|
|
|
- it: runs the proxy under its ServiceAccount with the token off by default
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.serviceAccountName
|
|
value: keycloak-kms-proxy
|
|
- equal:
|
|
path: spec.template.spec.automountServiceAccountToken
|
|
value: false
|
|
|
|
- it: mounts the ServiceAccount token only for Kubernetes auth
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.vault.svc:8200
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: kubernetes
|
|
encryption.kms.vault.kubernetes.role: keycloak-proxy
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: spec.template.spec.automountServiceAccountToken
|
|
value: true
|
|
|
|
- it: refuses to encrypt without a persistent DEK set
|
|
# Without KKP_DEKSET_FILE the proxy mints a new DEK on every start and
|
|
# cannot decrypt rows written before a restart.
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.deksetSecretName is required unless encryption.fields is"
|
|
|
|
- it: refuses to encrypt only emails without a persistent DEK set
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: email-only
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.deksetSecretName is required unless encryption.fields is"
|
|
|
|
- it: runs as a passthrough without a DEK set when fields are disabled
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
# Anchor the index before asserting on it. notContains passes whenever its
|
|
# path resolves to something that lacks the content, and a different
|
|
# container at [0] qualifies, so without this the guard goes green if a
|
|
# sidecar is ever placed ahead of the proxy.
|
|
- equal:
|
|
path: spec.template.spec.containers[0].name
|
|
value: proxy
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_FIELDS
|
|
value: disabled
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: KKP_DEKSET_FILE
|
|
- notExists:
|
|
path: spec.template.spec.volumes
|
|
|
|
- it: mounts the wrapped DEK set when deksetSecretName is set
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_DEKSET_FILE
|
|
value: /etc/kkp/dekset/dekset.json
|
|
- contains:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
content:
|
|
name: dekset
|
|
mountPath: /etc/kkp/dekset
|
|
readOnly: true
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: dekset
|
|
secret:
|
|
secretName: keycloak-kms-proxy-dekset
|
|
# Exactly one of each: the dekset and Vault CA blocks share these keys, so
|
|
# a CA volume rendered without its conditional shows up as a second entry.
|
|
- lengthEqual:
|
|
path: spec.template.spec.volumes
|
|
count: 1
|
|
- lengthEqual:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
count: 1
|
|
|
|
- it: rejects HA (replicas > 1) without a dekset
|
|
template: templates/proxy.yaml
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.replicas: 2
|
|
encryption.fields: disabled
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "encryption.replicas > 1 requires encryption.deksetSecretName"
|
|
|
|
- it: allows HA when a shared dekset is provided
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.replicas: 2
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- equal:
|
|
path: spec.replicas
|
|
value: 2
|
|
|
|
- it: honors a custom deksetSecretKey
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.deksetSecretKey: custom.json
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: KKP_DEKSET_FILE
|
|
value: /etc/kkp/dekset/custom.json
|
|
|
|
- it: trusts a private Vault CA supplied inline as caBundle
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caBundle: |
|
|
-----BEGIN CERTIFICATE-----
|
|
dGVzdA==
|
|
-----END CERTIFICATE-----
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
asserts:
|
|
- equal:
|
|
path: stringData["ca.crt"]
|
|
value: |
|
|
-----BEGIN CERTIFICATE-----
|
|
dGVzdA==
|
|
-----END CERTIFICATE-----
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: keycloak-kms-proxy-vault-ca
|
|
# SSL_CERT_FILE alone leaves the image's public roots in the pool; both
|
|
# variables together pin the Vault leg to this CA.
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: SSL_CERT_FILE
|
|
value: /etc/kkp/vault-ca/ca.crt
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: SSL_CERT_DIR
|
|
value: /etc/kkp/vault-ca
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
# Derived from the bundle, so rotating it rolls the pods — the process
|
|
# memoizes its root pool and would otherwise keep the old CA.
|
|
- equal:
|
|
path: spec.template.metadata.annotations["checksum/vault-ca"]
|
|
value: de63913efff35e2e9be70b97bd7a0e12a2205f3a0ca00a114606d778abf65fe0
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
- contains:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
content:
|
|
name: vault-ca
|
|
mountPath: /etc/kkp/vault-ca
|
|
readOnly: true
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: vault-ca
|
|
secret:
|
|
secretName: keycloak-kms-proxy-vault-ca
|
|
items:
|
|
- key: ca.crt
|
|
path: ca.crt
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
|
|
- it: mounts a pre-seeded CA Secret when caSecretName is set
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caSecretName: vault-ca
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: SSL_CERT_FILE
|
|
value: /etc/kkp/vault-ca/ca.crt
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: SSL_CERT_DIR
|
|
value: /etc/kkp/vault-ca
|
|
- contains:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
content:
|
|
name: vault-ca
|
|
mountPath: /etc/kkp/vault-ca
|
|
readOnly: true
|
|
# No checksum annotation on this path: the chart does not own the Secret
|
|
# and cannot see its contents, so rotation needs a manual rollout restart.
|
|
- notExists:
|
|
path: spec.template.metadata.annotations
|
|
# Only one key is projected: a cert-manager TLS Secret would otherwise hand
|
|
# tls.key to the proxy, and a bundle under another key would fail the mount
|
|
# instead of looking like an unconfigured CA at runtime.
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: vault-ca
|
|
secret:
|
|
secretName: vault-ca
|
|
items:
|
|
- key: ca.crt
|
|
path: ca.crt
|
|
# No dekset here, so a dekset volume rendered without its conditional
|
|
# (with an empty secretName) shows up as a second entry.
|
|
- lengthEqual:
|
|
path: spec.template.spec.volumes
|
|
count: 1
|
|
- lengthEqual:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
count: 1
|
|
|
|
- it: fails when both caBundle and caSecretName are set
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caSecretName: vault-ca
|
|
encryption.kms.vault.caBundle: PEM
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: mutually exclusive
|
|
|
|
- it: leaves the proxy on the system trust store when no CA is configured
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: SSL_CERT_FILE
|
|
- notExists:
|
|
path: spec.template.spec.volumes
|
|
- notExists:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
|
|
# The volume and mount are pod-level, outside the vault-transit env block, so
|
|
# an ungated caSecretName would have the static backend mount a Secret the
|
|
# chart never renders — the pod then never leaves ContainerCreating and takes
|
|
# all Keycloak DB traffic with it.
|
|
- it: ignores a pre-seeded Vault CA Secret under the static backend
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
encryption.kms.vault.caSecretName: vault-ca
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
- notExists:
|
|
path: spec.template.spec.volumes
|
|
- notExists:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
- notContains:
|
|
path: spec.template.spec.containers[0].env
|
|
any: true
|
|
content:
|
|
name: SSL_CERT_FILE
|
|
|
|
- it: ignores an inline Vault CA bundle under the static backend
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.fields: disabled
|
|
encryption.kms.vault.caBundle: PEM
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
asserts:
|
|
# KEK Secret, ServiceAccount, Deployment, Service — no CA Secret.
|
|
- hasDocuments:
|
|
count: 4
|
|
- notExists:
|
|
path: spec.template.spec.volumes
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
|
|
# Every vault.* key is inert under the static backend, the mutual-exclusion
|
|
# check included: rejecting a combination that cannot reach Vault anyway would
|
|
# break a render that is otherwise valid.
|
|
- it: does not enforce Vault CA mutual exclusion under the static backend
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.vault.caSecretName: vault-ca
|
|
encryption.kms.vault.caBundle: PEM
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
asserts:
|
|
- notFailedTemplate: {}
|
|
- hasDocuments:
|
|
count: 4
|
|
|
|
- it: rolls the pods when a chart-owned caBundle is rotated
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caBundle: |
|
|
-----BEGIN CERTIFICATE-----
|
|
cm90YXRlZA==
|
|
-----END CERTIFICATE-----
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
# Differs from the checksum asserted for the bundle above.
|
|
- equal:
|
|
path: spec.template.metadata.annotations["checksum/vault-ca"]
|
|
value: 76da7d3279a7bc1e42a021a7c3fdc0e79b506bc152171128003ae15f56512741
|
|
|
|
- it: rejects a caBundle that is not a PEM certificate bundle
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caBundle: not-a-certificate
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "caBundle must be a PEM bundle"
|
|
|
|
- it: reads a pre-seeded bundle from a custom caSecretKey
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caSecretName: vault-serving-cert
|
|
encryption.kms.vault.caSecretKey: ca-bundle.crt
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
# The key varies, the projected path does not, so SSL_CERT_FILE is fixed.
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: vault-ca
|
|
secret:
|
|
secretName: vault-serving-cert
|
|
items:
|
|
- key: ca-bundle.crt
|
|
path: ca.crt
|
|
- contains:
|
|
path: spec.template.spec.containers[0].env
|
|
content:
|
|
name: SSL_CERT_FILE
|
|
value: /etc/kkp/vault-ca/ca.crt
|
|
|
|
# Both optional mounts at once: the dekset and CA blocks share the volumes and
|
|
# volumeMounts keys, so dropping either inner conditional must fail here.
|
|
- it: mounts the dekset and the Vault CA side by side
|
|
set:
|
|
encryption.enabled: true
|
|
encryption.kms.backend: vault-transit
|
|
encryption.kms.vault.address: https://vault.example
|
|
encryption.kms.vault.keyName: keycloak
|
|
encryption.kms.vault.auth: approle
|
|
encryption.kms.vault.appRole.secretName: keycloak-vault-approle
|
|
encryption.kms.vault.caSecretName: vault-ca
|
|
encryption.deksetSecretName: keycloak-kms-proxy-dekset
|
|
_cluster:
|
|
root-host: example.org
|
|
cluster-domain: cozy.local
|
|
template: templates/proxy.yaml
|
|
documentSelector:
|
|
path: kind
|
|
value: Deployment
|
|
asserts:
|
|
- lengthEqual:
|
|
path: spec.template.spec.volumes
|
|
count: 2
|
|
- lengthEqual:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
count: 2
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: dekset
|
|
secret:
|
|
secretName: keycloak-kms-proxy-dekset
|
|
- contains:
|
|
path: spec.template.spec.volumes
|
|
content:
|
|
name: vault-ca
|
|
secret:
|
|
secretName: vault-ca
|
|
items:
|
|
- key: ca.crt
|
|
path: ca.crt
|
|
- contains:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
content:
|
|
name: dekset
|
|
mountPath: /etc/kkp/dekset
|
|
readOnly: true
|
|
- contains:
|
|
path: spec.template.spec.containers[0].volumeMounts
|
|
content:
|
|
name: vault-ca
|
|
mountPath: /etc/kkp/vault-ca
|
|
readOnly: true
|