forked from panchal-ravi/confused-deputy-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Role: You are a DevOps automation engineer specialized in Identity and Access Management with Terraform, Keycloak, and multi-service application deployments.
Task:
Convert the current authentication and authorization setup from Microsoft Entra ID to Keycloak, maintaining all current security and agentic behavior. The new configuration must be fully automated through Terraform (under /terraform) and integrate with the existing multi-service app structure:
products-web→ Streamlit UI (Frontend)products-agent→ FastAPI Agent APIproducts-mcp→ Model Context Protocol (MCP) Server
🧩 Current Architecture Summary
- Each service authenticates via OAuth2 + JWT validation using Microsoft Entra ID.
products-agentacts as an OBO (On-Behalf-Of) intermediary, exchanging and validating tokens between the UI and MCP.products-mcpuses HCP Vault to generate dynamic database credentials and validate identity scopes.- All configuration and environment variables are generated via Terraform (
export-env.sh), and deployments occur via Docker Compose or AWS bastion host.
🎯 Goal
Replace Microsoft Entra ID with Keycloak as the identity provider across all components, keeping the same functional and security model.
🛠️ Required Actions
-
Terraform Integration
- Use the Keycloak Terraform provider.
- Create a new Terraform module under
/terraform/keycloakthat:- Deploys or references a Keycloak realm (e.g.,
confused-deputy-realm). - Creates clients for:
products-web(public client, PKCE flow)products-agent(confidential client with client secret)products-mcp(confidential client)
- Defines realm roles for user groups (e.g.,
readonly,admin). - Adds protocol mappers for group/role claims in JWTs.
- Configures OBO token exchange between clients using Keycloak’s
token_exchangefeature.
- Deploys or references a Keycloak realm (e.g.,
- Expose Terraform outputs for each client ID and secret to be used in
.envfiles.
-
Environment & App Configuration
- Update each app’s
.envfiles generated byexport-env.sh:- Replace all
MS_ENTRA_*variables withKEYCLOAK_*equivalents:KEYCLOAK_URL,KEYCLOAK_REALM,KEYCLOAK_CLIENT_ID,KEYCLOAK_CLIENT_SECRET
- Update redirect URIs and audience claims for each service.
- Replace all
- Adjust JWT validation logic in
products-agentandproducts-mcp:- Use Keycloak’s OpenID Connect discovery endpoint for public keys.
- Replace Entra ID issuer/audience validation with Keycloak’s issuer.
- Preserve the same OBO flow between
products-web → products-agent → products-mcp.
- Update each app’s
-
Docker Compose Integration
- Add a Keycloak service to
docker-compose/for local testing:keycloak: image: quay.io/keycloak/keycloak:latest command: start-dev --import-realm ports: - "8080:8080" environment: KEYCLOAK_ADMIN: admin KEYCLOAK_ADMIN_PASSWORD: admin
- Mount the exported realm JSON file generated by Terraform (if applicable).
- Add a Keycloak service to
-
Documentation Updates
- Update
/README.mdand/terraform/README.md:- Replace all mentions of Microsoft Entra ID with Keycloak.
- Include instructions for initializing and applying the new Keycloak configuration:
cd terraform terraform init terraform apply -target=module.keycloak ./export-env.sh local
- Note: JWT validation and token delegation now use Keycloak OIDC endpoints.
- Update
🧾 Expected Output
- Complete Terraform configuration for Keycloak under
/terraform/keycloak/. - Updated
.envtemplates for all apps (products-web,products-agent,products-mcp). - Optional
docker-composesnippet to run Keycloak locally. - Updated documentation reflecting Keycloak-based auth flow.
- Maintained end-to-end secure OBO token exchange between services.
✅ Closure Conditions
- All apps can authenticate via Keycloak and communicate securely.
- Terraform deploys the realm, clients, and roles automatically.
- Token validation, delegation, and policy enforcement remain consistent with the previous Entra ID setup.
- No manual steps are required outside Terraform and Docker Compose.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels