mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 07:03:45 +09:00
The HTTP listener and Dashboards ran on certificates the operator minted itself, so a client outside the cluster had no anchor it could obtain through the platform and no way to verify the endpoint it was handed. Issue the HTTP chain from cert-manager instead, and give the operator the same CA through spec.security.tls.http.caSecret so it signs the securityadmin admin certificate with it. Without that the admin certificate would keep the operator's own CA while the listener trusted cert-manager's, and securityadmin could no longer authenticate to apply users, roles and audit policy. tls.issuer names the authority rather than a switch, because the listener serves TLS under either value and only the signer changes. It is tri-state: an explicit value is obeyed, an absent one follows external, because a release nobody publishes has no third party to prove anything to. The cert-manager issuer needs OpenSearch 2.0.0 or newer, since the operator honours the HTTP CA only from that version and silently signs with its transport CA below it. An explicit choice under that floor fails the render and one resolved from external falls back to the operator, so asking for a verifiable certificate never quietly yields less than was asked, and turning on external access never breaks an upgrade. BREAKING CHANGE: an externally published release on OpenSearch 2.0.0 or newer serves the HTTP API from a cert-manager CA rather than the operator's own. A client pinned to the operator CA must move to the trust anchor the platform projects into the tenant. BREAKING CHANGE: the external-dns name of an externally published release moves from <release>.<namespace>.<cluster-domain> to <release>.<tenant-host>, and the Dashboards name with it. This half is gated on external alone and does not depend on the issuer. external-dns runs upsert-only here, so the old record stays in the zone until it is removed by hand. BREAKING CHANGE: with dashboards enabled the application name is limited to 41 characters, and to 32 when external access is also on. A release above either limit now fails to render rather than converging. Such a release was already stalled: the Dashboards Service built from its name exceeds the 63-character DNS label limit, and the operator returns that failure ahead of its upgrade, restart and snapshot-repository reconcilers, so it has not upgraded or rolled since it was created. Set dashboards.enabled to false to converge again, or recreate the application under a shorter name. Assisted-by: LLM Signed-off-by: Arsolitt <arsolitt@gmail.com> [lexfrei: reworded subject and body for the issuer field rename] Signed-off-by: Aleksei Sviridkin <f@lex.la>
350 lines
18 KiB
YAML
350 lines
18 KiB
YAML
{{- /*
|
|
NOTE: Transport mTLS is always operator-managed (spec.security.tls.transport.generate: true
|
|
with perNode: true). This file covers HTTP layer (port 9200) and Dashboards HTTPS only.
|
|
Selecting tls.issuer: operator does NOT disable transport mTLS: the operator enforces
|
|
it regardless, as it is required by the OpenSearch security plugin.
|
|
|
|
Design: ONE leaf Certificate PER SERVICE — the HTTP API (port 9200) and Dashboards
|
|
(port 5601) each get their own, from a shared CA Issuer. They are deliberately not
|
|
combined: a single leaf covering both would hand the Dashboards pod a private key
|
|
valid for the API names. The Dashboards leaf renders last and only when Dashboards is
|
|
enabled, so the chain is 4 resources without it and 5 with it.
|
|
|
|
IMPORTANT: The CA Secret is named {{ .Release.Name }}.http-ca, with a DOT before
|
|
http-ca. Two reasons stack, and the second is what the dot answers.
|
|
|
|
It cannot be {{ .Release.Name }}-ca, because the operator hardcodes <clusterName>-ca for
|
|
its own transport CA Secret (ReadOrGenerateCaCert in
|
|
https://github.com/opensearch-project/opensearch-k8s-operator/blob/main/opensearch-operator/pkg/reconcilers/util/util.go).
|
|
The operator would read the cert-manager Secret as that CA and fail with "tls: failed to
|
|
find any PEM data in key input", because it expects ca.key where cert-manager writes
|
|
tls.key.
|
|
|
|
Nor is -http-ca far enough away, because every one of these names is a release name plus
|
|
a suffix, and a SIBLING RELEASE supplies the difference between two suffixes. A release is
|
|
<prefix><app> with prefix opensearch-, so release opensearch-foo's chart CA
|
|
(<release>-http-ca) and release opensearch-foo-http's operator transport CA
|
|
(<clusterName>-ca) are both opensearch-foo-http-ca — and foo-http is a legal application
|
|
name. Whichever object reaches the name first keeps it, and the other side then reads or
|
|
writes key material it did not create; that goes wrong in both directions and is not
|
|
recoverable in place. The dot ends it: application names are validated as DNS-1035 labels
|
|
(pkg/apis/apps/validation), which cannot contain a dot, and neither can the release prefix,
|
|
so no operator-composed <clusterName><suffix> can equal this name. Secret names are
|
|
DNS-1123 subdomains, which can. The platform's tenant-CA projection carries the dot for
|
|
the same reason (projectionSuffix in internal/controller/cacert).
|
|
|
|
So the rule: a suffix needs the dot when it is a tail of another suffix in the combined
|
|
set, or has one as a tail. Names collide within a kind and not across kinds, so each kind
|
|
has its own set; the one below is the SECRET suffixes. At operator 2.8.0 that set is -ca,
|
|
-transport-cert, -http-cert, -admin-cert, -dashboards-cert and -admin-password on the
|
|
operator's side, and .http-ca, -http-server, -dashboards-server, -credentials,
|
|
-admin-credentials and -security-config on this chart's. The two leaf Secrets keep the hyphen — {{ .Release.Name }}-http-server and
|
|
{{ .Release.Name }}-dashboards-server — because neither stands in that relation to any
|
|
entry: no other suffix ends in -server, and neither leaf ends in another suffix. A suffix
|
|
added later has to be checked the same way, against the set for its own kind. This chart's
|
|
-security-config does have -config as a tail, and is harmless only because the operator
|
|
composes <clusterName>-config as a ConfigMap (buildConfigMap in the configuration
|
|
reconciler) rather than a Secret.
|
|
|
|
That test is pairwise between FIXED suffixes, and one name here is not fixed:
|
|
templates/users.yaml renders <release>-user-<username> for every key under .Values.users,
|
|
and the key is tenant-chosen with no pattern constraining it in values.schema.json. A
|
|
suffix whose tail a tenant supplies can be made to end in any name in the set, so the
|
|
test answers "no collision" for one that is constructible: application x with a user
|
|
named http-server, and application x-user on the cert-manager issuer, both write
|
|
opensearch-x-user-http-server — once as the basic-auth Secret the operator watches for
|
|
credentials, once as the HTTP server key. The dot does not close this one the way it
|
|
closes the operator's names: that argument rests on application names being DNS-1035
|
|
labels, and a users key is not, so it can carry a dot of its own. The two leaf names
|
|
below are reachable through that family, which ships today and is open by construction;
|
|
closing it means constraining the users key in that file, not moving a suffix here.
|
|
|
|
One pair on that list does stand in it, outside this chain: -admin-credentials against
|
|
-credentials, which makes release foo's admin Secret release foo-admin's user-facing one.
|
|
Both names ship today and -credentials is what the ResourceDefinition grants the tenant by
|
|
name, so moving either is a breaking change of its own rather than part of this file.
|
|
|
|
securityadmin trust: the securityadmin job connects to the HTTP endpoint (port 9200 for
|
|
OpenSearch >= 2.0) and validates the server certificate against the admin certificate's
|
|
ca.crt, authenticating with that same admin certificate. To make both anchor on this CA,
|
|
the CR passes {{ .Release.Name }}.http-ca to spec.security.tls.http.caSecret. Two separate
|
|
mechanisms then act on that one field, and the annotation is involved in only one of
|
|
them. The admin certificate is signed through providedCaCert, which reads the Secret's
|
|
tls.crt/tls.key as the CA and does that only because cert-manager stamps
|
|
cert-manager.io/issuer-kind on it. The listener's trust anchor is not that path: handleHttp
|
|
mounts the key ca.crt out of the same Secret by subPath and points
|
|
plugins.security.ssl.http.pemtrustedcas_filepath at it, with no remap anywhere. So the
|
|
listener half rests on cert-manager writing ca.crt into the CA Secret alongside tls.crt,
|
|
which is the second dependency, and the one the operator's CRD states as "must contain
|
|
ca.crt and ca.key fields". The two halves fail separately; neither is evidence for the
|
|
other. What the pair buys is one CA under both the server certificate securityadmin
|
|
validates and the admin certificate it presents, so users and roles apply. The securityadmin job reaches the cluster on the operator's DNS
|
|
base, which the platform sets from networking.clusterDomain.
|
|
|
|
NAME-LENGTH GUARD: see opensearch.validateReleaseName in _names.tpl, which owns the
|
|
limits table and is invoked below. Keeping a second copy of those numbers here is how
|
|
the two drifted apart before.
|
|
*/}}
|
|
{{- $certManagerIssued := (include "opensearch.tls.certManagerIssued" .) | eq "true" -}}
|
|
{{- if $certManagerIssued }}
|
|
{{- include "opensearch.validateReleaseName" . -}}
|
|
{{- /*
|
|
The OpenSearch >= 2.0.0 floor for the cert-manager HTTP issuer is enforced in
|
|
opensearch.tls.certManagerIssued, which fails on an explicit choice and degrades
|
|
one resolved from external, so reaching this point already implies a supported
|
|
version.
|
|
*/}}
|
|
{{- /*
|
|
_cluster is defaulted before the read because `index` on an absent map is a hard
|
|
render error, not a nil result — the `| default` below never runs. The platform
|
|
always injects it, so the failure only shows up rendering the chart on its own.
|
|
*/}}
|
|
{{- $clusterDomain := (index (.Values._cluster | default dict) "cluster-domain") | default "cozy.local" }}
|
|
---
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Issuer
|
|
metadata:
|
|
name: {{ .Release.Name }}-http-selfsigned
|
|
spec:
|
|
selfSigned: {}
|
|
---
|
|
{{- /*
|
|
HTTP-layer CA Certificate. rotationPolicy: Never keeps the CA stable so existing
|
|
client trust bundles remain valid across cert-manager renewals.
|
|
|
|
Certificate and Issuer names are this chart's alone — no other component composes
|
|
names of those kinds — so they cannot be reached from the other side and the hyphen
|
|
is safe on them.
|
|
*/}}
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: {{ .Release.Name }}-http-ca
|
|
spec:
|
|
{{- /*
|
|
A dot, not a hyphen: hyphenated, this name is also the operator's transport CA Secret
|
|
for the sibling release one -http longer. See the header.
|
|
*/}}
|
|
secretName: {{ .Release.Name }}.http-ca
|
|
{{- /*
|
|
This Secret is the extraction source named by templates/tenant-projection.yaml,
|
|
which is what publishes ca.crt to the tenant. Nothing is stamped on the Secret
|
|
itself: the controller reads the sentinel's sourceSecretName and never a label,
|
|
so the CA private key stored here under tls.key stays unpublishable by any edit
|
|
that only touches this file.
|
|
|
|
Withdrawal rides on the sentinel. Helm owns it, so moving back to the operator
|
|
issuer removes it, and the projection Secret is collected with it through the owner
|
|
reference the controller sets (sentinelOwnerRef in the cacert reconciler). The
|
|
cert-manager Secrets here do outlive that — enableCertificateOwnerRef is false
|
|
— but they are no longer published to anyone, so a tenant is never left holding
|
|
an anchor for an endpoint that has gone back to an operator-issued certificate.
|
|
*/}}
|
|
duration: 87600h # 10 years
|
|
isCA: true
|
|
{{- /*
|
|
NOT {{ .Release.Name }}: that is the subject of the operator's own transport CA
|
|
(GenerateCA(clusterName)), and the operator decides whether to re-mint the admin
|
|
certificate by comparing DN bytes rather than verifying a signature --
|
|
IsSignedByCA is bytes.Equal(cert.RawIssuer, ca.RawSubject). A colliding subject
|
|
therefore reads as "already signed by this CA" on a release upgrading off
|
|
operator-managed TLS: the admin certificate keeps its transport-CA issuer while
|
|
the listener trusts this one, and securityadmin fails to authenticate with only a
|
|
job timeout to show for it.
|
|
*/}}
|
|
commonName: {{ .Release.Name }}-http-ca
|
|
{{- /*
|
|
No key encipherment: RFC 5480 section 3 forbids it for ECDSA keys, which do no
|
|
key transport. Every certificate this file renders is ECDSA P-256.
|
|
*/}}
|
|
usages:
|
|
- signing
|
|
- cert sign
|
|
privateKey:
|
|
rotationPolicy: Never
|
|
algorithm: ECDSA
|
|
size: 256
|
|
issuerRef:
|
|
name: {{ .Release.Name }}-http-selfsigned
|
|
kind: Issuer
|
|
group: cert-manager.io
|
|
---
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Issuer
|
|
metadata:
|
|
name: {{ .Release.Name }}-http-ca
|
|
spec:
|
|
ca:
|
|
secretName: {{ .Release.Name }}.http-ca
|
|
---
|
|
{{- /*
|
|
Leaf TLS Certificate for the OpenSearch HTTP API (port 9200), passed to
|
|
spec.security.tls.http.secret.name. Dashboards gets its OWN certificate below.
|
|
|
|
ONE CERTIFICATE PER SERVICE, not one covering both. The operator issues separately
|
|
(<clusterName>-http-cert and <clusterName>-dashboards-cert), and collapsing them
|
|
into a single combined-SAN leaf would hand the Dashboards pod a private key valid
|
|
for the OpenSearch API names — including the external hostname. Dashboards is the
|
|
far more exposed of the two, so a compromise there would let it impersonate the
|
|
API endpoint for the whole certificate lifetime, which is ten years here. Keeping
|
|
them apart costs one more Certificate and preserves the operator's isolation.
|
|
|
|
NAMED -http-server, NOT -http-cert, for the first of the two reasons the CA above is
|
|
not named -ca: the operator reserves <clusterName>-http-cert for the HTTP certificate
|
|
it generates itself (nodeSecretName in handleHttp), alongside -ca,
|
|
-transport-cert, -admin-cert and -dashboards-cert. Reusing the reserved name
|
|
breaks the moment the release moves back to the operator issuer: cert-manager
|
|
keeps its Secret when the Certificate goes away (the platform ships
|
|
enableCertificateOwnerRef=false), the operator then finds a Secret already
|
|
sitting at the name it was about to generate, skips generation, and mounts the
|
|
stale cert-manager one — while signing the admin certificate with its own
|
|
transport CA. securityadmin cannot authenticate against that, and the security
|
|
config silently stops applying.
|
|
Staying outside the operator's namespace of names avoids the collision entirely.
|
|
*/}}
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: {{ .Release.Name }}-http-server
|
|
spec:
|
|
secretName: {{ .Release.Name }}-http-server
|
|
{{- /*
|
|
LIFETIME MATCHES THE CA, AND THERE IS NO renewBefore, because a reissue cannot
|
|
reach the running pods. The reason that does not depend on any operator version:
|
|
OpenSearch reads its certificates once at startup, the pinned operator's CRD has
|
|
no enableHotReload, and nothing restarts the pods when the Secret changes. So a
|
|
one-year leaf expired in place — cert-manager reissued into the Secret while the
|
|
pods kept serving the old certificate until it ran out, taking HTTPS on 9200 down
|
|
and breaking securityadmin on a timer. Matching the CA's lifetime removes that fuse.
|
|
|
|
At operator 2.8.0 (the pinned version) the mount shape compounds it. handleHttp makes
|
|
its three mount() calls carrying SubPath: filename only where http.generate is off and
|
|
http.caSecret is set, which is the pair this chart renders under the cert-manager
|
|
issuer; every other branch, generate with a caSecret included, mounts a whole folder.
|
|
The kubelet never refreshes a subPath-mounted file at all.
|
|
Upstream main has since moved every http branch back to mountFolder, so DO NOT
|
|
treat that half as durable across a `make update` bump.
|
|
The startup-read reason above is what keeps the conclusion correct either way.
|
|
(Dropping renewBefore does not disable reissue — cert-manager still defaults to
|
|
duration/3 — it only stops promising a 30-day cycle nothing can honour.)
|
|
Rotating this certificate is a deliberate act: delete the Secret named below,
|
|
then restart the OpenSearch pods so the new material is actually mounted.
|
|
*/}}
|
|
duration: 87600h # 10 years, matching the CA above
|
|
isCA: false
|
|
usages:
|
|
- server auth
|
|
- signing
|
|
{{- /*
|
|
MUST COVER EVERY SHAPE THE OPERATOR'S OWN HTTP CERTIFICATE COVERED. The
|
|
cert-manager issuer replaces the operator-issued certificate, so any name
|
|
missing here stops verifying for a client that was using it. The operator issues
|
|
for <name>, the service name, <name>-discovery and the <name>.<ns>[.svc[.domain]]
|
|
ladder. The two-label form is load-bearing: with ndots:5 and the default search
|
|
list, <name>.<ns> is what a client inside another namespace actually resolves and
|
|
therefore what its TLS verification runs against.
|
|
|
|
The fully-qualified rung agrees with what the operator emits, because both
|
|
sides read one platform value: DNS_BASE arrives through
|
|
opensearch-operator.manager.dnsBase and $clusterDomain here through _cluster,
|
|
and packages/core/platform/templates/apps.yaml fills both from
|
|
networking.clusterDomain. Rendered without the platform values the two fall
|
|
back to different defaults, cozy.local here and cluster.local there, which is
|
|
a shape no deployment takes.
|
|
*/}}
|
|
dnsNames:
|
|
{{- $ns := .Release.Namespace }}
|
|
{{- $name := .Release.Name }}
|
|
# OpenSearch HTTP API service (operator-created ClusterIP)
|
|
- {{ $name }}
|
|
- {{ $name }}.{{ $ns }}
|
|
- {{ $name }}.{{ $ns }}.svc
|
|
- {{ $name }}.{{ $ns }}.svc.{{ $clusterDomain }}
|
|
# Headless discovery service the operator issues for as well
|
|
- {{ $name }}-discovery
|
|
{{- $extHost := (.Values._namespace | default dict).host | default "" }}
|
|
{{- if and (.Values.external | default false) $extHost }}
|
|
# External LoadBalancer DNS name (used by external-dns)
|
|
- {{ printf "%s.%s" $name $extHost }}
|
|
{{- end }}
|
|
privateKey:
|
|
{{- /*
|
|
PKCS#8, not cert-manager's PKCS1 default. For an ECDSA key that default writes
|
|
SEC1 ("BEGIN EC PRIVATE KEY"), and the reader here is a JVM: the operator mounts
|
|
this key as plugins.security.ssl.http.pemkey_filepath and the security plugin
|
|
hands the file to Netty, whose PEM loader builds a PKCS8EncodedKeySpec and tries
|
|
RSA, DSA and EC against it. A SEC1 key fails all three, the HTTPS listener never
|
|
starts, and the failure is a startup exception rather than anything the chart or
|
|
the operator can report. RSA would not help — PKCS#1 fails the same loader.
|
|
*/}}
|
|
encoding: PKCS8
|
|
rotationPolicy: Always
|
|
algorithm: ECDSA
|
|
size: 256
|
|
issuerRef:
|
|
name: {{ .Release.Name }}-http-ca
|
|
kind: Issuer
|
|
group: cert-manager.io
|
|
{{- if .Values.dashboards.enabled }}
|
|
---
|
|
{{- /*
|
|
Leaf TLS Certificate for Dashboards (port 5601), passed to
|
|
spec.dashboards.tls.secret.name. Deliberately a separate key from the API
|
|
certificate above — see the note there. Same CA, so a client that trusts the
|
|
published anchor verifies both, and the names mirror what the operator's own
|
|
Dashboards certificate covered.
|
|
|
|
Rendered last and only when Dashboards is enabled, so the document order of the
|
|
four resources above does not depend on this value.
|
|
*/}}
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: {{ .Release.Name }}-dashboards-server
|
|
spec:
|
|
secretName: {{ .Release.Name }}-dashboards-server
|
|
{{- /*
|
|
Same lifetime as the API certificate, for a DIFFERENT reason — the subPath
|
|
argument above does not apply here. The operator mounts an externally provided
|
|
Dashboards certificate as a whole secret volume with no SubPath, so the kubelet
|
|
does refresh those files. What does not happen is Dashboards noticing: it reads
|
|
server.ssl.certificate and server.ssl.key once at startup, and the operator adds
|
|
no checksum annotation for a provided secret, so nothing restarts the Deployment
|
|
when the material changes. A shorter life would still expire rather than rotate.
|
|
*/}}
|
|
duration: 87600h # 10 years, matching the CA
|
|
isCA: false
|
|
usages:
|
|
- server auth
|
|
- signing
|
|
dnsNames:
|
|
{{- $ns := .Release.Namespace }}
|
|
{{- $name := .Release.Name }}
|
|
# Dashboards service (operator-created ClusterIP)
|
|
- {{ $name }}-dashboards
|
|
- {{ $name }}-dashboards.{{ $ns }}
|
|
- {{ $name }}-dashboards.{{ $ns }}.svc
|
|
- {{ $name }}-dashboards.{{ $ns }}.svc.{{ $clusterDomain }}
|
|
{{- $extHost := (.Values._namespace | default dict).host | default "" }}
|
|
{{- if and (.Values.external | default false) $extHost }}
|
|
# External LoadBalancer DNS name (used by external-dns)
|
|
- {{ printf "%s-dashboards.%s" $name $extHost }}
|
|
{{- end }}
|
|
privateKey:
|
|
{{- /*
|
|
Node reads this one and accepts SEC1, so the encoding is not forced here the way
|
|
it is on the API leaf. It is set anyway: two leaves of one chain differing in key
|
|
encoding is a difference nothing explains, and the next reader would have to
|
|
re-derive which of the two is the constrained one.
|
|
*/}}
|
|
encoding: PKCS8
|
|
rotationPolicy: Always
|
|
algorithm: ECDSA
|
|
size: 256
|
|
issuerRef:
|
|
name: {{ .Release.Name }}-http-ca
|
|
kind: Issuer
|
|
group: cert-manager.io
|
|
{{- end }}
|
|
{{- end }}
|