feat(valkey)!: issue the password through the credentials API

Valkey runs on the same operator as Redis and had the same chart-made
password in a tenant-readable <release>-auth. The chart now renders a
CredentialTemplate for the default account while authEnabled is on and
points the operator at that account's Secret. As for Redis, the operator
keeps replication, the Sentinels and the exporter on its internal
account, so a mint reaches only the default user and applies with no
restart, and the ResourceDefinition excludes the internal account's
Secret.

BREAKING CHANGE: <release>-auth is no longer rendered or readable;
clients get the password by minting the default credential.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
Andrei Kvapil committed 2026-12-02 20:38:25 +01:00
1 parent 0999d9cfd2
commit 3c0a113c14
8 files changed
+118 -25

No files matched your search

+1 -1
View File
@@ -39,7 +39,7 @@ type ConfigSpec struct {
// Valkey major version to deploy
// +kubebuilder:default:="v8"
Version Version `json:"version"`
// 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"`
// 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.
+1 -1
View File
@@ -33,7 +33,7 @@ Service runs Valkey on the freshworks-oss redis-operator, which manages Sentinel
| 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` |
| `schedulingClass` | 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. | `string` | `""` |
@@ -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, <release>.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 }}
@@ -6,23 +6,7 @@
{{- fail (trim (printf "valkey: _cluster.scheduling.globalAppTopologySpreadConstraints must be YAML with a non-empty topologySpreadConstraints list. %s" (get $policy "Error"))) }}
{{- end }}
{{- 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 }}
---
apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
@@ -113,8 +97,13 @@ spec:
- save ""
{{- 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 }}
---
@@ -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-valkey
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-valkey.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/valkeyfailover.yaml
documentSelector:
path: kind
value: RedisFailover
asserts:
- equal:
path: spec.auth.secretPath
value: my-valkey.default.account
- it: gives the operator no Secret without authentication
templates:
- templates/valkeyfailover.yaml
set:
authEnabled: false
documentSelector:
path: kind
value: RedisFailover
asserts:
- notExists:
path: spec.auth
- it: renders no password Secret
templates:
- templates/valkeyfailover.yaml
asserts:
- containsDocument:
kind: Secret
apiVersion: v1
name: my-valkey-auth
not: true
+1 -1
View File
@@ -137,7 +137,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
},
+1 -1
View File
@@ -86,7 +86,7 @@ version: v8
## @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 {string} schedulingClass - 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.
+7 -4
View File
@@ -8,7 +8,7 @@ spec:
plural: valkeys
singular: valkey
openAPISchema: |-
{"title":"Chart Values","type":"object","properties":{"replicas":{"description":"Number of Valkey replicas.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each Valkey 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"]},"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.","type":"boolean","default":false},"version":{"description":"Valkey major version to deploy","type":"string","default":"v8","enum":["v8","v7"]},"authEnabled":{"description":"Enable password generation.","type":"boolean","default":true},"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 Valkey replicas.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each Valkey 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"]},"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.","type":"boolean","default":false},"version":{"description":"Valkey major version to deploy","type":"string","default":"v8","enum":["v8","v7"]},"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},"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: valkey-
labels:
@@ -27,10 +27,13 @@ spec:
icon: PHN2ZyB3aWR0aD0iMTQ0IiBoZWlnaHQ9IjE0NCIgdmlld0JveD0iMCAwIDE0NCAxNDQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgPHJlY3Qgd2lkdGg9IjE0NCIgaGVpZ2h0PSIxNDQiIHJ4PSIyNCIgZmlsbD0idXJsKCN2YWxrZXlfYmcpIi8+CiAgPHBhdGggZD0iTTM2IDQwaDE4bDE4IDQ0IDE4LTQ0aDE4TDgwIDEwOGgtMTZMMzYgNDB6IiBmaWxsPSIjZmZmZmZmIi8+CiAgPGNpcmNsZSBjeD0iNzIiIGN5PSI1MiIgcj0iNyIgZmlsbD0iI2ZmZmZmZiIvPgogIDxkZWZzPgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJ2YWxrZXlfYmciIHgxPSIwIiB5MT0iMCIgeDI9IjE0NCIgeTI9IjE0NCIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPgogICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjN0EzQkZGIi8+CiAgICAgIDxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI0M2MjQ5QiIvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICA8L2RlZnM+Cjwvc3ZnPgo=
keysOrder: [["apiVersion"], ["appVersion"], ["kind"], ["metadata"], ["metadata", "name"], ["spec", "replicas"], ["spec", "resources"], ["spec", "resourcesPreset"], ["spec", "size"], ["spec", "storageClass"], ["spec", "external"], ["spec", "version"], ["spec", "authEnabled"], ["spec", "schedulingClass"]]
secrets:
exclude: []
include:
exclude:
# The operator's internal account, which replication, the Sentinels,
# the probes and the exporter authenticate with. It carries an
# ownerReference to the RedisFailover, so a lineage walk resolves it.
- resourceNames:
- valkey-{{ .name }}-auth
- rfr-valkey-{{ .name }}-internal
include: []
services:
exclude: []
include: