Add Keycloak OIDC auth middleware with tenant-scoped access control #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Repo
forgejo_admin/minio-apiLineage
plan-minio-mobile→ Phase 2 → Phase 2b (Keycloak Auth + Tenant Scoping)User Story
As a platform admin
I want all API requests authenticated via Keycloak tokens
So that only authorized users can access MinIO assets, scoped to their project
As a project stakeholder
I want to see only my project's files when I hit the API
So that I can't accidentally (or intentionally) access other projects' assets
Context
Phase 2a shipped the FastAPI service with 15 REST endpoints and no auth. This phase adds Keycloak OIDC token validation and tenant-scoped access control. After this, every request requires a valid Bearer token and stakeholders are restricted to their project prefix.
The Keycloak instance is at
keycloak.tail5b443a.ts.net. Check what realms, clients, and groups already exist before creating new ones — Keycloak has built-in admin and account consoles.Key decisions:
westsidemaps to MinIO prefixassets/westside/File Targets
Files to create:
src/minio_api/auth.py— Keycloak OIDC middleware: JWKS fetching, JWT validation, role/group extraction, tenant contextsrc/minio_api/permissions.py— access control logic:is_admin(),get_allowed_prefix(),check_access()tests/test_auth.py— unit tests with mock JWTs (no Keycloak needed)tests/test_permissions.py— unit tests for access control logicFiles to modify:
src/minio_api/main.py— add auth middleware, configure Keycloak settingssrc/minio_api/routes/buckets.py— inject auth dependency, scope bucket list for stakeholderssrc/minio_api/routes/objects.py— inject auth dependency, scope prefix, block delete for stakeholderssrc/minio_api/routes/presign.py— inject auth dependency, scope presigned URLs to allowed prefixsrc/minio_api/routes/multipart.py— inject auth dependency, scope multipart to allowed prefixsrc/minio_api/dependencies.py— add auth dependency (current user from token)Files NOT to touch:
src/minio_sdk/— SDK is a separate repo/packageAcceptance Criteria
assetsbucket, scoped to their group prefixAUTH_DISABLED=trueskips validation)Test Expectations
AUTH_DISABLED=truepytest tests/ -vConstraints
https://keycloak.tail5b443a.ts.net/realms/{realm}/protocol/openid-connect/certsminio-mobileclient if neededAUTH_DISABLED=trueenv var must bypass all auth for local dev and existing testscurrent_user = Depends(get_current_user)Checklist
Related
phase-minio-mobile-2b-keycloak-auth— phase notephase-minio-mobile-2a-fastapi-routes— prerequisite (completed)project-minio-mobile— project this advances