Compare commits

..

19 Commits

Author SHA1 Message Date
Stéphane Tailland 62d0b371f6 Add the restocker role, assigned to Supply's service account
Copies the shape of read_only rather than inventing the schema. Supply keeps
read_only for its existing read tools and gains restocker for the one
patch-product tool it now needs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 16:18:23 +02:00
Stéphane Tailland dc1e7de204 Rename the supply agent's Keycloak client and scope
Its Vault key moves with it; the secret value is unchanged, so nothing has to
be re-issued.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 14:58:41 +02:00
Stéphane Tailland 9f2bd159d8 feat(realm): a machine identity for the autonomous run
serviceAccountsEnabled on the Approvisionnement client, and its service account
holds read_only — the least privilege its periodic run needs. The MCP server
maps that to a consumer group, so the catalog's write tool is invisible to this
identity rather than merely unused.

The classic-models-mandate client added earlier stays, unused. An autonomous run
acts for itself; a mandate belongs where a person's own authority is in play.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 17:51:20 +02:00
Stéphane Tailland 5048a154c5 feat(realm): grant Approvisionnement read access to sales
Needed to deduct quantities committed on open orders from availability. Not
granted: catalog:write, which the design's scope list names but which has no
reachable target — the schema has no purchase order and the catalog's only
write tool belongs to the Catalogue agent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 17:36:20 +02:00
Stéphane Tailland 04d0d65863 feat(realm): add the Approvisionnement client
Its own client so the exchanged token carries azp = the agent that acted, and
an audience scope so Catalogue, the Assistant and librechat can name it as a
callee. Granted mcp-catalog, the token-exchange broker and llm-proxy — not
sales, and no write scope, which is what the autonomous half will need.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 13:51:59 +02:00
Stéphane Tailland 7e7e9d741b feat(realm): add the Assistant client and its audience scope
The orchestrator is its own client so the exchanged token carries azp = the
agent doing the asking. It is granted two optional scopes — the Catalogue
agent's audience, and llm-proxy-audience because it has to reason — and no
domain audience at all. Every mcp-* and *-api scope it could request comes back
Invalid scopes, which is what makes 'the orchestrator holds nothing' a property
of the realm rather than a line in a prompt.

Note for the next client added by hand: CLIENT.DESCRIPTION is varchar(255), and
a longer one crash-loops the import with 'value too long' rather than a
validation message.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 12:27:47 +02:00
Stéphane Tailland eed8c3da3b refactor(realm): rename the token-exchange broker, drop the middleware's name
Every agent has to name this client in the audience scopes it requests, so the
one thing an agent could not avoid naming was the very thing it should know
nothing about. The gateway serving those URLs is replaceable; the contract
should not imply otherwise.

kong-token-exchange-broker becomes token-exchange-broker, same credential, same
behaviour. The rename was rolled out in order — new client alongside the old,
then the callers, then the gateways, then removal — so no call ever hit a realm
that had forgotten the name its caller was still using. Followed through the
client scope, the audience mappers, the fine-grained admin policy
allow-broker-client, and the roles map.

The Vault property keeps the old name. Renaming it there means re-issuing the
value to every gateway holding a copy, for no gain; the ExternalSecret maps it
to KC_SECRET_TOKEN_EXCHANGE_BROKER instead, so everything the cluster can see
is neutral.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 07:52:58 +02:00
Stéphane Tailland 6c89f6124d feat(realm): add the llm-proxy audience so agents can authenticate to the AI gateway
The AI gateway's openid-connect plugin requires audience ["llm-proxy"], but no
client or client scope in the realm could mint it, so every OIDC call fell
through to the anonymous consumer and was terminated with 401 "Authentication
required". Adds the bearer-only llm-proxy client, the llm-proxy-audience scope,
and grants it to the catalogue agent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 10:49:19 +02:00
Stéphane Tailland f9900a5fb9 Take the realm's client secrets and user passwords out of git
configmap-realm.yaml carried fourteen client secrets and five user
passwords in clear, in a tracked file. Five were there from its first
commit; I added the fourteenth yesterday by following the existing pattern
without questioning it. Making this file authoritative on every start did
not increase the exposure, but it did make the file the place those
secrets live for good — and it is inconsistent with the rest of the
estate, where infra-observability and kong-v2 both take theirs from Vault.

Keycloak resolves ${PLACEHOLDER} in a realm import file from the
environment, so the structure stays in git and the values move to Vault at
secrets/keycloak/classic-models-realm, reaching the import container
through External Secrets.

A store of its own, vault-keycloak, rather than reusing vault-kong-v2 or
vault-observability: each carries a policy scoped to its own path, so a
reader for one estate cannot see another's. Widening an existing policy
would have handed Kong's reader every client secret in the realm.

dataFrom.extract pulls the whole path, so adding a client means adding its
secret in Vault with no edit to the ExternalSecret.

Verified after the switch: the import logs "Realm 'classic-models' imported"
under OVERWRITE_EXISTING, and all three credential paths still work — the
broker's client_credentials, librechat with pm-user's password, and the
Catalogue agent's exchange reaching catalog-mcp with 200. Re-checked that
none of the nineteen original values appears anywhere in the file.

Note the values themselves were committed and are in this repo's history.
They are lab credentials behind a private CA with no real data, but they
should be rotated if that ever stops being true.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 10:13:40 +02:00
Stéphane Tailland a97399c2bf Import the realm on every start, so the file is the source of truth
configmap-realm.yaml was a first-install seed: `start --import-realm`
skips a realm that already exists and logs "Import skipped", so editing
the file changed nothing on a restart and the truth drifted into the
database. It already had — four scope grants existed only in the running
realm.

There is no option to make the startup import overwrite. The --override
flag exists only on the standalone `import` command, and the Keycloak
documentation is explicit that re-creating realms means running that
command before starting the server. So the import moves into an init
container that runs `import --dir ... --override true`, and --import-realm
comes off the main container's args.

The init container empties JAVA_OPTS_APPEND for itself. It inherits the
main container's env, which loads the OpenTelemetry agent from a volume
the other init container downloads into and this one does not mount;
inherited verbatim, the JVM fails before the import runs.

What this costs, deliberately: the realm is replaced at every start, so
anything created at runtime and not written back to this file is lost, and
active sessions are dropped. Checked before enabling it — the five users
in the realm are the five declared here, and the only live sessions were
two LibreChat ones. Nothing is to be created through the admin console
expecting it to last.

Verified after the switch: the import logs "Strategy: OVERWRITE_EXISTING",
the realm still has its 21 clients with no optionalClientScopes
divergence, and the full identity chain still returns 200 — pm-user token,
exchanged by the Catalogue agent, accepted by catalog-mcp.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 09:37:35 +02:00
Stéphane Tailland 1b613768e7 Realign the realm seed with what Keycloak actually runs
This file is a bootstrap seed, not the live realm. Keycloak starts with
--import-realm under IGNORE_EXISTING and logs "Realm 'classic-models'
already exists. Import skipped", so editing it changes nothing on a
restart and the truth lives in Keycloak's database.

That divergence had already opened, in the direction that hurts: four
authorisations existed only in the running realm, granted through the
admin API while working out which audiences the gateway actually needs.

  classic-models-agent-catalogue  +catalog-api-audience
                                  +sales-api-audience
                                  +kong-token-exchange-broker-audience
  librechat                       +classic-models-agent-catalogue-audience

Rebuilding the realm from this file would have left the Catalogue agent
with two of its five scopes and no indication why it stopped working.

Compared object by object against the live realm: the inventories already
matched — 21 clients, 38 client scopes, none missing either way — so the
drift was in contents, not in the lists. optionalClientScopes are now
copied back for every client that differed, and a re-comparison reports no
remaining gap.

This closes today's drift; it does not fix the mechanism that allows it.
Keeping a seed honest by hand is the same arrangement the Flux entrypoints
had before they were made self-reconciling, and it will drift again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 09:18:09 +02:00
Stéphane Tailland c1eaead5d2 Declare the Catalogue agent as a Keycloak client
First of the six agents to need an identity. It exchanges the end user's
token for one narrowly-scoped token per MCP server, so `azp` names the
agent while `sub` stays the human — which is what makes the audit trail
able to answer "which agent asked, on whose behalf".

Deliberately narrower than the librechat client it is modelled on:

  * no browser flow at all. standardFlowEnabled, implicitFlow and
    directAccessGrants are off, because the agent never logs a user in —
    it receives an already-issued token over A2A. Any of those three
    would be a way to obtain a token it has no business obtaining.
  * no service account. It has no standing access of its own; everything
    it can reach, it reaches on behalf of a user who asked.
  * two optional scopes, mcp-catalog-audience and mcp-sales-audience, and
    nothing else. librechat carries all of them because it fronts every
    domain; an agent serving the product manager must not be able to mint
    a payments token.

Adds classic-models-agent-catalogue-audience, the scope whoever issues
the user's token requests so the agent appears in that token's audience.
Keycloak's Standard Token Exchange refuses otherwise, with "Client is not
within the token audience" — which reads as a permissions problem on the
target rather than a missing audience on the source.

Verified against the running realm: catalog and sales exchange
successfully and return aud=[mcp-catalog] / aud=[mcp-sales] with
azp=classic-models-agent-catalogue, while payments is refused with
invalid_scope. The confinement is enforced by Keycloak, not by the
agent's own restraint.

Note this file is a bootstrap seed, not the live realm: Keycloak starts
with --import-realm under IGNORE_EXISTING and logs "Realm
'classic-models' already exists. Import skipped", so editing it changes
nothing on a restart. The client and scope were created through the admin
API and recorded here so a fresh install matches. That divergence is
worth closing separately.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 08:57:50 +02:00
Stéphane Tailland 80a2a27ca9 Stop versioning the real secret.yaml
k8s/secret.yaml held the actual PostgreSQL password, Keycloak admin
password and OIDC client secrets, and .gitignore only covered .DS_Store
and *.tmp. Untrack it and ignore it, matching what infra-librechat already
does, and extend the ignore list to TLS key material.

kustomization.yaml still references the file, so the README now documents
creating it from secret.example.yaml — whose key set is identical — before
the first apply.

This only stops future leaks. The values remain in commit 6d3431c and on
the remote, so they must still be treated as compromised and rotated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 07:30:20 +02:00
Stéphane Tailland 01d2082f3b Send traces to Tempo and expose metrics to Prometheus
Point the OTel Java agent at Tempo instead of Jaeger, so Keycloak's traces
land in the same backend as the rest of the stack and correlate with the
Loki logs of the same requests.

