feat(platform): expose Keycloak truststores through platform values (#5144)

## What this PR does

Fixes #5140.

#5039 added `truststores` to the Keycloak chart, but that capability was
not reachable through the administrator-owned platform Package: the
system bundle rendered `Package cozystack.keycloak` without a components
override. This PR adds the optional
`authentication.oidc.keycloakTruststores` platform value and forwards it
unchanged to `spec.components.keycloak.values.truststores` on that child
Package.

Administrators can configure it under `spec.components.platform.values`
on `Package cozystack.cozystack-platform`:

```yaml
authentication:
  oidc:
    keycloakTruststores:
      - configMapName: organization-ca
        key: ca.crt
      - secretName: partner-ca
        key: certificates.pem
```

When OIDC is enabled and the list is non-empty, the complete list is
forwarded, including entry order, explicitly selected keys, and entries
that omit `key` so the chart's `ca.crt` default remains effective. When
the value is unset or explicitly empty, the platform continues to use
the default Package helper without introducing `spec.components`. When
OIDC is disabled, the value is ignored because no Keycloak Package is
emitted.

The platform layer only forwards references; it does not create Secrets
or ConfigMaps. Referenced objects and keys must already exist in
`cozy-keycloak`, and the Keycloak chart remains responsible for
validation and mounting. Its existing semantics are unchanged: trust
applies server-wide across all realms, only public certificate material
should be supplied, and changing an object's contents requires a
Keycloak restart or a versioned object reference to reload the
truststore.

### Validation

- `make test` in `packages/core/platform`: all 295 tests pass. The new
suite covers unset, empty and null defaults, complete list forwarding,
false-y malformed values, both `isp-full` and `isp-slim`, and disabled
OIDC; removing the forwarding path or restoring truthiness-based empty
checks makes the regression suite fail.
- `make test` in `packages/system/keycloak`: all 121 tests pass.
- With the system bundle and OIDC enabled, the unset render is
byte-identical to `upstream/main`. The explicitly empty case is
separately verified to omit `spec.components`; malformed false-y values
reach the Keycloak chart and are rejected by its existing `truststores
must be a list` validation.
- `make generate` has no target in `packages/core/platform`; there are
no generated platform schema artifacts to update.
- `make show` could not run because `cozyhr` is unavailable. A direct
`helm template` render of the system bundle was checked in a temporary
chart copy with `templates/repository.yaml` removed because its `lookup`
requires a live source. This verifies rendering and forwarding, not a
live-cluster deployment or an end-to-end Keycloak TLS connection.

### Screenshots

Not applicable; no UI changes.

### Downstream repositories

Changing `packages/core/platform/values.yaml` directly triggers the
website's hand-written platform-package reference. The existing
cozystack/website#765 follow-up covers both the chart-level value and
this platform configuration path, including
`content/en/docs/next/operations/configuration/platform-package.md`; no
other downstream trigger applies to this diff.

- [ ] No downstream repository is affected by this change
- [x] [cozystack/website](https://github.com/cozystack/website) -
follow-up: https://github.com/cozystack/website/issues/765 (covers the
platform value and platform-package reference as well as the chart-level
guide)
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
feat(platform): add `authentication.oidc.keycloakTruststores` so administrators can forward existing Secret or ConfigMap CA references from the platform Package to the bundled Keycloak server for private-CA LDAPS, external identity-provider, and SMTP TLS connections.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added the `authentication.oidc.keycloakTruststores` setting for
configuring additional CA certificates from Secrets or ConfigMaps in
`cozy-keycloak`. Certificate entries default to `ca.crt`, and configured
certificates apply across all Keycloak realms.
* The setting defaults to an empty list. Configured truststores are
passed to Keycloak when OIDC is enabled; when OIDC is disabled, the
setting is ignored and existing Keycloak package settings remain
unchanged.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-14 00:40:57 +03:00
commit 06ca603f4f
3 files changed
+226

No files matched your search

@@ -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) }}
@@ -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
+13
View File
@@ -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: