DEV Community

Cover image for Configure Keycloak by a CLI extension
Ulrich VACHON
Ulrich VACHON

Posted on • Edited on

2

Configure Keycloak by a CLI extension

Today I will show you how to configure a Keycloak property by command-line interface.

The main advantage in the Keycloak world is the possibility to extend it. 🔧 Indeed, it exists several way to extend or manage this software and one of these is to use a CLI script.

In this article we will change the value at the startup time of the global property named staticMaxAge responsible of the caching for all assets of all themes. To be noted that we cannot configure this value by the UI but only by the standalone(-ha).xml file.

Search the node path of the property

Whatever the selected Keycloak profile (standalone or cluster mode), we will find the expected node here :

server > profile > subsystem:keycloak-server > theme > staticMaxAge
Enter fullscreen mode Exit fullscreen mode

Create the CLI script

As soon as we have the node we have to translate it to JBoss script.

embed-server --server-config=standalone.xml

/subsystem=keycloak-server/theme=defaults/:write-attribute(name=staticMaxAge,value=3600)

quit
Enter fullscreen mode Exit fullscreen mode
  • The first one line indicates to the engine the target profile,
  • The second one line writes the expected value in the property (staticMaxAge).

📝 One little tip, you can use a environment variable to fill the property :

embed-server --server-config=standalone.xml

/subsystem=keycloak-server/theme=defaults/:write-attribute(name=staticMaxAge,value="${env.KEYCLOAK_ADMIN_STATIC_MAX_AGE:3600})

quit
Enter fullscreen mode Exit fullscreen mode

Push the CLI script in the right folder

If you want to configure your instance at the startup time (the common case for the production environment) you have to push the script in the following path : /opt/jboss/startup-scripts

This is an example of my Docker 🐋 configuration :

RUN mkdir /opt/jboss/startup-scripts

ADD --chown=jboss:root cli/update_assets_cache.cli /opt/jboss/startup-scripts/
Enter fullscreen mode Exit fullscreen mode

Let me try it

If you want a complete example with a Docker configuration, you can clone the repository https://github.com/ulrich/keycloak-configuration-with-cli

Crédit photo : Vanille

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more