Repository navigation
Conversation
- pyro-api client scope: adds pyro-api to aud and the realm roles as a top-level roles claim - pyro-organization claim renamed to organization_id, which avoids Keycloak's built-in Organizations claim - new-pyro-platform gets both scopes by default - pyro-api confidential client, used by the API to introspect tokens - pyro-scripts service account (admin, org 1, 10h tokens) for the init script and notebooks - test-admin user (admin, org 1)
…and scripts - Keycloak leaves the tools profile, pins its issuer with KC_HOSTNAME and reports readiness from /health/ready - pyro_api gets KEYCLOAK_ISSUER, the backchannel URL and the pyro-api client secret - init_script and notebooks get the pyro-scripts credentials, with defaults for .env files created before Keycloak
The init script and notebooks use client credentials instead of logging in with the superadmin password. The notebooks' legacy get_token stays for local scripts while pyro-api still accepts API-issued user tokens.
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.
Stacked on #45. Makes the Keycloak realm from #45 usable by pyro-api, and moves the init script and notebooks off the superadmin password.
Needs the pyro-api Keycloak support (pyronear/pyro-api#728) to verify tokens. Until a release ships it, build the API image from that branch (
make build-external).Demo
Recorded against this stack with pyronear/pyro-api#728 and pyronear/new-pyro-platform#295. The bottom panel is a network log the recording script draws from the Chrome DevTools Protocol, since Chrome's own DevTools can't be captured in a headless recording.
Platform login through the realm: the redirect to the themed Keycloak login, the token with
aud: pyro-api, top-levelrolesandorganization_id, then the platform's API calls with that token (organization 2's cameras only). The firstGET /alerts/unlabeled/latestgets a 401 because the platform sends it before attaching the token, a race in #295.keycloak-platform-demo.mp4
Revocation through the
pyro-apiclient:GET /login/validatewith test77's token returns 200. An admin then signs test77 out in Keycloak, and the API's introspection call (as thepyro-apiclient) turns the same unexpired token into a 401.keycloak-api-demo.mp4
Realm
pyro-apiclient scope: addspyro-apitoaudand the realm roles as a top-levelrolesclaim, which the platform PR already reads.pyro-organizationclaim is renamed fromorganizationtoorganization_id.organizationis the claim Keycloak's built-in Organizations feature writes, and that scope is already optional on the platform client.new-pyro-platformgets both scopes by default.pyro-apiclient with every login flow off. The API authenticates as it to introspect each token, so a revoked session fails on its next request.pyro-scriptsservice account (realm roleadmin, org 1). Its tokens last 10 hours, the realm's session maximum, because the scripts fetch one token per run.test-adminuser (admin, org 1, passwordtest).Compose
toolsprofile, somake run-backendstarts it.KC_HOSTNAME=http://localhost:9310gives every token the same issuer whether it was requested from the browser or from a container onkeycloak:9310./health/readyon the management port. The old one grepped aserver.logthat Keycloak never writes, so it always reported unhealthy.pyro_apigetsKEYCLOAK_ISSUER,KEYCLOAK_BACKCHANNEL_URLand thepyro-apiclient secret.init_scriptandnotebooksget thepyro-scriptscredentials, with defaults so a.envcreated before Keycloak still works.init_scriptwaits for Keycloak to be healthy.Scripts
get_service_token()(client credentials) replaces the superadmin login in the init script and the five notebooks.get_token()stays for local scripts while pyro-api still accepts API-issued user tokens.How to test
docker compose up -d --force-recreate keycloak. The realm only imports into a new container.test77/test.init_script. It now authenticates through Keycloak.test77out from the Keycloak admin console (http://localhost:9310/admin/). The platform's next API call should get a 401.All secrets in the realm export are dev-only values.
Stack created with GitHub Stacks CLI • Give Feedback 💬