Commit Graph
19 Commits
Author SHA1 Message Date
Yasar Rahman 8be7fb2e66 feat(redis): expose min-replicas-to-write and min-replicas-max-lag
Lets an operator bound the writes lost when an isolated Redis master is
failed over: the master refuses writes while fewer replicas than
configured are connected and recent. Both values are unset by default, so
the rendered Redis config is unchanged.

Redis treats 0 in either directive as disabling the check, so the
chart refuses minReplicasMaxLag 0 next to a replica requirement
instead of silently turning the protection off.

Negative values are refused by the schema (minimum 0), since Redis
rejects them at CONFIG SET and the operator would stop healing the
Sentinels of that instance. A requirement of replicas or more is
refused at render: a master with replicas pods has replicas-1
replicas, so it would refuse every write for good.

Assisted-by: LLM
Signed-off-by: Yasar Rahman <yasar.rehman@gmail.com>
2026-10-12 02:03:17 +05:00
Yasar Rahman 9a88afe6ca feat(redis): run Sentinel on the same image as the Redis pods
The Sentinels were left on redis:6.2.6-alpine when the operator moved to
the freshworks-oss fork, so that its new compiled-in default could not
move them on upgrade. 6.2 is end of life, and every instance now runs a
Sentinel one or two major versions behind the Redis it monitors.

The rollback risk behind that pin, a newer engine rewriting dump.rdb in
a format the older one cannot load, does not apply to Sentinel. It
stores no RDB or AOF, only sentinel.conf on an emptyDir that the
config-copy init container rewrites from the operator's ConfigMap on
every start, so moving back to an older image starts from a clean
config. Taking the image from the same version map as the data pods also
means one image per node instead of two.

The e2e comment that relied on busybox's timeout exit code in the
Sentinel container is updated, since that container now carries
coreutils.

Signed-off-by: Yasar Rahman <yasar.rehman@gmail.com>
Assisted-by: LLM
2026-10-11 13:16:11 +05:00
Yasar Rahman 8580a9d46d feat(redis): size the Sentinel pods separately from Redis
Every Sentinel pod gets the Redis pods' resources, so the three
Sentinels of an instance reserve three times a Redis replica's memory
while holding only their configuration and the failover state. On a
t1.nano instance that is 3 x 128Mi while the VPA recommender's uncapped
target for a Sentinel container is 16Mi, and the waste grows with every
larger preset, because the dataset that drives the Redis sizing never
reaches a Sentinel.

sentinel.resources and sentinel.resourcesPreset follow the convention of
the top-level pair, and sentinel.resourcesPreset falls back to
resourcesPreset. Explicit Redis resources are not carried over once the
sentinel block sets either key, since they were sized for the dataset.
An empty sentinel.resources map counts as unset, as an empty top-level
resources does.

An empty sentinel block keeps today's sizing, so existing instances
render unchanged and an upgrade does not roll their Sentinels. The
Sentinel WorkloadMonitor reports the preset the Sentinels actually use.

Signed-off-by: Yasar Rahman <yasar.rehman@gmail.com>
Assisted-by: LLM
2026-10-11 00:27:32 +05:00
Aleksei Sviridkin 48e3d1d611 feat(redis,postgres): certify the per-engine external hostname
The tenant Gateway's TLS-passthrough listeners are designed to route
databases by SNI under a per-engine subdomain (*.redis.<apex>,
*.postgres.<apex>), and a passthrough listener forwards the handshake
untouched, so the engine's own server certificate must carry
<release>.<engine>.<apex> or a verifying client fails the hostname
check.

The name is issued next to the existing flat <release>.<apex>, under
the same TLS-and-external condition, so that a later move between the
two hostname schemes reissues no certificate and leaves clients on the
same trust anchor. Nothing renders a route yet; the certificate is
prepared ahead of it. Adding the name changes the SAN list, so existing
external TLS releases get their server certificate reissued once on
upgrade, from the same CA.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-10-07 04:43:15 +03:00
Aleksei Sviridkin 77f6cd1af8 test(redis): assert no external SAN when no namespace map is injected
The null-namespace case only checked that the in-cluster name is
present, so a chart that emitted a bare "my-redis." SAN, or fell back
to the suite-level host, would still pass. It now carries the same
absence check as the empty-host case, plus the suite host itself.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-10-01 22:23:25 +03:00
Aleksei Sviridkin 2fee484dea test(redis): pin the schema rejection of an unknown tls.authClients value
The no / optional / yes constraint on tls.authClients lives in
values.schema.json, and nothing the chart renders shows whether it is
enforced: a bogus value either fails validation up front or reaches the
template as a string. Assert the failure, so the enum cannot be dropped
from the schema without a red test.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:58:06 +03:00
Aleksei Sviridkin d0cab491f3 feat(redis): move the tenant trust anchor onto the platform projection
The tenant read path was two grants on Secret names: the operator's
CA-only <release>-ca-cert in the dashboard Role, and the same name in the
ApplicationDefinition's include list. Replace both with the projection
the previous commit declares.

