feat: Keycloak: Delegate user authentication to Keycloak (keep camera auth unchanged)
Maintainers usually reply within 7 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with get_jwt, get_current_user, and TokenPayload, then trace POST /login/creds and the protected user routes. Done means user tokens are validated through Keycloak while camera tokens and /cameras/{id}/token remain unchanged, migration and client updates are covered, and the users table and obsolete login routes are removed.
Written by the indexing model from the issue text.
Description
Part of the epic pyronear/roadmap#23 (Keycloak).
Context & objective
We want to move user authentication to a Keycloak service (SSO, user management, password policies, MFA…).
This will be done in steps: this issue covers user authentication only. Camera authentication must keep working as is.
Follow-up: camera authentication via Keycloak (#699 ).
What is done currently
- Users are stored in the
userstable (login, bcrypt password, role,organization_id). No other table references it. - Users log in via
POST /login/credsand receive an API-signed JWT (JWT_SECRET, HS256). - Routes are protected by
get_jwt/get_current_user, using scopes (admin,agent,user,camera) andorganization_idfrom the token. - Camera tokens are issued separately via
POST /cameras/{id}/token(same JWT mechanism,camerascope). GET /login/validateisn't used by any client.
What has to be done
- Validate Keycloak-issued tokens for user routes (realm JWKS) and map claims →
TokenPayload(sub, roles → scopes,organization_id). - Move users to Keycloak: role and
organization_idheld there (roles / attribute or group). - Throwaway script for a one-shot manual migration of existing users.
- Remove the
userstable,/usersroutes,/login/credsand/login/validate. - Keep API-issued camera tokens (
/cameras/{id}/token) working, with no change on devices. - Update clients currently using
/login/creds:new-pyro-platform,pyro-envdevinit scripts,pyro-annotatoringestion client (→ Keycloak service account).
Technical considerations
- During this step the API receives two kinds of tokens: Keycloak-signed (users, verified with the realm public keys) and API-signed (cameras, verified with
JWT_SECRET). Read the token'sissclaim to pick the right verification. TokenPayload.subis typedint, but a Keycloak usersubis a UUID string. Allow both, or split user and camera payloads (for cameras,subis still used ascamera_id, e.g. inposes.py).- User management (create, roles, org) is done in Keycloak from now on.
- Dev & e2e: rely on the Keycloak service in
pyro-envdev(pyronear/pyro-envdev#45). Keycloak deployment on prod is out of scope. - Keep the issuer dispatch simple and isolated, so that the API-issued path can be dropped once cameras are migrated.
- Dominant language
- Python
- Stars
- 31
- Forks
- 15
- Avg merge
- 7d 18h
- Merged PRs (30d)
- 17
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pyronear/pyro-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 7 days
-
endpoint: detections type: fix
Difficulty 4/5 1-2 days Newbie friendliness 68/100
Maintainers usually reply within 7 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 7 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 7 days
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
Maintainers usually reply within 7 days
All issues in pyronear/pyro-api
Similar issues
-
area: ci enhancement perceived difficulty: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Nitjsefnie-Harness-Commons/daedalus#1826 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vllm-project/vllm-sail#398 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DiamondLightSource/sm-bluesky#476 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100