mariadb-operator up to v0.0.27 mounted the referenced ConfigMap key as
/etc/mysql/conf.d/my.cnf whatever the key was called. Since v0.0.28 the
file takes the key's own name, so the chart's key "config" became
/etc/mysql/conf.d/config, and the server's !includedir reads only *.cnf
files from that directory. Every setting in the chart's my.cnf has been
ignored since that operator bump: instances run on stock defaults,
including a 128M InnoDB buffer pool inside the 128Mi default limit.
Renaming the key restores the file as intended. Existing instances roll
their pods once, since the projected volume in the pod template changes,
and come back with the chart's settings in effect, including sql-mode
and innodb_flush_log_at_trx_commit, not only the resource sizing.
Fixes: a9c42c8ef0 ("Update mariadb-operator v0.28.1 (#124)")
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
users[].password is gone from the chart, its schema and the API type.
Every password, root included, is generated into <release>-credentials
and kept across reconciles by lookup, and a password left in values is
ignored. An upgrade that finds no credentials Secret fails instead of
minting new passwords, because mariadb-operator applies root only at
datadir bootstrap and would advertise a root it never set. The Secret
carries k8s.mariadb.com/watch so the operator applies a changed password
without waiting for its requeue interval.
A username or database name becomes a Secret key and a resource name, so
render-time guards reject a name outside the DNS-1123 rule or past its
limit: 80 for a username, as the User CRD allows, and 64 for a database,
as the server allows. Names that differ only in "_" and "-" collide on
one resource; that is rejected on install only, since an existing
release already applied the overwrite. A user in both admin and readonly
of a database keeps a single ALL grant under the unchanged Grant name,
because renaming a Grant makes the operator revoke the live privilege. A
role member past 128 characters, the server's account-name limit, and a
database name of 65-80 characters, which the Database CRD accepts but
the server does not, are rejected on install and on upgrade only when
their Grant or Database does not exist yet, so a release that already
applied one keeps upgrading. User CR names and keys are quoted so a
username that reads as a YAML scalar stays a string.
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
With watch granted, kubectl delete waits for the claims to be gone, and
its default for that wait is a week. A claim held by a pod that will not
stop, or a stuck detach, would hold the post-delete hook until
helm-controller's 300s uninstall budget ran out and leave the
HelmRelease stuck uninstalling.
The PVC deletes in the clickhouse, harbor, mariadb and qdrant hooks now
wait 120s at most and report the claims still terminating by name, and
each Job carries activeDeadlineSeconds 270 with a 10s termination grace
period, the numbers packages/apps/tenant/templates/cleanup-job.yaml
documents against that budget, so a kubectl that never returns cannot
hold the hook either.
The mariadb Role no longer grants watch on the named Secrets: they carry
no finalizer, so the delete never reaches the watch, and a resourceNames
rule does not authorize a collection watch anyway.
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
Assisted-by: LLM
kubectl delete waits for the object to disappear unless told otherwise,
and that wait is a watch. The post-delete hook Roles of harbor,
clickhouse, mariadb and qdrant granted get, list and delete only, so
every uninstall logged a forbidden watch, the wait was skipped and the
hook reported success before the PVCs were actually gone.
The rules now carry watch for every resource the hooks delete, including
the named Secrets the mariadb hook removes.
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
Both cleanup suites asserted the delete as
"(?s)kubectl delete secret -n \S+.*<name>". Under (?s) the dot matches a
newline, so the gap runs past the end of the command: any earlier
"kubectl delete secret" satisfies the opening and the names may then sit
on any later command in the script. The pattern never established that
they are arguments of the delete at all.
Moving the two cert-manager Secrets off the delete onto a "kubectl get",
leaving the password delete above them untouched, keeps both suites green
while the CA private key and the server private key outlive the release
in a namespace the tenant shares with its other applications — the one
outcome this hook exists to prevent. The comments beside the assertions
already claimed the verb was pinned, so a reader trusting them had no
reason to re-check; they stand unchanged because the patterns now do what
they say.
Pin the whole invocation with its argument list instead, spelling out the
shell's line continuations rather than stepping over them. Whitespace and
backslashes are the only separators the pattern admits, and no command
can be written in those, so a match cannot leave the command it began in.
That mutation now reddens both suites, as does dropping one name from the
list, as does swapping the verb for a read.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The issuer resolver maps anything that is not exactly "cert-manager" to
operator issuance, so a typo fails open: the instance keeps the operator's
CA and nothing at render time reports that the value was not understood.
The enum is the only thing that refuses it, and one kubebuilder marker
generates that enum into both the chart's values.schema.json and the
ResourceDefinition's copy, so a single lost marker opens both guards at
once.
The suite already pins the rejection for the sibling field on this object
and left this one, the direction that fails quietly, uncovered. Removing
the enum from the schema fails this case and no other.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The chart asks cert-manager for two Secrets and names them after the
release: "<release>-ca-tls" for the CA and "<release>-tls" for the leaf.
The release prefix is "mariadb-", so an application named foo produces
mariadb-foo-ca-tls, and an application named foo-ca produces
mariadb-foo-ca-tls as well. One release's CA private key and another
release's server private key claim the same object. Two sibling
applications in one tenant namespace are enough to hit it: whichever
cert-manager writes last owns the Secret, and each instance then serves
or trusts material issued for the other.
The suffix set is what makes it ambiguous. It holds both "-tls" and
"-ca-tls", and one is a tail of the other, so a hyphen leaves nothing to
say where the release name ends. A dot does: an application name is
validated as a DNS-1035 label and the release prefix as ^[a-z0-9-]*$, so
neither can contain one, and "<release>.ca-tls" and "<release>.tls" split
uniquely. Secret names are DNS-1123 subdomains, which admit the dot.
Only the two suffixes this chart chooses move. The Certificate and Issuer
object names keep the hyphen, because their suffixes are not a pair where
one is a tail of the other, and the operator-managed
"<release>-ca-bundle" that the trust-anchor projection reads is not this
chart's to rename.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The case titled "renders regardless of tls.issuer" set issuer: operator,
which is the chart default, so both sides of its claim were the same
side. Hiding the sentinel behind the cert-manager gate — the one edit
the title rules out — left it green.
Being ungated is the projection's entire contract, so each state is now
its own case: the default, operator, cert-manager, and an explicit null,
which the issuer helper treats as unset rather than as a spelling of the
default.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The notContains element omitted optional: true, and contains compares
each list element whole rather than as a subset, so the element it
described equalled nothing the template can render. Mounting the server
key Secret as the backup CA volume — the exact substitution the
assertion names — left it green, and only the neighbouring positive
caught the mutation.
The comment two cases below already described this trap as handled,
which is how it survived being reintroduced.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Both suites matched only the Secret name list in the hook's script, so
replacing kubectl delete with kubectl get left all 106 cases green while
the CA private key and the server private key survived the release. The
verb is the claim these tests exist to make; the names alone are just
text that happens to appear in a shell script.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The comment sent the reader to certmanager_test.yaml, which this chart
does not have. Its cert-manager coverage — the rendering of the CA and
leaf Certificates under each tls.issuer value — lives in tls_test.yaml.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The publication guards asserted notExists on the labels
internal.cozystack.io/publish-ca-cert and its -release variant. Neither
name exists anywhere in the tree. The chart renders only
k8s.mariadb.com/watch into secretTemplate.labels, so a notExists on a
path no template can produce holds under every value, and the two cases
titled for a CA publication source could not fail for what they named.
The labels that decide tenant visibility are tenant-ca, which the
ApplicationDefinition's secrets.include selects on, and tenantresource,
which tenantsecrets serves on. Both are now asserted absent on each
key-bearing Certificate. Exclude-by-name in the ApplicationDefinition
stays the backstop behind them, not a substitute.
The documents are addressed by the Secret each Certificate writes plus
an explicit kind rather than by documentIndex, because an index follows
the slot: reordering the template would slide a labelled key-bearing
Certificate out from under the assertion and pass green. metadata.name
cannot serve, as the CA Certificate and the CA Issuer share the name
<release>-ca.
The operator-issuer case promised a label check its body never made; it
asserts only that the template renders nothing. Under that issuer no
Certificate exists to label, so zero documents is the whole statement
available, and the title now says that instead.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The dashboard Role and the ApplicationDefinition granted the operator's
key-free mariadb-<name>-ca-bundle Secret directly by name. Every other
converged engine (mongodb, postgres, nats, qdrant) instead renders a
TenantProjection that lifts ca.crt into the canonical <release>.tenant-ca
object, reached through core.cozystack.io/tenantsecrets rather than a
per-Secret grant.
Add templates/tenant-projection.yaml sourcing from the operator's
ca-bundle, drop the name grant from the dashboard Role and from the
ApplicationDefinition's secrets.include (the existing tenant-ca
matchLabels selector now has something to match), and remove the
ApplicationDefinition's caCert field, which named a field the
ApplicationDefinition CRD does not define and would have rejected the
whole object under server-side apply.
Update the README and the pinned RBAC tests to the new tenant-ca name.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The backup CA case is called "checks the CA file exists and names it" but
only guarded the first half. Deleting the Secret name from the error left
the suite green, so the reason MYSQL_CA_SECRET is passed to the CronJob at
all — telling the operator which Secret to go look at, since the client
reports a missing CA without naming a file or its source — was unpinned.
The cozyrds suite header also counted its own coverage wrong. It claimed
two live tests and three placeholders; there are seven and four. The four
exclude guards are live and went unmentioned, and the case reading the
source key is inert like its neighbours but carried no placeholder marker.
That header is the file's honest-coverage statement, so an understated
ledger is the one error it cannot afford.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Three assertions matched text that survived the mutation they exist to
catch.
The backup CA guard was pinned by three separate substrings: the two test
expressions and the message. Flipping its exit status to 0, or short
circuiting the condition with `false &&`, leaves all three intact and the
suite green — while the backup runs on with --ssl-ca pointing at a file
that is missing or empty, and in the exit-0 case reports success having
dumped nothing. Match the whole construct through its exit instead.
The exclude entries were checked by name without checking they still sit
under resourceNames. A nil resourceNames matches every name, so dropping
that key turns the backstop into a match-everything selector while each
name is still present in the block. Assert the key.
The leaf certificate pinned renewBefore but not duration. cert-manager
rejects a duration that does not exceed renewBefore, so pinning one of
the pair lets the other drift into a certificate that renders but cannot
be applied.
Each is verified by the mutation it was blind to: exit 1 to exit 0, a
short-circuited condition, a renamed resourceNames key, and an 8760h
duration shrunk to 1h all now fail the suite.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The guard asserting that the trust anchor is surfaced to the tenant
grepped the whole file. The bundle is also named in a comment and in the
caCert declaration, so either of those could satisfy it while the
secrets.include entry it exists to protect was gone. Scope it to the
include block, the way the sibling key-bearing-Secret guard already does.
Verified by deleting the include entry with a matching string left
elsewhere in the file: the guard now fails, where before it passed.
The suite header described a comment as stating that spec.tls.issuer is
true. There is no such field on the MariaDB CR — issuer is a chart value,
and what the chart renders is spec.tls.enabled, which is what the rest of
that sentence already describes. Name the field the assertions actually
check.
Also drop the claim that an 11.4 client verifies by default. The default
that changed in 11.4 is the --ssl-verify-server-cert flag, not whether
verification happens: without --ssl-ca that client has no trust anchor,
and falls back to an anti-tampering check derived from the password hash
which establishes neither the chain nor the hostname, and which cannot be
derived at all for a passwordless user. Passing both flags is what gives
chain and hostname verification, on either client version. The documented
command was already correct; the sentence around it invited dropping the
flag that carries it.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The exclude backstop enumerated the internal credential Secrets but
omitted `-metrics-config`. The operator writes it for every instance —
`MetricsConfigSecretKeyRef` at the pinned 25.10.2 fixes the name as
`<name>-metrics-config` — and its `exporter.cnf` carries
[client]
user=...
password=...
in plaintext. The exporter user is granted SELECT, PROCESS, REPLICATION
CLIENT, REPLICA MONITOR and SLAVE MONITOR on `*.*`, so that password
reads every table in every database.
It is not a hypothetical Secret: the chart sets `metrics.enabled: true`
unconditionally, so it exists on every ready instance. The include side
selects by label with no name constraint, and a nil `resourceNames`
matches everything, so the exclude list is what keeps it away from the
tenant. Exclude beats include, so naming it there is sufficient.
This is inside the enumerable part of the gap, not the part the comment
already disclaims: that carve-out covers Secrets a future operator adds
or creates mid-rotation, and this one exists today under a stable name.
Also complete a sentence in the suite that lost the words naming which
issuer it describes.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The eight cases covering the backup client's TLS flags read as coverage
of a live path. They are not: that CronJob cannot start, because it reads
the root password from a Secret name and key the chart does not render,
and the mismatch predates this branch.
Keep the cases — the flag defect was real, and they are what will stop
--ssl-mode returning whenever the job is repaired or dropped — but say in
the header what they actually pin, so the suite does not quietly claim a
path it never exercises.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Renaming the field left the suite describing the design it replaced:
titles about keeping TLS off, comments about a tri-state falling through
to external inheritance, one case named for a boolean value the enum no
longer has. The suite is where the contract is read, so it was still
teaching the old one.
The migration note also claimed the backup client's new verification is a
live change to running jobs. It is not: that CronJob reads the root
password from a Secret name the chart does not render, so it cannot start
in the first place. Say that, and point at the supported backup flow
instead of implying the deprecated one works.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
tls.enabled read as a switch and was not one — TLS is served under every
value, and what the field actually chose was which authority issues the
server certificate. The same key means on/off in other charts here, so a
tenant carrying that habit across would have read this exactly backwards.
Replace it with tls.issuer: operator | cert-manager, defaulting to
operator. The value now states the behaviour instead of needing prose to
undo the name: operator is what runs today, so the fact that nothing
changes on upgrade is visible in the default rather than argued in a
comment. Being an enum, a typo is rejected by the schema, which a bool
could not do.
The explanation the old name required is gone with it — the helper
docblock and the CR comment lose the paragraphs that existed only to say
this was not a switch, and the README states the split in a table.
Not marked breaking: the field is introduced by this series and does not
exist on the target branch, so there is no released spelling to migrate
from. Breaking is measured against what is merged, not against the
intermediate history of the branch.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The kindIs "invalid" guard on required had no coverage, and writing one
showed why: the schema types the field as a boolean and rejects null
before the template runs, so the guard is defensive rather than a live
path. Assert the rejection instead of inventing a rendering that cannot
happen, which also catches the schema being relaxed later.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The guard tested only readability, so a present-but-empty ca.crt passed
it and the run continued into exactly the unnamed client error the guard
was added to replace. Empty is reachable rather than theoretical: the
operator omits expired certificates when it assembles the bundle, so a CA
set that has fully expired leaves the file in place with nothing in it.
Check size as well, and say "missing or empty" so the message matches
both cases. Verified by running the rendered script against an absent and
an empty file.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
cert-manager is deployed with enableCertificateOwnerRef disabled, so
removing a Certificate leaves the Secret it issued in place. Uninstalling
an instance that used managed TLS therefore left <release>-ca-tls, which
holds the CA signing key, and <release>-tls, which holds the server key,
sitting in a namespace the tenant shares with its other applications, for
as long as the namespace exists.
The chart already had the mechanism: the post-delete hook deletes the
operator-generated password Secrets by name under an RBAC rule scoped to
exactly those names. Add these two to both lists. -ca-bundle stays out —
the operator gives it an ownerRef, so Kubernetes collects it, and naming
it here would widen the grant for nothing.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The client reports an unreadable CA only as "TLS/SSL error: No such file
or directory", with no path and no filename — verified against the
MariaDB client the backup image ships. Since the bundle is an optional
mount, that message is exactly what an operator sees during the window
before the trust bundle is reconciled, and it says nothing about what to
look at. Check the file first and fail with its path and the Secret it
comes from.
Correct the migration note as well. It said nothing changes on upgrade
until TLS is opted into, which is not true for instances still using the
deprecated backup CronJob: their backup client now verifies the server
where before it did not. It verifies against the operator's own bundle
and the operator's certificate already covers the host the job dials, so
no action is needed — but a behaviour change to a running job should be
stated rather than contradicted.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The bundle volume was a required mount. The operator reconciles it only
after certificates settle, so on first install with managed TLS there is
a window where it does not exist, and a required mount leaves the pod in
ContainerCreating rather than failing. With concurrencyPolicy: Forbid
that one stuck pod blocks every subsequent backup for as long as it
hangs. Marking it optional turns that into a run that fails with a
message naming the missing file, retries, and lets the schedule proceed.
Correct the reason given for enforcement defaulting to false while here.
It said the tenant had nothing to verify the server against, but this
same change grants the tenant read access to the bundle, so the anchor
is reachable. The default is still right — enforcement refuses clients
that have not moved yet, which is a decision to make rather than
something an upgrade does — but that is the reason, and it was stated in
five places, all fed from the values annotations.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Making managed TLS opt-in left the suite describing the behaviour it
replaced: the header still mapped external=true with tls.enabled unset
to managed, the section comment and several test titles still said TLS
was enabled via external, and every one of those cases only passed
because it now sets tls.enabled explicitly. The suite is where someone
reads the tri-state contract, so it was the one place still teaching the
old one.
The SAN comment also promised more than the test delivers. Pinning the
list catches an accidental edit to the template, but the expected values
are a copy of what the template renders, so an operator-side rename
would leave it green — and the operator skips certificate reconciliation
entirely when both secret refs are supplied, so it does not check
either. Say that the gap is real and that closing it needs a handshake,
rather than implying it is covered.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
tls.enabled defaulted to the value of external, so every existing
external instance would have moved from the operator's CA to a
chart-issued one on the next platform upgrade, without its owner doing
anything. Clients pinning the operator's ca.crt fail chain validation
the moment the new certificate is served, and external instances are
exactly the population where a copied ca.crt is most likely.
The usual argument for applying something on upgrade does not hold
here: taking over the CA does not raise the security floor. These
instances already serve TLS under the operator's CA, and what changes is
which authority issues it — an architectural move toward the platform
trust contract, not protection against a threat. There is no security
gain to weigh the breakage against, so it becomes a choice.
Rendered for an existing external instance, the result is now identical
to what the operator already applies on its own: TLS on, enforcement
off, no chart-issued certificates. Nothing happens on upgrade.
The default flips as an announced change together with the published
trust anchor, the same way tls.required does.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The backup client's TLS wiring was gated on the chart managing the
certificates, but enforcement is not. Setting tls.required on an
instance that uses the operator's own CA produced a server refusing
plaintext and a backup job with no CA mounted and no verification
flags, so every run failed — the same failure the MariaDB-dialect fix
addressed, reintroduced through a different gate.
Nothing was gained by the gate. The server serves TLS in every
configuration and the operator reconciles the CA bundle alongside it, so
the client can always verify; connecting unverified was never the
better option.
Two of the tests covering this asserted absence with a partial list
entry, which never matches a whole one, so they passed regardless of
what the template did. They now assert the mount that has to be there.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
tls.required was only emitted when the chart managed the certificates,
so setting it on an instance using the operator's own CA was accepted by
the schema and then dropped on the way to the CR — no enforcement, no
error, no warning. For a setting whose entire purpose is refusing
unprotected connections, silently ignoring it is the worst available
outcome.
The coupling was artificial: in the operator API required sits beside
enabled with no dependency on either certificate reference, and
enforcement works against operator-issued certificates just as well.
Emit it in every configuration and let it mean what it says.
Also loosen the two negative guards in the ApplicationDefinition check,
which required a literal closing quote and exact brace spacing and so
would have missed an unquoted key-bearing source.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Enforcement has to follow the trust anchor, not lead it. The platform
does not yet publish a key-free CA to the tenant, so requiring TLS today
tells clients they must encrypt while giving them nothing to verify the
server against — protection on paper, unverified connections in
practice.
It also cannot be opted out of in time. Enforcement would arrive with a
platform upgrade rather than a user action, and the escape hatch lives
in a field this change is the first to introduce, so an operator has no
way to set it beforehand. The only available order was upgrade, break,
then repair.
Default required to false and let enforcement be chosen. Managed TLS
still issues the per-instance CA and certificate, so the path to
verified connections is in place; what is deferred is refusing the
connections that predate it. The default flips to true as an announced
change once the published anchor is universal, and the field
descriptions say so rather than leaving it implied.
This does not change any running instance: enforcement was never applied
to one. The chart previously sent no enforcement at all unless it managed
the certificates, and managing them is itself opt-in, so an existing
instance keeps the operator's unenforced default either way.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The backup-script guards checked the explicit and the disabled states but
not the inherited one, which is what an external instance actually gets
by default and therefore the state most likely to run a backup against a
server that enforces TLS. Reintroducing the MySQL-only option now fails
three tests instead of two.
The surrounding prose had also fallen behind the behaviour it describes:
the suite header still called the unmanaged rows "TLS disabled" when the
tests below pin TLS as on but unmanaged, one comment still named the leaf
Secret as the trust-anchor source under a test asserting the CA bundle,
another blurred an explicit tls.enabled: null against blanking the whole
tls map, and one case was named for a string input it does not use.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Three corrections to what the rendered objects claim.
The schema defaulted tls.required to true unconditionally, so every CR
carried required: true even where the chart renders no enforcement at
all. The operator reads an absent required as not-enforced, so anyone
reading the CR was told plaintext is refused on an instance that
accepts it. Drop the schema default and let the template supply the
managed default, which keeps enforcement on for managed instances and
silent for the rest.
The tenant grant for the CA bundle was gated on TLS being managed, but
the operator reconciles that bundle whenever TLS is on, which for this
chart is always. Ungate it: the default instance serves TLS, so leaving
the tenant unable to fetch the CA meant it could not verify the server
it was talking to.
Reword the claim that TLS cannot be switched off. The operator does
honour an explicit disable; what is true is narrower, that omitting the
field is not how you select it and this chart always asks for TLS. The
text is what a reader relies on when deciding whether a connection is
protected, so it has to describe the chart rather than invent an
operator invariant.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Two corrections to what the chart tells the platform and the user.
The tls values never controlled whether TLS runs. The operator substitutes
an enabled TLS spec whenever the field is absent, so every instance has
always served TLS, and a chart that omits the block only hides that.
Render it explicitly and let the values select what they actually select:
who owns the CA, and whether TLS is enforced. Rendering the resolved
value instead would be the one change that genuinely turns TLS off on
instances that have it today, which is not something to ship silently.
The field descriptions said the opposite and are corrected with it.
Publication of the trust anchor moves to a declaration on the
ApplicationDefinition, naming the operator's <release>-ca-bundle. That
Secret holds ca.crt alone and carries the previous CA across a rollover,
so the publication path never runs next to a private key at all — better
than labelling the chart's own CA Secret, which does hold one. The labels
on that Secret are dropped rather than left as a second, redundant path.
The tenant keeps direct read access to the bundle so the feature is
usable before the extraction controller exists; that grant is key-free
and comes out once the published anchor is universal.
Also set a commonName on the leaf, which cert-manager otherwise leaves
empty, breaking clients that verify the hostname against the subject
rather than the SAN list.
The CA for external instances changes hands here, from the operator's to
one issued for the instance. A client verifying against
<release>-ca-bundle follows that automatically, because the bundle
carries both CAs; a client that pinned a copied ca.crt has to re-read it.
Enforcement is a separate, opt-in setting and is not changed by this
commit.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The leaf carried client auth alongside server auth. MariaDB treats
server and client certificates as separate roles, and a user declared
REQUIRE X509 accepts any client certificate signed by a trusted CA, so
a server key that also bears client auth can authenticate as that user.
The operator issues its own server certificates with server auth alone
and keeps client auth on the client certificates it manages separately;
match that split.
Drop key encipherment at the same time. It covers RSA key transport and
is inapplicable to the P-256 key this chart issues, where the usage that
matters is digital signature for the ECDHE signature.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Two things the chart got wrong about how mariadb-operator handles TLS.
The operator only reconciles on changes to the Secrets behind
serverCASecretRef and serverCertSecretRef when those Secrets carry its
watch label; the watches are predicate-gated on it. Neither Secret had
the label, and cert-manager owns them rather than the MariaDB resource,
so ownership does not trigger a reconcile either. The leaf rotates its
private key on every renewal, so a renewal would land in the Secret and
the running pods would keep serving the superseded certificate until
the next full resync. Label both Secrets.
The operator also reconciles a trust bundle of its own, named
<release>-ca-bundle, whenever TLS is enabled. It contains only ca.crt,
never a private key, and it spans a CA rollover. That is exactly the
trust anchor the tenant needs, and it already exists in the namespace,
so grant it to the tenant instead of stating that no CA is available.
The previous wording told operators to skip verification or to turn
enforcement off, which weakened security to work around a problem that
was not real.
Point the backup job at the bundle too. It was projecting ca.crt out of
the leaf Secret, which only ever holds the CA that signed the current
certificate and needlessly couples backups to leaf rotation.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The headless wildcard was listed at three resolution depths while every
named service was listed at four. A client resolving the missing
3-label form presents that name during the handshake, and a SAN gap
fails verification, so the wildcard now covers the same depths as the
rest of the list.
The external hostname was also read straight off _namespace, which
raises a raw nil pointer error naming neither the value nor the reason
when the key is absent. Route it through required, and tolerate an
absent or null _namespace so the explanatory message is what surfaces
rather than an index error.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The tenant needs the CA certificate to verify TLS connections, but the
cert-manager Secrets that back the chain are key-bearing: <name>-ca-tls
holds the CA private key and <name>-tls holds the server private key.
The dashboard Role granted the tenant read access to both whenever TLS
was on, which handed out signing material where only a trust anchor was
required.
Drop both from the tenant grant and mark the CA Secret as the source of
a key-free projection instead. The chart owns the cert-manager chain
here, so it labels the CA Secret directly, inside the existing TLS gate:
with TLS disabled the chain is not rendered and nothing is marked. Only
the CA carries the labels, never the leaf.
The selector added to the ApplicationDefinition is deliberately specific.
An empty selector would compile to a match-everything label selector and
project every Secret in the namespace to the tenant.
The source Secret and the projection are matched by two different
labels on purpose: the source stays key-bearing and internal, while the
published copy is key-free. Selecting the source directly from the
consumer would defeat the split and leak the CA private key.
Note that the labels and the selector are inert until the controller
that produces the projection exists: nothing reads the labels yet, and
the selector matches no Secret.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The backup image is alpine plus mariadb-client, so the backup script is
parsed by the MariaDB client. That client implements no ssl-mode option:
it is MySQL 8 syntax, and the MariaDB client rejects it while parsing
arguments ("unknown variable", exit 7) before it ever opens a
connection. Every TLS-enabled backup run therefore failed at the first
client invocation.
Replace it with the MariaDB equivalent, --ssl-ca combined with
--ssl-verify-server-cert, which validates the chain against the CA and
checks the server hostname against the certificate SANs.
Also align the cluster-domain fallback in the certificate template with
the rest of the catalog, which defaults to cozy.local rather than the
upstream Kubernetes cluster.local. These names go into the leaf
certificate SAN list that the backup client now verifies against, so a
mismatched fallback would produce certificates that fail hostname
verification.
The previous assertions only checked that an SSL string appeared in the
rendered script, so they stayed green against a script the client
refuses to parse. They now pin the client dialect instead: the MariaDB
verification flags must be present, the MySQL-only option must never be
emitted in any TLS state, and both client invocations must carry the
options.
Signed-off-by: Aleksei Sviridkin <f@lex.la>
When mariadb-operator sets require_secure_transport=ON (tls.required:
true), the server rejects plaintext TCP connections. The backup CronJob
used plain mysql and mysqldump commands with no SSL flags, causing all
backups to fail silently.
The leaf certificate SAN list already covers the primary and secondary
service names that the backup uses via MYSQL_HOST, so
--ssl-mode=VERIFY_IDENTITY (strictest mode with hostname validation)
is correct here.
The fix conditionally adds:
- SSL_OPTS variable in the backup script with --ssl-ca and --ssl-mode
- A tls-ca volume mounting ca.crt from the leaf TLS Secret
- A corresponding volumeMount at /etc/mysql-ssl in the backup container
The TLS path is activated through the same mariadb.tls.enabled helper
used elsewhere in the chart, so it follows the external inheritance
tri-state correctly.
Assisted-by: LLM
Signed-off-by: Arsolitt <arsolitt@gmail.com>
ECDSA P-256 keys offer equivalent or better security than RSA-4096 with
significantly smaller key material and faster handshake operations. Both
CA and leaf certificates are updated; existing rotation policies are
preserved (Never for CA, Always for leaf).
Note: cert-manager will re-issue both CA and leaf on next reconcile.
Existing trust anchors that pin the CA cert will break; tenants must
refresh their ca.crt after upgrading.
Assisted-by: LLM
Signed-off-by: Arsolitt <arsolitt@gmail.com>
Some DNS clients shorten hostnames before resolving them based on the
ndots setting. For example, a client inside the same namespace with
ndots:5 may try "svc-name.namespace" before the full
"svc-name.namespace.svc.cluster.local" form. Without the short-form
SANs in the certificate, the TLS handshake fails for those clients
even though they reach the correct endpoint.
Adds "*.name-internal" and "name.namespace" (without .svc suffix)
variants to the leaf certificate SAN list.
Assisted-by: LLM
Signed-off-by: Arsolitt <arsolitt@gmail.com>
Adds the crl sign key usage to the CA certificate for conventional
compliance with RFC 5280. CA certificates that may sign CRLs should
advertise this usage even when CRL distribution is not currently
configured.
Assisted-by: LLM
Signed-off-by: Arsolitt <arsolitt@gmail.com>
TLS 1.3 and TLS 1.2 ECDHE require the server certificate to have the
digital signature key usage so that ephemeral key-exchange parameters
can be signed. Without it, strict TLS stacks (Go crypto/tls, BoringSSL)
reject the handshake at the ServerKeyExchange step.
Assisted-by: LLM
Signed-off-by: Arsolitt <arsolitt@gmail.com>
The leaf cert now covers the base ClusterIP service `<release>` alongside
the existing `-primary` and `-secondary` services so a client connection
that uses the unqualified release name (e.g. via cozystack platform DNS)
passes hostname verification. The headless `-internal` wildcard and the
external LoadBalancer hostname are unaffected.
Signed-off-by: Arsolitt <arsolitt@gmail.com>
Add helm-unittest assertions covering the chart changes:
- spec.tls.serverCASecretRef.name in both TLS-enabled MariaDB CR cases
- localhost and wildcard headless-service SAN entries in the leaf
certificate SAN tests for both external=true and explicit
tls.enabled=true scenarios
Signed-off-by: Arsolitt <arsolitt@gmail.com>
## What this PR does
The chart shipped a my.cnf with sizing hardcoded for a large dedicated
host — `innodb_buffer_pool_size=60G`, `innodb_log_file_size=4096M`,
`key_buffer_size=1024M`, `max_connections=4096` — while the default
preset `t1.nano` gives the pod 250m CPU and 128Mi of memory, and the
default volume is 10Gi. Nothing connected the two, so the defaults asked
a 128Mi container for a 60G buffer pool and made every first boot
preallocate a redo log worth 40% of the volume.
That is not only a slow start. On the current default, MariaDB 10.6 is
OOM-killed before it finishes checking its configuration, and on 11.8
the server refuses to start at higher limits with `Cannot map
innodb_buffer_pool_size_max`. It survives in practice only because a
large node's overcommit heuristics allow the mapping and a small
database never touches most of it.
Sizing now derives from the instance's own limits through the same
helper that fills `resources` on the CR, so both `resourcesPreset` and
an explicit `resources` block work. The buffer pool takes half the
memory limit, rounded down to a 128 MiB multiple because InnoDB on the
10.6 line allocates in chunks of that size and rounds requests up — a
naive value would hand the pod a pool larger than its own limit. Half
rather than the conventional 70-80% because that advice assumes a
dedicated host where the remainder is page cache and overshoot means
swapping; under a cgroup limit the same budget also has to cover
per-connection buffers, temporary tables, the key cache and mysqld's own
heap, and overshoot means the kernel kills the process. The redo log
follows the smaller of the pool and 5% of the volume, and the remaining
allocations scale from memory or CPU with floors at the server's own
defaults.
`innodb_buffer_pool_instances` and `innodb_thread_concurrency` are
removed rather than scaled: every shipped server version logs that they
were removed and now do nothing, so this only drops a startup warning.
Settings that describe durability or disk behaviour rather than instance
size — `innodb_flush_log_at_trx_commit`, `innodb_flush_method`,
`innodb_io_capacity`, `innodb_fast_shutdown` — are deliberately left
alone, since the chart cannot derive them from a pod's resources.
### Upgrade safety
An existing instance has a 4096M redo log and will get a smaller one.
Shrinking it was verified on every shipped server version — 10.6.24,
10.11.15, 11.4.9 and 11.8.5 — after both a clean shutdown and a SIGKILL
with writes still unflushed. In all cases the server replayed crash
recovery first and resized the log afterwards, with data intact by
checksum and `CHECK TABLE ... EXTENDED`.
The ConfigMap carries no operator watch label, so a running healthy
instance keeps its current sizing until its next restart; an instance
already crash-looping on the old values picks the new ones up when it
restarts.
### Release note
```release-note
fix(mariadb): size my.cnf from the instance's own CPU, memory and volume instead of hardcoded values that assumed a large dedicated host. Instances on small presets previously advertised `max_connections=4096`, which they could not serve; the limit now scales with memory and starts at the server default of 151.
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- MariaDB server settings now scale automatically based on CPU, memory,
storage, and configured resource limits.
- Improved buffer pool, redo log, connection, cache, temporary table,
and thread sizing across instance presets.
- Large instances can use buffer pools beyond the previous fixed limit.
- **Bug Fixes**
- Improved sizing for small-volume deployments.
- Removed obsolete MariaDB configuration options for improved version
compatibility.
- Explicit resource settings now take precedence over preset values.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
The shipped my.cnf hardcoded the tuning of a large bare-metal host: a 60G
buffer pool, a 4096M redo log, a 1024M MyISAM key cache, 4096 connections
and 24 pool threads. The chart defaults to t1.nano, which is 250m of CPU
and 128Mi of memory with a 10Gi volume, so by default a 128Mi container
was asked to map 60G of buffer pool and preallocate a redo log worth 40%
of its data volume.
That is not merely wasteful. With the Linux default heuristic overcommit
the 60G mapping is refused outright on a node without the memory to back
it, and mariadbd exits with "Cannot map innodb_buffer_pool_size_max"; where
the mapping is permitted, the eagerly allocated key cache alone exceeds a
small instance's limit and the pod is OOM killed during startup. A nano
instance only survives on a node large enough for the mapping to be granted
and with a working set small enough never to touch it.
Every value that is a memory allocation or a thread count now derives from
the memory and CPU limits resolved by the same cozy-lib helper that fills
the MariaDB CR's resource stanza, so an explicit resources block and a
preset both flow through. Settings that encode durability or storage
behaviour rather than size -- the flush method, flush_log_at_trx_commit,
io_capacity, fast_shutdown -- are left alone, because the chart cannot
infer them from the pod.
The buffer pool takes half of the memory limit. The usual advice to give
InnoDB 70-80% of RAM assumes a dedicated host where the rest is page cache
and overshooting merely swaps; under a cgroup limit the same budget must
also cover per-connection buffers, temp tables, the key cache and mysqld's
own heap, and overshooting is a kill rather than a slowdown. Sizes above
128 MiB are rounded down to a whole number of 128 MiB chunks. On the 10.6
line InnoDB allocates the pool in 128 MiB chunks and rounds a request up,
which would hand the pod more pool than its limit allows; the newer lines
either autosize the chunk or ignore it outright, so there the rounding only
costs a little pool on a limit that is at least 256 MiB and not a multiple
of it -- the rounding applies to half the limit, and below one whole chunk
it does not fire at all -- and buys one effective size across every version
the chart ships.
Most caps are the previously shipped value, so an instance large enough to
reach one is sized as it is today, and most floors are the server's own
default, so a small instance is not configured more restrictively than an
untuned MariaDB. Three clamps deliberately break that symmetry. The buffer
pool has no cap: pinning it to the old 60G would keep the largest instances
sized for a host they do not run on, so an instance with 128Gi or more of
memory is the one case where a value goes up rather than down, to half of a
limit it already has. The MyISAM key cache goes the other way, capped at
128M against the 1024M shipped and floored at 8M against a 128M default,
because it is allocated eagerly at startup and MariaDB's own system tables
are Aria rather than MyISAM, so on a small instance it is close to dead
weight charged against the limit. The IO threads are the third, floored at
2 against a default of 4, because they should follow the CPU limit rather
than the host. The one user-visible narrowing is
max_connections on small instances, which falls from 4096 to the stock
default of 151 -- a limit those instances could not have served anyway, and
one that now rises automatically as the instance is sized up.
Changing the redo log size is safe on every version this chart ships.
InnoDB replays the existing log during crash recovery and only then rewrites
it at the new size. This was verified on all four shipped versions --
10.6.24, 10.11.15, 11.4.9 and 11.8.5 -- after both a clean shutdown and a
SIGKILL mid-write, with the data intact afterwards. The size is also
bounded by a twentieth of the data volume, so first boot no longer
preallocates a large part of it -- below roughly 2Gi of volume the 96M
floor wins instead and the server's own default is what lands.
The ConfigMap is not labelled k8s.mariadb.com/watch, so the operator does
not roll an instance when it changes. That is left as it was. An instance
crashlooping on the old config picks the new one up as soon as the kubelet
restarts it, which is the case this fixes, while a healthy instance keeps
its current sizing until it next restarts for some other reason. Rolling
every tenant database on a chart upgrade would be the larger risk.
innodb_buffer_pool_instances and innodb_thread_concurrency are dropped
rather than scaled. Both were removed from the server in 10.6, below the
oldest version this chart ships, and each start logged "was removed. It
does nothing now and exists only for compatibility with old my.cnf files".
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The operator builds the MariaDB startup probe without setting
failureThreshold, so it falls back to the Kubernetes default of 3. The
kubelet only starts probing once initialDelaySeconds has elapsed and
kills the container on the Nth consecutive failure, so with the
operator's initialDelaySeconds of 20 and periodSeconds of 10 the budget
is 20 + (3 - 1) * 10 = 40 seconds -- exactly what the liveness probe
allows, which leaves the startup probe deferring nothing.
Bootstrapping a fresh datadir does not reliably fit in 40 seconds under
a constrained CPU limit or slow replicated storage. Overrunning the
budget is not a slow start that recovers on the next attempt: the
kubelet kills the container after mariadb-install-db has created the
system tables but before the entrypoint's temporary server applies the
root grant. The restarted entrypoint keys DATABASE_ALREADY_EXISTS off
that directory and skips initialization for good, so the server comes
up with the install-time root account -- local only and passwordless --
rather than the credentials the operator holds. Every probe from then
on fails with "Access denied for user 'root'", so the pod crash-loops
permanently with no path back and the install times out waiting for a
MariaDB that can never become ready.
Raise failureThreshold to 30, giving first boot 310 seconds. Only the
threshold is set, so the operator keeps its own probe handler -- the
agent HTTP endpoint when replication is enabled, the exec check
otherwise -- and the liveness and readiness probes keep their
defaults, so a server that hangs after a successful start is still
caught as quickly as before.
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
The post-delete cleanup Jobs in the harbor and mariadb charts hardcoded
`docker.io/clastix/kubectl:v1.32` — a moving tag pulled directly from
Docker Hub. This broke build reproducibility (the tag can be re-pushed),
was a supply-chain risk, and could not be satisfied on air-gapped /
mirrored clusters, where it failed at the worst moment: during uninstall,
when the post-delete hook runs and stalls release teardown.
Add a canonical `cozy-lib.image` helper that prefixes a registry-relative
image path with `cozy-lib.images-registry` when set and returns it
unchanged (no leading "/") when empty, so standard installs resolve from
the default registry and mirrored installs resolve internally. Consume it
from both cleanup hooks with the image digest-pinned to the immutable
multi-arch index sha256:b9ef7d8dbe65bcc81a46c09b8dc7543103055021c4f43287bf59e92a8f4fe05c
(the same digest already pinned for postgres-operator's webhook hook).
Keep the pin fresh with a custom Renovate manager: the repo disables the
helm-values manager (enabledManagers), and the ref is built at render time
by the helper rather than being a Dockerfile/go.mod dependency, so the
built-in managers cannot see it. A regex manager over the hook templates
tracks clastix/kubectl by tag+digest — mirroring the existing extra/etcd
manager — so the supply-chain pin does not silently age.
Also harden `cozy-lib.images-registry` against a nil .Values._cluster so
the helper never crashes the render — relevant precisely because the hook
renders during teardown. Helm unit tests assert the rendered image (routed,
digest-pinned, no leading slash) by pattern rather than an exact digest, so
a Renovate bump keeps them green.
Closes#3088
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Алексей Артамонов <alexeyartamonov1987@gmail.com>