Annotate the pod for scraping. KC_METRICS_ENABLED already served /metrics
on the management port, so this only makes Prometheus discover it — on
port 9000, never on the application port.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 07:27:14 +02:00
Stéphane Tailland aac85b2f7a Update of classic models realm config 2026-08-23 17:22:57 +02:00
Stéphane Tailland cf456f10a1 fix(realm): Persist client secret and realm CaC 2026-08-23 15:54:16 +02:00
Stéphane Tailland d5242f68ca fix(secrets): Update kong-token-exchange-broker secret to match Vault/ExternalSecret 2026-08-23 08:05:23 +02:00
Stéphane Tailland b9287761bf feat(telemetry): Enable OpenTelemetry distributed tracing and JSON logging with MDC 2026-08-23 07:45:23 +02:00
Stéphane Tailland 08200a7df0 feat(k8s): Add Keycloak 26.6.0 with PostgreSQL 16 and classic-models realm CaC 2026-08-23 07:40:40 +02:00
16 changed files with 623 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
.DS_Store
*.tmp
# Real secrets: only secret.example.yaml is versioned.
# k8s/kustomization.yaml still references secret.yaml, so a fresh clone must
# create it first — see README.
k8s/secret.yaml
# TLS material
*.crt
*.key
*.pem
+59
View File
@@ -0,0 +1,59 @@
# Infra Keycloak (Kubernetes / CaC)
Déploiement de **Keycloak 26.6.0** et **PostgreSQL 16** en Configuration-as-Code (CaC) sous Kubernetes dans le namespace `keycloak`.
## Structure du Répertoire
```text
k8s/
├── kustomization.yaml # Manifeste Kustomize principal
├── namespace.yaml # Namespace keycloak
├── secret.yaml # Secrets (Admin, DB, OIDC secrets)
├── secret.example.yaml # Gabarit des secrets
├── postgresql/
│ ├── pvc.yaml # Stockage persistant PostgreSQL (2Gi)
│ ├── statefulset.yaml # Base de données PostgreSQL 16
│ └── service.yaml # Service PostgreSQL (port 5432)
├── keycloak/
│ ├── configmap-realm.yaml # Realm classic-models (Configuration-as-Code)
│ ├── deployment.yaml # Déploiement Keycloak 26.6.0 (--import-realm)
│ └── service.yaml # Service Keycloak (ports 8080, 9000)
└── ingress/
├── tls.yaml # Secret TLS wildcard (*.sttlab.local)
└── ingress.yaml # Ingress NGINX (keycloak.sttlab.local)
```
## Fonctionnalités Clés
- **Version Keycloak** : `quay.io/keycloak/keycloak:26.6.0` (Runtime Quarkus).
- **Import Automatique du Realm (CaC)** : Le realm `classic-models` est chargé au démarrage via l'option `--import-realm` depuis le `ConfigMap` monté dans `/opt/keycloak/data/import/`.
- **Token Exchange RFC 8693** : Activé via `KC_FEATURES: "token-exchange,admin-fine-grained-authz"`.
- **Clients Configurés** :
- `librechat` : Client OIDC pour le login et le flux OAuth MCP.
- `mcp-catalog` : Audience du serveur MCP.
- `kong-token-exchange-broker` : Échangeur de jetons RFC 8693 de Kong Gateway.
- `catalog-api` & `classic-models-api` : Audiences des services backend.
- **Utilisateurs & Rôles** :
- `admin-user` (`admin`)
- `pm-user` (`product_manager`)
- `ro-user` (`read_only`)
- `customer-user` (`customer`)
- `support-user` (`support`)
## Déploiement
`k8s/secret.yaml` n'est pas versionné : il porte les mots de passe réels (base
PostgreSQL, admin Keycloak, secrets clients OIDC). Le créer une fois depuis le
gabarit, puis renseigner chaque `<CHANGE_ME>` :
```bash
cp k8s/secret.example.yaml k8s/secret.yaml
$EDITOR k8s/secret.yaml
```
`k8s/kustomization.yaml` le référence, donc le déploiement échoue tant qu'il
est absent.
```bash
kubectl apply -k k8s/
```
+30
View File
@@ -0,0 +1,30 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: keycloak
namespace: keycloak
annotations:
nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"
nginx.ingress.kubernetes.io/proxy-busy-buffers-size: "256k"
nginx.ingress.kubernetes.io/proxy-body-size: "20m"
nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
spec:
ingressClassName: nginx
tls:
- hosts:
- keycloak.sttlab.local
secretName: keycloak-tls
rules:
- host: keycloak.sttlab.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: keycloak
port:
number: 8080
+9
View File
@@ -0,0 +1,9 @@
apiVersion: v1
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURQRENDQWlTZ0F3SUJBZ0lVZC91dERmK2YweVFSM3YzcVRqWnF4K3d2VFpNd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0dURVhNQlVHQTFVRUF3d09LaTV6ZEhSc1lXSXViRzlqWVd3d0hoY05NalV4TVRJME1UVXpPRFExV2hjTgpNall4TVRJME1UVXpPRFExV2pBWk1SY3dGUVlEVlFRRERBNHFMbk4wZEd4aFlpNXNiMk5oYk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mJyMXlvaDh0TEZpM3hYZXdvQkpleHc0bU14MTNXQXhkcW42a0ZtaGF5WnZsT2NteklmVTVCbkkKUUEyQWd5MmV0dU1vTUhLaGdQVm5vRis0bExqRXozRHRXcUJLcU9rQ2dZQlN6SHo3N1RkR0pRUVVMajJRVUFDOQozSXlaaXJmL0k4YnhPSnZrQnA3dktWODcxdHJmQXBaMDQwWDhIb1ZwZUErdjVZM3N4WkNKbUhwclhMNXZ1T1NaCnJoaHVvbTZuNHhUMi9qa2YybnR5c0UveFZGQUVrS2hVNEZISXNPR091V21YSWlSSzFLa2hJQXFhNzVBeVhESU4KdEVycWpTaGtFNHArdkQ0T0QzSmNqZz09Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
kind: Secret
metadata:
name: keycloak-tls
namespace: keycloak
type: kubernetes.io/tls
File diff suppressed because one or more lines are too long
+288
View File
@@ -0,0 +1,288 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: keycloak
namespace: keycloak
labels:
app.kubernetes.io/name: keycloak
app.kubernetes.io/component: idp
app.kubernetes.io/part-of: keycloak
spec:
replicas: 1
selector:
matchLabels:
app: keycloak
template:
metadata:
labels:
app: keycloak
app.kubernetes.io/name: keycloak
app.kubernetes.io/component: idp
app.kubernetes.io/part-of: keycloak
annotations:
# Discovered by the Prometheus in the observability namespace.
# Endpoint exposed by KC_METRICS_ENABLED=true, on the management
# port (9000), never on the application port.
prometheus.io/scrape: "true"
prometheus.io/port: "9000"
prometheus.io/path: "/metrics"
spec:
initContainers:
# Re-imports the realm from configmap-realm.yaml on every start, so that
# file is the source of truth rather than a first-install seed.
#
# It has to be a separate command: `start --import-realm` skips a realm
# that already exists and there is no option to change that — the
# --override flag exists only on the standalone `import` command. With
# the default behaviour, editing the ConfigMap changed nothing on a
# restart and the truth drifted into the database. It already had: four
# scope grants existed only in the running realm.
#
# What this costs, deliberately: the realm is replaced at every start,
# so anything created at runtime and not written back to the file is
# lost, and active sessions are dropped. Users survive only because they
# are declared in the file. Create nothing through the admin console
# expecting it to last.
- name: import-realm
image: quay.io/keycloak/keycloak:26.6.0
args:
- "import"
- "--dir"
- "/opt/keycloak/data/import"
- "--override"
- "true"
env:
- name: KC_DB
value: "postgres"
- name: KC_DB_URL_HOST
value: "keycloak-postgresql"
- name: KC_DB_URL_PORT
value: "5432"
- name: KC_DB_URL_DATABASE
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: POSTGRES_DB
- name: KC_DB_USERNAME
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_DB_USERNAME
- name: KC_DB_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_DB_PASSWORD
- name: KC_BOOTSTRAP_ADMIN_USERNAME
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_BOOTSTRAP_ADMIN_USERNAME
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_BOOTSTRAP_ADMIN_PASSWORD
- name: KEYCLOAK_ADMIN
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KEYCLOAK_ADMIN
- name: KEYCLOAK_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KEYCLOAK_ADMIN_PASSWORD
- name: KC_HTTP_ENABLED
value: "true"
- name: KC_PROXY_HEADERS
value: "xforwarded"
- name: KC_HOSTNAME
value: "https://keycloak.sttlab.local"
- name: KC_HOSTNAME_STRICT
value: "false"
- name: KC_HOSTNAME_BACKCHANNEL_DYNAMIC
value: "false"
- name: KC_FEATURES
value: "token-exchange,admin-fine-grained-authz,log-mdc"
# Emptied for this container only: it inherits the main container's env,
# which loads the OpenTelemetry agent from a volume the other init
# container downloads into and this one does not mount. Inheriting it
# verbatim fails the JVM before the import runs.
- name: JAVA_OPTS_APPEND
value: ""
- name: OTEL_SERVICE_NAME
value: "keycloak"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://tempo.observability.svc.cluster.local:4318"
- name: OTEL_EXPORTER_OTLP_PROTOCOL
value: "http/protobuf"
- name: OTEL_TRACES_EXPORTER
value: "otlp"
- name: OTEL_METRICS_EXPORTER
value: "none"
- name: OTEL_LOGS_EXPORTER
value: "none"
- name: KC_HTTP_ACCESS_LOG_ENABLED
value: "true"
- name: KC_LOG_LEVEL
value: "INFO,org.keycloak.events:DEBUG"
- name: KC_LOG_CONSOLE_OUTPUT
value: "json"
- name: KC_LOG_MDC_ENABLED
value: "true"
- name: KC_LOG_SERVICE_NAME
value: "keycloak"
- name: KC_LOG_SERVICE_ENVIRONMENT
value: "local"
- name: KC_HEALTH_ENABLED
value: "true"
- name: KC_METRICS_ENABLED
value: "true"
volumeMounts:
- name: realm-import
mountPath: /opt/keycloak/data/import
envFrom:
# Supplies the ${KC_SECRET_*} and ${KC_USER_*} placeholders the realm
# file carries in place of the values it used to hold in clear.
# Keycloak resolves them from the environment at import time.
- secretRef:
name: keycloak-realm-secrets
- name: download-otel-agent
image: curlimages/curl:8.10.0
command:
- "sh"
- "-c"
- "curl -sSL -o /otel/opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.31.0/opentelemetry-javaagent.jar"
volumeMounts:
- name: otel-agent
mountPath: /otel
containers:
- name: keycloak
image: quay.io/keycloak/keycloak:26.6.0
args:
- "start"
ports:
- name: http
containerPort: 8080
- name: https
containerPort: 8443
- name: management
containerPort: 9000
env:
- name: KC_DB
value: "postgres"
- name: KC_DB_URL_HOST
value: "keycloak-postgresql"
- name: KC_DB_URL_PORT
value: "5432"
- name: KC_DB_URL_DATABASE
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: POSTGRES_DB
- name: KC_DB_USERNAME
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_DB_USERNAME
- name: KC_DB_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_DB_PASSWORD
- name: KC_BOOTSTRAP_ADMIN_USERNAME
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_BOOTSTRAP_ADMIN_USERNAME
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KC_BOOTSTRAP_ADMIN_PASSWORD
- name: KEYCLOAK_ADMIN
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KEYCLOAK_ADMIN
- name: KEYCLOAK_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: KEYCLOAK_ADMIN_PASSWORD
- name: KC_HTTP_ENABLED
value: "true"
- name: KC_PROXY_HEADERS
value: "xforwarded"
- name: KC_HOSTNAME
value: "https://keycloak.sttlab.local"
- name: KC_HOSTNAME_STRICT
value: "false"
- name: KC_HOSTNAME_BACKCHANNEL_DYNAMIC
value: "false"
- name: KC_FEATURES
value: "token-exchange,admin-fine-grained-authz,log-mdc"
- name: JAVA_OPTS_APPEND
value: "-javaagent:/otel/opentelemetry-javaagent.jar"
- name: OTEL_SERVICE_NAME
value: "keycloak"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://tempo.observability.svc.cluster.local:4318"
- name: OTEL_EXPORTER_OTLP_PROTOCOL
value: "http/protobuf"
- name: OTEL_TRACES_EXPORTER
value: "otlp"
- name: OTEL_METRICS_EXPORTER
value: "none"
- name: OTEL_LOGS_EXPORTER
value: "none"
- name: KC_HTTP_ACCESS_LOG_ENABLED
value: "true"
- name: KC_LOG_LEVEL
value: "INFO,org.keycloak.events:DEBUG"
- name: KC_LOG_CONSOLE_OUTPUT
value: "json"
- name: KC_LOG_MDC_ENABLED
value: "true"
- name: KC_LOG_SERVICE_NAME
value: "keycloak"
- name: KC_LOG_SERVICE_ENVIRONMENT
value: "local"
- name: KC_HEALTH_ENABLED
value: "true"
- name: KC_METRICS_ENABLED
value: "true"
readinessProbe:
httpGet:
path: /health/ready
port: 9000
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 5
livenessProbe:
httpGet:
path: /health/live
port: 9000
initialDelaySeconds: 30
periodSeconds: 15
failureThreshold: 5
resources:
requests:
cpu: 500m
memory: 1024Mi
limits:
cpu: 2000m
memory: 2048Mi
volumeMounts:
- name: realm-import
mountPath: /opt/keycloak/data/import
readOnly: true
- name: otel-agent
mountPath: /otel
volumes:
- name: realm-import
configMap:
name: keycloak-realm-classic-models
- name: otel-agent
emptyDir: {}
+19
View File
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: keycloak
namespace: keycloak
labels:
app.kubernetes.io/name: keycloak
app.kubernetes.io/component: idp
app.kubernetes.io/part-of: keycloak
spec:
ports:
- name: http
port: 8080
targetPort: 8080
- name: management
port: 9000
targetPort: 9000
selector:
app: keycloak
+15
View File
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- secrets
- namespace.yaml
- secret.yaml
- postgresql/pvc.yaml
- postgresql/statefulset.yaml
- postgresql/service.yaml
- keycloak/configmap-realm.yaml
- keycloak/deployment.yaml
- keycloak/service.yaml
- ingress/tls.yaml
- ingress/ingress.yaml
+4
View File
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: keycloak
+11
View File
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgresql-data
namespace: keycloak
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
+16
View File
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: keycloak-postgresql
namespace: keycloak
labels:
app.kubernetes.io/name: postgresql
app.kubernetes.io/component: database
app.kubernetes.io/part-of: keycloak
spec:
ports:
- port: 5432
targetPort: 5432
name: postgresql
selector:
app: keycloak-postgresql
+61
View File
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: keycloak-postgresql
namespace: keycloak
labels:
app.kubernetes.io/name: postgresql
app.kubernetes.io/component: database
app.kubernetes.io/part-of: keycloak
spec:
serviceName: keycloak-postgresql
replicas: 1
selector:
matchLabels:
app: keycloak-postgresql
template:
metadata:
labels:
app: keycloak-postgresql
app.kubernetes.io/name: postgresql
app.kubernetes.io/component: database
app.kubernetes.io/part-of: keycloak
spec:
containers:
- name: postgresql
image: postgres:16-alpine
ports:
- containerPort: 5432
name: postgresql
env:
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: POSTGRES_DB
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: keycloak-secrets
key: POSTGRES_PASSWORD
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
volumes:
- name: data
persistentVolumeClaim:
claimName: postgresql-data
+19
View File
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Secret
metadata:
name: keycloak-secrets
namespace: keycloak
type: Opaque
stringData:
POSTGRES_USER: keycloak
POSTGRES_PASSWORD: <CHANGE_ME>
POSTGRES_DB: keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: <CHANGE_ME>
KC_BOOTSTRAP_ADMIN_USERNAME: admin
KC_BOOTSTRAP_ADMIN_PASSWORD: <CHANGE_ME>
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: <CHANGE_ME>
LIBRECHAT_OIDC_SECRET: <CHANGE_ME>
CLIENT_SECRET: <CHANGE_ME>
USER_PASSWORD: <CHANGE_ME>
+33
View File
@@ -0,0 +1,33 @@
# Reads secrets/keycloak/* from Vault. A store of its own rather than reusing
# vault-kong-v2 or vault-observability: each carries a policy scoped to its own
# path, so a reader for one estate cannot see another's. Widening an existing
# policy would have handed Kong's reader every client secret in the realm.
#
# The AppRole credentials are NOT in git. Created once against Vault:
# vault policy write keycloak-readonly (read on secrets/{data,metadata}/keycloak/*)
# vault write auth/approle/role/keycloak-eso token_policies=keycloak-readonly
# vault read auth/approle/role/keycloak-eso/role-id
# vault write -f auth/approle/role/keycloak-eso/secret-id
# kubectl -n external-secrets create secret generic vault-approle-keycloak \
# --from-literal=roleId=<...> --from-literal=secretId=<...>
apiVersion: external-secrets.io/v1
kind: ClusterSecretStore
metadata:
name: vault-keycloak
spec:
provider:
vault:
server: https://vault.sttlab.eu
path: secrets
version: v2
auth:
appRole:
path: approle
roleRef:
name: vault-approle-keycloak
namespace: external-secrets
key: roleId
secretRef:
name: vault-approle-keycloak
namespace: external-secrets
key: secretId
+31
View File
@@ -0,0 +1,31 @@
# The client secrets and user passwords the realm file used to carry in clear.
# Keycloak resolves ${PLACEHOLDER} in a realm import file from the environment,
# so the file keeps the structure and this Secret supplies the values.
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: keycloak-realm-secrets
namespace: keycloak
spec:
refreshInterval: 1h
secretStoreRef:
kind: ClusterSecretStore
name: vault-keycloak
target:
name: keycloak-realm-secrets
creationPolicy: Owner
dataFrom:
# Whole-path pull: adding a client in the realm means adding its secret in
# Vault, with no edit here.
- extract:
key: keycloak/classic-models-realm
data:
# The token-exchange broker was renamed to drop the middleware's name from
# a contract every agent has to repeat. The Vault property still carries the
# old name — renaming it there means re-issuing the value to every gateway
# that holds a copy — so it is mapped here instead. Same secret, neutral
# name everywhere the cluster can see.
- secretKey: KC_SECRET_TOKEN_EXCHANGE_BROKER
remoteRef:
key: keycloak/classic-models-realm
property: KC_SECRET_KONG_TOKEN_EXCHANGE_BROKER
+5
View File
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- clustersecretstore.yaml
- externalsecret-realm.yaml