Skip to content

Implement real Keycloak client for drift detection#18

Merged
LahkLeKey merged 1 commit into
mainfrom
feature/keycloak-integration
Jul 12, 2026
Merged

Implement real Keycloak client for drift detection#18
LahkLeKey merged 1 commit into
mainfrom
feature/keycloak-integration

Conversation

@LahkLeKey

Copy link
Copy Markdown
Owner

Closes: #17

Summary

Implements HttpKeycloakClient to connect to live Keycloak instances for auth stack reconciliation and drift detection. Phase 3 of the implementation roadmap.

Architecture

  • HttpKeycloakClient — Implements KeycloakClient interface with bearer token auth
  • Token caching — Automatic refresh with expiry tracking
  • HTTPS/HTTP support — Works with both production and development Keycloak instances
  • Zero dependencies — Uses Node's built-in https/http modules

Changes

  • src/keycloak/index.ts (270 lines) — Real Keycloak client with three methods
    • readLiveState(deployment) — Queries /admin/realms/{realm} for clients, roles, groups, users
    • applyDesiredState(deployment, desired) — Creates realms, clients, roles
    • verifyLiveState(deployment, desired) — Validates live state matches desired
  • src/keycloak/index.test.ts (175 lines) — 4 comprehensive tests with mock Keycloak server
  • src/keycloak/README.md — Setup instructions and API endpoint documentation
  • src/keycloak/keycloak.ts — Public exports

Testing

npm test
# Output: 14 passing tests (10 existing + 4 Keycloak)

Tests verify:

  • Token authentication and caching
  • Reading realm, client, role, group, and user state from Keycloak REST API
  • Applying desired state (realm/client/role creation)
  • Verifying live state matches desired state
  • Error handling when state doesn't match

Configuration

Keycloak Setup (for local testing)

docker run -d \
  -e KEYCLOAK_ADMIN=admin \
  -e KEYCLOAK_ADMIN_PASSWORD=admin \
  -p 8080:8080 \
  quay.io/keycloak/keycloak:latest start-dev

Next Steps

  • Phase 4: Real infrastructure provisioning (AWS/GCP)
  • Phase 5: Deployment pipeline (Docker, Kubernetes, CI/CD)

- HttpKeycloakClient connects to live Keycloak instances via HTTPS/HTTP
- Bearer token authentication with caching and expiry tracking
- Reads live realm state (clients, roles, groups, users)
- Applies desired state (creates realms, clients, roles)
- Verifies live state matches desired state
- Comprehensive test suite with mock Keycloak server
- All 14 tests passing
@LahkLeKey LahkLeKey self-assigned this Jul 12, 2026
Copilot AI review requested due to automatic review settings July 12, 2026 02:42
@LahkLeKey
LahkLeKey merged commit 6ab88dc into main Jul 12, 2026
@LahkLeKey
LahkLeKey deleted the feature/keycloak-integration branch July 12, 2026 02:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants