Files
cozystack/packages/system/redis-operator/patches/crd-tls.diff
T
Aleksei Sviridkin 9ef1f28855 build(redis-operator): carry TLS support as a downstream patch
freshworks-oss/redis-operator v3.3.5 has no TLS support. The operator
work that packages/apps/redis renders against was ported upstream as
freshworks-oss/redis-operator#85 and is not in a release yet, so carry it
here over the v3.3.5 tarball until one lands.

Three pieces, and TLS is silently off unless all three are present:

- images/redis-operator/patches/tls.diff is the source half. The
  Dockerfile already applies patches/*.diff, and the shell expands that
  to labels.diff then tls.diff; they touch disjoint files, so the order
  does not matter, but it is alphabetically stable either way.
- patches/crd-tls.diff teaches the vendored CRD about spec.tls. Without
  it the apiserver prunes spec.tls from every RedisFailover the redis
  chart renders and the patched binary waits for a field it never sees.
- patches/rbac-tls.diff grants Create, Get and Update on Secrets, so the
  operator can publish the CA-only Secret named by
  spec.tls.caCertSecretName. Those are the only Secret calls in the
  patched source: upstream v3.3.5 only ever reads one, and the patch
  adds Create and Update on a Secret it addresses by name, so nothing
  lists, watches, patches or deletes.

tls.diff is cut from that PR's commit 2ad2ed8d1 rebased onto v3.3.5, and
its header pins that SHA so the next refresh can be diffed against it.
Beyond the TLS listener it carries the renewal roll: on every reconcile the operator stamps a hash of the TLS
Secret's tls.crt and ca.crt into the pod template of the Redis
StatefulSet and the Sentinel Deployment, so a renewed certificate rolls
Redis through the operator's own roller and Sentinel through its
Deployment. The effective spec.tls.authClients value is folded into
the same hash, so changing it rolls the pods the same way instead of
landing at the next unrelated restart, and the operator presents its
client certificate whenever the Secret carries one, independent of that
field, so neither direction of the change locks it out of the instance
it reconciles. It also mounts the TLS volume 0440 when the pod declares an
fsGroup, rejects a caCertSecretName that names the TLS Secret itself,
and waits for the TLS material before it writes the ConfigMaps and the
workloads, so a first TLS install starts its pods once.

tls.enabled is fixed at creation. Redis replication and Sentinel cannot
straddle plaintext and TLS: a replica restarted onto the other protocol
cannot sync from the master, and Sentinels restarted onto it fail over
to such a replica while the master still takes writes. The rule that
refuses the change is a CEL transition rule on the RedisFailover spec;
it lives in the CRD, so it ships here through patches/crd-tls.diff
together with the schema block it references. The cut carries source
only, and the Dockerfile strips the tarball's manifests/, charts/,
example/ and .github/ before applying the patches, so the image builds
from source alone and the two upstream tests that read the CRD YAML skip
instead of failing against v3.3.5's stale copy; the CRD half is
patches/crd-tls.diff.

cert-manager Certificates get no grant. The patched operator manages a
Certificate only under spec.tls.certManager, and packages/apps/redis
pins the other mode: it always supplies spec.tls.certificateSecret, so
that code path is unreachable as the platform ships it. A comment at
the rule site records the decision and names the verbs the rule would
need, so a re-vendor review reads the absence as deliberate.

The chart patches go through the mechanism the packages that customise a
vendored chart already use — reloader, grafana-operator, ingress-nginx,
seaweedfs and kamaji all re-apply a patches/*.diff at the end of update:
— because `rm -rf charts` discards a hand-edit and the next `make update`
would take TLS back out without failing.

tls.diff also carries one change that is not TLS and takes effect with
TLS off: MakeSlaveOfWithPort connects to the replica on its own port
rather than on the master's. It changes a dial, not a pod template, so
nothing rolls when this image ships; the probes dial localhost only
under TLS, and the plaintext pod templates stay byte-identical to
v3.3.5. The patch header names it, so a reader of patches/ does not
take the file for TLS-only.

The grant is narrower than the ported operator's own chart asks for:
that one also grants patch on Secrets, and create, delete, get, list,
patch, update and watch on Certificates. None of that is reachable from
the source as shipped here.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-02 17:58:06 +03:00

221 lines
12 KiB
Diff

# The RedisFailover CRD gains spec.tls, matching the downstream TLS support the
# operator image carries as images/redis-operator/patches/tls.diff. The two have
# to move together: the schema is what the apiserver validates against, so
# without this block every RedisFailover packages/apps/redis renders has its
# spec.tls pruned on admission and TLS is silently off, while the patched binary
# waits for a field it never sees.
#
# The x-kubernetes-validations rule on spec fixes tls.enabled at creation: an
# absent block and enabled: false are one state, a change between that state
# and enabled: true is refused with the message the rule carries. Redis
# replication and Sentinel cannot straddle plaintext and TLS, so the operator
# refuses the flip rather than half-performing it; on a running release the
# refusal surfaces as a failed HelmRelease upgrade. The rule references
# self.tls, so it and the schema block land together or not at all.
#
# Generated by running controller-gen 0.17.3 with crd:crdVersions=v1 over the
# v3.3.5 ./api tree with tls.diff applied, and diffing against the same
# generator run on the unpatched tree. Regenerate it that way rather than
# hand-editing, and regenerate it whenever tls.diff touches
# api/redisfailover/v1/types.go.
#
# The block sits after `sentinel` because controller-gen sorts properties
# alphabetically; keeping that order is what makes the regenerated output match
# this patch instead of reordering the whole map.
#
# controller-gen stamps its own version into the
# controller-gen.kubebuilder.io/version annotation while the vendored chart
# carries (devel); that one-line difference is not part of the change and is
# left out of this patch.
--- a/charts/redis-operator/crds/databases.spotahome.com_redisfailovers.yaml
+++ b/charts/redis-operator/crds/databases.spotahome.com_redisfailovers.yaml
@@ -15319,7 +15319,188 @@
type: object
type: array
type: object
+ tls:
+ description: |-
+ TLSSettings configures TLS for the Redis failover cluster.
+ When Enabled is true, exactly one of CertManager or CertificateSecret must
+ be set. The resulting Kubernetes Secret must contain the standard cert-manager
+ keys (tls.crt, tls.key, ca.crt) and is mounted read-only into both Redis and
+ Sentinel pods at /tls.
+
+ TLS is chosen when the RedisFailover is created and cannot be turned on or
+ off afterwards. Redis replication and Sentinel cannot straddle two wire
+ protocols: a replica restarted onto the other protocol cannot sync from the
+ master, and Sentinels restarted onto it declare the master down and fail
+ over to such a replica while the master still serves writes. The other
+ fields stay mutable; a renewed certificate reaches the pods through a
+ restart.
+ properties:
+ authClients:
+ description: |-
+ AuthClients maps to the Redis tls-auth-clients directive.
+ One of "no", "optional", "yes". Defaults to "no" — server certificate
+ is presented but client certificates are not validated.
+ Changing it rolls the Redis and Sentinel pods, because the directive
+ is read from the config file once at startup.
+ enum:
+ - "no"
+ - optional
+ - "yes"
+ type: string
+ caCertSecretName:
+ description: |-
+ CACertSecretName names the Opaque Secret the operator publishes with
+ only the CA certificate (ca.crt) extracted from the TLS material. It
+ never contains tls.key, so RBAC can be scoped to it to let clients
+ verify the server without exposing any private key. When TLS is
+ enabled the operator always publishes this Secret; this field only
+ overrides its name. Defaults to "<tls-secret-name>-ca" when empty.
+ type: string
+ certManager:
+ description: |-
+ CertManager provisions the server certificate by creating a
+ cert-manager Certificate that references the given Issuer.
+ Mutually exclusive with CertificateSecret.
+ properties:
+ duration:
+ description: |-
+ Duration is the requested certificate validity. Optional;
+ cert-manager uses its own default (typically 90 days) when unset.
+ type: string
+ extraSANs:
+ description: |-
+ ExtraSANs is a list of additional Subject Alternative Names to add
+ to the generated certificate. Entries are auto-classified: values
+ that parse as IPv4 or IPv6 addresses become IP SANs, everything
+ else becomes a DNS SAN. Extras are appended to — never replace —
+ the service and per-pod SANs the operator computes, so in-cluster
+ connectivity is preserved when extras are added.
+ items:
+ type: string
+ type: array
+ issuerRef:
+ description: |-
+ IssuerRef points at an Issuer or ClusterIssuer. The Name field is
+ required. Kind defaults to "Issuer" and Group defaults to
+ "cert-manager.io" when empty.
+ properties:
+ group:
+ description: Group of the resource being referred to.
+ type: string
+ kind:
+ description: Kind of the resource being referred to.
+ type: string
+ name:
+ description: Name of the resource being referred to.
+ type: string
+ required:
+ - name
+ type: object
+ privateKey:
+ description: |-
+ PrivateKey configures the private key algorithm, size and rotation
+ policy. Optional; cert-manager uses RSA 2048 with rotation policy
+ "Never" when unset.
+ properties:
+ algorithm:
+ description: |-
+ Algorithm is the private key algorithm of the corresponding private key
+ for this certificate.
+
+ If provided, allowed values are either `RSA`, `ECDSA` or `Ed25519`.
+ If `algorithm` is specified and `size` is not provided,
+ key size of 2048 will be used for `RSA` key algorithm and
+ key size of 256 will be used for `ECDSA` key algorithm.
+ key size is ignored when using the `Ed25519` key algorithm.
+ enum:
+ - RSA
+ - ECDSA
+ - Ed25519
+ type: string
+ encoding:
+ description: |-
+ The private key cryptography standards (PKCS) encoding for this
+ certificate's private key to be encoded in.
+
+ If provided, allowed values are `PKCS1` and `PKCS8` standing for PKCS#1
+ and PKCS#8, respectively.
+ Defaults to `PKCS1` if not specified.
+ enum:
+ - PKCS1
+ - PKCS8
+ type: string
+ rotationPolicy:
+ description: |-
+ RotationPolicy controls how private keys should be regenerated when a
+ re-issuance is being processed.
+
+ If set to `Never`, a private key will only be generated if one does not
+ already exist in the target `spec.secretName`. If one does exist but it
+ does not have the correct algorithm or size, a warning will be raised
+ to await user intervention.
+ If set to `Always`, a private key matching the specified requirements
+ will be generated whenever a re-issuance occurs.
+ Default is `Always`.
+ The default was changed from `Never` to `Always` in cert-manager >=v1.18.0.
+ The new default can be disabled by setting the
+ `--feature-gates=DefaultPrivateKeyRotationPolicyAlways=false` option on
+ the controller component.
+ enum:
+ - Never
+ - Always
+ type: string
+ size:
+ description: |-
+ Size is the key bit size of the corresponding private key for this certificate.
+
+ If `algorithm` is set to `RSA`, valid values are `2048`, `4096` or `8192`,
+ and will default to `2048` if not specified.
+ If `algorithm` is set to `ECDSA`, valid values are `256`, `384` or `521`,
+ and will default to `256` if not specified.
+ If `algorithm` is set to `Ed25519`, Size is ignored.
+ No other values are allowed.
+ type: integer
+ type: object
+ renewBefore:
+ description: |-
+ RenewBefore is how long before expiry cert-manager should renew.
+ Optional; cert-manager uses its own default (typically 2/3 of
+ Duration) when unset.
+ type: string
+ secretName:
+ description: |-
+ SecretName overrides the default Secret name (rftls-<rfname>) into
+ which cert-manager writes the issued certificate.
+ type: string
+ required:
+ - issuerRef
+ type: object
+ certificateSecret:
+ description: |-
+ CertificateSecret uses an existing Secret managed outside the operator.
+ Mutually exclusive with CertManager.
+ properties:
+ secretName:
+ description: |-
+ SecretName is the name of the Secret that contains the TLS material
+ (tls.crt, tls.key, ca.crt).
+ type: string
+ required:
+ - secretName
+ type: object
+ enabled:
+ description: |-
+ Enabled toggles TLS. Immutable after creation, together with the
+ presence of this block: a missing block and Enabled=false are the same
+ state. Leaving Enabled=false is the default.
+ type: boolean
+ type: object
type: object
+ x-kubernetes-validations:
+ - message: TLS cannot be enabled or disabled on an existing RedisFailover;
+ create a new one
+ rule: (has(self.tls) && has(self.tls.enabled) && self.tls.enabled) ==
+ (has(oldSelf.tls) && has(oldSelf.tls.enabled) && oldSelf.tls.enabled)
required:
- spec
type: object