diff --git a/api/apps/v1alpha1/mariadb/types.go b/api/apps/v1alpha1/mariadb/types.go index 4a0fa2d79..646cd20bc 100644 --- a/api/apps/v1alpha1/mariadb/types.go +++ b/api/apps/v1alpha1/mariadb/types.go @@ -42,7 +42,7 @@ type ConfigSpec struct { // MariaDB major.minor version to deploy // +kubebuilder:default:="v11.8" Version Version `json:"version"` - // Users configuration map. + // Users configuration map. Passwords (including the `root` account) are always auto-generated and stored in the `-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret. // +kubebuilder:default:={} Users map[string]User `json:"users,omitempty"` // Databases configuration map. @@ -110,8 +110,6 @@ type TLS struct { type User struct { // Maximum number of connections. MaxUserConnections int `json:"maxUserConnections"` - // Password for the user. - Password string `json:"password"` } // +kubebuilder:validation: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" diff --git a/packages/apps/mariadb/README.md b/packages/apps/mariadb/README.md index 983d398e1..ebedfc5a0 100644 --- a/packages/apps/mariadb/README.md +++ b/packages/apps/mariadb/README.md @@ -203,15 +203,14 @@ Uninstalling the instance does this for you; only the turn-it-off-and-keep-runni ### Application-specific parameters -| Name | Description | Type | Value | -| -------------------------------- | ---------------------------------------- | ------------------- | ----- | -| `users` | Users configuration map. | `map[string]object` | `{}` | -| `users[name].password` | Password for the user. | `string` | `""` | -| `users[name].maxUserConnections` | Maximum number of connections. | `int` | `0` | -| `databases` | Databases configuration map. | `map[string]object` | `{}` | -| `databases[name].roles` | Roles assigned to users. | `object` | `{}` | -| `databases[name].roles.admin` | List of users with admin privileges. | `[]string` | `[]` | -| `databases[name].roles.readonly` | List of users with read-only privileges. | `[]string` | `[]` | +| Name | Description | Type | Value | +| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- | +| `users` | Users configuration map. Passwords (including the `root` account) are always auto-generated and stored in the `-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret. | `map[string]object` | `{}` | +| `users[name].maxUserConnections` | Maximum number of connections. | `int` | `0` | +| `databases` | Databases configuration map. | `map[string]object` | `{}` | +| `databases[name].roles` | Roles assigned to users. | `object` | `{}` | +| `databases[name].roles.admin` | List of users with admin privileges. | `[]string` | `[]` | +| `databases[name].roles.readonly` | List of users with read-only privileges. | `[]string` | `[]` | ### Backup parameters (DEPRECATED) @@ -255,12 +254,12 @@ See [`docs/operations/resource-presets.md`](../../../docs/operations/resource-pr users: user1: maxUserConnections: 1000 - password: hackme user2: maxUserConnections: 1000 - password: hackme ``` +Passwords cannot be set here — they (and the `root` account) are auto-generated and stored in the `-credentials` Secret. Read a user's password with `kubectl get secret -credentials -o json | jq -r '.data["user1"]' | base64 -d` (a username may contain a `.`, which `jsonpath` would treat as a path step and return nothing). + ### databases diff --git a/packages/apps/mariadb/templates/db.yaml b/packages/apps/mariadb/templates/db.yaml index 338da2695..d61627445 100644 --- a/packages/apps/mariadb/templates/db.yaml +++ b/packages/apps/mariadb/templates/db.yaml @@ -1,17 +1,119 @@ +{{/* + A database name also names Kubernetes resources: the Database CR + {{ .Release.Name }}-{{ replace "_" "-" $name }} and, under it, each Grant. So + the same DNS-1123 rule and "_"/"-" collision that the username guard enforces + apply here — a name like "My.Db" or "foo-" renders but the apiserver rejects + the Database CR with an opaque error, and two names differing only in "_" vs + "-" collide on one Database CR (one silently overwrites the other). Reject an + invalid name on both install and upgrade (it never applied either way), but the + "_"/"-" collision only on a fresh install, mirroring the username guard in + secret.yaml: an existing release already took the overwrite, and blocking its + upgrades only makes a running release worse. Database names are not Secret keys, + so the DNS-1123 name is the binding rule. +*/}} +{{- $seenDBDNS := dict }} +{{- range $name, $db := .Values.databases }} + {{- $crName := printf "%s-%s" $.Release.Name (replace "_" "-" $name) }} + {{- if or (gt (len $crName) 253) (not (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$" $crName)) }} + {{- fail (printf "invalid database name %q: it also names the Database resource %q, which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, \"-\" and \".\", starting and ending with a letter or digit); use a lowercase name without a leading or trailing \"-\" or \".\"" $name $crName) }} + {{- end }} + {{- /* + The name is also the MariaDB database identifier (Database CR spec.name). The + server caps an identifier at 64 characters and rejects a longer CREATE DATABASE + with "Incorrect database name", but the Database CRD allows 80, so a name of 65-80 + characters renders a Database the apiserver accepts and only the operator's SQL + fails. A release that already applied such a Database must keep upgrading, so on + upgrade the 64 cap applies only when the Database does not exist yet; past 80 the + apiserver rejects the object itself, so that holds on both paths. An offline + render sees no Database and stays strict. The DNS-1123 check above admits only + ASCII, so len (bytes) equals characters. + */}} + {{- if or (gt (len $name) 80) (and (gt (len $name) 64) (or $.Release.IsInstall (not (lookup "k8s.mariadb.com/v1alpha1" "Database" $.Release.Namespace $crName)))) }} + {{- fail (printf "invalid database name %q: a MariaDB database identifier is at most 64 characters" $name) }} + {{- end }} + {{- $dbDNS := replace "_" "-" $name }} + {{- if and $.Release.IsInstall (hasKey $seenDBDNS $dbDNS) }} + {{- fail (printf "database names %q and %q both map to the Database resource name %q (\"_\" renders as \"-\"); rename one of them" (index $seenDBDNS $dbDNS) $name (printf "%s-%s" $.Release.Name $dbDNS)) }} + {{- end }} + {{- $_ := set $seenDBDNS $dbDNS $name }} +{{- end }} + +{{/* + The Grant CR name is --. Two DIFFERENT (database, user) + pairs whose "-"/"_" split differently collide there — (database "a", user "b-c") + and (database "a-b", user "c") both render -a-b-c — and one silently + overwrites the other at apply, dropping a privilege the tenant configured. A + user in both admin and readonly of one database would also collide with itself; + that user needs only the admin grant (ALL is a superset of the readonly SELECT), + so the readonly grant is SKIPPED for them rather than the name role-scoped — + role-scoping renames the Grant, and renaming a Grant on upgrade makes the + operator revoke the tenant's live privilege while the old CR is pruned. Track + the whole rendered Grant name plus its length (the apiserver caps a resource + name at 253) and reject an over-long or charset-invalid name on both install and + upgrade, but the "_"/"-" collision only on a fresh install — like the sibling + guards, an existing release already took the overwrite and blocking its upgrades + only makes a running release worse. +*/}} +{{- $seenGrant := dict }} +{{- range $name, $db := .Values.databases }} + {{- $dbDNS := replace "_" "-" $name }} + {{- $roles := $db.roles | default dict }} + {{- $adminUsers := $roles.admin | default (list) | uniq }} + {{- $grantUsers := $adminUsers }} + {{- range $user := ($roles.readonly | default (list) | uniq) }} + {{- if not (has $user $adminUsers) }}{{- $grantUsers = append $grantUsers $user }}{{- end }} + {{- end }} + {{- range $user := $grantUsers }} + {{- $g := printf "%s-%s-%s" $.Release.Name $dbDNS (replace "_" "-" $user) }} + {{- if gt (len $g) 253 }} + {{- fail (printf "the Grant resource name %q for (database %q, user %q) exceeds the 253-character limit Kubernetes puts on a resource name; shorten the database or user name" $g $name $user) }} + {{- end }} + {{- if not (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$" $g) }} + {{- fail (printf "invalid role member %q for database %q: it names the Grant resource %q, which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, \"-\" and \".\", starting and ending with a letter or digit). A name in databases..roles.admin/readonly is not one of .Values.users, so the username guard never sees it - use a lowercase name without special characters" $user $name $g) }} + {{- end }} + {{- /* + The member is also the Grant's spec.username, a MariaDB account name the + server caps at 128 characters. A declared user is held to 80 by secret.yaml, + matching the User CRD, but a member declared only under databases..roles + has no User CR and never passes through that cap. Checked after the DNS-1123 guard above, which admits + only lowercase ASCII, so len (bytes) equals characters here and a non-ASCII + member is reported for its charset rather than as too long; and after the 253 + guard, so a member long enough to blow the Grant name reports that first. + Unlike those two guards, whose invalid name the apiserver rejects so the + object never applied, a too-long member renders a Grant the apiserver + ACCEPTS: its metadata.name is valid and the Grant CRD puts no maxLength on + spec.username, so only mariadb-operator's CREATE USER/GRANT SQL fails. A + release that already applied such a Grant must keep upgrading, but a member + added on upgrade is new and must still be named here, so on upgrade the cap + applies only when the Grant does not exist yet. An offline render sees no + Grant and stays strict. + */}} + {{- if and (gt (len $user) 128) (or $.Release.IsInstall (not (lookup "k8s.mariadb.com/v1alpha1" "Grant" $.Release.Namespace $g))) }} + {{- fail (printf "invalid role member %q for database %q: a MariaDB account name is at most 128 characters, so the server rejects the GRANT for a longer one. A name in databases..roles.admin/readonly is not one of .Values.users, so the username length cap in secret.yaml never sees it" $user $name) }} + {{- end }} + {{- $desc := printf "(database %q, user %q)" $name $user }} + {{- if and $.Release.IsInstall (hasKey $seenGrant $g) }} + {{- fail (printf "the Grant resource name %q is produced by both %s and %s (\"_\" renders as \"-\"); rename a database or user so their Grants do not collide" $g (index $seenGrant $g) $desc) }} + {{- end }} + {{- $_ := set $seenGrant $g $desc }} + {{- end }} +{{- end }} {{- range $name, $db := .Values.databases }} {{ $dbDNSName := replace "_" "-" $name }} +{{- $roles := $db.roles | default dict }} +{{- $adminUsers := $roles.admin | default (list) | uniq }} --- apiVersion: k8s.mariadb.com/v1alpha1 kind: Database metadata: name: {{ $.Release.Name }}-{{ $dbDNSName }} spec: - name: {{ $name }} + name: {{ $name | quote }} mariaDbRef: name: {{ $.Release.Name }} characterSet: utf8 collate: utf8_general_ci -{{- range $user := $db.roles.admin }} +{{- range $user := $adminUsers }} {{ $userDNSName := replace "_" "-" $user }} --- apiVersion: k8s.mariadb.com/v1alpha1 @@ -22,13 +124,26 @@ spec: mariaDbRef: name: {{ $.Release.Name }} privileges: ['ALL'] - database: {{ $name }} + database: {{ $name | quote }} table: "*" - username: {{ $user }} + username: {{ $user | quote }} grantOption: true {{- end }} -{{- range $user := $db.roles.readonly }} +{{- range $user := ($roles.readonly | default (list) | uniq) }} +{{- if not (has $user $adminUsers) }} {{ $userDNSName := replace "_" "-" $user }} +{{- /* + No -readonly suffix: the Grant name must match what earlier releases rendered, or the + operator revokes the live privilege as the renamed CR is pruned on upgrade. A + user also in admin gets ALL and is skipped above, so there is no same-name + collision to disambiguate. Corollary of the shared name: when a user moves + between readonly-only and admin across an upgrade, the chart keeps ONE Grant CR + under a stable name and only its `privileges` value changes (SELECT<->ALL) — the + chart never forces a rename, so it never drives a revoke-and-prune. How the + operator applies that privilege change on the live grant is the operator's + concern and is not asserted here. This rationale is a template comment so it does + not ship into every rendered Grant manifest. +*/}} --- apiVersion: k8s.mariadb.com/v1alpha1 kind: Grant @@ -38,10 +153,11 @@ spec: mariaDbRef: name: {{ $.Release.Name }} privileges: ['SELECT'] - database: {{ $name }} + database: {{ $name | quote }} table: "*" - username: {{ $user }} + username: {{ $user | quote }} grantOption: true {{- end }} +{{- end }} {{- end }} diff --git a/packages/apps/mariadb/templates/secret.yaml b/packages/apps/mariadb/templates/secret.yaml index aa2bd50e3..16a489fe5 100644 --- a/packages/apps/mariadb/templates/secret.yaml +++ b/packages/apps/mariadb/templates/secret.yaml @@ -7,15 +7,96 @@ {{- end }} {{- end }} -{{- $usersWithRoot := .Values.users }} -{{- if not (and .Values.users.root .Values.users.root.password) }} - {{- $_ := set $usersWithRoot "root" dict }} +{{/* + Reject a username outside the Secret-key charset before it becomes a Secret + data key, the spec.name of a mariadb-operator User CR and (with "_" mapped to + "-") that User's metadata.name. The apiserver would reject such a name later + as an invalid Secret key or resource name, but only once Flux applies the + render, as an opaque error; failing here names the offending username. The + check mirrors k8s IsConfigMapKey (the charset plus its rejection of ".", of any + name starting with ".."). The length cap is 80 because the mariadb-operator + User CRD caps spec.name at 80 (the server itself allows 128): the apiserver + rejects a longer User at apply, so capping here names it at render instead. So + it rejects nothing that could otherwise install. There is no shell interpolation here (the operator + applies the SQL), so this is a diagnosability guard, not an injection fix; + postgres carries the analogous guard in its init-script. +*/}} +{{- range $user, $u := .Values.users }} + {{- if or (not (regexMatch "^[-._a-zA-Z0-9]+$" $user)) (eq $user ".") (hasPrefix ".." $user) (gt (len $user) 80) }} + {{- fail (printf "invalid username %q: a username may contain only letters, digits and the characters -._ , must not be \".\" or start with \"..\", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)" $user) }} + {{- end }} {{- end }} +{{/* + The username also names the User CR: user.yaml renders + {{ .Release.Name }}-{{ replace "_" "-" $name }} as metadata.name, and Kubernetes + requires that to be a DNS-1123 subdomain (lowercase, alnum start/end) — a + stricter charset than the Secret key above, which permits uppercase and a + leading/trailing "-"/".". A name like "Bob", "foo-" or "foo." passes the Secret + charset yet renders an invalid User name that the apiserver rejects at apply with + an opaque error. Validate the rendered User name against the DNS-1123 subdomain + rule so such a username is named here instead. Checked on the full rendered name + so the "-" join to the release prefix (e.g. a leading-dot username) is covered. +*/}} +{{- range $user, $u := .Values.users }} + {{- $crName := printf "%s-%s" $.Release.Name (replace "_" "-" $user) }} + {{- if or (gt (len $crName) 253) (not (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$" $crName)) }} + {{- fail (printf "invalid username %q: it also names the mariadb-operator User resource %q, which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, \"-\" and \".\", starting and ending with a letter or digit); use a lowercase name without a leading or trailing \"-\" or \".\"" $user $crName) }} + {{- end }} +{{- end }} + +{{/* + user.yaml renders each User CR as {{ .Release.Name }}-{{ replace "_" "-" $name }}, + so two usernames that differ only in "_" vs "-" (e.g. "a_b" and "a-b") collide on + one User resource name. range sorts keys, so the later one silently overwrites the + earlier User CR on apply — one user ends up with a credentials-Secret entry but no + backing mariadb-operator User (no error, no warning). Reject the collision on a + fresh install, naming both offenders, rather than create a half-configured user. + Gated to install: an existing release that already carries the pair took the + overwrite when it was first applied, so a platform-driven chart upgrade must not + wedge it into a failed reconcile it cannot clear without editing users — blocking + the upgrade would only make a running release worse, since one of the two Users is + live. The charset and DNS-1123 guards above stay on both paths because an invalid + name never applied at all. +*/}} +{{- $seenDNS := dict }} +{{- range $user, $u := .Values.users }} + {{- $dns := replace "_" "-" $user }} + {{- if and $.Release.IsInstall (hasKey $seenDNS $dns) }} + {{- fail (printf "usernames %q and %q both map to the User resource name %q (\"_\" renders as \"-\"); rename one of them" (index $seenDNS $dns) $user (printf "%s-%s" $.Release.Name $dns)) }} + {{- end }} + {{- $_ := set $seenDNS $dns $user }} +{{- end }} + +{{/* + Distinguish a first install from an upgrade whose lookup came back empty. Every + password below (root included) is minted only when the lookup did not already + carry it, so an upgrade that finds NO credentials Secret at all -- deleted, or + the release renamed out from under it -- would silently re-mint all of them. + Helm's lookup returns empty only on a genuine NotFound, so a normal upgrade finds + the Secret and this never fires; when it does, the Secret is really gone and + re-minting would rotate every account. root is the sharp edge: mariadb-operator + writes rootPasswordSecretKeyRef only at datadir bootstrap, so a fresh root value + on an existing cluster is advertised but never applied and the real root password + is lost for good. Fail instead, and let a first install (no Secret expected) + through. +*/}} +{{- if and .Release.IsUpgrade (not $existingSecret) }} + {{- fail (printf "%s-credentials Secret not found while upgrading: refusing to mint fresh passwords, which would rotate every account and, because mariadb-operator applies root only at datadir bootstrap, leave the cluster advertising a root password it never set. If the Secret was deleted, restore it before upgrading (a first install does not hit this path)." .Release.Name) }} +{{- end }} + +{{/* root is always chart-managed and never accepts a value-supplied password. */}} +{{- $usersWithRoot := deepCopy .Values.users }} +{{- $_ := set $usersWithRoot "root" dict }} + +{{/* + Passwords (root included) are always chart-generated and preserved across + reconciles via the lookup above: a user keeps whatever password is already + stored in the Secret, and only a user without one yet gets a freshly generated + value. +*/}} {{- range $user, $u := $usersWithRoot }} - {{- if $u.password }} - {{- $_ := set $passwords $user $u.password }} - {{- else if not (index $passwords $user) }} + {{- if not (index $passwords $user) }} {{- $_ := set $passwords $user (randAlphaNum 16) }} {{- end }} {{- end }} @@ -25,7 +106,17 @@ apiVersion: v1 kind: Secret metadata: name: {{ .Release.Name }}-credentials + labels: + {{- /* + mariadb-operator only re-applies a User password from its + passwordSecretKeyRef when the referenced Secret carries this label; without + it a change to this Secret (e.g. a newly added user's generated password) + reaches the server only on the operator's --requeue-sql tick (10h + up to 1h + of jitter) instead of promptly. (root is not indexed on the Secret at all - + MariaDB.spec.rootPasswordSecretKeyRef lands only at datadir bootstrap.) + */}} + k8s.mariadb.com/watch: "" stringData: {{- range $name, $u := $usersWithRoot }} - {{ $name }}: {{ index $passwords $name }} + {{ $name | quote }}: {{ index $passwords $name | quote }} {{- end }} diff --git a/packages/apps/mariadb/templates/user.yaml b/packages/apps/mariadb/templates/user.yaml index 28cb7ba6e..901f69daf 100644 --- a/packages/apps/mariadb/templates/user.yaml +++ b/packages/apps/mariadb/templates/user.yaml @@ -7,12 +7,12 @@ kind: User metadata: name: {{ $.Release.Name }}-{{ $dnsName }} spec: - name: {{ $name }} + name: {{ $name | quote }} mariaDbRef: name: {{ $.Release.Name }} passwordSecretKeyRef: name: {{ $.Release.Name }}-credentials - key: {{ $name }} + key: {{ $name | quote }} maxUserConnections: {{ $u.maxUserConnections }} {{- end }} {{- end }} diff --git a/packages/apps/mariadb/tests/credentials_lookup_test.yaml b/packages/apps/mariadb/tests/credentials_lookup_test.yaml new file mode 100644 index 000000000..1a341591f --- /dev/null +++ b/packages/apps/mariadb/tests/credentials_lookup_test.yaml @@ -0,0 +1,41 @@ +suite: MariaDB credentials lookup-backed preservation +release: + name: mariadb-test + namespace: tenant-test +templates: + - templates/secret.yaml +tests: + - it: preserves existing passwords (including root) across renders + # The lookup in secret.yaml reads back the current Secret, so each user keeps + # the password already stored rather than getting a fresh one on every + # reconcile. kubernetesProvider mocks that existing Secret. + kubernetesProvider: + scheme: + "v1/Secret": + gvr: + version: v1 + resource: secrets + namespaced: true + objects: + - apiVersion: v1 + kind: Secret + metadata: + name: mariadb-test-credentials + namespace: tenant-test + data: + testuser: ZXhpc3RpbmdwYXNzd29yZA== + root: ZXhpc3Rpbmdyb290 + set: + users: + testuser: + maxUserConnections: 1000 + documentSelector: + path: metadata.name + value: mariadb-test-credentials + asserts: + - equal: + path: stringData.testuser + value: existingpassword + - equal: + path: stringData.root + value: existingroot diff --git a/packages/apps/mariadb/tests/credentials_test.yaml b/packages/apps/mariadb/tests/credentials_test.yaml new file mode 100644 index 000000000..6e2d6af1e --- /dev/null +++ b/packages/apps/mariadb/tests/credentials_test.yaml @@ -0,0 +1,57 @@ +suite: MariaDB credentials generation + +# Passwords (including root) are always chart-generated (no plaintext input) and +# preserved across reconciles by the lookup in secret.yaml. This suite renders +# without a kubernetesProvider, so lookup() returns nothing and every render +# generates fresh passwords; the lookup-backed preserve path is covered in +# credentials_lookup_test.yaml. + +release: + name: mariadb-test + namespace: tenant-test + +templates: + - templates/secret.yaml + +tests: + - it: always generates a root password even with no users + asserts: + - matchRegex: + path: stringData.root + pattern: ^[a-zA-Z0-9]{16}$ + - equal: + # The watch label makes mariadb-operator react to a change on this + # Secret (e.g. a newly added user's generated password) promptly rather + # than on its --requeue-sql tick. + path: metadata.labels["k8s.mariadb.com/watch"] + value: "" + + - it: generates a 16-char alphanumeric password for each defined user + set: + users: + testuser: + maxUserConnections: 1000 + asserts: + - matchRegex: + path: stringData.testuser + pattern: ^[a-zA-Z0-9]{16}$ + - matchRegex: + path: stringData.root + pattern: ^[a-zA-Z0-9]{16}$ + + - it: ignores a value-supplied password and generates one instead + # Pins the breaking-change contract: the schema no longer declares + # `password`, but nothing rejects a leftover key, so prove it is dropped + # rather than honoured. + set: + users: + testuser: + maxUserConnections: 1000 + password: value-supplied-secret + asserts: + - matchRegex: + path: stringData.testuser + pattern: ^[a-zA-Z0-9]{16}$ + - notMatchRegex: + path: stringData.testuser + pattern: value-supplied-secret diff --git a/packages/apps/mariadb/tests/database_validation_test.yaml b/packages/apps/mariadb/tests/database_validation_test.yaml new file mode 100644 index 000000000..65ca29121 --- /dev/null +++ b/packages/apps/mariadb/tests/database_validation_test.yaml @@ -0,0 +1,485 @@ +suite: db.yaml rejects a database name that cannot install + +# A database name becomes the Database CR spec.name and (via "_"->"-") the +# Database CR metadata.name -, plus each Grant's database and +# metadata.name. Kubernetes requires that resource name to be a DNS-1123 +# subdomain, and two names differing only in "_" vs "-" collide on one Database +# CR. Without a guard such names render and fail opaquely at apply — the same +# class the username guard already catches. Mirror it for databases. Reverting +# the guard in db.yaml lets the render succeed, so the reject tests fail. + +templates: + - templates/db.yaml + +release: + name: mdb-test + namespace: tenant-test + +set: + users: + app: + maxUserConnections: 10 + +tests: + - it: fails for an uppercase database name (invalid Database CR name) + set: + databases: + My.Db: + roles: + admin: [app] + asserts: + - failedTemplate: + errorMessage: 'invalid database name "My.Db": it also names the Database resource "mdb-test-My.Db", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + - it: fails for a database name with a trailing "-" + set: + databases: + foo-: + roles: + admin: [app] + asserts: + - failedTemplate: + errorMessage: 'invalid database name "foo-": it also names the Database resource "mdb-test-foo-", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + - it: fails for two database names that collide after the "_"->"-" mapping + set: + databases: + a_b: + roles: + admin: [app] + a-b: + roles: + admin: [app] + asserts: + - failedTemplate: + errorMessage: 'database names "a-b" and "a_b" both map to the Database resource name "mdb-test-a-b" ("_" renders as "-"); rename one of them' + + # The Grant CR name is the join ---, so two + # different (database, user) pairs that split the "-"/"_" differently collide + # on one Grant even when each database and each username is individually unique + # and valid. Per-field guards miss this join; the guard must track the whole + # rendered Grant name. Here (db "a", user "b-c") and (db "a-b", user "c") both + # render mdb-test-a-b-c-admin. + - it: fails when two (database,user) admin grants collide on one Grant name + set: + users: + b-c: + maxUserConnections: 10 + c: + maxUserConnections: 10 + databases: + a: + roles: + admin: [b-c] + a-b: + roles: + admin: [c] + asserts: + - failedTemplate: + errorMessage: 'the Grant resource name "mdb-test-a-b-c" is produced by both (database "a", user "b-c") and (database "a-b", user "c") ("_" renders as "-"); rename a database or user so their Grants do not collide' + + # The Grant name -- can exceed 253 even when the database + # name fits: a Grant role member need not be a declared user, so the username + # cap never sees it, and the 128-char member cap is checked after this guard. A + # long database name cannot drive it, because the 64-char MariaDB database cap + # rejects that first. Assert the guard's OWN message (errorPattern) so a fixture + # tripping a sibling guard cannot masquerade as coverage. + - it: fails when the Grant name exceeds 253 characters though the database name fits + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - failedTemplate: + errorPattern: 'the Grant resource name .* exceeds the 253-character limit Kubernetes puts on a resource name' + + # A role list has no uniqueItems in the schema, so admin: [bob, bob] is legal + # and renders as a single Grant. The collision guard must + # not treat a user duplicated within one role as a collision with itself and + # abort the whole render — dedupe first. + - it: renders one Grant for a user listed twice in the same role + set: + users: + bob: + maxUserConnections: 10 + databases: + testdb: + roles: + admin: [bob, bob] + asserts: + # doc 0 Database, doc 1 the single Grant; no self-collision failure + - hasDocuments: + count: 2 + - documentIndex: 1 + equal: + path: metadata.name + value: mdb-test-testdb-bob + - documentIndex: 1 + equal: + path: spec.privileges[0] + value: ALL + + # A name in databases..roles.admin/readonly is NOT one of .Values.users, + # so it never passes the username guard in secret.yaml, yet it forms the Grant + # CR name --. A member outside the DNS-1123 charset (here + # "Weird.User!") renders a Grant name the apiserver rejects opaquely — the + # class the guards exist to close. The Grant guard must check the charset too, + # not only the length. + - it: fails for a role member that is not a valid DNS-1123 name + set: + users: + gooduser: + maxUserConnections: 10 + databases: + mydb: + roles: + admin: ["Weird.User!"] + asserts: + - failedTemplate: + errorMessage: 'invalid role member "Weird.User!" for database "mydb": it names the Grant resource "mdb-test-mydb-Weird.User!", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit). A name in databases..roles.admin/readonly is not one of .Values.users, so the username guard never sees it - use a lowercase name without special characters' + + - it: renders normally for a valid lowercase database name + set: + databases: + mydb: + roles: + admin: [app] + asserts: + - documentIndex: 0 + equal: + path: kind + value: Database + - documentIndex: 0 + equal: + path: spec.name + value: mydb + + # The database and Grant "_"/"-" collision guards are gated to install, for the + # same reason as the username one: an existing release already took the silent + # overwrite, and blocking its upgrades only makes a running release worse. On + # upgrade both colliding pairs render instead of failing. Removing + # ".Release.IsInstall" from either guard turns the matching test red. + - it: renders on upgrade for two database names that collide on install + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + databases: + a_b: + roles: + admin: [app] + a-b: + roles: + admin: [app] + asserts: + - hasDocuments: + count: 4 + + - it: renders on upgrade for two (database,user) grants that collide on install + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + users: + b-c: + maxUserConnections: 10 + c: + maxUserConnections: 10 + databases: + a: + roles: + admin: [b-c] + a-b: + roles: + admin: [c] + asserts: + - hasDocuments: + count: 4 + + # A charset/DNS-invalid database name never applied, so its guard stays on the + # upgrade path too rather than deferring an opaque apiserver rejection. + - it: still fails on upgrade for an invalid Database CR name + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + databases: + My.Db: + roles: + admin: [app] + asserts: + - failedTemplate: + errorMessage: 'invalid database name "My.Db": it also names the Database resource "mdb-test-My.Db", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + # The database name is the MariaDB database identifier (Database CR spec.name), + # capped by the server at 64 characters; a longer CREATE DATABASE fails with + # "Incorrect database name". Cap it at render. 65 fails, 64 renders. + - it: fails the render for a database name of 65 characters (past the MariaDB identifier limit) + set: + databases: + "daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": + roles: + admin: [app] + asserts: + - failedTemplate: + errorMessage: 'invalid database name "daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": a MariaDB database identifier is at most 64 characters' + + - it: renders normally for a database name at the 64-character boundary + set: + databases: + "daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": + roles: + admin: [app] + asserts: + - documentIndex: 0 + equal: + path: spec.name + value: "daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + # A Grant role member need not be one of .Values.users, so the 80-character + # username cap in secret.yaml (which iterates only .Values.users) never sees it. + # The server caps an account name at 128 characters, so a longer member renders + # a Grant whose GRANT the server rejects. Cap it at render. The database is kept + # short so the Grant name stays under 253 and THIS guard, not the length guard, + # fires; assert its own message so a sibling cannot shadow it. + - it: fails for a role member longer than the 128-character MariaDB account limit + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - failedTemplate: + errorMessage: 'invalid role member "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" for database "db": a MariaDB account name is at most 128 characters, so the server rejects the GRANT for a longer one. A name in databases..roles.admin/readonly is not one of .Values.users, so the username length cap in secret.yaml never sees it' + + - it: renders normally for a role member at the 128-character boundary + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - hasDocuments: + count: 2 + - documentIndex: 1 + equal: + path: spec.username + value: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + # Unlike the 253 and DNS-1123 Grant guards, a too-long member renders a Grant + # the apiserver accepts (spec.username has no CRD maxLength), so a release that + # already applied it must keep upgrading: on upgrade the cap skips a member + # whose Grant already exists. Applying the cap on upgrade regardless of the + # Grant makes this fail to render. + - it: renders on upgrade for an over-128 role member whose Grant already exists + release: + name: mdb-test + namespace: tenant-test + upgrade: true + kubernetesProvider: + scheme: + "k8s.mariadb.com/v1alpha1/Grant": + gvr: {group: k8s.mariadb.com, version: v1alpha1, resource: grants} + namespaced: true + objects: + - apiVersion: k8s.mariadb.com/v1alpha1 + kind: Grant + metadata: + name: mdb-test-db-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + namespace: tenant-test + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - hasDocuments: + count: 2 + - documentIndex: 1 + equal: + path: spec.username + value: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + # The DNS-1123 Grant-member charset guard, by contrast, stays on both paths: an + # invalid name renders a Grant metadata.name the apiserver rejects, so it never + # applied and gating it to install would only defer the same opaque failure to + # the apiserver on upgrade. Wrapping that guard in ".Release.IsInstall" turns + # this red. + - it: still fails on upgrade for a role member that is not a valid DNS-1123 name + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + users: + gooduser: + maxUserConnections: 10 + databases: + mydb: + roles: + admin: ["Weird.User!"] + asserts: + - failedTemplate: + errorMessage: 'invalid role member "Weird.User!" for database "mydb": it names the Grant resource "mdb-test-mydb-Weird.User!", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit). A name in databases..roles.admin/readonly is not one of .Values.users, so the username guard never sees it - use a lowercase name without special characters' + + # A member added on upgrade has no Grant yet, so it is as new as one on install + # and the cap still names it; gating the cap to install alone would let the + # common path, adding a member to a running release, render silently. Dropping + # the "not lookup" conjunct lets the render succeed, so this fails. + - it: still fails on upgrade for a NEW over-128 role member + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - failedTemplate: + errorMessage: 'invalid role member "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" for database "db": a MariaDB account name is at most 128 characters, so the server rejects the GRANT for a longer one. A name in databases..roles.admin/readonly is not one of .Values.users, so the username length cap in secret.yaml never sees it' + + # A non-ASCII member fails the DNS-1123 guard for its charset, which runs before + # the 128 cap: 65 characters of 2-byte "é" are 130 bytes, and reporting them as + # "at most 128 characters" would send the tenant shortening a name that is short + # enough. Moving the 80 cap back above the DNS-1123 guard turns this red. + - it: reports a non-ASCII role member for its charset, not its byte length + set: + databases: + db: + roles: + admin: ["ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé"] + asserts: + - failedTemplate: + errorPattern: 'invalid role member .* which Kubernetes requires to be a DNS-1123 subdomain' + + # A fresh install has no running release to protect, so the cap holds even when + # a stale Grant of that name is already in the namespace. Dropping the + # ".Release.IsInstall" conjunct lets the render succeed, so this fails. + - it: still fails on install for an over-128 role member a stale Grant carries + kubernetesProvider: + scheme: + "k8s.mariadb.com/v1alpha1/Grant": + gvr: {group: k8s.mariadb.com, version: v1alpha1, resource: grants} + namespaced: true + objects: + - apiVersion: k8s.mariadb.com/v1alpha1 + kind: Grant + metadata: + name: mdb-test-db-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + namespace: tenant-test + set: + databases: + db: + roles: + admin: ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] + asserts: + - failedTemplate: + errorPattern: 'a MariaDB account name is at most 128 characters' + + # The Database CRD allows a spec.name of 80 characters while the server allows + # 64, so a name of 65-80 renders a Database the apiserver accepts and only the + # operator's SQL fails. A release that already applied one must keep upgrading: + # on upgrade the 64 cap skips a name whose Database already exists. Applying the + # cap on upgrade regardless of the Database makes this fail to render. + - it: renders on upgrade for a 65-character database whose Database already exists + release: + name: mdb-test + namespace: tenant-test + upgrade: true + kubernetesProvider: + scheme: + "k8s.mariadb.com/v1alpha1/Database": + gvr: {group: k8s.mariadb.com, version: v1alpha1, resource: databases} + namespaced: true + objects: + - apiVersion: k8s.mariadb.com/v1alpha1 + kind: Database + metadata: + name: mdb-test-ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd + namespace: tenant-test + set: + databases: + "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd": + roles: + admin: [app] + asserts: + - documentIndex: 0 + equal: + path: spec.name + value: "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" + + # A database added on upgrade has no Database yet, so it is as new as one on + # install. Dropping the "not lookup" conjunct lets the render succeed, so this + # fails. + - it: still fails on upgrade for a NEW 65-character database name + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + databases: + "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd": + roles: + admin: [app] + asserts: + - failedTemplate: + errorPattern: 'a MariaDB database identifier is at most 64 characters' + + # A fresh install has no release to protect, so the cap holds even when a stale + # Database of that name is in the namespace. Dropping the ".Release.IsInstall" + # conjunct lets the render succeed, so this fails. + - it: still fails on install for a 65-character database a stale Database carries + kubernetesProvider: + scheme: + "k8s.mariadb.com/v1alpha1/Database": + gvr: {group: k8s.mariadb.com, version: v1alpha1, resource: databases} + namespaced: true + objects: + - apiVersion: k8s.mariadb.com/v1alpha1 + kind: Database + metadata: + name: mdb-test-ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd + namespace: tenant-test + set: + databases: + "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd": + roles: + admin: [app] + asserts: + - failedTemplate: + errorPattern: 'a MariaDB database identifier is at most 64 characters' + + # Past 80 characters the apiserver rejects the Database itself (CRD maxLength), + # so such a name never applied and is rejected on upgrade too, even if a + # Database of that name somehow exists. Dropping the 80 conjunct lets the render + # succeed, so this fails. + - it: still fails on upgrade for an 81-character database name + release: + name: mdb-test + namespace: tenant-test + upgrade: true + kubernetesProvider: + scheme: + "k8s.mariadb.com/v1alpha1/Database": + gvr: {group: k8s.mariadb.com, version: v1alpha1, resource: databases} + namespaced: true + objects: + - apiVersion: k8s.mariadb.com/v1alpha1 + kind: Database + metadata: + name: mdb-test-ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd + namespace: tenant-test + set: + databases: + "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd": + roles: + admin: [app] + asserts: + - failedTemplate: + errorPattern: 'a MariaDB database identifier is at most 64 characters' diff --git a/packages/apps/mariadb/tests/grant_username_quoting_test.yaml b/packages/apps/mariadb/tests/grant_username_quoting_test.yaml new file mode 100644 index 000000000..494c6ef06 --- /dev/null +++ b/packages/apps/mariadb/tests/grant_username_quoting_test.yaml @@ -0,0 +1,121 @@ +suite: Grant CR quotes the username so a YAML-special name stays a string + +# The Grant CR's spec.username must match the User CR's spec.name and the Secret +# key, which user.yaml/secret.yaml already quote. Emitted bare, a username that +# is a YAML-special scalar decodes to the wrong type: Kubernetes reads manifests +# through sigs.k8s.io/yaml (YAML 1.1), where a numeric name like 123 becomes an +# integer and a name like "on" becomes a boolean, so the Grant names a value the +# User CR (string) does not, and the privilege is silently never applied. +# +# A numeric name is used deliberately: helm-unittest's own loader keeps a bare +# "on" as the string "on" (it does not apply YAML 1.1 booleans), so only a +# numeric exercises the coercion here — bare 123 loads as the integer 123, the +# quoted form as the string "123". Asserting the string form pins the quoting; +# dropping "| quote" in db.yaml loads it as an integer and turns this red. +# +# Document order from db.yaml for one database granting one user admin+readonly: +# 0 Database, 1 Grant(ALL/admin), 2 Grant(SELECT/readonly). + +templates: + - templates/db.yaml + +release: + name: mdb-test + namespace: tenant-test + +set: + users: + "123": + maxUserConnections: 10 + "456": + maxUserConnections: 10 + databases: + db1: + roles: + admin: ["123"] + readonly: ["456"] + +tests: + - it: keeps the admin Grant username the string "123" + documentIndex: 1 + asserts: + - equal: + path: kind + value: Grant + - equal: + path: spec.privileges[0] + value: ALL + - equal: + path: spec.username + value: "123" + + - it: keeps the readonly Grant username the string "456" + documentIndex: 2 + asserts: + - equal: + path: kind + value: Grant + - equal: + path: spec.privileges[0] + value: SELECT + - equal: + path: spec.username + value: "456" + + # A database name is subject to the same YAML-1.1 coercion: bare, a numeric + # name loads as an integer on the Database CR and the Grant, so they name a + # database that is not the one asked for. Quote both. + - it: keeps the Database and Grant database name the string "123" + set: + users: + app: + maxUserConnections: 10 + databases: + "123": + roles: + admin: [app] + asserts: + - documentIndex: 0 + equal: + path: kind + value: Database + - documentIndex: 0 + equal: + path: spec.name + value: "123" + - documentIndex: 1 + equal: + path: kind + value: Grant + - documentIndex: 1 + equal: + path: spec.database + value: "123" + + # A user in both admin and readonly of one database must render a SINGLE Grant, + # named -- with no role suffix (renaming a Grant on upgrade + # makes the operator revoke the live privilege). The admin grant wins (ALL is a + # superset of the readonly SELECT); the readonly grant is skipped, so there is + # no same-name collision to disambiguate. + - it: renders a single unsuffixed admin Grant for a user in both roles + set: + users: + app: + maxUserConnections: 10 + databases: + db1: + roles: + admin: [app] + readonly: [app] + asserts: + # doc 0 Database, doc 1 the one Grant; only two documents (no readonly Grant) + - hasDocuments: + count: 2 + - documentIndex: 1 + equal: + path: metadata.name + value: mdb-test-db1-app + - documentIndex: 1 + equal: + path: spec.privileges[0] + value: ALL diff --git a/packages/apps/mariadb/tests/root_password_ignored_test.yaml b/packages/apps/mariadb/tests/root_password_ignored_test.yaml new file mode 100644 index 000000000..36fadec97 --- /dev/null +++ b/packages/apps/mariadb/tests/root_password_ignored_test.yaml @@ -0,0 +1,51 @@ +suite: root password is always chart-generated, never taken from values + +# root is special: the operator applies it once at datadir bootstrap via +# rootPasswordSecretKeyRef, so a value-supplied root password would be a +# plaintext credential in tenant values that cannot even be rotated. The chart +# forces root to a chart-generated password by overwriting any supplied entry +# (`set $usersWithRoot "root" dict`). Two independent facts are pinned. (1) A value +# that tries to set root's password is ignored and the Secret carries a freshly +# generated one; this holds because the generation loop never reads a supplied +# password for ANY user, so a mutation that only restores root's pass-through +# (guarding `set ... dict`) does not redden it -- that half is the general rule +# credentials_test.yaml covers. (2) The `set $usersWithRoot "root" dict` line's own +# job is to force root into the generated set even when the tenant never declares +# it: the second test declares no root and asserts the Secret still carries a +# generated root, so deleting that line drops root from the Secret and reddens it. + +templates: + - templates/secret.yaml + +release: + name: mdb-test + namespace: tenant-test + +tests: + - it: ignores a value-supplied root password and generates one instead + set: + users: + root: + maxUserConnections: 10 + password: this-is-a-supplied-root-password-not-generated + asserts: + - matchRegex: + path: stringData.root + pattern: ^[a-zA-Z0-9]{16}$ + - notMatchRegex: + path: stringData.root + pattern: supplied + + # The `set $usersWithRoot "root" dict` line forces root into the generated set + # even when the tenant never declares it. Declare no root and pin that the Secret + # still carries a generated root password; deleting the line drops root from the + # Secret entirely, reddening this — the specific mutation the header credits. + - it: generates a root password even when root is not declared in users + set: + users: + app: + maxUserConnections: 10 + asserts: + - matchRegex: + path: stringData.root + pattern: ^[a-zA-Z0-9]{16}$ diff --git a/packages/apps/mariadb/tests/user_key_quoting_test.yaml b/packages/apps/mariadb/tests/user_key_quoting_test.yaml new file mode 100644 index 000000000..e28c71421 --- /dev/null +++ b/packages/apps/mariadb/tests/user_key_quoting_test.yaml @@ -0,0 +1,29 @@ +suite: MariaDB User CR quotes a YAML-special username + +# The credentials Secret quotes each key (secret.yaml), so a Secret key is always +# a string. The User CR must reference the same string. A username that is a bare +# YAML scalar — a number like `123`, or `true`/`false`/`no` — renders unquoted to a +# non-string, so spec.name and passwordSecretKeyRef.key diverge from the quoted +# Secret key and the operator cannot find the password. Both must be quoted. + +release: + name: mariadb-test + namespace: tenant-test + +templates: + - templates/user.yaml + +tests: + - it: renders a numeric username as a string in name and passwordSecretKeyRef.key + template: templates/user.yaml + set: + users: + "123": + maxUserConnections: 10 + asserts: + - equal: + path: spec.name + value: "123" + - equal: + path: spec.passwordSecretKeyRef.key + value: "123" diff --git a/packages/apps/mariadb/tests/username_validation_test.yaml b/packages/apps/mariadb/tests/username_validation_test.yaml new file mode 100644 index 000000000..d1c3c5042 --- /dev/null +++ b/packages/apps/mariadb/tests/username_validation_test.yaml @@ -0,0 +1,218 @@ +suite: secret rejects a username outside the safe charset + +# A MariaDB username becomes a Kubernetes Secret data key, the spec.name of a +# mariadb-operator User CR, and (with "_" mapped to "-") the User CR's own +# metadata.name. A name outside the Secret-key charset renders a Secret and a +# User the apiserver later rejects with an opaque error; ".", ".." and names +# over 253 chars match the charset yet k8s IsConfigMapKey still rejects them. +# Postgres already guards this at render time; MariaDB must too, for parity and +# to name the offending username instead of failing opaquely at apply. There is +# no shell interpolation here (the operator applies the SQL), so this is a +# diagnosability guard, not an injection fix. Reverting the guard in secret.yaml +# lets the render succeed, so the first test fails. + +templates: + - templates/secret.yaml + +release: + name: mdb-test + namespace: tenant-test + +tests: + - it: fails the render for a username with a space + set: + users: + 'a b': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "a b": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + - it: fails the render for a username with a slash + set: + users: + 'a/b': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "a/b": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + - it: fails the render for the reserved name "." + set: + users: + '.': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username ".": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + - it: fails the render for the reserved name ".." + set: + users: + '..': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "..": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + # IsConfigMapKey rejects ANY name starting with ".." (hasChDirPrefix), not just + # the literal "..", so "..foo" is charset-legal yet cannot install. + - it: fails the render for a name starting with ".." + set: + users: + '..foo': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "..foo": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + # The username names a mariadb-operator User, whose CRD caps spec.name at 80, so a + # longer name is rejected by the apiserver at apply; cap it here (81 chars) + # to name it at render. Reverting the cap to 253 lets this through. + - it: fails the render for a username of 81 characters (past the User CRD limit) + set: + users: + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": a username may contain only letters, digits and the characters -._ , must not be "." or start with "..", and must be at most 80 characters (the mariadb-operator User resource caps its name at 80, and the name also becomes a Kubernetes Secret key)' + + + # The username also names the User CR (-, "_"->"-"), which k8s + # requires to be a DNS-1123 subdomain: lowercase, alnum start/end. These pass + # the Secret-key charset but the User CR name is invalid, so they cannot install + # and must be named at render time rather than failing opaquely at apply. + - it: fails the render for an uppercase username (invalid User CR name) + set: + users: + Bob: + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "Bob": it also names the mariadb-operator User resource "mdb-test-Bob", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + - it: fails the render for a username with a trailing "-" (invalid User CR name) + set: + users: + 'foo-': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "foo-": it also names the mariadb-operator User resource "mdb-test-foo-", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + - it: fails the render for a username with a trailing "." (invalid User CR name) + set: + users: + 'foo.': + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "foo.": it also names the mariadb-operator User resource "mdb-test-foo.", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' + + # "a_b" and "a-b" both render the User CR name -a-b ("_" -> "-"), so + # one silently overwrites the other on apply. The guard must reject the pair. + - it: fails the render when two usernames collide after the "_"->"-" mapping + set: + users: + a_b: + maxUserConnections: 10 + a-b: + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'usernames "a-b" and "a_b" both map to the User resource name "mdb-test-a-b" ("_" renders as "-"); rename one of them' + + - it: renders normally for names using the full safe charset (root always added) + set: + users: + a-b.c_1: + maxUserConnections: 10 + asserts: + - matchRegex: + path: stringData["a-b.c_1"] + pattern: ^[a-zA-Z0-9]{16}$ + + # The "_"/"-" collision guard is gated to install. An existing release that + # already carries the pair took the silent overwrite when it was first applied; + # a platform-driven chart upgrade must not then wedge it into a failed reconcile + # it cannot clear without editing users. On upgrade the colliding pair renders + # instead of failing. Dropping ".Release.IsInstall" from the guard turns this + # test red (the render fails on upgrade), the mutation signal that the gate is + # load-bearing. + - it: renders on upgrade for a colliding pair the install path rejects + release: + name: mdb-test + namespace: tenant-test + upgrade: true + # A real upgrade finds the credentials Secret, so seed it: otherwise the + # upgrade-with-missing-Secret guard fires first and this would not exercise the + # collision gate at all. + kubernetesProvider: + scheme: + "v1/Secret": + gvr: {version: v1, resource: secrets} + namespaced: true + objects: + - apiVersion: v1 + kind: Secret + metadata: + name: mdb-test-credentials + namespace: tenant-test + data: + root: cm9vdHNlZWRwYXNzd29yZDA= + set: + users: + a_b: + maxUserConnections: 10 + a-b: + maxUserConnections: 10 + asserts: + - matchRegex: + path: stringData["a-b"] + pattern: ^[a-zA-Z0-9]{16}$ + + # On a first install there is no credentials Secret yet, so minting fresh + # passwords is correct and the render succeeds (lookup returns nothing here). + - it: mints on a first install when no credentials Secret exists + set: + users: + app: + maxUserConnections: 10 + asserts: + - matchRegex: + path: stringData.root + pattern: ^[a-zA-Z0-9]{16}$ + + # On an upgrade the Secret must exist; a lookup that finds nothing means it was + # deleted or the release renamed, and re-minting would rotate every account (root + # unrecoverable after bootstrap), so the render fails loudly. Removing the + # .Release.IsUpgrade guard lets it mint instead — the mutation signal. + - it: fails an upgrade when the credentials Secret is missing + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + users: + app: + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'mdb-test-credentials Secret not found while upgrading: refusing to mint fresh passwords, which would rotate every account and, because mariadb-operator applies root only at datadir bootstrap, leave the cluster advertising a root password it never set. If the Secret was deleted, restore it before upgrading (a first install does not hit this path).' + + # A charset/DNS-invalid name never applied at all, so its guard stays on the + # upgrade path too: gating it would only defer the same failure to the apiserver + # as an opaque error rather than naming the offending username here. + - it: still fails on upgrade for an invalid User CR name + release: + name: mdb-test + namespace: tenant-test + upgrade: true + set: + users: + Bob: + maxUserConnections: 10 + asserts: + - failedTemplate: + errorMessage: 'invalid username "Bob": it also names the mariadb-operator User resource "mdb-test-Bob", which Kubernetes requires to be a DNS-1123 subdomain (lowercase letters, digits, "-" and ".", starting and ending with a letter or digit); use a lowercase name without a leading or trailing "-" or "."' diff --git a/packages/apps/mariadb/values.schema.json b/packages/apps/mariadb/values.schema.json index 38edbca1c..ab66b1c67 100644 --- a/packages/apps/mariadb/values.schema.json +++ b/packages/apps/mariadb/values.schema.json @@ -159,23 +159,18 @@ ] }, "users": { - "description": "Users configuration map.", + "description": "Users configuration map. Passwords (including the `root` account) are always auto-generated and stored in the `\u003crelease\u003e-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret.", "type": "object", "default": {}, "additionalProperties": { "type": "object", "required": [ - "maxUserConnections", - "password" + "maxUserConnections" ], "properties": { "maxUserConnections": { "description": "Maximum number of connections.", "type": "integer" - }, - "password": { - "description": "Password for the user.", - "type": "string" } } } diff --git a/packages/apps/mariadb/values.yaml b/packages/apps/mariadb/values.yaml index 68199a6af..6999b793f 100644 --- a/packages/apps/mariadb/values.yaml +++ b/packages/apps/mariadb/values.yaml @@ -110,19 +110,16 @@ version: v11.8 ## ## @typedef {struct} User - User configuration. -## @field {string} password - Password for the user. ## @field {int} maxUserConnections - Maximum number of connections. -## @param {map[string]User} users - Users configuration map. +## @param {map[string]User} users - Users configuration map. Passwords (including the `root` account) are always auto-generated and stored in the `-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret. users: {} ## Example: ## users: ## user1: ## maxUserConnections: 1000 -## password: hackme ## user2: ## maxUserConnections: 1000 -## password: hackme ## @typedef {struct} DatabaseRoles - Role assignments for a database. ## @field {[]string} [admin] - List of users with admin privileges. diff --git a/packages/system/mariadb-rd/cozyrds/mariadb.yaml b/packages/system/mariadb-rd/cozyrds/mariadb.yaml index fa743a092..66b852518 100644 --- a/packages/system/mariadb-rd/cozyrds/mariadb.yaml +++ b/packages/system/mariadb-rd/cozyrds/mariadb.yaml @@ -8,7 +8,7 @@ spec: plural: mariadbs singular: mariadb openAPISchema: |- - {"title":"Chart Values","type":"object","properties":{"replicas":{"description":"Number of MariaDB replicas.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each MariaDB 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":"10Gi","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},"tls":{"description":"TLS configuration. Selects who issues the certificates and whether plaintext is refused; TLS itself is always served.","type":"object","default":{},"properties":{"issuer":{"description":"Who issues the server certificate: `operator` uses the CA mariadb-operator manages itself, `cert-manager` gives the instance its own CA and is what covers the external hostname. Named for the issuer because TLS is served under both, unlike the similarly-spelled `tls.enabled` in some other charts, which does switch TLS on and off.","type":"string","default":"operator","enum":["operator","cert-manager"]},"required":{"description":"Refuse plaintext connections (sets MariaDB require_secure_transport=ON). Applies under either issuer. Opt-in: turn it on once every client connects over TLS, since it disconnects those that do not.","type":"boolean"}}},"version":{"description":"MariaDB major.minor version to deploy","type":"string","default":"v11.8","enum":["v11.8","v11.4","v10.11","v10.6"]},"users":{"description":"Users configuration map.","type":"object","default":{},"additionalProperties":{"type":"object","required":["maxUserConnections","password"],"properties":{"maxUserConnections":{"description":"Maximum number of connections.","type":"integer"},"password":{"description":"Password for the user.","type":"string"}}}},"databases":{"description":"Databases configuration map.","type":"object","default":{},"additionalProperties":{"type":"object","properties":{"roles":{"description":"Roles assigned to users.","type":"object","properties":{"admin":{"description":"List of users with admin privileges.","type":"array","items":{"type":"string"}},"readonly":{"description":"List of users with read-only privileges.","type":"array","items":{"type":"string"}}}}}}},"backup":{"description":"DEPRECATED: Backup configuration. Prefer the BackupClass / Plan flow under examples/backups/mariadb/.","type":"object","default":{},"required":["cleanupStrategy","enabled","resticPassword","s3AccessKey","s3Bucket","s3Region","s3SecretKey","schedule"],"properties":{"cleanupStrategy":{"description":"DEPRECATED: Retention strategy for cleaning up old backups.","type":"string","default":"--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"},"enabled":{"description":"DEPRECATED: Enable regular backups (default: false).","type":"boolean","default":false},"resticPassword":{"description":"DEPRECATED: Password for Restic backup encryption.","type":"string","default":""},"s3AccessKey":{"description":"DEPRECATED: Access key for S3 authentication.","type":"string","default":""},"s3Bucket":{"description":"DEPRECATED: S3 bucket used for storing backups.","type":"string","default":"s3.example.org/mariadb-backups"},"s3Region":{"description":"DEPRECATED: AWS S3 region where backups are stored.","type":"string","default":"us-east-1"},"s3SecretKey":{"description":"DEPRECATED: Secret key for S3 authentication.","type":"string","default":""},"schedule":{"description":"DEPRECATED: Cron schedule for automated backups.","type":"string","default":"0 2 * * *"}}}}} + {"title":"Chart Values","type":"object","properties":{"replicas":{"description":"Number of MariaDB replicas.","type":"integer","default":2},"resources":{"description":"Explicit CPU and memory configuration for each MariaDB 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":"10Gi","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},"tls":{"description":"TLS configuration. Selects who issues the certificates and whether plaintext is refused; TLS itself is always served.","type":"object","default":{},"properties":{"issuer":{"description":"Who issues the server certificate: `operator` uses the CA mariadb-operator manages itself, `cert-manager` gives the instance its own CA and is what covers the external hostname. Named for the issuer because TLS is served under both, unlike the similarly-spelled `tls.enabled` in some other charts, which does switch TLS on and off.","type":"string","default":"operator","enum":["operator","cert-manager"]},"required":{"description":"Refuse plaintext connections (sets MariaDB require_secure_transport=ON). Applies under either issuer. Opt-in: turn it on once every client connects over TLS, since it disconnects those that do not.","type":"boolean"}}},"version":{"description":"MariaDB major.minor version to deploy","type":"string","default":"v11.8","enum":["v11.8","v11.4","v10.11","v10.6"]},"users":{"description":"Users configuration map. Passwords (including the `root` account) are always auto-generated and stored in the `-credentials` Secret; they cannot be set from values — read a user's password from that Secret. A `password` left over in values from before the field was removed is ignored by the render and draws an admission warning, but it is not inert on an upgraded release: the chart preserves whatever password is already in the Secret, which on the first upgrade is the value that was set before removal, so that value stays the live credential until it is rotated (dedicated rotation is tracked in cozystack/community#72). The live password lives only in the Secret.","type":"object","default":{},"additionalProperties":{"type":"object","required":["maxUserConnections"],"properties":{"maxUserConnections":{"description":"Maximum number of connections.","type":"integer"}}}},"databases":{"description":"Databases configuration map.","type":"object","default":{},"additionalProperties":{"type":"object","properties":{"roles":{"description":"Roles assigned to users.","type":"object","properties":{"admin":{"description":"List of users with admin privileges.","type":"array","items":{"type":"string"}},"readonly":{"description":"List of users with read-only privileges.","type":"array","items":{"type":"string"}}}}}}},"backup":{"description":"DEPRECATED: Backup configuration. Prefer the BackupClass / Plan flow under examples/backups/mariadb/.","type":"object","default":{},"required":["cleanupStrategy","enabled","resticPassword","s3AccessKey","s3Bucket","s3Region","s3SecretKey","schedule"],"properties":{"cleanupStrategy":{"description":"DEPRECATED: Retention strategy for cleaning up old backups.","type":"string","default":"--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"},"enabled":{"description":"DEPRECATED: Enable regular backups (default: false).","type":"boolean","default":false},"resticPassword":{"description":"DEPRECATED: Password for Restic backup encryption.","type":"string","default":""},"s3AccessKey":{"description":"DEPRECATED: Access key for S3 authentication.","type":"string","default":""},"s3Bucket":{"description":"DEPRECATED: S3 bucket used for storing backups.","type":"string","default":"s3.example.org/mariadb-backups"},"s3Region":{"description":"DEPRECATED: AWS S3 region where backups are stored.","type":"string","default":"us-east-1"},"s3SecretKey":{"description":"DEPRECATED: Secret key for S3 authentication.","type":"string","default":""},"schedule":{"description":"DEPRECATED: Cron schedule for automated backups.","type":"string","default":"0 2 * * *"}}}}} release: prefix: mariadb- labels: