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.2.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.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pykeycloak_realm-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 082370f3062b49a51aaed145bc93d3ce49d9c6f5bfe94925d6c59cdf07b9a181
MD5 967bd33d421a3a0554089de4852a1dd1
BLAKE2b-256 2a57ed570736e927356f9bc8286c81ec2fa6ed0e127833c32dc78b2eac644569

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykeycloak_realm-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pykeycloak_realm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d8e858deaef39172fb4d80dff4bc9344e38a69dbf868572b314d347023cb40f
MD5 0aba059b4a5b6fd552ea2eef9a3a2996
BLAKE2b-256 e936b4cf75aebb6612535bcd7d19b387b3783955b1297c05da456144bf937e35

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykeycloak_realm-0.1.2-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