Skip to main content

A library for splitting and assembling Keycloak realm configurations.

Project description

  1. Realm Builder pykeycloak
  2. Methodology for Defining Realm Configurations

Pykeycloak Realm Builder

This library allows you to split the configuration and assemble a Keycloak realm configuration.

It is especially useful for local development, when you need a full Keycloak instance running on your local machine for testing, and later upload it to your local Keycloak instance, a containerized Keycloak, or your own Keycloak instance running on a server.

Special Note

Keycloak validation is weird. When you upload a realm configuration file, you never get a detailed error explaining what’s wrong. It just reports vague issues like duplicated resources or invalid JSON, even when the JSON file itself is valid.

otago.realm.yml is provided as an example for future realms and should not be used in production.

How it works

  1. ./data/realms/templates/otago.realm.yml - keycloak template

Data directory

The default structure consists of two main directories for different purposes:

  • templates - contains all realm configuration templates that need to be uploaded to Keycloak
  • exports - contains all finalized realm JSON configurations
data/
└── realms/
    ├── templates/
    │   └── otago.realm.yml # config as an example
    ├── export/
        └── otago.realm.json # real Keycloak config transformed from templates

Install

make install

Dependencies

  • no specific dependencies

Commands

There are multiple options how to run the tool:

For shell environment

PYTHONPATH=src bin/realm_builder --from-realm otago --to-realm otago

For UV

uv run python src/pykeycloak_realm/realm.py --from-realm=otago --to-realm=otago - will generate a new config

Shortcuts using MAKE

#build and upload realm (alias for make docker-kc-export-realm-otago)
make otago
# generate new config
make docker-kc-build-realm-%
# generate and export config to Keycloak
make docker-kc-export-realm-%

Configs

All configs here

./src/pykeycloak_realm/config.py

You can manage them using system environment variables or .env files.

.env files are supported only via Makefiles (no dotenv dependencies are used); in other cases, they are intended as helper files for environment setup.

.env        # All variables available for configuring
.env.kc     # Docker Keycloak
.env.local  # optional (for local usage)

Docker

make help
make dup # up docker container with keycloak
make dd  # down docker container
...

Tests

make tests - run tests


Methodology for Defining Realm Configurations

Sections: envs, vars, realms

To make the entire configuration manageable, it is important to separate the configuration into its components.

envs

The envs section is defined at the global scope of the realm and contains clients along with their environment variables (IDs, secrets, etc.).

vars

The vars section contains all configuration variables and presets based on them, which are duplicated or may be duplicated across the configuration.

realms

The main configuration containing all parameters.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykeycloak_realm-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykeycloak_realm-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pykeycloak_realm-0.1.1.tar.gz.

File metadata

  • Download URL: pykeycloak_realm-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pykeycloak_realm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3437433900031e8d7ec04e91a9ad4fe898e4c349d3ced902cbad90ac9a9873e3
MD5 820affa877122061c4b9b32448785cc2
BLAKE2b-256 c779fa9739d7bab624a5fc90f92bb295049ea7ed800828f0b434a298b52a5719

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykeycloak_realm-0.1.1.tar.gz:

Publisher: workflow.yml on jaddek/pykeycloak-realm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pykeycloak_realm-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pykeycloak_realm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5104a39a788cebaf399f45e2de2c58f7148cbbb3c05a2fc0d02a86e34edc997b
MD5 c59713a7722da7fb0780b44b4096dd5e
BLAKE2b-256 3464c1e7da92226233969798d9237c409ce30df4d24d521377d532bb75590091

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykeycloak_realm-0.1.1-py3-none-any.whl:

Publisher: workflow.yml on jaddek/pykeycloak-realm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page