Skip to content

Commit 2f095b2

Browse files
authored
fix: pass OIDC default env vars to meridian container (#1259)
* feat: enable Dex OIDC authentication for demo environment Replace fake JWT workarounds with real Dex OIDC authentication. The backend now gracefully handles standard OIDC tokens by falling back to the sub claim for user ID and applying configurable defaults for tenant ID and roles when custom Meridian claims are absent. Backend: - Add Email/Name OIDC fields and EffectiveUserID() to Claims - Add DEFAULT_TENANT_ID and DEFAULT_ROLES env vars to gateway config - JWT middleware injects configured defaults for missing claims - Wire defaults through CombinedAuthMiddleware to JWTMiddleware Frontend: - parseJWT accepts standard OIDC tokens (sub fallback, array aud) - Login page with email/password form using Dex password grant - Dev-only fake JWT buttons preserved for local development - Demo mode defaults to platform lens for DevTenantAutoSelector Dex config: - Real bcrypt hashes for admin@volterra.energy and operator@volterra.energy - Password: demo2026 * fix: store effective claims object in context for platform-admin bypass TenantAuthorizationMiddleware checks claims.HasRole() on the Claims object stored in context. The previous approach stored default roles only as context values, making them invisible to the authorization check. Fix by creating a shallow copy of claims with effective values (UserID, TenantID, Roles) applied, then storing the copy in context. This ensures platform-admin default role is visible when DEFAULT_ROLES=platform-admin is configured with empty DEFAULT_TENANT_ID, enabling cross-tenant access for demo users. * fix: pass DEFAULT_TENANT_ID and DEFAULT_ROLES to meridian container These env vars were defined in .env but not listed in the docker-compose.yml environment section, so they were never passed to the container. Also update .env.demo.example to document the new vars and enable AUTH_ENABLED=true by default. * fix: trim whitespace from DEFAULT_TENANT_ID env var --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 0272d07 commit 2f095b2

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

deploy/demo/.env.demo.example

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ HTTP_PORT=8090
6868
# ---------------------------------------------------------------------------
6969

7070
# [OPTIONAL] Enable JWT authentication on the gateway.
71-
# Set to "false" for demo mode (API open, frontend uses local JWT for UI routing).
72-
# Set to "true" when Dex OIDC is fully configured with real credentials.
73-
AUTH_ENABLED=false
71+
# Set to "true" to require Dex OIDC tokens for API access.
72+
AUTH_ENABLED=true
7473

7574
# [OPTIONAL] JWKS endpoint for JWT validation.
7675
# Default points to the bundled Dex container.
@@ -92,14 +91,17 @@ JWKS_URL=http://dex:5556/dex/keys
9291
# Example: "sk_demo_abc123:demo-client,sk_test_def456:test-runner"
9392
#API_KEYS=
9493

94+
# [OPTIONAL] Default tenant ID injected into context when OIDC token lacks x-tenant-id.
95+
# Leave empty for platform-admin cross-tenant access (recommended for demo).
96+
#DEFAULT_TENANT_ID=
97+
98+
# [OPTIONAL] Comma-separated default roles injected when OIDC token lacks roles claim.
99+
# Set to "platform-admin" so demo Dex users get cross-tenant access.
100+
DEFAULT_ROLES=platform-admin
101+
95102
# [OPTIONAL] Gateway base domain for subdomain-based tenant resolution.
96103
BASE_DOMAIN=demo.meridianhub.cloud
97104

98-
# [OPTIONAL] Enable X-Tenant-Slug header for tenant resolution (dev/demo only).
99-
# When true, tenants can be identified via the X-Tenant-Slug HTTP header instead
100-
# of subdomain extraction. Must not be enabled in production namespaces.
101-
LOCAL_DEV_MODE=true
102-
103105
# ---------------------------------------------------------------------------
104106
# Billing
105107
# ---------------------------------------------------------------------------

deploy/demo/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ services:
8787
JWT_ISSUER: ${JWT_ISSUER:-}
8888
JWT_AUDIENCE: ${JWT_AUDIENCE:-}
8989
API_KEYS: ${API_KEYS:-}
90+
DEFAULT_TENANT_ID: ${DEFAULT_TENANT_ID:-}
91+
DEFAULT_ROLES: ${DEFAULT_ROLES:-}
9092
BASE_DOMAIN: ${BASE_DOMAIN:-demo.meridianhub.cloud}
9193
LOCAL_DEV_MODE: ${LOCAL_DEV_MODE:-false}
9294

services/gateway/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func LoadAuthConfig() AuthConfig {
266266
}
267267

268268
// Parse OIDC fallback defaults
269-
config.DefaultTenantID = os.Getenv("DEFAULT_TENANT_ID")
269+
config.DefaultTenantID = strings.TrimSpace(os.Getenv("DEFAULT_TENANT_ID"))
270270
config.DefaultRoles = env.GetEnvAsSlice("DEFAULT_ROLES", nil)
271271

272272
return config

0 commit comments

Comments
 (0)