From 0999d9cfd2cbc9d7f9abc8c5c21483f4ffaa8d2d Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Mon, 23 Nov 2026 16:40:23 +0100 Subject: [PATCH] feat(redis)!: issue the password through the credentials API The chart generated the password of the default user itself, kept it readable by the tenant in -auth, and shared it with replication, the Sentinels, the exporter and backups. It now renders a CredentialTemplate for the default account while authEnabled is on, and points the operator at that account's Secret, which the platform seeds and rewrites on a mint and which the tenant cannot read. The operator keeps replication, the Sentinels, the probes and the exporter on an internal account of its own, so the minted password reaches only the servers' default user and the backup Job, which is why the backup strategy reads the same Secret, and a mint restarts no pod. The ResourceDefinition no longer selects -auth and excludes the internal account's Secret, which carries an ownerReference to the RedisFailover, so the tenant-visible set holds the trust anchor alone. The e2e mint step fails if a mint restarts a pod or moves the master. BREAKING CHANGE: -auth is no longer rendered or readable; clients get the password by minting the default credential. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- api/apps/v1alpha1/redis/types.go | 2 +- examples/backups/redis/00-helpers.sh | 15 ++- examples/backups/redis/redis-strategy.yaml | 2 +- hack/check-redis-rd-secrets.bats | 10 +- hack/e2e-chainsaw/redis/chainsaw-test.yaml | 108 +++++++++++++++--- hack/redis-backup-demo-helpers.bats | 2 +- packages/apps/redis/README.md | 2 +- .../apps/redis/templates/credentials.yaml | 21 ++++ .../apps/redis/templates/redisfailover.yaml | 21 +--- .../tests/credential_templates_test.yaml | 80 +++++++++++++ packages/apps/redis/values.schema.json | 2 +- packages/apps/redis/values.yaml | 2 +- .../templates/strategy-redis-default.yaml | 9 +- .../tests/strategy_redis_test.yaml | 16 +++ packages/system/redis-rd/cozyrds/redis.yaml | 8 +- 15 files changed, 248 insertions(+), 52 deletions(-) create mode 100644 packages/apps/redis/templates/credentials.yaml create mode 100644 packages/apps/redis/tests/credential_templates_test.yaml diff --git a/api/apps/v1alpha1/redis/types.go b/api/apps/v1alpha1/redis/types.go index 2c95eb6cc..602b5203d 100644 --- a/api/apps/v1alpha1/redis/types.go +++ b/api/apps/v1alpha1/redis/types.go @@ -46,7 +46,7 @@ type ConfigSpec struct { // TLS configuration. TLS is opt-in and is not inferred from `external`. // +kubebuilder:default:={} Tls TLS `json:"tls,omitempty"` - // Enable password generation. + // Require a password. The password of the `default` user is issued through the credentials API, and issuing a new one takes effect without restarting anything. Replication, the Sentinels and the metrics exporter use an internal account of their own; backups use the `default` password. // +kubebuilder:default:=true AuthEnabled bool `json:"authEnabled"` // Redis `min-replicas-to-write`: the master refuses writes unless at least this many replicas are connected and within `minReplicasMaxLag`. Unset by default, which leaves the Redis default (disabled). With `replicas: 2` and a value of 1 the master rejects writes while its only replica is down, trading availability for a bound on the writes lost if an isolated master is failed over. Replication stays asynchronous, so this bounds the loss, it does not remove it. Must be 0 or more and below `replicas` (a master with `replicas` pods has `replicas - 1` replicas), otherwise every write is refused; the chart refuses such a value. diff --git a/examples/backups/redis/00-helpers.sh b/examples/backups/redis/00-helpers.sh index 8c7272a57..e20ee6916 100755 --- a/examples/backups/redis/00-helpers.sh +++ b/examples/backups/redis/00-helpers.sh @@ -80,13 +80,16 @@ print_header() { source "$(dirname "${BASH_SOURCE[0]}")/../_lib/wait-helpers.sh" # The cozystack redis chart names its RedisFailover (hence the operator's rfr-/ -# rfs- Services and the -auth Secret) redis-, the valkey chart valkey-, -# mirroring the strategy driver that derives the same base from .Release.Prefix -# and .Release.Name. So app X's password lives in X-auth. The chart -# renders that Secret only with authEnabled, so its absence reads as no -# password; any other error still fails the read. +# rfs- Services) redis-, the valkey chart valkey-, mirroring the +# strategy driver that derives the same base from .Release.Prefix and +# .Release.Name. App X's password lives in the account Secret of its default +# CredentialTemplate, X.default.account, which holds the password itself +# and which this walkthrough reads with the platform credentials it runs under; +# a tenant gets the password by minting it instead. The Secret exists only with +# authEnabled, so its absence reads as no password; any other error still fails +# the read. redis_pw() { - kubectl -n "$NAMESPACE" get secret "${APP_PREFIX}$1-auth" --ignore-not-found -o jsonpath='{.data.password}' | base64 -d + kubectl -n "$NAMESPACE" get secret "${APP_PREFIX}$1.default.account" --ignore-not-found -o jsonpath='{.data.password}' | base64 -d } # Run a redis-cli command against an application's CURRENT master. Master diff --git a/examples/backups/redis/redis-strategy.yaml b/examples/backups/redis/redis-strategy.yaml index 6533b0e38..88ee39f8d 100644 --- a/examples/backups/redis/redis-strategy.yaml +++ b/examples/backups/redis/redis-strategy.yaml @@ -51,7 +51,7 @@ spec: - name: REDIS_PASSWORD valueFrom: secretKeyRef: - name: '{{ .Release.Prefix | default "redis-" }}{{ .Release.Name }}-auth' + name: '{{ .Release.Prefix | default "redis-" }}{{ .Release.Name }}.default.account' key: password optional: true # S3 coordinates come from this demo's Bucket: the access keys are diff --git a/hack/check-redis-rd-secrets.bats b/hack/check-redis-rd-secrets.bats index 915e870fa..888d29886 100644 --- a/hack/check-redis-rd-secrets.bats +++ b/hack/check-redis-rd-secrets.bats @@ -44,11 +44,13 @@ load test_helper REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" CHART="$REPO_ROOT/packages/system/redis-rd" -# The complete tenant-visible Secret surface. The generated password by name; -# the trust anchor by label. Nothing else. The two key-bearing Secrets are +# The complete tenant-visible Secret surface: the trust anchor by label, and +# nothing else. The password is issued through the credentials API, and its +# account Secret is the platform's. The operator's internal account joins the +# key-bearing Secrets in exclude. The two key-bearing Secrets are # named in exclude, which is evaluated before include and so backstops the # label-only entry against a mis-stamp. -EXPECTED_SECRETS='{"exclude":[{"resourceNames":["redis-{{ .name }}.ca-tls","redis-{{ .name }}.tls","redis-{{ .name }}.ca-cert"]}],"include":[{"resourceNames":["redis-{{ .name }}-auth"]},{"matchLabels":{"internal.cozystack.io/tenant-ca":"true"}}]}' +EXPECTED_SECRETS='{"exclude":[{"resourceNames":["redis-{{ .name }}.ca-tls","redis-{{ .name }}.tls","redis-{{ .name }}.ca-cert","rfr-redis-{{ .name }}-internal"]}],"include":[{"matchLabels":{"internal.cozystack.io/tenant-ca":"true"}}]}' # Order within include is meaningless -- the matcher ORs across entries -- so # both arrays are sorted before comparing, and a missing exclude is normalized @@ -115,7 +117,7 @@ NORMALIZE='{exclude: ((.exclude // []) | sort), include: (.include | sort)}' # Whole-structure comparison. Anything added to the tenant's Secret surface -- # by name, by label, or by an unrestricted entry -- changes this string. -@test "redis-rd exposes no Secret beyond the password and the trust anchor" { +@test "redis-rd exposes no Secret beyond the trust anchor" { rendered=$(helm template redis-rd "$CHART") || return 1 if [ -z "$rendered" ]; then diff --git a/hack/e2e-chainsaw/redis/chainsaw-test.yaml b/hack/e2e-chainsaw/redis/chainsaw-test.yaml index 61ac67dd0..7b7c126a9 100644 --- a/hack/e2e-chainsaw/redis/chainsaw-test.yaml +++ b/hack/e2e-chainsaw/redis/chainsaw-test.yaml @@ -81,6 +81,87 @@ spec: status: readyReplicas: 2 + # The password is the platform's to issue: a mint reaches every running + # server with CONFIG SET, restarts no pod and moves no master (replication, + # the Sentinels, the probes and the exporter use the operator's internal + # account, not this password), and a second mint replaces the first. + - name: verify-minted-credential + try: + - assert: + timeout: 2m + resource: + apiVersion: core.cozystack.io/v1alpha1 + kind: Credential + metadata: + name: redis-test.default + spec: + application: + kind: Redis + name: test + user: default + status: + password: + origin: NotIssued + # bash for pipefail and process substitution; the sandbox's /bin/sh is dash. + - script: + timeout: 10m + shell: bash + content: | + set -euo pipefail + cred=redis-test.default + mint() { + kubectl create --raw "/apis/core.cozystack.io/v1alpha1/namespaces/$NAMESPACE/credentials/$cred/mint" \ + -f <(printf '{"apiVersion":"core.cozystack.io/v1alpha1","kind":"CredentialRequest"}') \ + | jq -r '.status.password' + } + # The password goes to redis-cli on stdin: exec arguments travel in + # the request URI, which the audit log records at any level. + cli() { + local password=$1; shift + local pod + pod=$(kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=redis,app.kubernetes.io/instance=redis-test \ + --field-selector status.phase=Running -o name | head -n1) + [ -n "$pod" ] || return 0 + printf '%s\n' "$password" | kubectl -n "$NAMESPACE" exec -i "$pod" -c redis -- \ + sh -c 'IFS= read -r REDISCLI_AUTH; export REDISCLI_AUTH; exec redis-cli -h rfrm-redis-test "$@"' sh \ + "$@" 2>/dev/null | tr -d '\r' || true + } + login() { cli "$1" ping; } + # Every redis pod with its uid and restart count, and which one the + # master label is on: a mint must change none of it. + pods() { + kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=redis,app.kubernetes.io/instance=redis-test \ + -o jsonpath='{range .items[*]}{.metadata.name} {.metadata.uid} {.status.containerStatuses[*].restartCount} {.metadata.labels.redisfailovers-role}{"\n"}{end}' | sort + } + before=$(pods) + [ "$(printf '%s\n' "$before" | grep -c ' master$')" = 1 ] || { echo "no single master before the mint: $before" >&2; exit 1; } + + first=$(mint) + [ "${#first}" -eq 32 ] || { echo "minted password has ${#first} characters, want 32" >&2; exit 1; } + # The operator applies the changed account Secret on its next + # reconcile; a readiness wait on that, not a retry. + until [ "$(login "$first")" = "PONG" ]; do sleep 5; done + view=$(kubectl -n "$NAMESPACE" get credentials.core.cozystack.io "$cred" -o json) + [ "$(printf '%s' "$view" | jq -r .status.password.origin)" = "Minted" ] || { echo "origin is not Minted: $view" >&2; exit 1; } + if printf '%s' "$view" | grep -qF -- "$first"; then echo "the Credential carries the minted password" >&2; exit 1; fi + + second=$(mint) + [ "$second" != "$first" ] || { echo "a second mint returned the same password" >&2; exit 1; } + until [ "$(login "$second")" = "PONG" ]; do sleep 5; done + # The operator drops the replaced password once every server takes + # the new one, a pass after it applies it. + while [ "$(login "$first")" = "PONG" ]; do sleep 5; done + # Replication outlived both rotations, and nothing restarted or + # failed over to get there. + until cli "$second" info replication | grep -qx 'connected_slaves:1'; do sleep 5; done + after=$(pods) + if [ "$after" != "$before" ]; then + printf 'a mint restarted a pod or moved the master:\nbefore:\n%s\nafter:\n%s\n' "$before" "$after" >&2 + exit 1 + fi + check: + ($error == null): true + # One replica runs one Sentinel with its PDB disabled. The PDB the operator # created for the three Sentinels of two replicas has to go with it, or its # minAvailable: 1 pins the only Sentinel against every eviction. @@ -267,20 +348,10 @@ spec: try: # Positive control, and it comes first: the negatives below are satisfied # by an ABSENT label, which is also what a webhook that stamped nothing - # this run looks like. The auth Secret is chart-rendered, traces to the - # Redis CR and is included by name, so it MUST be stamped. - - assert: - timeout: 2m - resource: - apiVersion: v1 - kind: Secret - metadata: - name: redis-secure-auth - labels: - internal.cozystack.io/tenantresource: "true" - # tenant-ca is stamped by the CA-extraction controller; tenantresource is - # the lineage webhook's verdict from the redis ApplicationDefinition's - # matchLabels include. Both true means the whole chain held. + # this run looks like. tenant-ca is stamped by the CA-extraction + # controller; tenantresource is the lineage webhook's verdict from the + # redis ApplicationDefinition's matchLabels include. Both true means the + # whole chain held. - assert: timeout: 2m resource: @@ -320,6 +391,15 @@ spec: metadata: name: redis-secure.ca-cert (metadata.labels."internal.cozystack.io/tenantresource" != 'true'): true + # The account Secret holds the password itself and is the platform's. + - assert: + timeout: 2m + resource: + apiVersion: v1 + kind: Secret + metadata: + name: redis-secure.default.account + (metadata.labels."internal.cozystack.io/tenantresource" != 'true'): true # No retry around this script. The replica link it reads is settled by # none of the asserts above and carries its own bounded wait below. The # whole step measured 3.0s on run 34711755303, so link_wait is wide diff --git a/hack/redis-backup-demo-helpers.bats b/hack/redis-backup-demo-helpers.bats index bbc9fdaa3..432bf40fd 100644 --- a/hack/redis-backup-demo-helpers.bats +++ b/hack/redis-backup-demo-helpers.bats @@ -20,7 +20,7 @@ make_stubs() { cat > "$stub/kubectl" <<'EOF' #!/bin/bash printf '%s\n' "$*" >> "$STUB_DIR/kubectl.argv" -if [ "$*" = "-n tenant-root get secret redis-demo-auth --ignore-not-found -o jsonpath={.data.password}" ]; then +if [ "$*" = "-n tenant-root get secret redis-demo.default.account --ignore-not-found -o jsonpath={.data.password}" ]; then printf '%s' "${STUB_PW_B64:-}" exit 0 fi diff --git a/packages/apps/redis/README.md b/packages/apps/redis/README.md index 0986a3e13..12a231d96 100644 --- a/packages/apps/redis/README.md +++ b/packages/apps/redis/README.md @@ -44,7 +44,7 @@ Service utilizes the freshworks-oss Redis Operator (a maintained fork of the arc | Name | Description | Type | Value | | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------ | -| `authEnabled` | Enable password generation. | `bool` | `true` | +| `authEnabled` | Require a password. The password of the `default` user is issued through the credentials API, and issuing a new one takes effect without restarting anything. Replication, the Sentinels and the metrics exporter use an internal account of their own; backups use the `default` password. | `bool` | `true` | | `minReplicasToWrite` | Redis `min-replicas-to-write`: the master refuses writes unless at least this many replicas are connected and within `minReplicasMaxLag`. Unset by default, which leaves the Redis default (disabled). With `replicas: 2` and a value of 1 the master rejects writes while its only replica is down, trading availability for a bound on the writes lost if an isolated master is failed over. Replication stays asynchronous, so this bounds the loss, it does not remove it. Must be 0 or more and below `replicas` (a master with `replicas` pods has `replicas - 1` replicas), otherwise every write is refused; the chart refuses such a value. | `*int` | `null` | | `minReplicasMaxLag` | Redis `min-replicas-max-lag`, in seconds: a replica whose last acknowledgement is older than this does not count towards `minReplicasToWrite`. Unset by default, which leaves the Redis default (10). Has no effect unless `minReplicasToWrite` is set. Must be at least 1 when `minReplicasToWrite` is set: Redis treats 0 as disabling the check, so the chart refuses it. | `*int` | `null` | | `maxmemory` | Redis `maxmemory`: the dataset size at which Redis applies `maxmemoryPolicy`. Unset by default, which renders `maxmemory 0` (no limit, the Redis default), so a value set by hand with `CONFIG SET` is reset on the next reconcile. Must be at most 90% of the memory request of each Redis pod (from `resources` or `resourcesPreset`): the operator silently drops a larger value, so the chart refuses it. Leave headroom below that for replication and snapshot buffers. | `quantity` | `""` | diff --git a/packages/apps/redis/templates/credentials.yaml b/packages/apps/redis/templates/credentials.yaml new file mode 100644 index 000000000..4bb33d42d --- /dev/null +++ b/packages/apps/redis/templates/credentials.yaml @@ -0,0 +1,21 @@ +{{- /* + The one account of this kind: the default user, whose password the + Cozystack credentials API mints and revokes. cozystack-controller keeps its + account Secret, .default.account, which auth.secretPath names, and + the operator applies a changed password with CONFIG SET, restarting + nothing. The chart renders no password, and nobody can log in until a mint. + + Replication, the Sentinels, the probes and the metrics exporter do not use + it: the operator gives them an internal account of their own. The backup + Job does, reading it when the Job starts. +*/ -}} +{{- if .Values.authEnabled }} +apiVersion: cozystack.io/v1alpha1 +kind: CredentialTemplate +metadata: + name: {{ printf "%s.default" .Release.Name | quote }} +spec: + username: default + format: + name: plaintext +{{- end }} diff --git a/packages/apps/redis/templates/redisfailover.yaml b/packages/apps/redis/templates/redisfailover.yaml index 143f29d6b..fa409dd8f 100644 --- a/packages/apps/redis/templates/redisfailover.yaml +++ b/packages/apps/redis/templates/redisfailover.yaml @@ -30,20 +30,6 @@ {{- if or $sentinel.resources $sentinel.resourcesPreset -}} {{- $sentinelResources = $sentinel.resources | default dict -}} {{- end -}} -{{- if .Values.authEnabled }} - {{- $existingPassword := lookup "v1" "Secret" .Release.Namespace (printf "%s-auth" .Release.Name) }} - {{- $password := randAlphaNum 32 | b64enc }} - {{- if $existingPassword }} - {{- $password = index $existingPassword.data "password" }} - {{- end }} ---- -apiVersion: v1 -kind: Secret -metadata: - name: {{ .Release.Name }}-auth -data: - password: {{ $password }} -{{- end }} --- @@ -214,8 +200,13 @@ spec: - min-replicas-max-lag {{ .Values.minReplicasMaxLag | int }} {{- end }} {{- if .Values.authEnabled }} + {{- /* The account Secret of the default CredentialTemplate (credentials.yaml), + which cozystack-controller keeps and the credentials API rewrites on a + mint. The operator reads its password key on every reconcile and + applies a changed one to the running servers with CONFIG SET; nothing + else it runs authenticates with it. */}} auth: - secretPath: {{ .Release.Name }}-auth + secretPath: {{ printf "%s.default.account" .Release.Name }} {{- end }} --- diff --git a/packages/apps/redis/tests/credential_templates_test.yaml b/packages/apps/redis/tests/credential_templates_test.yaml new file mode 100644 index 000000000..6a3db93e8 --- /dev/null +++ b/packages/apps/redis/tests/credential_templates_test.yaml @@ -0,0 +1,80 @@ +suite: the default account is a CredentialTemplate whose account Secret the operator reads + +# The template is the account the credentials API mints through; its name plus +# ".account" must be the auth.secretPath of the RedisFailover, or the operator +# reads a Secret nobody writes. The chart itself renders no password. + +release: + name: my-redis + namespace: tenant-test + +tests: + - it: renders the default account while authentication is on + templates: + - templates/credentials.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: CredentialTemplate + - equal: + path: apiVersion + value: cozystack.io/v1alpha1 + - equal: + path: metadata.name + value: my-redis.default + - equal: + path: spec.username + value: default + # The operator reads the password itself from the account Secret. + - equal: + path: spec.format.name + value: plaintext + # The operator re-reads the Secret on its own resync and watches nothing + # a label would select. + - notExists: + path: spec.secret + - notExists: + path: spec.valuesPath + + - it: renders no account without authentication + templates: + - templates/credentials.yaml + set: + authEnabled: false + asserts: + - hasDocuments: + count: 0 + + - it: points the operator at the account Secret + templates: + - templates/redisfailover.yaml + documentSelector: + path: kind + value: RedisFailover + asserts: + - equal: + path: spec.auth.secretPath + value: my-redis.default.account + + - it: gives the operator no Secret without authentication + templates: + - templates/redisfailover.yaml + set: + authEnabled: false + documentSelector: + path: kind + value: RedisFailover + asserts: + - notExists: + path: spec.auth + + - it: renders no password Secret + templates: + - templates/redisfailover.yaml + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: my-redis-auth + not: true diff --git a/packages/apps/redis/values.schema.json b/packages/apps/redis/values.schema.json index bfeae6c9f..a3696cc07 100644 --- a/packages/apps/redis/values.schema.json +++ b/packages/apps/redis/values.schema.json @@ -176,7 +176,7 @@ } }, "authEnabled": { - "description": "Enable password generation.", + "description": "Require a password. The password of the `default` user is issued through the credentials API, and issuing a new one takes effect without restarting anything. Replication, the Sentinels and the metrics exporter use an internal account of their own; backups use the `default` password.", "type": "boolean", "default": true }, diff --git a/packages/apps/redis/values.yaml b/packages/apps/redis/values.yaml index 5422c8dd5..21622a10a 100644 --- a/packages/apps/redis/values.yaml +++ b/packages/apps/redis/values.yaml @@ -119,7 +119,7 @@ tls: {} ## @section Application-specific parameters ## -## @param {bool} authEnabled - Enable password generation. +## @param {bool} authEnabled - Require a password. The password of the `default` user is issued through the credentials API, and issuing a new one takes effect without restarting anything. Replication, the Sentinels and the metrics exporter use an internal account of their own; backups use the `default` password. authEnabled: true ## @param {*int} [minReplicasToWrite] - Redis `min-replicas-to-write`: the master refuses writes unless at least this many replicas are connected and within `minReplicasMaxLag`. Unset by default, which leaves the Redis default (disabled). With `replicas: 2` and a value of 1 the master rejects writes while its only replica is down, trading availability for a bound on the writes lost if an isolated master is failed over. Replication stays asynchronous, so this bounds the loss, it does not remove it. Must be 0 or more and below `replicas` (a master with `replicas` pods has `replicas - 1` replicas), otherwise every write is refused; the chart refuses such a value. diff --git a/packages/system/backupstrategy-controller/templates/strategy-redis-default.yaml b/packages/system/backupstrategy-controller/templates/strategy-redis-default.yaml index dc930f394..c969262ab 100644 --- a/packages/system/backupstrategy-controller/templates/strategy-redis-default.yaml +++ b/packages/system/backupstrategy-controller/templates/strategy-redis-default.yaml @@ -82,14 +82,15 @@ spec: {{- end }} env: {{- /* - Redis password, when the app has authEnabled (the default). The chart - emits the Secret -auth; mount it optionally so a no-auth - app still schedules. + Redis password, when the app has authEnabled (the default): the + account Secret .default.account of its default + CredentialTemplate, which a mint rewrites. Mount it optionally so a + no-auth app still schedules. */}} - name: REDIS_PASSWORD valueFrom: secretKeyRef: - name: {{ printf `{{ .Release.Prefix | default "redis-" }}{{ .Release.Name }}-auth` | quote }} + name: {{ printf `{{ .Release.Prefix | default "redis-" }}{{ .Release.Name }}.default.account` | quote }} key: password optional: true {{- /* diff --git a/packages/system/backupstrategy-controller/tests/strategy_redis_test.yaml b/packages/system/backupstrategy-controller/tests/strategy_redis_test.yaml index 24cbe3343..fd76c481e 100644 --- a/packages/system/backupstrategy-controller/tests/strategy_redis_test.yaml +++ b/packages/system/backupstrategy-controller/tests/strategy_redis_test.yaml @@ -92,3 +92,19 @@ tests: content: name: S3_INSECURE_SKIP_VERIFY value: "true" + + - it: "reads the password from the account Secret of the app's default account" + asserts: + # The app's chart no longer renders -auth: the password lives in the + # account Secret of its default CredentialTemplate, which a mint + # rewrites, so the next backup authenticates with the new password. The + # reference stays optional so an app without authentication schedules. + - contains: + path: spec.template.spec.containers[0].env + content: + name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: '{{ .Release.Prefix | default "redis-" }}{{ .Release.Name }}.default.account' + key: password + optional: true diff --git a/packages/system/redis-rd/cozyrds/redis.yaml b/packages/system/redis-rd/cozyrds/redis.yaml index 92eead0bb..768fd25b1 100644 --- a/packages/system/redis-rd/cozyrds/redis.yaml +++ b/packages/system/redis-rd/cozyrds/redis.yaml @@ -8,7 +8,7 @@ spec: plural: redises singular: redis openAPISchema: |- - {"title":"Chart Values","type":"object","properties":{"replicas":{"description":"Number of Redis replicas. Three Sentinels watch them, or a single one when `replicas` is 1, since a lone pod has no replica to fail over to.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each Redis replica. When omitted, the preset defined in `resourcesPreset` is applied.","type":"object","default":{},"properties":{"cpu":{"description":"CPU available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"memory":{"description":"Memory (RAM) available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true}}},"resourcesPreset":{"description":"Default sizing preset used when `resources` is omitted.","type":"string","default":"t1.nano","enum":["t1.nano","t1.micro","t1.small","t1.medium","t1.large","t1.xlarge","t1.2xlarge","t1.4xlarge","c1.nano","c1.micro","c1.small","c1.medium","c1.large","c1.xlarge","c1.2xlarge","c1.4xlarge","s1.nano","s1.micro","s1.small","s1.medium","s1.large","s1.xlarge","s1.2xlarge","s1.4xlarge","u1.nano","u1.micro","u1.small","u1.medium","u1.large","u1.xlarge","u1.2xlarge","u1.4xlarge","m1.nano","m1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m1.2xlarge","m1.4xlarge","nano","micro","small","medium","large","xlarge","2xlarge"]},"affinity":{"description":"Kubernetes affinity configuration for Redis and Sentinel pods.","type":"object","default":{},"properties":{"redis":{"description":"Kubernetes Affinity for Redis pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.","type":"object","default":{},"x-kubernetes-preserve-unknown-fields":true},"sentinel":{"description":"Kubernetes Affinity for Sentinel pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.","type":"object","default":{},"x-kubernetes-preserve-unknown-fields":true}}},"size":{"description":"Persistent Volume Claim size available for application data.","default":"1Gi","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"storageClass":{"description":"StorageClass used to store the data.","type":"string","default":"","x-kubernetes-validations":[{"rule":"self == oldSelf","message":"storageClass is immutable"}],"x-cozystack-options":{"source":"storageclass"}},"external":{"description":"Enable external access from outside the cluster. Can be enabled only when the instance is created, together with `tls.enabled: true`; turning it on for an existing instance, or changing `tls.enabled` while it is on, is refused at admission.","type":"boolean","default":false},"version":{"description":"Redis major version to deploy. The Redis and Sentinel pods run the same image.","type":"string","default":"v8","enum":["v8","v7"]},"tls":{"description":"TLS configuration. TLS is opt-in and is not inferred from `external`.","type":"object","default":{},"properties":{"authClients":{"description":"Maps to the Redis `tls-auth-clients` directive. Defaults to `no` — the server certificate is presented but client certificates are not validated. `yes` requires a client certificate signed by this release's CA, which the platform does not issue. Changing it restarts the Redis and Sentinel pods, because the directive is read from the config file once at startup.","type":"string","enum":["no","optional","yes"]},"enabled":{"description":"Enable TLS for Redis and Sentinel connections. Disabled unless set. Enabling it moves Redis and Sentinel to a TLS-only listener, so existing plaintext clients must be migrated at the same time. Encryption is provided by the redis-operator fork that mounts the certificate Secret into both Redis and Sentinel pods at `/tls`.","type":"boolean"}}},"authEnabled":{"description":"Enable password generation.","type":"boolean","default":true},"minReplicasToWrite":{"description":"Redis `min-replicas-to-write`: the master refuses writes unless at least this many replicas are connected and within `minReplicasMaxLag`. Unset by default, which leaves the Redis default (disabled). With `replicas: 2` and a value of 1 the master rejects writes while its only replica is down, trading availability for a bound on the writes lost if an isolated master is failed over. Replication stays asynchronous, so this bounds the loss, it does not remove it. Must be 0 or more and below `replicas` (a master with `replicas` pods has `replicas - 1` replicas), otherwise every write is refused; the chart refuses such a value.","type":"integer","minimum":0},"minReplicasMaxLag":{"description":"Redis `min-replicas-max-lag`, in seconds: a replica whose last acknowledgement is older than this does not count towards `minReplicasToWrite`. Unset by default, which leaves the Redis default (10). Has no effect unless `minReplicasToWrite` is set. Must be at least 1 when `minReplicasToWrite` is set: Redis treats 0 as disabling the check, so the chart refuses it.","type":"integer","minimum":0},"maxmemory":{"description":"Redis `maxmemory`: the dataset size at which Redis applies `maxmemoryPolicy`. Unset by default, which renders `maxmemory 0` (no limit, the Redis default), so a value set by hand with `CONFIG SET` is reset on the next reconcile. Must be at most 90% of the memory request of each Redis pod (from `resources` or `resourcesPreset`): the operator silently drops a larger value, so the chart refuses it. Leave headroom below that for replication and snapshot buffers.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"maxmemoryPolicy":{"description":"Redis `maxmemory-policy`: what Redis does once `maxmemory` is reached. `noeviction` refuses writes; `allkeys-lru` evicts the least recently used keys, which suits an instance used purely as a cache. Has no effect while `maxmemory` is unset.","type":"string","default":"noeviction","enum":["noeviction","allkeys-lru","allkeys-lfu","allkeys-random","volatile-lru","volatile-lfu","volatile-random","volatile-ttl"]},"snapshots":{"description":"Write RDB snapshots to the persistent volume (the Redis `save` directive, with the Redis default schedule). Set to `false` for an instance used purely as a cache: `save \"\"` is rendered and the volume is kept, so no further scheduled snapshot is written while replicas still have room for the full-sync RDB they write to disk. An RDB file already on the volume is not removed, and Redis loads it on restart, so turning snapshots off does not by itself empty the dataset. Always off when `size` is empty.","type":"boolean","default":true},"sentinel":{"description":"Sentinel configuration. When `sentinel.resources` is empty and `sentinel.resourcesPreset` is unset, the Sentinel pods are sized like the Redis pods (`resources` and `resourcesPreset`). An empty `sentinel.resources` map counts as unset, as an empty top-level `resources` does.","type":"object","default":{},"properties":{"resources":{"description":"Explicit CPU and memory configuration for each Sentinel pod. Keys left out are filled from the preset in `sentinel.resourcesPreset`.","type":"object","properties":{"cpu":{"description":"CPU available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"memory":{"description":"Memory (RAM) available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true}}},"resourcesPreset":{"description":"Sizing preset for the Sentinel pods. Defaults to `resourcesPreset`.","type":"string","enum":["t1.nano","t1.micro","t1.small","t1.medium","t1.large","t1.xlarge","t1.2xlarge","t1.4xlarge","c1.nano","c1.micro","c1.small","c1.medium","c1.large","c1.xlarge","c1.2xlarge","c1.4xlarge","s1.nano","s1.micro","s1.small","s1.medium","s1.large","s1.xlarge","s1.2xlarge","s1.4xlarge","u1.nano","u1.micro","u1.small","u1.medium","u1.large","u1.xlarge","u1.2xlarge","u1.4xlarge","m1.nano","m1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m1.2xlarge","m1.4xlarge","nano","micro","small","medium","large","xlarge","2xlarge"]}}},"schedulingClass":{"description":"Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`. Setting any other value is refused, and the pods of an application whose class is not, or no longer, in that list get the tenant's class. Empty means inherit from the tenant.","type":"string","default":"","maxLength":63}}} + {"title":"Chart Values","type":"object","properties":{"replicas":{"description":"Number of Redis replicas. Three Sentinels watch them, or a single one when `replicas` is 1, since a lone pod has no replica to fail over to.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each Redis replica. When omitted, the preset defined in `resourcesPreset` is applied.","type":"object","default":{},"properties":{"cpu":{"description":"CPU available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"memory":{"description":"Memory (RAM) available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true}}},"resourcesPreset":{"description":"Default sizing preset used when `resources` is omitted.","type":"string","default":"t1.nano","enum":["t1.nano","t1.micro","t1.small","t1.medium","t1.large","t1.xlarge","t1.2xlarge","t1.4xlarge","c1.nano","c1.micro","c1.small","c1.medium","c1.large","c1.xlarge","c1.2xlarge","c1.4xlarge","s1.nano","s1.micro","s1.small","s1.medium","s1.large","s1.xlarge","s1.2xlarge","s1.4xlarge","u1.nano","u1.micro","u1.small","u1.medium","u1.large","u1.xlarge","u1.2xlarge","u1.4xlarge","m1.nano","m1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m1.2xlarge","m1.4xlarge","nano","micro","small","medium","large","xlarge","2xlarge"]},"affinity":{"description":"Kubernetes affinity configuration for Redis and Sentinel pods.","type":"object","default":{},"properties":{"redis":{"description":"Kubernetes Affinity for Redis pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.","type":"object","default":{},"x-kubernetes-preserve-unknown-fields":true},"sentinel":{"description":"Kubernetes Affinity for Sentinel pods. When set, redis-operator uses it verbatim and does not add its default soft podAntiAffinity; include podAntiAffinity unless replica co-location is intended.","type":"object","default":{},"x-kubernetes-preserve-unknown-fields":true}}},"size":{"description":"Persistent Volume Claim size available for application data.","default":"1Gi","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"storageClass":{"description":"StorageClass used to store the data.","type":"string","default":"","x-kubernetes-validations":[{"rule":"self == oldSelf","message":"storageClass is immutable"}],"x-cozystack-options":{"source":"storageclass"}},"external":{"description":"Enable external access from outside the cluster. Can be enabled only when the instance is created, together with `tls.enabled: true`; turning it on for an existing instance, or changing `tls.enabled` while it is on, is refused at admission.","type":"boolean","default":false},"version":{"description":"Redis major version to deploy. The Redis and Sentinel pods run the same image.","type":"string","default":"v8","enum":["v8","v7"]},"tls":{"description":"TLS configuration. TLS is opt-in and is not inferred from `external`.","type":"object","default":{},"properties":{"authClients":{"description":"Maps to the Redis `tls-auth-clients` directive. Defaults to `no` — the server certificate is presented but client certificates are not validated. `yes` requires a client certificate signed by this release's CA, which the platform does not issue. Changing it restarts the Redis and Sentinel pods, because the directive is read from the config file once at startup.","type":"string","enum":["no","optional","yes"]},"enabled":{"description":"Enable TLS for Redis and Sentinel connections. Disabled unless set. Enabling it moves Redis and Sentinel to a TLS-only listener, so existing plaintext clients must be migrated at the same time. Encryption is provided by the redis-operator fork that mounts the certificate Secret into both Redis and Sentinel pods at `/tls`.","type":"boolean"}}},"authEnabled":{"description":"Require a password. The password of the `default` user is issued through the credentials API, and issuing a new one takes effect without restarting anything. Replication, the Sentinels and the metrics exporter use an internal account of their own; backups use the `default` password.","type":"boolean","default":true},"minReplicasToWrite":{"description":"Redis `min-replicas-to-write`: the master refuses writes unless at least this many replicas are connected and within `minReplicasMaxLag`. Unset by default, which leaves the Redis default (disabled). With `replicas: 2` and a value of 1 the master rejects writes while its only replica is down, trading availability for a bound on the writes lost if an isolated master is failed over. Replication stays asynchronous, so this bounds the loss, it does not remove it. Must be 0 or more and below `replicas` (a master with `replicas` pods has `replicas - 1` replicas), otherwise every write is refused; the chart refuses such a value.","type":"integer","minimum":0},"minReplicasMaxLag":{"description":"Redis `min-replicas-max-lag`, in seconds: a replica whose last acknowledgement is older than this does not count towards `minReplicasToWrite`. Unset by default, which leaves the Redis default (10). Has no effect unless `minReplicasToWrite` is set. Must be at least 1 when `minReplicasToWrite` is set: Redis treats 0 as disabling the check, so the chart refuses it.","type":"integer","minimum":0},"maxmemory":{"description":"Redis `maxmemory`: the dataset size at which Redis applies `maxmemoryPolicy`. Unset by default, which renders `maxmemory 0` (no limit, the Redis default), so a value set by hand with `CONFIG SET` is reset on the next reconcile. Must be at most 90% of the memory request of each Redis pod (from `resources` or `resourcesPreset`): the operator silently drops a larger value, so the chart refuses it. Leave headroom below that for replication and snapshot buffers.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"maxmemoryPolicy":{"description":"Redis `maxmemory-policy`: what Redis does once `maxmemory` is reached. `noeviction` refuses writes; `allkeys-lru` evicts the least recently used keys, which suits an instance used purely as a cache. Has no effect while `maxmemory` is unset.","type":"string","default":"noeviction","enum":["noeviction","allkeys-lru","allkeys-lfu","allkeys-random","volatile-lru","volatile-lfu","volatile-random","volatile-ttl"]},"snapshots":{"description":"Write RDB snapshots to the persistent volume (the Redis `save` directive, with the Redis default schedule). Set to `false` for an instance used purely as a cache: `save \"\"` is rendered and the volume is kept, so no further scheduled snapshot is written while replicas still have room for the full-sync RDB they write to disk. An RDB file already on the volume is not removed, and Redis loads it on restart, so turning snapshots off does not by itself empty the dataset. Always off when `size` is empty.","type":"boolean","default":true},"sentinel":{"description":"Sentinel configuration. When `sentinel.resources` is empty and `sentinel.resourcesPreset` is unset, the Sentinel pods are sized like the Redis pods (`resources` and `resourcesPreset`). An empty `sentinel.resources` map counts as unset, as an empty top-level `resources` does.","type":"object","default":{},"properties":{"resources":{"description":"Explicit CPU and memory configuration for each Sentinel pod. Keys left out are filled from the preset in `sentinel.resourcesPreset`.","type":"object","properties":{"cpu":{"description":"CPU available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true},"memory":{"description":"Memory (RAM) available to each replica.","pattern":"^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$","anyOf":[{"type":"integer"},{"type":"string"}],"x-kubernetes-int-or-string":true}}},"resourcesPreset":{"description":"Sizing preset for the Sentinel pods. Defaults to `resourcesPreset`.","type":"string","enum":["t1.nano","t1.micro","t1.small","t1.medium","t1.large","t1.xlarge","t1.2xlarge","t1.4xlarge","c1.nano","c1.micro","c1.small","c1.medium","c1.large","c1.xlarge","c1.2xlarge","c1.4xlarge","s1.nano","s1.micro","s1.small","s1.medium","s1.large","s1.xlarge","s1.2xlarge","s1.4xlarge","u1.nano","u1.micro","u1.small","u1.medium","u1.large","u1.xlarge","u1.2xlarge","u1.4xlarge","m1.nano","m1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m1.2xlarge","m1.4xlarge","nano","micro","small","medium","large","xlarge","2xlarge"]}}},"schedulingClass":{"description":"Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`. Setting any other value is refused, and the pods of an application whose class is not, or no longer, in that list get the tenant's class. Empty means inherit from the tenant.","type":"string","default":"","maxLength":63}}} release: prefix: redis- labels: @@ -59,9 +59,11 @@ spec: # of its labels, so it is the one of the three a lineage walk can # resolve at all. - redis-{{ .name }}.ca-cert + # The operator's internal account, which replication, the Sentinels, + # the probes and the exporter authenticate with. It carries an + # ownerReference to the RedisFailover, as the CA-only copy does. + - rfr-redis-{{ .name }}-internal include: - - resourceNames: - - redis-{{ .name }}-auth # The key-free trust anchor the CA-extraction controller publishes. This # is the single, engine-agnostic selector every converged engine shares; # it carries no per-release name templating.