diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 906c8d95f..814bf201e 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -178,9 +178,19 @@ {{- $controllerValues := dict "cozystackController" (dict "disableTelemetry" true) -}} {{- $_ := set $cozystackEngineComponents "cozystack-controller" (dict "values" $controllerValues) -}} {{- end -}} +{{- $keycloakTruststores := .Values.authentication.oidc.keycloakTruststores -}} +{{- $hasKeycloakTruststores := and (not (kindIs "invalid" $keycloakTruststores)) (or (not (kindIs "slice" $keycloakTruststores)) (not (empty $keycloakTruststores))) -}} +{{- $keycloakComponents := dict -}} +{{- if $hasKeycloakTruststores }} +{{- $_ := set $keycloakComponents "keycloak" (dict "values" (dict "truststores" $keycloakTruststores)) -}} +{{- end }} {{- if .Values.authentication.oidc.enabled }} {{include "cozystack.platform.package" (list "cozystack.cozystack-engine" "oidc" $ $cozystackEngineComponents) }} +{{- if $hasKeycloakTruststores }} +{{include "cozystack.platform.package" (list "cozystack.keycloak" "default" $ $keycloakComponents) }} +{{- else }} {{include "cozystack.platform.package.default" (list "cozystack.keycloak" $) }} +{{- end }} {{include "cozystack.platform.package.default" (list "cozystack.keycloak-operator" $) }} {{- else }} {{include "cozystack.platform.package" (list "cozystack.cozystack-engine" "default" $ $cozystackEngineComponents) }} diff --git a/packages/core/platform/tests/bundles_keycloak_truststores_test.yaml b/packages/core/platform/tests/bundles_keycloak_truststores_test.yaml new file mode 100644 index 000000000..6319c6dd9 --- /dev/null +++ b/packages/core/platform/tests/bundles_keycloak_truststores_test.yaml @@ -0,0 +1,203 @@ +suite: bundles.system Keycloak truststores wiring +templates: + - templates/bundles/system.yaml +release: + name: cozystack + namespace: cozy-system +tests: + - it: emits cozystack.keycloak without a components block when keycloakTruststores is unset + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: kind + value: Package + - equal: + path: spec.variant + value: default + - notExists: + path: spec.components + + - it: omits the components block when keycloakTruststores is explicitly empty + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: [] + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - notExists: + path: spec.components + + - it: omits the components block when keycloakTruststores is explicitly null + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: null + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - notExists: + path: spec.components + + - it: forwards false so the Keycloak chart can reject it instead of silently removing trust + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: false + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values.truststores + value: false + + - it: forwards zero so the Keycloak chart can reject it instead of silently removing trust + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: 0 + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values.truststores + value: 0 + + - it: forwards an empty string so the Keycloak chart can reject it instead of silently removing trust + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: "" + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values.truststores + value: "" + + - it: forwards an empty map so the Keycloak chart can reject it instead of silently removing trust + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: {} + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values.truststores + value: {} + + - it: forwards the complete truststores list without taking over chart defaults + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: true + keycloakTruststores: + - configMapName: organization-ca + - secretName: partner-ca + key: certificates.pem + - configMapName: secondary-ca + key: chain.pem + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values + value: + truststores: + - configMapName: organization-ca + - secretName: partner-ca + key: certificates.pem + - configMapName: secondary-ca + key: chain.pem + + - it: forwards keycloakTruststores on the isp-slim variant too + set: + bundles: + system: + enabled: true + variant: isp-slim + authentication: + oidc: + enabled: true + keycloakTruststores: + - configMapName: organization-ca + key: ca.crt + documentSelector: + path: metadata.name + value: cozystack.keycloak + asserts: + - equal: + path: spec.components.keycloak.values.truststores + value: + - configMapName: organization-ca + key: ca.crt + + - it: does not emit cozystack.keycloak for a malformed false-y value when OIDC is disabled + set: + bundles: + system: + enabled: true + variant: isp-full + authentication: + oidc: + enabled: false + keycloakTruststores: false + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.keycloak + any: true + not: true diff --git a/packages/core/platform/values.yaml b/packages/core/platform/values.yaml index e5a488498..8ea4a054a 100644 --- a/packages/core/platform/values.yaml +++ b/packages/core/platform/values.yaml @@ -549,6 +549,19 @@ authentication: # OIDC discovery; any other value -> used verbatim. An explicit value is not rewritten, so a # custom realm paired with an explicit URL must name the same realm. keycloakInternalUrl: null + # Additional CA trust anchors for the bundled Keycloak server (LDAPS, + # external IdPs, SMTP). Each entry selects one key from an existing Secret + # or ConfigMap in cozy-keycloak; key defaults to ca.crt. Trust applies to + # the entire server across all realms. See packages/system/keycloak/values.yaml + # for supported formats, incoming-client-mTLS scope and rotation behavior. + # Ignored when oidc.enabled is false: no Keycloak Package is emitted. An + # existing Package and its rendered truststores remain on the cluster + # (helm.sh/resource-policy: keep). + keycloakTruststores: [] + # - configMapName: organization-ca + # key: ca.crt + # - secretName: partner-ca + # key: certificates.pem # Gateway API configuration gateway: # Enable Gateway API support across the platform. When true: