feat: local Keycloak mock for SmartEM frontend dev#198
Open
vredchenko wants to merge 1 commit into
Open
Conversation
The smartem-frontend Keycloak integration currently has no local
development story — every dev needs `http://localhost:5173` added to
the SmartEM client's Valid Redirect URIs and Web Origins on
`identity-test.diamond.ac.uk`, which is an admin round-trip that has
to be repeated for every new port and every new developer.
A self-contained mock removes that dependency:
- `dls-realm.json` is the single source of truth — realm `dls`,
public client `SmartEM` with PKCE, localhost redirect URIs and
Web Origins, custom `fedId` claim mapper, two seeded users.
- Compose form for the fastest standalone cycle.
- Kustomize form integrated into the existing development overlay,
so `dev-k8s.sh up` now brings up Keycloak alongside the rest of
the stack.
Both forms read the same realm JSON, so editing it once propagates
to whichever form a developer prefers.
The architecture doc gains a "Local development" pointer and the
client-name discrepancy (`smartem-frontend` vs `SmartEM`) is
corrected to match the actual implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The SmartEM frontend Keycloak integration in
smartem-frontendPR #74 currently has no local development story. Out of the box,npm run dev:smartemfails becausehttp://localhost:5173isn't in theSmartEMclient's Valid Redirect URIs or Web Origins onidentity-test.diamond.ac.uk— and getting those entries added is an admin round-trip that has to be repeated for every new dev port and every new developer.This PR adds a self-contained Keycloak mock so the frontend team can develop and test the auth flow locally with no external dependencies, no shared identity-server config, and no permission round-trips.
What's included
keycloak-mock/— a self-contained mock with two equivalent deployment forms, both reading from one realm export:dls-realm.json— single source of truth. Realmdls, public clientSmartEMwith PKCE S256, localhost redirect URIs and Web Origins, customfedIdclaim mapper to mirror DLS realm claims, two seeded users.docker-compose.yml— Compose form, fastest standalone cycle.keycloak.yaml+kustomization.yaml— Kubernetes Deployment + Services + kustomizeconfigMapGeneratorfor the realm JSON.The Kustomize form is wired into the existing development overlay via
k8s/environments/development/kustomization.yaml, so./scripts/k8s/dev-k8s.sh upnow brings up Keycloak alongside Postgres, RabbitMQ, etc. The Compose form is independent and useful for frontend devs who don't want the rest of the dev stack running.Both forms read the same
dls-realm.json, so realm edits propagate to whichever form a developer is using.Docs
docs/development/local-keycloak.md— full how-to (when to use which form, how to point the frontend at it, how to edit the realm, limits and non-goals).docs/development/index.md— added to the TOC.docs/architecture/keycloak-spa-authentication.md— added a "Local development" pointer; corrected thesmartem-frontend→SmartEMclient-name discrepancy that existed in the doc but didn't match the implementation.Quick start
Then in
smartem-frontend/apps/smartem/.env.local:Log in as
devuser/devpass(orvaluser/valpass).Companion review
While building this I exercised the full auth flow end-to-end against the mock and uncovered two issues in
smartem-frontendPR #74 that are independent of this change: an init-failure bug inAuthProviderthat bricks the login button, and acheck-ssoredirect storm caused by missingsilentCheckSsoRedirectUri. Details and suggested fixes are in a review comment on that PR.Test plan
kubectl kustomize keycloak-mockbuilds cleanlykubectl kustomize k8s/environments/developmentbuilds cleanly with Keycloak resources includeddocker compose up -dinkeycloak-mock/imports thedlsrealm and exposes admin console athttp://localhost:8080./scripts/k8s/dev-k8s.sh upbrings Keycloak up alongside the rest of the stack, reachable athttp://<node-ip>:30080smartem-frontendPR Add app config #74 with the suggested AuthProvider fixes applied) successfully logs in via the mock and the account menu shows the user identity