A name grant conveys whatever occupies the name. The operator holds
create and update on Secrets cluster-wide, so what sits at
<release>-ca-cert is the operator's choice rather than the platform's,
and RBAC has no key-level filter to catch it if that ever stops being
just ca.crt. <release>.tenant-ca is written only by the CA-extraction
controller, which copies one named key and refuses PEM private key
material outright. That is the difference between a name that happens to
hold a certificate today and provenance the platform vouches for, and it
is the reason postgres, mongodb, nats and qdrant all reach the tenant
this way — mongodb's operator publishes a CA Secret of its own too, and
that one is excluded rather than granted.

Also drop spec.caCert from the ApplicationDefinition. The
ApplicationDefinition CRD does not define that field and Flux applies
these server-side, so the apiserver rejects the whole object with "field
not declared in schema" and the redis-rd release never goes ready. It was
carried deliberately as a merge-order gate for a controller that reads
it; that controller landed as the TenantProjection reconciler, which
reads a sentinel in the app chart instead, so the gate has nothing left
to wait for.

hack/check-redis-rd-secrets.bats pins the whole rendered Secret surface
rather than probing for known-bad names, alongside the existing guards
for nats, qdrant and mongodb: an include with neither resourceNames nor
matchLabels restricts nothing, and a second matchLabels entry selecting
a label cert-manager also stamps on the key-bearing Secrets would grant
the CA private key while every name in the file stayed correct.

The connection example passes the generated password as well. Password
generation is on by default, so the command as printed connected and then
answered NOAUTH on the first real command.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:58:06 +03:00
Aleksei Sviridkin cbde93b0cc feat(redis): declare the tenant trust anchor as a TenantProjection
The tenant needs the release's CA certificate to verify the server, and
the platform's contract for handing one over is the key-free
<release>.tenant-ca projection: the CA-extraction controller lifts a
single named key out of a source Secret, refuses to publish anything
that parses as PEM private key material, and stamps
internal.cozystack.io/tenant-ca on what it writes. postgres, mongodb,
nats and qdrant all reach the tenant this way; redis is the fifth.

Source the chart's own cert-manager CA Secret, <release>-ca-tls, rather
than the CA-only Secret the operator publishes at
spec.tls.caCertSecretName. Both carry the same certificate, but
<release>-ca-tls exists as soon as cert-manager issues the CA, so the
tenant read path does not also depend on the operator having reconciled
the RedisFailover and written its copy. That the source holds the CA
private key beside ca.crt is the intended shape rather than a
compromise — projecting one key out of a key-bearing Secret is what the
controller is for, and it refuses private key material outright.

Gated on tls.enabled, because the source Secret only exists when TLS is
on. The test pins that the gate is tls.enabled and not external access:
an externally exposed plaintext release must render no sentinel, or the
controller waits forever on a Secret nothing creates.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:58:05 +03:00
Aleksei Sviridkin 1d3499e36b fix(redis): certify the external LoadBalancer service name
When external access is on the chart creates <release>-external-lb
itself, but the leaf certificate covered only the four Services the
operator creates. That name resolves in-cluster like any other Service,
so a client dialing it under TLS failed hostname verification against a
Service this chart owns. Add its four DNS forms next to the operator's,
gated on the same flag that creates it.

Also record at the image pin how the digest moves: it is refreshed by release preparation, not by this change, so an edit to the Dockerfile under images/ ships only once the next repin lands.

The README list of in-cluster names the certificate covers names the
external LoadBalancer Service as well.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:58:05 +03:00
Aleksei Sviridkin eb4abc8d93 feat(redis): make TLS opt-in instead of following external access
TLS was enabled automatically whenever external was true. In this
operator TLS is not additive — the rendered config sets port 0 and moves
the listener to tls-port — so that inference turned every already-running
externally-reachable Redis into a TLS-only server on its first reconcile
after the upgrade and cut every plaintext client with it. A platform
upgrade must not sever working connections.

Resolve tls.enabled to false when unset, whatever external says. Enabling
TLS becomes an explicit act at creation time, and existing releases keep
the behaviour they have today.

Creation time, not any time: a running instance cannot change mode. A
replica restarted onto the TLS listener cannot replicate from a master
still on plaintext, and Sentinels already on TLS would fail over to a
stale replica, so the operator's RedisFailover schema rejects a change of
tls.enabled and the HelmRelease upgrade fails while the instance keeps
serving what it served before. The README says so and points at creating
a new instance and migrating.

Pin the decision directly: external: true on its own now has to leave the
cert-manager chain unrendered, the operator without spec.tls, and the
tenant without TLS secrets. Every case that previously reached TLS through
external says enabled: true instead, and the null and empty-map forms
resolve to off alongside the unset one.

