|
| 1 | +{{- /* |
| 2 | + Phase 1 — System mode: render one per-instance Keycloak client, a |
| 3 | + per-instance audience client scope, and the three role-mapping |
| 4 | + groups (`-admin` / `-editor` / `-viewer`) inside the platform `cozy` |
| 5 | + realm. |
| 6 | + |
| 7 | + The clientId is namespace-prefixed so it is globally unique across |
| 8 | + the realm; the audience scope binds `id_token.aud` to that clientId |
| 9 | + so a token minted for one Monitoring instance is rejected by |
| 10 | + another's Grafana — the per-instance isolation primitive in the |
| 11 | + absence of per-tenant realms. |
| 12 | + |
| 13 | + Nothing is rendered for `mode: CustomConfig` or `mode: None`: in |
| 14 | + those modes `cozy` is not in the path. |
| 15 | + |
| 16 | + The `_cluster.oidc-enabled` guard catches the case where an |
| 17 | + operator toggles `mode: System` without the platform-level OIDC |
| 18 | + feature (authentication.oidc.enabled) being on — the Keycloak |
| 19 | + operator CRDs would not be present and the chart would silently |
| 20 | + no-op without the fail-fast. |
| 21 | + |
| 22 | + The three KeycloakRealmGroup objects are chart-owned but their |
| 23 | + membership is not — a Keycloak operator adds users to them via the |
| 24 | + Keycloak UI or via a KeycloakRealmUser CR. Grafana's |
| 25 | + `role_attribute_path` (see grafana.yaml) evaluates group membership |
| 26 | + on login and assigns Admin / Editor / Viewer accordingly. |
| 27 | +*/}} |
| 28 | +{{- if eq .Values.oidc.mode "System" }} |
| 29 | +{{- include "monitoring.oidc.assertSystemEnabled" . }} |
| 30 | +{{- if .Capabilities.APIVersions.Has "v1.edp.epam.com/v1" }} |
| 31 | +{{- $clientId := include "monitoring.oidc.clientId" . }} |
| 32 | +{{- $scopeName := include "monitoring.oidc.audienceScopeName" . }} |
| 33 | +{{- $clientSecretName := include "monitoring.oidc.clientSecretName" . }} |
| 34 | +{{- $grafanaHost := include "monitoring.oidc.grafanaHost" . }} |
| 35 | +--- |
| 36 | +apiVersion: v1.edp.epam.com/v1 |
| 37 | +kind: KeycloakClientScope |
| 38 | +metadata: |
| 39 | + name: {{ $scopeName }} |
| 40 | + namespace: {{ .Release.Namespace }} |
| 41 | +spec: |
| 42 | + name: {{ $scopeName }} |
| 43 | + realmRef: |
| 44 | + name: keycloakrealm-cozy |
| 45 | + kind: ClusterKeycloakRealm |
| 46 | + description: "Per-instance audience for Grafana {{ .Release.Name }}" |
| 47 | + protocol: openid-connect |
| 48 | + default: false |
| 49 | + attributes: |
| 50 | + "include.in.token.scope": "true" |
| 51 | + protocolMappers: |
| 52 | + - name: audience |
| 53 | + protocol: openid-connect |
| 54 | + protocolMapper: "oidc-audience-mapper" |
| 55 | + config: |
| 56 | + "included.client.audience": {{ $clientId | quote }} |
| 57 | + "id.token.claim": "true" |
| 58 | + "access.token.claim": "true" |
| 59 | + "introspection.token.claim": "true" |
| 60 | + "lightweight.claim": "false" |
| 61 | +--- |
| 62 | +apiVersion: v1.edp.epam.com/v1 |
| 63 | +kind: KeycloakClient |
| 64 | +metadata: |
| 65 | + name: {{ $clientId }} |
| 66 | + namespace: {{ .Release.Namespace }} |
| 67 | +spec: |
| 68 | + clientId: {{ $clientId }} |
| 69 | + name: {{ $clientId }} |
| 70 | + realmRef: |
| 71 | + name: keycloakrealm-cozy |
| 72 | + kind: ClusterKeycloakRealm |
| 73 | + public: false |
| 74 | + directAccess: false |
| 75 | + advancedProtocolMappers: true |
| 76 | + secret: "${{ $clientSecretName }}:client-secret" |
| 77 | + webUrl: "https://{{ $grafanaHost }}" |
| 78 | + redirectUris: |
| 79 | + - "https://{{ $grafanaHost }}/login/generic_oauth" |
| 80 | + defaultClientScopes: |
| 81 | + - groups |
| 82 | + - {{ $scopeName }} |
| 83 | + attributes: |
| 84 | + "post.logout.redirect.uris": "+" |
| 85 | +--- |
| 86 | +apiVersion: v1.edp.epam.com/v1 |
| 87 | +kind: KeycloakRealmGroup |
| 88 | +metadata: |
| 89 | + name: {{ printf "%s-admin" $clientId }} |
| 90 | + namespace: {{ .Release.Namespace }} |
| 91 | +spec: |
| 92 | + name: {{ printf "%s-admin" $clientId }} |
| 93 | + realmRef: |
| 94 | + name: keycloakrealm-cozy |
| 95 | + kind: ClusterKeycloakRealm |
| 96 | +--- |
| 97 | +apiVersion: v1.edp.epam.com/v1 |
| 98 | +kind: KeycloakRealmGroup |
| 99 | +metadata: |
| 100 | + name: {{ printf "%s-editor" $clientId }} |
| 101 | + namespace: {{ .Release.Namespace }} |
| 102 | +spec: |
| 103 | + name: {{ printf "%s-editor" $clientId }} |
| 104 | + realmRef: |
| 105 | + name: keycloakrealm-cozy |
| 106 | + kind: ClusterKeycloakRealm |
| 107 | +--- |
| 108 | +apiVersion: v1.edp.epam.com/v1 |
| 109 | +kind: KeycloakRealmGroup |
| 110 | +metadata: |
| 111 | + name: {{ printf "%s-viewer" $clientId }} |
| 112 | + namespace: {{ .Release.Namespace }} |
| 113 | +spec: |
| 114 | + name: {{ printf "%s-viewer" $clientId }} |
| 115 | + realmRef: |
| 116 | + name: keycloakrealm-cozy |
| 117 | + kind: ClusterKeycloakRealm |
| 118 | +{{- end }} |
| 119 | +{{- end }} |
0 commit comments