Generate or terminate keycloak clients with machine efficiency.
- aws-vault installed and configured
- Profile in
~/.aws/config
to be used byaws-vault
- Recent terraform CLI (0.14+)
- UNIX-like OS with make, sed, etc.
The automation leverages aws-vault
to run terraform
using the configured AWS
profile. Client resources are created within Keycloak, and AWS is only used
for remote state (S3 bucket, DynamoDB table, etc).
To avoid collisions between teams or environments, each client uses its own state bucket. This is a safe starting point, but may hit account limits if you have hundreds or thousands of clients. In that case you could request a limit increase or refactor to leverage multiple state files in a single bucket (or other creative ideas). Depending on your use case that could pose more risk of destory opertions impacting unintended clients.
For each Keycloak server you want to manage, you'll need to create client credentials to be used by Keycloakinator. Follow Client Credentials Grant Setup, saving the client ID and secret for use below.
The Keycloak provider is configured via environment. Export the
required variables or use something like direnv
and create a .envrc
at the top level of this repo with the following
(adjust as needed):
export AWS_PROFILE="<profile to use from ~/.aws/config>"
export AWS_REGION="<preferred AWS region>"
export KEYCLOAK_URL="https://keycloak.your.tld"
export KEYCLOAK_REALM="yourRealm"
export KEYCLOAK_CLIENT_ID="keycloakinator"
export KEYCLOAK_CLIENT_SECRET="<client secret>"
To create a new Keycloak client, first identify the type of client you need:
Type | Template Directory | Notes |
---|---|---|
confidential | sample-oidc-confidential.acme.corp | User-facing REST or UI clients using client_id/client_secret or username/password. |
public | sample-oidc-public.acme.corp | Machine to machine communication with shared secret. |
saml | sample-saml.acme.corp |
The sample directories have common options ready to go in terraform.tfvars
. If you don't
find what you need, browse variables.tf
. Anything there can be added to
terraform.tfvars
to override defaults. Some options are mutually exclusive, or require
specific combinations. Let the comments guide you.
cd clients
./mkclient -c your.client.name -t client_type
- An editor will be spawned with
terraform.tfvars
, adjust as needed - Commit your updates (perhaps create a PR for review)
Deployment leverages make for less typing. The all
target will initialize modules,
deploy the client, and configure remote state to get critical bits off your workstation.
cd clients/client.name
make all
cd clients/client.name
vi terraform.tfvars
make apply
cd clients/client.name
make destroy
- Review proposed changes and type
yes
- Better document common variations
- Handle roles and groups
- Terratests