With nothing inferred there is no upgrade-time behaviour change left, so
the breaking-change marker and footer are gone from this branch.

Say how to get out of it as well. The cozystack Redis API accepts the
change, so the rejection lands on the HelmRelease, and every later edit
to that instance queues behind the failure until tls.enabled goes back
to what it was.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:08 +03:00
Aleksei Sviridkin a7ab8ca14f fix(redis): keep hostless tenants rendering when external access is on
Requiring _namespace.host turned a nil dereference into a hard render
failure for a shape that legitimately has no host. packages/apps/tenant
computes an empty host whenever neither the tenant nor its parent sets
one, and Helm's required rejects the empty string as readily as nil, so
an external Redis running in such a tenant would have stopped templating
altogether on upgrade — no object left to inspect and no error pointing
at the cause.

Emit the external SAN when a host exists and skip it when none does. A
tenant without a host has no external name to certify, so there is
nothing being silently dropped, and the in-cluster names still cover
every client that verifies inside the cluster. Reading through a
defaulted dict keeps an absent _namespace from dereferencing nil.

Replace the test that pinned the failure with two that pin rendering,
for an empty host and for an absent namespace map.

Add the coupling the CA-only secret name needs. Its name has to match
across the operator spec that publishes it and the tenant grant that
exposes it; renaming one alone leaves the tenant without a trust anchor
and produces no error anywhere.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:07 +03:00
Aleksei Sviridkin eb5302fb24 fix(redis): surface the CA-only secret to the tenant before the controller lands
The trust anchor was selected only by the internal.cozystack.io/tenant-ca
label, which nothing stamps until the CA-extraction controller merges. A
label-only entry selects nothing until then, so a TLS-enabled Redis gave
the tenant no way to obtain the certificate needed to verify the server —
the dashboard Role grants the Secret by name, but it never became a
tenant secret and so never appeared on the product surface.

Name the operator's CA-only Secret directly alongside the auth secret.
It holds ca.crt and no private key, so this widens tenant visibility by
exactly the object the tenant needs and nothing else. The label selector
stays for the converged path; once the controller publishes its
projection the anchor is reachable under both names.

Cover the two assertions the feature depended on and did not have:
caCertSecretName, which has to agree with both the dashboard Role and the
declared CA source, and the loopback IP SANs, added by their own fix
commit and until now asserted nowhere.

Correct the tri-state helper's comment. It claimed the kindIs "invalid"
guard covers an explicitly null tls.enabled; the schema types that field
as boolean and rejects null before any template runs. The guard covers
the reachable shape, a tls map with no enabled key, now tested.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-By: Claude <noreply@anthropic.com>
2026-09-02 17:56:07 +03:00
Aleksei Sviridkin 8ee652f734 fix(redis): name the failure when external is on without a namespace host
The external SAN dereferenced .Values._namespace.host directly, so a
render without that injected value aborted on a nil pointer with no
indication of what was missing. TLS now defaults on whenever external is
true, which puts that lookup on the default path for every externally
reachable Redis.

Wrap it in required with an explicit message, matching how the nats chart
guards the same lookup in its own certificate template. Failing is the
right behaviour rather than dropping the SAN: a certificate issued
without the external hostname is accepted by nothing outside the cluster
and the resulting handshake error points nowhere near the cause.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:07 +03:00
Aleksei Sviridkin ad9013c237 fix(redis): restore the storage class picker and guard the cluster-domain lookup
Two defects in the generated ApplicationDefinition and the certificate
template.

The regenerated openAPISchema had lost the x-cozystack-options extension
on storageClass that values.schema.json still carries, which is what
drives the storage class picker in the dashboard form. The schema was
generated with cozyvalues-gen 1.5.0 while CI pins 1.6.0, and the older
release drops the extension. Regenerated with the pinned version, which
restores it.

The cluster-domain lookup indexed .Values._cluster directly, so a render
where the platform injects no _cluster map failed with "index of untyped
nil" before the documented cozy.local fallback could apply. Default the
parent map so the fallback is actually reachable, and extend the test to
cover an absent map as well as an empty domain — the previous test only
exercised a domain set to the empty string, which never reached the
failing path.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:06 +03:00
Aleksei Sviridkin 8df75dfd89 fix(redis): fall back to the cozystack cluster domain in the leaf SAN list
The leaf certificate built its .svc.<domain> SANs from the platform's
cluster-domain value with cluster.local as the fallback, while every
other chart in the tree falls back to cozy.local, which is the domain
cozystack actually configures. The platform always injects the value so
the fallback does not fire today, but if it ever did the certificate
would carry names nothing resolves under and every TLS dial by FQDN
would fail hostname verification.

