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
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
- 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
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/
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
Top comments (0)