Files
cozystack/packages/apps/opensearch/tests/tls_test.yaml
T
Aleksei Sviridkin 84daf750d9 fix(opensearch): render the credentials Secret without platform values
Reading the cluster values through index aborts the whole release when
they are absent: index on an untyped nil is a hard render error, not a
miss returning nil, so the default written after it never runs. The
platform always injects them, so this surfaces only where the chart is
rendered on its own, which is where the unit suites and a bare helm
template both live.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-11 01:23:22 +03:00

1441 lines
47 KiB
YAML

suite: opensearch TLS cert-manager chain
# Covers the tri-state tls.issuer field:
# (a) external: false, issuer unset → operator generates the HTTP cert
# (b) external: true, issuer unset → cert-manager, with the external SAN
# (c) external: true, issuer: operator → operator generates the HTTP cert
# (d) external: false, issuer: cert-manager → cert-manager, no external SAN
# (e) external: true, issuer: cert-manager → cert-manager, with the external SAN
#
# Design: ONE leaf Certificate per service, both under the same CA. Sharing a key
# between the API and Dashboards would let a compromised Dashboards impersonate the
# API endpoint, so they are issued separately, as the operator itself does.
# Chain: selfsigned Issuer, CA Cert, CA Issuer, API leaf, and — only when Dashboards
# is enabled, appended last so the first four indices are stable — the Dashboards leaf.
# Transport mTLS remains operator-managed (generate: true, perNode: true) — not touched here.
release:
name: os-test
namespace: tenant-test
set:
_cluster:
scheduling: {}
cluster-domain: cozy.local
###############################################################################
# certmanager.yaml — case (a): external false, issuer unset → no resources
###############################################################################
templates:
- templates/certmanager.yaml
tests:
# The release-name bound is whatever the longest DNS label this configuration
# actually builds allows, and the limits differ by object kind: Service names and
# certificate SAN labels are bounded at 63, while Certificate/Secret/Role names are
# subdomains bounded at 253 and never bind. Both sides of each boundary are pinned.
#
# -dashboards-external (Service, external+dashboards) is the longest at 20 -> 43.
- it: rejects a name whose dashboards external Service would exceed 63
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
tls:
issuer: cert-manager
asserts:
- failedTemplate:
errorMessage: 'Release name "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is 44 chars; opensearch requires <=43 in this configuration so that "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-dashboards-external" stays within the 63-char DNS label limit. Set dashboards.enabled to false to drop this bound.'
- it: accepts the longest name that fits with external and dashboards both on
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
tls:
issuer: cert-manager
asserts:
- hasDocuments:
count: 5
# -dashboards (11 -> 52) is a bound, and besides -dashboards-external the only one
# Helm's own 53-character ceiling leaves reachable. Both sides are pinned. What
# overflows at 53 is the operator's Dashboards Service, and a Service the API server
# refuses by length stops the reconcilers queued behind it rather than costing that
# one object.
- it: rejects a name whose dashboards Service would exceed 63
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
asserts:
- failedTemplate:
errorMessage: 'Release name "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is 53 chars; opensearch requires <=52 in this configuration so that "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-dashboards" stays within the 63-char DNS label limit. Set dashboards.enabled to false to drop this bound.'
- it: renders the whole chain for the longest admissible name with dashboards on
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
asserts:
- hasDocuments:
count: 5
- contains:
path: spec.dnsNames
content: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-dashboards
documentIndex: 4
# The -discovery bound itself cannot be observed from a test: its cap is 53 and Helm
# rejects a release name above 53, so the branch never fires whatever is rendered here.
# Deleting it leaves this case green. What is pinned is the SAN that gives the suffix
# its reason to be in the table at all.
- it: covers the discovery SAN at the longest admissible name with dashboards off
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
tls:
issuer: cert-manager
asserts:
- hasDocuments:
count: 4
- contains:
path: spec.dnsNames
content: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-discovery
documentIndex: 3
# A release that never chose an issuer must not be lost to a name length either.
- it: still renders a long-named external release that never chose an issuer
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
external: true
_namespace:
host: example.cozy.local
asserts:
- hasDocuments:
count: 4
# Version floor: below OpenSearch 2.0.0 the operator signs the admin certificate
# with the transport CA instead of http.caSecret, so securityadmin cannot verify
# against the cert-manager HTTP CA and the security config silently never applies.
# An explicit choice fails; one resolved from external degrades (two cases below).
- it: fails when the cert-manager HTTP issuer is chosen explicitly below 2.0.0
set:
version: v1
tls:
issuer: cert-manager
asserts:
- failedTemplate:
errorMessage: "opensearch 1.3.20 (version: v1) does not support the cert-manager HTTP issuer: below 2.0.0 the operator signs the securityadmin admin certificate with the transport CA, which cannot verify against the cert-manager HTTP CA, so the admin certificate and the HTTP listener would never share a CA. Set tls.issuer: operator to use the operator's own HTTP CA, or use version v2 or later."
# A v1 + external release never chose cert-manager: the tri-state resolved it
# from external. Degrade to the operator issuer so such a release keeps
# rendering on upgrade instead of hard-failing on a field it never set.
- it: degrades to the operator issuer when external resolves it below 2.0.0
set:
version: v1
external: true
_namespace:
host: example.cozy.local
asserts:
- hasDocuments:
count: 0
- it: allows version v1 under the operator issuer
set:
version: v1
external: true
_namespace:
host: example.cozy.local
tls:
issuer: operator
asserts:
- hasDocuments:
count: 0
- it: allows the cert-manager issuer on v3, which is at or above 2.0.0
set:
version: v3
tls:
issuer: cert-manager
asserts:
- hasDocuments:
count: 4
# Passing http.caSecret moves the operator onto subPath mounts, which the kubelet
# never refreshes, and nothing restarts the pods when the Secret changes. A leaf
# that outlived its mount would expire in place and take HTTPS down on a timer, so
# the leaf must not be short-lived, and renewBefore must not promise a rotation
# that cannot happen.
- it: gives the leaf certificate no expiry the pods cannot survive
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.duration
value: 87600h
documentIndex: 3
- notExists:
path: spec.renewBefore
documentIndex: 3
- it: keeps the CA and the leaf on the same lifetime
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.duration
value: 87600h
documentIndex: 1
- notExists:
path: spec.renewBefore
documentIndex: 1
# Both names external-svc publishes to external-dns must appear in the leaf's SAN
# list, or an external client reaching the LoadBalancer fails hostname verification.
- it: covers both external-dns hostnames with certificate SANs
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
asserts:
- contains:
path: spec.dnsNames
content: os-test.example.cozy.local
documentIndex: 3
- contains:
path: spec.dnsNames
content: os-test-dashboards.example.cozy.local
documentIndex: 4
# Neither certificate may carry the other's name — that is the whole point of
# issuing them separately.
- notContains:
path: spec.dnsNames
content: os-test-dashboards.example.cozy.local
documentIndex: 3
- notContains:
path: spec.dnsNames
content: os-test.example.cozy.local
documentIndex: 4
# The operator reserves <release>-http-cert for the HTTP certificate it generates
# itself. If the chart's leaf took that name, moving back to the operator issuer would
# leave the cert-manager Secret behind (enableCertificateOwnerRef is false), the
# operator would find it already present, skip generation and mount it — while signing the
# admin certificate with its transport CA, silently breaking securityadmin.
# Anchored on the Certificate's own name, not on the field under test, which a
# selector would otherwise decide for the assertions. The equal is what refuses an
# absent spec.secretName: notEqual holds against a document carrying no such field,
# so the five below pass against any Issuer in the chain on their own.
- it: keeps the leaf secret out of the operator's reserved certificate names
set:
tls:
issuer: cert-manager
documentSelector:
path: metadata.name
value: os-test-http-server
asserts:
- equal:
path: spec.secretName
value: os-test-http-server
- notEqual:
path: spec.secretName
value: os-test-http-cert
- notEqual:
path: spec.secretName
value: os-test-transport-cert
- notEqual:
path: spec.secretName
value: os-test-dashboards-cert
- notEqual:
path: spec.secretName
value: os-test-admin-cert
- notEqual:
path: spec.secretName
value: os-test-ca
# Hyphenated, the CA Secret name is also what the operator composes for its own
# transport CA on the sibling release one -http longer: release os-test's
# <release>-http-ca is release os-test-http's <clusterName>-ca, and os-test-http is a
# legal application name. Whichever object reached the name first would keep it while
# the other side read or wrote key material it did not create. Application names are
# DNS-1035 labels and cannot contain a dot, so the dot puts this name beyond the
# operator's reach for every sibling at once.
- it: keeps the CA secret beyond the reach of any operator-composed name
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.secretName
value: os-test.http-ca
documentIndex: 1
# The transport CA of the sibling release named one -http longer.
- notEqual:
path: spec.secretName
value: os-test-http-ca
documentIndex: 1
- notEqual:
path: spec.secretName
value: os-test-ca
documentIndex: 1
- notEqual:
path: spec.secretName
value: os-test-http-cert
documentIndex: 1
- notEqual:
path: spec.secretName
value: os-test-admin-cert
documentIndex: 1
# Every Secret this template mints carries a private key: the CA's under tls.key,
# and each leaf's server key. The ApplicationDefinition grants by LABEL with no name
# constraint, so a tenant-visible label appearing on any of them hands the tenant
# that key while every other assertion in this file still passes. The tenant reads
# the projection the sentinel produces instead — see tenant_projection_test.yaml.
#
# Selected by the Secret each Certificate writes rather than by position: a
# documentIndex would follow the slot, so reordering this template would let a
# labelled key-bearing Certificate slide out from under the assertion and pass
# green. spec.secretName also discriminates Certificate from Issuer, which shares
# metadata.name os-test-http-ca with it and names the same Secret under
# spec.ca.secretName, and helm-unittest fails the test when a selector matches no
# document or more than one — so the anchor cannot go blind either.
- it: keeps the key-bearing CA secret off every tenant-visible label
set:
tls:
issuer: cert-manager
documentSelector:
path: spec.secretName
value: os-test.http-ca
asserts:
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenant-ca"]
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenantresource"]
- notExists:
path: spec.secretTemplate
- it: keeps the key-bearing API leaf off every tenant-visible label
set:
tls:
issuer: cert-manager
documentSelector:
path: spec.secretName
value: os-test-http-server
asserts:
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenant-ca"]
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenantresource"]
- notExists:
path: spec.secretTemplate
- it: keeps the key-bearing Dashboards leaf off every tenant-visible label
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentSelector:
path: spec.secretName
value: os-test-dashboards-server
asserts:
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenant-ca"]
- notExists:
path: spec.secretTemplate.labels["internal.cozystack.io/tenantresource"]
# Nothing else in the suite feeds an explicit `tls: null`, and it is a shape a
# hand-written values file produces: Helm deletes the key rather than coalescing it
# back to the `tls: {}` of values.yaml, so .Values.tls arrives nil. These two pin
# that it stays a supported input resolving by `external`, in both directions —
# a null that resolved to a constant either way would satisfy one of them by
# accident. They also discriminate the `| default dict` in _tls.tpl, which is what
# makes it load-bearing rather than defensive: `index` errors on nil, so dropping
# the default aborts the render for both.
- it: resolves a null tls block by external, to cert-manager
values:
- tls_null_values.yaml
set:
external: true
_namespace:
host: example.cozy.local
asserts:
- hasDocuments:
count: 4
- it: resolves a null tls block by external, to operator
values:
- tls_null_values.yaml
asserts:
- hasDocuments:
count: 0
- it: "(a) renders no resources when external false and issuer unset"
asserts:
- hasDocuments:
count: 0
- it: "(c) renders no resources when issuer is operator even with external true"
set:
external: true
_namespace:
host: example.cozy.local
tls:
issuer: operator
asserts:
- hasDocuments:
count: 0
- it: "(b) renders 4 cert-manager resources when external true resolves the issuer"
set:
external: true
_namespace:
host: example.cozy.local
asserts:
- hasDocuments:
count: 4
- it: "(d) renders 4 cert-manager resources when the issuer is cert-manager and external false"
set:
tls:
issuer: cert-manager
asserts:
- hasDocuments:
count: 4
- it: "(e) renders 4 resources and external SANs when issuer is cert-manager and external true"
set:
tls:
issuer: cert-manager
external: true
_namespace:
host: example.cozy.local
asserts:
- hasDocuments:
count: 4
- contains:
path: spec.dnsNames
content: os-test.example.cozy.local
documentIndex: 3
- it: "(e) adds a fifth resource, the dashboards certificate, when dashboards enabled"
set:
tls:
issuer: cert-manager
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
asserts:
- hasDocuments:
count: 5
- equal:
path: metadata.name
value: os-test-dashboards-server
documentIndex: 4
- contains:
path: spec.dnsNames
content: os-test-dashboards.example.cozy.local
documentIndex: 4
# --- Chain structure ---
- it: first document is selfsigned Issuer
set:
tls:
issuer: cert-manager
documentIndex: 0
asserts:
- isKind:
of: Issuer
- equal:
path: spec.selfSigned
value: {}
- equal:
path: metadata.name
value: os-test-http-selfsigned
- it: second document is CA Certificate with isCA true and rotationPolicy Never
set:
tls:
issuer: cert-manager
documentIndex: 1
asserts:
- isKind:
of: Certificate
- equal:
path: spec.isCA
value: true
# Mis-targeting issuerRef still issues and still goes Ready while anchoring on
# something other than the intended issuer, so pin the reference completely.
- equal:
path: spec.issuerRef.kind
value: Issuer
- equal:
path: spec.issuerRef.group
value: cert-manager.io
- equal:
path: spec.secretName
value: os-test.http-ca
- equal:
path: spec.issuerRef.name
value: os-test-http-selfsigned
- equal:
path: spec.privateKey.rotationPolicy
value: Never
# The subject is a cross-component invariant, not a label: it must differ from
# the operator's own CA subject, CN=<release>, because the operator compares
# DN bytes to decide whether the admin certificate still needs re-signing. See
# the note on the field in certmanager.yaml.
- equal:
path: spec.commonName
value: os-test-http-ca
- equal:
path: spec.privateKey.algorithm
value: ECDSA
- equal:
path: spec.privateKey.size
value: 256
- it: third document is CA Issuer referencing the CA secret
set:
tls:
issuer: cert-manager
documentIndex: 2
asserts:
- isKind:
of: Issuer
- equal:
path: metadata.name
value: os-test-http-ca
- equal:
path: spec.ca.secretName
value: os-test.http-ca
- it: fourth document is leaf Certificate referencing the CA Issuer
set:
tls:
issuer: cert-manager
documentIndex: 3
asserts:
- isKind:
of: Certificate
- equal:
path: spec.secretName
value: os-test-http-server
# isCA is independent of spec.usages: cert-manager derives certSign from this
# field alone, so a leaf flipped to true still renders the same usages list and
# still passes every usages assertion — while becoming an intermediate CA whose
# key sits in the pod and chains to the anchor tenants are told to trust.
- equal:
path: spec.isCA
value: false
- equal:
path: spec.issuerRef.name
value: os-test-http-ca
- equal:
path: spec.issuerRef.kind
value: Issuer
- equal:
path: spec.issuerRef.group
value: cert-manager.io
- equal:
path: spec.privateKey.algorithm
value: ECDSA
- equal:
path: spec.privateKey.size
value: 256
- equal:
path: spec.privateKey.rotationPolicy
value: Always
# Dropping this falls back to cert-manager's PKCS1 default, which for an ECDSA
# key is SEC1 — a format the JVM PEM loader behind the security plugin cannot
# read, so OpenSearch fails to start its HTTPS listener. Nothing else in this
# file would notice.
- equal:
path: spec.privateKey.encoding
value: PKCS8
# The same positive pin for the dashboards leaf, which also establishes that index 4
# IS that certificate — the negative guards below would otherwise pass vacuously
# against whatever landed there if document order ever shifted.
# issuerRef is the load-bearing one: pointing it at the bootstrap self-signed Issuer
# instead of the CA still issues, still serves HTTPS and still goes Ready, while the
# anchor the platform publishes silently stops verifying the dashboards endpoint.
- it: fifth document is the dashboards Certificate referencing the same CA Issuer
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentIndex: 4
asserts:
- isKind:
of: Certificate
- equal:
path: metadata.name
value: os-test-dashboards-server
- equal:
path: spec.secretName
value: os-test-dashboards-server
- equal:
path: spec.issuerRef.name
value: os-test-http-ca
- equal:
path: spec.issuerRef.kind
value: Issuer
- equal:
path: spec.issuerRef.group
value: cert-manager.io
# Same reasoning as the API leaf: usages cannot catch this.
- equal:
path: spec.isCA
value: false
- equal:
path: spec.privateKey.algorithm
value: ECDSA
- equal:
path: spec.privateKey.size
value: 256
- equal:
path: spec.privateKey.rotationPolicy
value: Always
- equal:
path: spec.privateKey.encoding
value: PKCS8
# Never the API leaf's Secret: two Certificates writing one Secret would race,
# and the CR points each service at its own name.
- notEqual:
path: spec.secretName
value: os-test-http-server
- it: gives the dashboards certificate the same non-expiring lifetime
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentIndex: 4
asserts:
- equal:
path: spec.duration
value: 87600h
- notExists:
path: spec.renewBefore
# --- SAN coverage for HTTP services ---
# SAN PARITY WITH THE OPERATOR. The cert-manager issuer replaces the certificate
# the operator was issuing, so every name that certificate covered has to be covered
# here too — otherwise an existing client silently stops verifying. The operator
# issues for <name>, the service name, <name>-discovery and the <name>.<ns>[.svc
# [.domain]] ladder, and its Dashboards certificate for the -dashboards ladder.
- it: leaf cert covers every DNS form the operator certificate covered
set:
tls:
issuer: cert-manager
documentIndex: 3
asserts:
- contains:
path: spec.dnsNames
content: os-test
- contains:
path: spec.dnsNames
content: os-test.tenant-test
- contains:
path: spec.dnsNames
content: os-test.tenant-test.svc
- contains:
path: spec.dnsNames
content: os-test.tenant-test.svc.cozy.local
- contains:
path: spec.dnsNames
content: os-test-discovery
# ...and none of the Dashboards names, which belong to its own certificate.
- notContains:
path: spec.dnsNames
content: os-test-dashboards
- notContains:
path: spec.dnsNames
content: os-test-dashboards.tenant-test.svc.cozy.local
- it: "(b) leaf cert includes external HTTP DNS SAN when external true"
set:
external: true
_namespace:
host: example.cozy.local
documentIndex: 3
asserts:
- contains:
path: spec.dnsNames
content: os-test.example.cozy.local
- it: "(d) leaf cert does NOT include external HTTP DNS SAN when external false"
set:
tls:
issuer: cert-manager
documentSelector:
path: spec.secretName
value: os-test-http-server
asserts:
- notContains:
path: spec.dnsNames
content: os-test.example.cozy.local
# Isolates the `external` operand of that guard. The case above leaves
# _namespace.host unset, and the guard is an `and`, so the empty host suppresses the
# SAN on its own and the assertion holds whatever `external` does. A host present
# with external cleared is the only shape where that operand alone decides.
- it: leaf cert omits the external HTTP SAN when a host exists but external is false
set:
tls:
issuer: cert-manager
external: false
_namespace:
host: example.cozy.local
documentSelector:
path: spec.secretName
value: os-test-http-server
asserts:
- notContains:
path: spec.dnsNames
content: os-test.example.cozy.local
# --- SAN coverage for Dashboards services ---
# THE SAME THREE GUARDS THE API LEAF HAS. The Dashboards certificate inherits every
# hazard its sibling documents — a shared key across services, a tenant-visible label
# on a Secret that holds a server key, and colliding with a name the operator
# generates into — so it has to inherit the assertions too.
- it: keeps the dashboards cert from carrying any API name
set:
tls:
issuer: cert-manager
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
documentSelector:
path: spec.secretName
value: os-test-dashboards-server
asserts:
- notContains:
path: spec.dnsNames
content: os-test
- notContains:
path: spec.dnsNames
content: os-test.tenant-test
- notContains:
path: spec.dnsNames
content: os-test.tenant-test.svc
- notContains:
path: spec.dnsNames
content: os-test.tenant-test.svc.cozy.local
- notContains:
path: spec.dnsNames
content: os-test-discovery
- notContains:
path: spec.dnsNames
content: os-test.example.cozy.local
# Stronger than the two label guards above, which name the two labels that reach a
# tenant: this says the chart writes nothing onto that Secret at all.
- it: stamps nothing at all onto the dashboards leaf Secret
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentSelector:
path: spec.secretName
value: os-test-dashboards-server
asserts:
- notExists:
path: spec.secretTemplate
# Anchored and positively pinned for the reason given on the API leaf above.
- it: keeps the dashboards secret out of the operator's reserved names
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentSelector:
path: metadata.name
value: os-test-dashboards-server
asserts:
- equal:
path: spec.secretName
value: os-test-dashboards-server
- notEqual:
path: spec.secretName
value: os-test-dashboards-cert
- notEqual:
path: spec.secretName
value: os-test-http-cert
- notEqual:
path: spec.secretName
value: os-test-transport-cert
- notEqual:
path: spec.secretName
value: os-test-admin-cert
- notEqual:
path: spec.secretName
value: os-test-ca
- it: dashboards cert carries the same ECDSA-correct usages as the API leaf
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentIndex: 4
asserts:
- contains:
path: spec.usages
content: server auth
- contains:
path: spec.usages
content: signing
- notContains:
path: spec.usages
content: key encipherment
- lengthEqual:
path: spec.usages
count: 2
- it: dashboards cert covers every DNS form the operator dashboards cert covered
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
documentIndex: 4
asserts:
- contains:
path: spec.dnsNames
content: os-test-dashboards.tenant-test
- contains:
path: spec.dnsNames
content: os-test-dashboards
- contains:
path: spec.dnsNames
content: os-test-dashboards.tenant-test.svc
- contains:
path: spec.dnsNames
content: os-test-dashboards.tenant-test.svc.cozy.local
- it: "(b) dashboards cert includes external Dashboards DNS SAN when external true"
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
documentIndex: 4
asserts:
- contains:
path: spec.dnsNames
content: os-test-dashboards.example.cozy.local
# The same isolation for the Dashboards leaf, which carries its own copy of the guard.
- it: dashboards cert omits the external SAN when a host exists but external is false
set:
tls:
issuer: cert-manager
external: false
_namespace:
host: example.cozy.local
dashboards:
enabled: true
documentSelector:
path: spec.secretName
value: os-test-dashboards-server
asserts:
- notContains:
path: spec.dnsNames
content: os-test-dashboards.example.cozy.local
# No key encipherment on either certificate: RFC 5480 section 3 forbids it for
# ECDSA keys, which do no key transport, and both keys here are ECDSA P-256.
- it: leaf cert includes usages server auth and signing, and no key encipherment
set:
tls:
issuer: cert-manager
documentIndex: 3
asserts:
- contains:
path: spec.usages
content: server auth
- contains:
path: spec.usages
content: signing
- notContains:
path: spec.usages
content: key encipherment
- lengthEqual:
path: spec.usages
count: 2
- notContains:
path: spec.usages
content: cert sign
- it: CA cert carries no key encipherment either
set:
tls:
issuer: cert-manager
documentIndex: 1
asserts:
- contains:
path: spec.usages
content: signing
- contains:
path: spec.usages
content: cert sign
- notContains:
path: spec.usages
content: key encipherment
- lengthEqual:
path: spec.usages
count: 2
# A platform with no root host leaves the tenant host empty all the way down, which
# is a supported state. The certificate keeps its in-cluster names and simply omits
# the external ones rather than failing the release.
- it: omits the external SANs when the tenant host is empty
set:
tls:
issuer: cert-manager
external: true
_namespace: {}
dashboards:
enabled: true
asserts:
- hasDocuments:
count: 5
- contains:
path: spec.dnsNames
content: os-test.tenant-test.svc.cozy.local
documentIndex: 3
- notContains:
path: spec.dnsNames
content: os-test.
documentIndex: 3
# The dashboards leaf carries the same guard and must be held to it — an empty
# host there would emit a trailing-dot SAN on the more exposed service.
- contains:
path: spec.dnsNames
content: os-test-dashboards.tenant-test.svc.cozy.local
documentIndex: 4
- notContains:
path: spec.dnsNames
content: os-test-dashboards.
documentIndex: 4
---
---
###############################################################################
# opensearch.yaml — TLS state reflected in OpenSearchCluster spec
###############################################################################
suite: opensearch CR TLS wiring
templates:
- templates/opensearch.yaml
release:
name: os-test
namespace: tenant-test
set:
_cluster:
scheduling: {}
cluster-domain: cozy.local
tests:
# THE UPGRADE PATH, pinned explicitly. An existing external release on a supported
# version has tls unset and runs operator-managed TLS today; once this chart ships
# the tri-state moves it onto the cert-manager issuer. That is a deliberate default, but
# it rolls the cluster and re-anchors it on a new CA, so it must not change by
# accident — hence an assertion of its own rather than incidental coverage.
- it: moves an existing external release onto cert-manager on a supported version
set:
version: v2
external: true
_namespace:
host: example.cozy.local
asserts:
- equal:
path: spec.security.tls.http.secret.name
value: os-test-http-server
documentIndex: 0
- equal:
path: spec.security.tls.http.caSecret.name
value: os-test.http-ca
documentIndex: 0
- notExists:
path: spec.security.tls.http.generate
documentIndex: 0
# A v1 + external release never chose cert-manager: the tri-state
# turned it on. Below 2.0.0 that combination degrades to operator-managed HTTP
# TLS rather than failing, so such a release keeps working across an upgrade.
- it: leaves HTTP TLS operator-generated when the resolved issuer degrades below 2.0.0
set:
version: v1
external: true
_namespace:
host: example.cozy.local
asserts:
- equal:
path: spec.security.tls.http.generate
value: true
documentIndex: 0
- notExists:
path: spec.security.tls.http.caSecret
documentIndex: 0
- notExists:
path: spec.security.tls.http.secret
documentIndex: 0
# The dashboards-only path: no external access, the operator issuer, so of the three
# templates that invoke the name guard this is the only one rendering anything at all.
# 52 is the longest name this path admits now that -dashboards is bound, and the CR
# must still render at it: the guard exists to refuse the length, not to withhold a
# release that fits inside it.
- it: renders the cluster for the longest admissible dashboards-only name
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
dashboards:
enabled: true
external: false
tls:
issuer: operator
asserts:
- isKind:
of: OpenSearchCluster
documentIndex: 0
- equal:
path: spec.dashboards.enable
value: true
documentIndex: 0
# The part whose loss actually hurts: an empty tenant host must not stop the cluster
# itself from rendering. A hard failure here takes the OpenSearchCluster CR, the
# credentials Secret and the RBAC with it, so a running release goes not-Ready.
- it: still renders the cluster when external is on and the tenant host is empty
set:
external: true
_namespace: {}
asserts:
- isKind:
of: OpenSearchCluster
documentIndex: 0
- equal:
path: metadata.name
value: os-test
documentIndex: 0
# --- Transport TLS: always operator-managed, never touched ---
- it: transport TLS always uses operator generate regardless of tls.issuer
asserts:
- equal:
path: spec.security.tls.transport.generate
value: true
documentIndex: 0
- equal:
path: spec.security.tls.transport.perNode
value: true
documentIndex: 0
- it: transport TLS stays operator generate even when the issuer is cert-manager
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.security.tls.transport.generate
value: true
documentIndex: 0
- equal:
path: spec.security.tls.transport.perNode
value: true
documentIndex: 0
# --- HTTP TLS: case (a) — operator generate when the issuer resolves to operator ---
- it: "(a) HTTP uses operator generate when external false and issuer unset"
asserts:
- equal:
path: spec.security.tls.http.generate
value: true
documentIndex: 0
- notExists:
path: spec.security.tls.http.secret
documentIndex: 0
- notExists:
path: spec.security.tls.http.caSecret
documentIndex: 0
# --- HTTP TLS: case (b) — cert-manager secret when external true and issuer unset ---
- it: "(b) HTTP uses cert-manager secret when external true and issuer unset"
set:
external: true
_namespace:
host: example.cozy.local
asserts:
- equal:
path: spec.security.tls.http.secret.name
value: os-test-http-server
documentIndex: 0
- equal:
path: spec.security.tls.http.caSecret.name
value: os-test.http-ca
documentIndex: 0
- notExists:
path: spec.security.tls.http.generate
documentIndex: 0
# --- HTTP TLS: case (c) — operator generate when the issuer is operator ---
- it: "(c) HTTP uses operator generate when the issuer is operator"
set:
external: true
_namespace:
host: example.cozy.local
tls:
issuer: operator
asserts:
- equal:
path: spec.security.tls.http.generate
value: true
documentIndex: 0
- notExists:
path: spec.security.tls.http.secret
documentIndex: 0
- notExists:
path: spec.security.tls.http.caSecret
documentIndex: 0
# --- HTTP TLS: case (d) — cert-manager secret when the issuer is cert-manager ---
- it: "(d) HTTP uses cert-manager secret when the issuer is cert-manager"
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.security.tls.http.secret.name
value: os-test-http-server
documentIndex: 0
- equal:
path: spec.security.tls.http.caSecret.name
value: os-test.http-ca
documentIndex: 0
- notExists:
path: spec.security.tls.http.generate
documentIndex: 0
# --- Dashboards TLS: operator generate by default, cert-manager secret when that issuer is resolved ---
- it: dashboards uses operator generate when enabled and the issuer resolves to operator
set:
dashboards:
enabled: true
replicas: 1
resourcesPreset: "c1.small"
resources: {}
asserts:
- equal:
path: spec.dashboards.tls.enable
value: true
documentIndex: 0
- equal:
path: spec.dashboards.tls.generate
value: true
documentIndex: 0
- notExists:
path: spec.dashboards.tls.secret
documentIndex: 0
- it: dashboards uses cert-manager secret when enabled and external true resolves the issuer
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
replicas: 1
resourcesPreset: "c1.small"
resources: {}
asserts:
- equal:
path: spec.dashboards.tls.enable
value: true
documentIndex: 0
- equal:
path: spec.dashboards.tls.secret.name
value: os-test-dashboards-server
documentIndex: 0
# Never the API certificate: a shared key would let a compromised Dashboards
# impersonate the OpenSearch API endpoint.
- notEqual:
path: spec.dashboards.tls.secret.name
value: os-test-http-server
documentIndex: 0
- notExists:
path: spec.dashboards.tls.generate
documentIndex: 0
- it: dashboards uses cert-manager secret when the issuer is cert-manager
set:
tls:
issuer: cert-manager
dashboards:
enabled: true
replicas: 1
resourcesPreset: "c1.small"
resources: {}
asserts:
- equal:
path: spec.dashboards.tls.enable
value: true
documentIndex: 0
- equal:
path: spec.dashboards.tls.secret.name
value: os-test-dashboards-server
documentIndex: 0
# Never the API certificate: a shared key would let a compromised Dashboards
# impersonate the OpenSearch API endpoint.
- notEqual:
path: spec.dashboards.tls.secret.name
value: os-test-http-server
documentIndex: 0
- notExists:
path: spec.dashboards.tls.generate
documentIndex: 0
---
---
###############################################################################
# external-svc.yaml — required guard for _namespace.host
###############################################################################
suite: external service tenant-host guard
templates:
- templates/external-svc.yaml
release:
name: os-test
namespace: tenant-test
set:
_cluster:
scheduling: {}
cluster-domain: cozy.local
tests:
# An empty tenant host must not take the release down. The LoadBalancers still get
# addresses and still serve; only the external-dns hostname is withheld, because
# there is no name to publish. Previously this failed the whole render, which took
# the OpenSearchCluster CR with it on a configuration that works on main.
# That bound has nothing to do with TLS — the Service renders on external alone —
# so the guard has to fire under the operator issuer too.
- it: applies the Service bound even under the operator issuer
release:
name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
namespace: tenant-test
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
tls:
issuer: operator
asserts:
- failedTemplate:
errorMessage: 'Release name "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is 44 chars; opensearch requires <=43 in this configuration so that "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-dashboards-external" stays within the 63-char DNS label limit. Set dashboards.enabled to false to drop this bound.'
- it: still renders both Services when the tenant host is empty
set:
external: true
_namespace: {}
dashboards:
enabled: true
asserts:
- hasDocuments:
count: 2
- equal:
path: metadata.name
value: os-test-external
documentIndex: 0
- notExists:
path: metadata.annotations
documentIndex: 0
- equal:
path: metadata.name
value: os-test-dashboards-external
documentIndex: 1
- notExists:
path: metadata.annotations
documentIndex: 1
# _namespace absent entirely, not merely missing its host key — the deref must not
# raise a nil pointer either.
- it: still renders both Services when _namespace is absent entirely
set:
external: true
dashboards:
enabled: true
asserts:
- hasDocuments:
count: 2
- notExists:
path: metadata.annotations
documentIndex: 0
# The external-dns hostname is built from the tenant host, not the in-cluster
# domain: cozy.local does not resolve outside the cluster, and the name published
# here has to be one the leaf certificate carries a SAN for.
# The operator labels Dashboards pods with opensearch.cluster.dashboards only.
# A selector naming opster.io/opensearch-cluster or app.kubernetes.io/* matches
# nothing, so the LoadBalancer comes up with no endpoints and no error, while the
# chart issues a certificate SAN and documents a hostname for that very Service.
- it: selects dashboards pods by the label the operator actually sets
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
asserts:
- equal:
path: spec.selector["opensearch.cluster.dashboards"]
value: os-test
documentIndex: 1
- notExists:
path: spec.selector["app.kubernetes.io/component"]
documentIndex: 1
- notExists:
path: spec.selector["opster.io/opensearch-cluster"]
documentIndex: 1
# The API Service keeps the label the operator does set on data pods.
- equal:
path: spec.selector["opster.io/opensearch-cluster"]
value: os-test
documentIndex: 0
- it: publishes external-dns hostnames under the tenant host
set:
external: true
_namespace:
host: example.cozy.local
dashboards:
enabled: true
asserts:
- equal:
path: metadata.annotations["external-dns.alpha.kubernetes.io/hostname"]
value: os-test.example.cozy.local
documentIndex: 0
- equal:
path: metadata.annotations["external-dns.alpha.kubernetes.io/hostname"]
value: os-test-dashboards.example.cozy.local
documentIndex: 1
---
---
###############################################################################
# The cluster domain read must survive _cluster being absent
###############################################################################
#
# Every other suite in this file injects _cluster, which is what the platform does
# in production — so none of them can see what happens without it. `index` on an
# absent map is not a miss returning nil, it is a hard render error ("index of
# untyped nil"), and it takes the whole chart down rather than the one value it
# was reading. The default that follows the read never gets a chance to apply.
#
# No suite-level `set` here on purpose: adding _cluster back is exactly the thing
# this suite must not do.
suite: cluster domain defaulting without _cluster
templates:
- templates/certmanager.yaml
release:
name: os-test
namespace: tenant-test
tests:
- it: falls back to the default cluster domain when _cluster is absent
set:
tls:
issuer: cert-manager
asserts:
- equal:
path: spec.dnsNames[3]
value: os-test.tenant-test.svc.cozy.local
documentIndex: 3
---
---
###############################################################################
# security.yaml — the same read, on a path that renders no certificate
###############################################################################
#
# Its own suite rather than a second test in the one above, because helm-unittest
# renders every template a suite declares for every test in it: listing both would
# make the certificate test report a security.yaml render error, a reason that has
# nothing to do with what it asserts.
suite: cluster domain defaulting without _cluster in the credentials Secret
templates:
- templates/security.yaml
release:
name: os-test
namespace: tenant-test
tests:
# This template renders under either issuer, so an unguarded read here takes
# down a release that mints no certificate at all. The host it composes is the
# one the tenant connects to.
- it: falls back to the default cluster domain when _cluster is absent
asserts:
- equal:
path: stringData.host
value: os-test.tenant-test.svc.cozy.local
documentIndex: 2