Pin the fallback with a test; the existing cluster-domain coverage only
exercised values that were explicitly set.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:06 +03:00
Aleksei Sviridkin eedd08f6fc fix(redis): stop granting the tenant the server private key under TLS
The dashboard Role handed the tenant the release's leaf Secret whenever
tls.authClients was yes, on the reasoning that a client needing to
authenticate can reuse the server identity as its own. That Secret holds
tls.key, so any subject at the tenant's use level could read the private
key of the certificate Redis and Sentinel present and impersonate those
endpoints to every client that trusts the release CA.

Withhold it. The tenant keeps read access to the CA-only Secret, which is
what verifying the server actually requires and which carries no private
key at all.

This leaves authClients=optional and =yes without a client certificate a
tenant can obtain, since the CA private key needed to sign one is also
withheld by design. Document that limitation in README.md rather than
paper over it: in-cluster components are unaffected because the operator
mounts the leaf for them, but an external client has no supported path to
a certificate this CA accepts, so those two values are only usable when
the certificate is supplied out of band.

Also correct the neighbouring comment, which described the per-release CA
as trusted by the whole cluster. It is self-signed and scoped to one
release, and nothing outside that release trusts it.

Add the test target the package was missing. The TLS suite added with
this feature sat in tests/ with no way to invoke it, so CI had never run
any of it; the assertions covering this Role were passing only in
principle. All 24 now run, including the two that pin the leaf Secret as
withheld at both authClients values.

The authClients sentence also says to quote the value: an unquoted yes or
no in a manifest is read as a boolean and the string field rejects it.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:56:06 +03:00
Arsolitt e6ffe10c47 feat(redis): consume CA-only secret for tenant trust in dashboard RBAC
The redis-operator now publishes an Opaque Secret holding only ca.crt
(no private key) via spec.tls.caCertSecretName. Point that field at
<release>-ca-cert and grant the dashboard Role get/list/watch on it so
tenants can verify the server without touching any private key.

Drop the dashboard grant on <release>-ca-tls: that cert-manager secret
holds the CA private key and must never be exposed to tenants. The leaf
secret <release>-tls is now granted only when authClients=yes, where
clients reuse it as their client identity.

Refresh the vendored RedisFailover CRD with the new caCertSecretName
field and update the helm-unittest RBAC cases for the new layout.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-09-02 17:56:05 +03:00
Arsolitt 46bafd6eda feat(redis): add digital signature to leaf cert usages for ECDSA TLS handshake
TLS_ECDHE_ECDSA cipher suites require the server certificate to assert the
digital signature key usage so the server can sign ephemeral key-exchange
parameters. Without it, strict TLS clients reject the handshake even though
the cert is otherwise valid. Added the usage to the leaf Certificate and
extended the helm-unittest suite to cover it.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-09-02 17:56:05 +03:00
Arsolitt 2ea4aad5de feat(redis): add operator-managed TLS via cert-manager PKI chain
Expose tls.enabled in the Redis chart values, mirroring the pattern
already in use by mariadb, nats, opensearch, qdrant and rabbitmq. The
flag is tri-state: when unset, TLS follows the value of `external`; an
explicit boolean overrides the default.

When TLS is enabled the chart renders the standard cozystack 4-resource
cert-manager chain in the release namespace:

  - Issuer (self-signed bootstrap)
  - Certificate (CA, ECDSA, isCA, rotationPolicy: Never, 5y)
  - Issuer (CA-backed)
  - Certificate (leaf, secret <release>-tls, ECDSA, 1y, rotationPolicy: Always)

The leaf certificate covers the SAN list the redis-operator computes for
its own Certificate (operator/redisfailover/service/generator.go:
redisCertificateDNSNames): short, namespace, .svc and .svc.<clusterDomain>
forms for rfr- / rfrm- / rfrs- / rfs- services plus a wildcard for
per-pod headless DNS names of the redis statefulset. Localhost is
included for in-pod readiness probes; when `external` is true the
tenant LB hostname is added too.

The chart hands the resulting Secret to the operator via
spec.tls.certificateSecret.secretName so the operator never creates a
duplicate Certificate; it just mounts the Secret into both Redis and
Sentinel pods and wires the redis tls-* directives. tls.authClients
maps to the Redis tls-auth-clients directive and defaults to "no".

The dashboard-resources Role is extended with the new TLS secret names
only when TLS is on, so the cozystack dashboard can read them to
display connection details.

Helm unit tests in tests/tls_test.yaml cover the tri-state resolution
(four enable/external combinations), SAN list coverage for all four
service names and the wildcard, custom cluster-domain handling, the
external SAN injection path, authClients propagation, and dashboard
RBAC expansion.

The comment above the CA usages named the wrong bits: cert-manager maps
signing to the digital signature bit, and crl sign and ocsp signing are
separate usages this chart does not request.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-09-02 17:56:05 +03:00