Tutorial 6 of 6 · Authentication
Authentication & Tenant Isolation
Keycloak OIDC, NextAuth, Google OAuth broker, RLS policies, tenant schemas vs shared schema, and subaccount isolation.
Reference Architecture
Authentication Architecture
Browser → NextAuth → Keycloak OIDC (lca-dashboard client) └→ kc_idp_hint=google └→ Google OAuth └→ Keycloak broker callback └→ Keycloak session → NextAuth
Pre-Provisioned User Accounts
| Username | Password | Role | Access Level |
|---|---|---|---|
| admin | password | SuperAdmin | Full access, system overrides |
| auditor | password | ExternalAuditor | Read-only audit views |
| manager | password | SustainabilityManager | Carbon footprint logs |
Two Tenant Isolation Models
Daemon (lca-daemon)
Uses PostgreSQL tenant schemas. Each request sets search_path to "<client_id>, impact_analytics, ...".
SELECT set_config('app.current_tenant', :tenant_id, true)
Connector (lca-erp-connector)
Does NOT use tenant schemas. Uses tenant_id as a column in impact_analytics.sku_mappings. Isolation is row-level via the tenant_id column.
INSERT INTO impact_analytics.sku_mappings ... ON CONFLICT (tenant_id, sku)
RLS Access Matrix
| Tier | impact_analytics | ontology_graph | currency |
|---|---|---|---|
| Tier4_Enterprise | ALL via RLS | ALL via RLS | ALL via RLS |
| Tier3_Business | ALL via RLS | SELECT via RLS | — |
| Tier2_Professional | SELECT via RLS | — | — |
| Tier1_Starter | SELECT via RLS | — | — |
| Tier0_Free | SELECT via RLS | — | — |
Tenant is set per-request via SELECT set_config('app.current_tenant', :tenant_id, true); role via SELECT set_config('app.current_user_role', :role, true).
Keycloak OIDC & Google OAuth Broker
NextAuth talks to Keycloak as an OIDC provider with kc_idp_hint=google; Keycloak then redirects to Google using its own stored Google credentials.
http://localhost:8080/realms/lca-ecosystem/broker/google/endpoint
Copy Google Client ID and Secret into .env and dashboard/lca-dashboard/.env as GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. Wildcard redirect URIs ("*") are temporary development conveniences — replace with explicit production callback URLs before deploying.
Admin Commands (.env Admin Only)
| Command | Purpose |
|---|---|
| /goal <objective> | Initialize a long-running autonomous goal loop |
| /subgoal <description> | Append a milestone to the active goal |
| /stop | Halt and terminate the active agent loop |
| /steer <instruction> | Real-time course correction to the running loop |
| /new | Reset session history and clear active goal state |
| /model [model_name] | Inspect or switch the active LLM model |
Restricted via RBAC to the system .env admin (@admin_corporate.com:matrix.lca.local).