Summary
This PR fixes multiple issues that prevented admin users from creating clubs:
Changes
1. Fixed RLS Permission Issue in Tests
Added BYPASSRLS privilege to app_admin role
Granted full schema and table access to app_admin
Allow rls_test_user to assume app_admin role
2. Fixed JWT Validation
Added custom IssuerSigningKeyResolver to fetch JWKS from internal Keycloak URL
Configured MetadataAddress for Docker internal communication
Fixed middleware order: Authentication before TenantValidation
Added CORS configuration for frontend requests
3. Fixed Admin Authorization
Properly parse realm_access claim as JSON (not string contains)
Fixed RequireGlobalAdmin policy, TenantValidationMiddleware, and ClubRoleClaimsTransformation
4. Frontend Changes
Added .env.local with correct API URL
Updated displays to show member names instead of UUIDs
Testing
All 63 backend tests passing
Admin can now create clubs via UI
JWT tokens validated correctly
Summary
This PR fixes multiple issues that prevented admin users from creating clubs:
## Changes
### 1. Fixed RLS Permission Issue in Tests
- Added BYPASSRLS privilege to app_admin role
- Granted full schema and table access to app_admin
- Allow rls_test_user to assume app_admin role
### 2. Fixed JWT Validation
- Added custom IssuerSigningKeyResolver to fetch JWKS from internal Keycloak URL
- Configured MetadataAddress for Docker internal communication
- Fixed middleware order: Authentication before TenantValidation
- Added CORS configuration for frontend requests
### 3. Fixed Admin Authorization
- Properly parse realm_access claim as JSON (not string contains)
- Fixed RequireGlobalAdmin policy, TenantValidationMiddleware, and ClubRoleClaimsTransformation
### 4. Frontend Changes
- Added .env.local with correct API URL
- Updated displays to show member names instead of UUIDs
## Testing
- All 63 backend tests passing
- Admin can now create clubs via UI
- JWT tokens validated correctly
- Add BYPASSRLS privilege to app_admin role
- Grant full schema and table access to app_admin
- Allow rls_test_user to assume app_admin role
- Fixes: permission denied for table clubs (42501)
The realm_access claim in JWT is a JSON object, not a simple string.
Previous string contains check was looking for escaped quotes in wrong format.
- Parse realm_access as JSON to extract roles array
- Check if 'admin' exists in roles array
- Fallback to string contains check if JSON parsing fails
- Applied fix in RequireGlobalAdmin policy, TenantValidationMiddleware,
and ClubRoleClaimsTransformation
Fixes: Admin users getting 401 when trying to create clubs
- Add CORS policy to allow frontend requests from localhost:3000
- Exempt /api/debug endpoints from tenant validation
- Fix JSON parsing in realm_access claim checks
- Added JWT authentication event logging to diagnose validation failures
- Fixed docker-compose networking for API to reach Keycloak via hostname
- Debug endpoint now accessible without auth for troubleshooting
- Still investigating why claims are not populated despite token being present
The JWT middleware needs to fetch signing keys from Keycloak before
tenant validation runs. The previous order caused signature validation
to fail because the middleware was blocking the JWKS endpoint requests.
- Moved Authentication before TenantValidationMiddleware
- Removed realm endpoint from exemption list (not needed with correct order)
- This allows JWT middleware to fetch signing keys and validate tokens
- Add MetadataAddress configuration to JWT middleware for internal Docker URLs
- Add KC_HOSTNAME_ADMIN and KC_SPI_HOSTNAME_DEFAULT_ADMIN to Keycloak env
- This ensures API can fetch JWKS from Keycloak via internal Docker network
- Tests passing: 63/63
- Added IssuerSigningKeyResolver to fetch JWKS directly from internal Keycloak URL
- This bypasses the localhost:8080 URLs in Keycloak's discovery document
- Ensures JWT tokens are validated against correct signing keys
The test was expecting Forbidden when no tenant context is provided,
but the middleware actually returns BadRequest when X-Tenant-Id header
is missing. Updated the test and added GetClubsCurrent_InvalidTenant_ReturnsForbidden
to properly test the Forbidden case.
MasterMito
merged commit 984ab77137 into epic/admin_rework_second_try2026-03-20 11:42:05 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
This PR fixes multiple issues that prevented admin users from creating clubs:
Changes
1. Fixed RLS Permission Issue in Tests
2. Fixed JWT Validation
3. Fixed Admin Authorization
4. Frontend Changes
Testing