Files
cozystack/packages/apps/opensearch/templates/_names.tpl
T
Arsolitt 85fa60a33f feat(opensearch)!: issue the HTTP API certificate from cert-manager
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>
2026-09-11 01:23:13 +03:00

86 lines
4.7 KiB
Smarty

{{/*
opensearch.validateReleaseName fails the render when the release name is long enough
that some object THIS CHART renders would be rejected by the API server, or would
carry a DNS label the certificate cannot legally contain. Ownership is the whole of
it: a name the chart does not render is not a name a render failure can save.
Two different limits are in play, and conflating them is how this went wrong before:
- Certificate, Issuer, Secret, Role and RoleBinding names are DNS-1123 SUBDOMAINS,
bounded at 253. Nothing here approaches that, so they never bind.
- Service names are DNS-1035 LABELS, bounded at 63. So is every label inside a
certificate SAN. These are what actually bind.
Which one binds depends on the configuration, because the longest name is only built
in some of them. The suffixes, longest first:
-dashboards-external (20) Service, when external and dashboards are both on
-dashboards (11) Service the operator creates when dashboards are on
-discovery (10) Service the operator always creates, and a SAN label when
the cert-manager issuer is selected. NewDiscoveryServiceForCR runs on
every path, so this name exists regardless of TLS — the
TLS branch below is about the SAN, not about the Service.
-external (9) Service, when external is on
The guard takes the longest suffix that the current values actually produce and caps
the release name at 63 minus its length. It is invoked from every template that
renders one of these names, including the ones that render under the operator
issuer, because the Service names have nothing to do with the issuer.
THE -dashboards BOUND COSTS THE LAST LEGAL NOTCH, deliberately. It caps the release
name at 52 while the apps API admits 53 (maxHelmReleaseName in
pkg/registry/apps/application/rest.go), so one length a tenant may legitimately ask for
is refused at render time. The alternative is worse at that same length. The operator
composes the Dashboards Service as <spec.general.serviceName>-dashboards
(NewDashboardsSvcForCr) and creates it last in DashboardsReconciler.Reconcile, whose
combined result carries the failure; controllers/opensearchController.go runs its
component reconcilers in one loop that returns on the first error, and
dashboards.Reconcile sits ahead of upgrade.Reconcile, restart.Reconcile and
snapshotrepository.Reconcile. A Service the API server refuses by length therefore does
not cost one object: it stops those three on every pass for the life of the release, so
the cluster comes up, converges, and then never upgrades, never rolls and never takes a
snapshot repository, with the reason only in the operator log. Both outcomes are bad at
53 characters. This one announces itself.
The Dashboards SAN carries the same overflowing label and is not a second bound:
cert-manager does not validate DNS label length in dnsNames, so nothing refuses the
Certificate.
REACHABILITY: Helm itself rejects a release name over 53 characters
(chartutil.ValidateReleaseName), so two of these bounds can fire, -dashboards-external
at 43 and -dashboards at 52. The -discovery (53) and -external (54) bounds are unreachable through
Helm and kept as a backstop only: they are what makes the table above complete, and
the arithmetic stays correct if the suffixes change. Do not read a passing render at
53 characters as those branches working.
*/}}
{{- define "opensearch.validateReleaseName" -}}
{{- $external := .Values.external | default false -}}
{{- $dashboards := .Values.dashboards.enabled | default false -}}
{{- $certManagerIssued := (include "opensearch.tls.certManagerIssued" .) | eq "true" -}}
{{- $suffix := "" -}}
{{- if and $external $dashboards -}}
{{- $suffix = "-dashboards-external" -}}
{{- else if $dashboards -}}
{{- $suffix = "-dashboards" -}}
{{- else if $certManagerIssued -}}
{{- $suffix = "-discovery" -}}
{{- else if $external -}}
{{- $suffix = "-external" -}}
{{- end -}}
{{- if $suffix -}}
{{- $max := sub 63 (len $suffix) | int -}}
{{- if gt (len .Release.Name) $max -}}
{{- /*
An application name cannot be changed in place, so "use a shorter name" is the
one remedy an existing release does not have. Both reachable bounds come from
the Dashboards Service, so name the knob that drops them.
*/ -}}
{{- $escape := "" -}}
{{- if $dashboards -}}
{{- $escape = " Set dashboards.enabled to false to drop this bound." -}}
{{- end -}}
{{- fail (printf "Release name %q is %d chars; opensearch requires <=%d in this configuration so that %q stays within the 63-char DNS label limit.%s" .Release.Name (len .Release.Name) $max (printf "%s%s" .Release.Name $suffix) $escape) -}}
{{- end -}}
{{- end -}}
{{- end -}}