Back to Tutorials
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

UsernamePasswordRoleAccess Level
adminpasswordSuperAdminFull access, system overrides
auditorpasswordExternalAuditorRead-only audit views
managerpasswordSustainabilityManagerCarbon 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

Tierimpact_analyticsontology_graphcurrency
Tier4_EnterpriseALL via RLSALL via RLSALL via RLS
Tier3_BusinessALL via RLSSELECT via RLS—
Tier2_ProfessionalSELECT via RLS——
Tier1_StarterSELECT via RLS——
Tier0_FreeSELECT 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)

CommandPurpose
/goal <objective>Initialize a long-running autonomous goal loop
/subgoal <description>Append a milestone to the active goal
/stopHalt and terminate the active agent loop
/steer <instruction>Real-time course correction to the running loop
/newReset 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).