Skip to main content
Complete deployment guide for the Keycloak-centric authentication architecture with service principals, API keys, identity federation, and SCIM provisioning.

Architecture Overview

Key Features:
  • Single source of truth (Keycloak)
  • JWT standardization (all auth → JWT)
  • Service principals (long-lived credentials)
  • API key management (exchange for JWT)
  • Identity federation (LDAP, SAML, OIDC)
  • SCIM 2.0 provisioning
  • OpenFGA permission inheritance

Prerequisites

  • Kubernetes cluster (1.24+)
  • Helm 3.x
  • kubectl configured
  • PostgreSQL (for Keycloak)
  • Redis (for sessions)
  • OpenFGA deployed

Deployment Checklist

Phase 1: Keycloak Setup (Week 1)

  • 1.1 Deploy Keycloak
  • 1.2 Initialize Realm
    See setup_keycloak.py for details.
  • 1.3 Enable Service Accounts
    • Edit client configuration
    • Set serviceAccountsEnabled: true
    • Verify client credentials flow
  • 1.4 Configure Token Lifetimes

Phase 2: OpenFGA Update (Week 1)

  • 2.1 Deploy New Authorization Model
  • 2.2 Verify Model
  • 2.3 Test Permission Inheritance

Phase 3: Kong Configuration (Week 2)

  • 3.1 Extract Keycloak Public Key
    See update_kong_jwks.py for details.
  • 3.2 Update Kong JWT Plugin
  • 3.3 Deploy JWKS Updater CronJob
  • 3.4 Deploy Kong Custom Plugin (Optional)
  • 3.5 Configure Hybrid Routes

Phase 4: MCP Server Deployment (Week 2)

  • 4.1 Update Configuration
  • 4.2 Deploy Updated Application
  • 4.3 Verify New API Endpoints

Phase 5: Identity Federation (Week 3) - Optional

  • 5.1 Configure LDAP (if needed)
    See setup_ldap_federation.py for details.
  • 5.2 Configure SAML (if needed)
    See setup_saml_idp.py for details.
  • 5.3 Configure OIDC (if needed)
    See setup_oidc_idp.py for details.
  • 5.4 Test Federated Login
    • Login with LDAP user
    • Verify JWT issuance
    • Check OpenFGA role sync

Phase 6: Testing (Week 3)

  • 6.1 Run Integration Tests
  • 6.2 Performance Testing
  • 6.3 Security Audit
    • Token tampering test
    • Expired token rejection
    • Permission escalation attempts
    • API key brute force protection

Phase 7: Production Rollout (Week 4)

  • 7.1 Staging Deployment
    • Deploy to staging environment
    • Run smoke tests
    • Monitor for 48 hours
  • 7.2 Create Service Principals
    • Migrate batch jobs to service principals
    • Create API keys for integrations
    • Document credentials securely
  • 7.3 Client Migration
    • Update client SDKs
    • Implement token refresh logic
    • Test end-to-end flows
  • 7.4 Production Deployment
    • Blue-green deployment
    • Monitor authentication metrics
    • Gradual traffic shift (10% → 50% → 100%)
  • 7.5 Cleanup
    • Remove old authentication mechanisms
    • Clean up unused Kong consumers
    • Archive legacy configuration

Configuration Reference

Environment Variables

Kubernetes Resources

Monitoring

Key Metrics

Health Checks

Logs

Security Considerations

Secrets Management

Never commit secrets to git. Use one of:
  1. Kubernetes Secrets
  2. External Secrets Operator
  3. Infisical (Already integrated)

Network Policies

Troubleshooting

Common Issues

Keycloak Unavailable
Symptom: 503 Service Unavailable Solutions:
  • Check Keycloak pod status: kubectl get pods -l app=keycloak
  • Check PostgreSQL connectivity
  • Verify resource limits (CPU/memory)
  • Check logs for errors
JWT Validation Fails at Kong
Symptom: 401 Unauthorized from Kong Solutions:
  • Verify JWKS is up-to-date: Check CronJob logs
  • Run manual update: kubectl create job --from=cronjob/kong-jwks-updater manual-update
  • Verify issuer matches: Token iss claim must match Kong configuration
  • Check public key in Kong consumer
Service Principal Authentication Fails
Symptom: 401 when using client credentials Solutions:
  • Verify service principal exists in Keycloak
  • Check client_id and client_secret
  • Ensure serviceAccountsEnabled=true
  • Verify Keycloak token endpoint URL
API Key Not Working
Symptom: 401 Invalid or expired API key Solutions:
  • Verify key not expired: Check expires_at
  • Check user is enabled in Keycloak
  • Clear Kong cache if recently created
  • Verify Kong plugin is deployed
Permission Denied (OpenFGA)
Symptom: 403 Forbidden Solutions:
  • Check OpenFGA tuples exist
  • Verify acts_as relationship for service principals
  • Check role mapping configuration
  • Test with openfga-cli: openfga-cli check

Rollback Plan

If issues arise, rollback steps:

1. Revert to Previous Auth

2. Revert Kong Configuration

3. Disable New Features

Performance Tuning

Keycloak

Kong

OpenFGA

Migration from Old Auth

Step 1: Dual Authentication (Week 1)

Run both old and new auth in parallel:

Step 2: Client Migration (Week 2-3)

Gradually migrate clients:
  • Week 2: 25% of clients
  • Week 3: 75% of clients
  • Week 4: 100% of clients

Step 3: Sunset Old Auth (Week 4)

Remove old authentication system:

Validation

End-to-End Test

References

Architecture Decision Records

User Guides

Scripts

Configuration Files