Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #728 +/- ##
==========================================
+ Coverage 95.68% 95.77% +0.08%
==========================================
Files 65 66 +1
Lines 3685 3831 +146
==========================================
+ Hits 3526 3669 +143
- Misses 159 162 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
323b520 to
172b7e5
Compare
|
@ThbltLmr is this still in draft ? no rush just to organiez reviews :) |
It's ready for review! but the matching PRs on the dev env and the platform are still in draft, so I matched their status (the API PR should not be merged before the dev env side I assume) |
fe51
left a comment
There was a problem hiding this comment.
Hi @ThbltLmr, thanks a lot for thoses exciting changes
The approach is nice. I tested it locally with the envdev stack and the platform branch: Keycloak login, organization isolation and role restrictions all behave as expected.
What is blocking (and related to a branch recentrly merged after your last commit)
- The branch conflicts with main. The textual conflicts are trivial (main.py, imports and decode_token in dependencies.py).
-
After the rebase, POST /shares/ (pyronear/pyro-api#731) will break for Keycloak users: it stores created_by=token_payload.sub in an integer column with a foreign key to users.id, but a Keycloak sub is a UUID and the user has no row in users. Suggestion: make created_by a string holding the token subject, without the foreign key, and add a test creating a share with a Keycloak token.
Non-blocking
A single introspection or JWKS failure triggers a 10 s 503 for every Keycloak user of the process. Fine as a first version; we could later trip only after several consecutive failures.
To keep in mind for follow-ups
- Set LEGACY_USER_TOKENS_ENABLED=false in production once the remaining clients (envdev init script and ETL, notebooks, pyro-annotator) are migrated.
- Then rename agent / user to operator / viewer, and remove the users table and the /users and /login/creds endpoints.
-Move cameras to Keycloak. - organization_id comes from Keycloak and is not checked against the database; a realm admin is an API super-admin. Acceptable for now.
Reconstruct PR #728 on current main while retaining newer camera image cleanup, share functionality, and service shutdown handling. Store share creators as token subjects without a users foreign key. Add a data-preserving Alembic migration and regression coverage for Keycloak shares, legacy tokens, authorization, organization isolation, and migration round trips.
b2f8dfd to
de86cc4
Compare
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision: str = "a9c6d1e5f7b4" |
| from alembic import op | ||
|
|
||
| revision: str = "a9c6d1e5f7b4" | ||
| down_revision: Union[str, None] = "f8b5c0d4e6a3" |
|
|
||
| revision: str = "a9c6d1e5f7b4" | ||
| down_revision: Union[str, None] = "f8b5c0d4e6a3" | ||
| branch_labels: Union[str, Sequence[str], None] = None |
| revision: str = "a9c6d1e5f7b4" | ||
| down_revision: Union[str, None] = "f8b5c0d4e6a3" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None |
|
Thanks for the rework, 2 previous blocking points are addressed (rebuilt on main, created_by stored as the token subject with migration and tests). One new blocker, caused by pyronear/pyro-api#741 merged on main this morning: its migration a9c2e5f7b1d3 and the one in this PR (a9c6d1e5f7b4) both revise f8b5c0d4e6a3. Git sees no conflict, but Alembic ends up with two heads and alembic upgrade head fails at startup. Suggested fix:
I will be happy to approve once this is done :) |
admin/operator/viewerto API scopesadmin/agent/user, using theorganization_idclaim for organization access.LEGACY_USER_TOKENS_ENABLED=falserejects them and disables/login/credswith a 410./login/validatenow returns a stringsubandauth_source. Swagger authorization takes a pasted bearer token.Set
KEYCLOAK_ISSUERandKEYCLOAK_CLIENT_SECRETto enable Keycloak.KEYCLOAK_BACKCHANNEL_URLcan point to its internal Docker address.Tests cover token validation, role mapping, legacy compatibility, revocation and outage handling with mocked Keycloak responses. Local suite: 803 passed, 1 skipped. Logout was also checked against the envdev Keycloak.
Related: pyronear/new-pyro-platform#295, pyronear/pyro-envdev#68.
Demo
Keycloak token accepted by
/login/validate, then rejected after an admin logs the user out.keycloak-api-demo.mp4
Platform login through Keycloak and authenticated API calls. The initial 401 is a platform request sent without an Authorization header, tracked in pyronear/new-pyro-platform#295.
keycloak-platform-demo.mp4