From 119adb623319337bf5914c67d0e5c912b7733a47 Mon Sep 17 00:00:00 2001 From: Chris Kucharczyk <23062974+chrisjkuch@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:09:39 +0000 Subject: [PATCH] Drop the Keycloak realm patch now that upstream defines kc-admin-api PhilanthropyDataCommons/service#2687 added the kc-admin-api scope and organization roles to the upstream realm. Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 2 +- just/patch_realm.py | 44 -------------------------------------------- just/pdc.just | 3 +-- 3 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 just/patch_realm.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 14909e1..8441df7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,7 @@ PYTHON=3.12 LOWEST_DIRECT=true just test -k token `uv.lock` pins the versions used for development and CI. Update it with `uv lock --upgrade`. CI also runs both suites weekly with `UPGRADE=true`, and opens an issue when that run or a push to main fails. -`just pdc up` downloads PDC's [`compose-ci.yml`](https://github.com/PhilanthropyDataCommons/service/blob/main/compose-ci.yml) and Keycloak realm from the service repo's main branch and starts the stack: the PDC API, Keycloak, Postgres, and S3. `just/patch_realm.py` adds the `kc-admin-api` scope the Keycloak sync needs, which the realm lacks; it warns once the realm defines it, and then should be deleted. CI starts the stack the same way. The integration tests reach Keycloak at `pdc-auth`, so add this line to `/etc/hosts`: +`just pdc up` downloads PDC's [`compose-ci.yml`](https://github.com/PhilanthropyDataCommons/service/blob/main/compose-ci.yml) and Keycloak realm from the service repo's main branch and starts the stack: the PDC API, Keycloak, Postgres, and S3. CI starts the stack the same way. The integration tests reach Keycloak at `pdc-auth`, so add this line to `/etc/hosts`: ```text 127.0.0.1 pdc-api pdc-auth pdc-s3 diff --git a/just/patch_realm.py b/just/patch_realm.py deleted file mode 100644 index eaad7ed..0000000 --- a/just/patch_realm.py +++ /dev/null @@ -1,44 +0,0 @@ -import json -import sys -from pathlib import Path - -ADMIN_API_SCOPE = { - "name": "kc-admin-api", - "description": "Grants access to the Keycloak Admin REST API by adding its required audience to the token", - "protocol": "openid-connect", - "attributes": {"include.in.token.scope": "true", "display.on.consent.screen": "false"}, - "protocolMappers": [ - { - "name": "admin-api-audience", - "protocol": "openid-connect", - "protocolMapper": "oidc-admin-api-audience-mapper", - "consentRequired": False, - "config": {"access.token.claim": "true", "introspection.token.claim": "true"}, - } - ], -} -ADMIN_API_CLIENTS = {"pdc-dev-ingest", "pdc-openapi-docs"} -ORGANIZATION_ROLES = ["query-organizations", "view-organizations", "manage-organizations"] - - -# Keycloak creates kc-admin-api for new and migrated realms but not imported ones; remove once service's realm.json defines it. -def add_admin_api_access(realm: dict) -> None: - realm["clientScopes"].append(ADMIN_API_SCOPE) - for client in realm["clients"]: - if client["clientId"] in ADMIN_API_CLIENTS: - client["optionalClientScopes"].append(ADMIN_API_SCOPE["name"]) - [admin_group] = [group for group in realm["groups"] if group["name"] == "pdc-admin"] - admin_group["clientRoles"]["realm-management"].extend(ORGANIZATION_ROLES) - - -def main(path: Path) -> None: - realm = json.loads(path.read_text()) - if any(scope["name"] == ADMIN_API_SCOPE["name"] for scope in realm["clientScopes"]): - print(f"warning: {path} already defines kc-admin-api; delete just/patch_realm.py", file=sys.stderr) - return - add_admin_api_access(realm) - path.write_text(json.dumps(realm, indent="\t") + "\n") - - -if __name__ == "__main__": - main(Path(sys.argv[1])) diff --git a/just/pdc.just b/just/pdc.just index c50ac79..91a5b40 100644 --- a/just/pdc.just +++ b/just/pdc.just @@ -9,12 +9,11 @@ compose := 'docker compose -f ' + cache + '/compose-ci.yml' _default: @just --list pdc --unsorted -# Fetch PDC's compose file and Keycloak realm, adding the admin API access the realm lacks +# Fetch PDC's compose file and Keycloak realm fetch: mkdir -p {{cache}}/keycloak curl -fsSL {{base}}/compose-ci.yml -o {{cache}}/compose-ci.yml curl -fsSL {{base}}/keycloak/realm.json -o {{cache}}/keycloak/realm.json - uv run --no-project python -I just/patch_realm.py {{cache}}/keycloak/realm.json # Start the stack and wait until it is healthy up: fetch