Skip to content

Commit

Permalink
Merge pull request #114 from vshn/keycloak/config
Browse files Browse the repository at this point in the history
Document custom configuration and env variables for Keycloak
  • Loading branch information
TheBigLee authored Jul 24, 2024
2 parents 75399f3 + ac73c4b commit 7f97b71
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions docs/modules/ROOT/pages/vshn-managed/keycloak/customization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,133 @@ spec:
<1> Container image url.
<2> Secret name containing credentials for the registry.
<3> Secret namespace


== Configuration

You can provide a custom configuration to Keycloak using a `ConfigMap`.
The content of the `ConfigMap` is a JSON file based on the Keycloak export files.
The configuration *must* be in the key `keycloak-config.json` inside the `ConfigMap`

The configuration will be read during the startup of Keycloak and loaded into the database.

An extensive set of configuration examples can be found https://github.com/inventage/keycloak-config-cli/tree/main/src/test/resources/import-files[here^].

The configuration also supports variable substitution.

Variables exposed by Spring Boot (through https://docs.spring.io/spring-boot/reference/features/external-config.html[configtree or external configuration^]) can be accessed by `$(property.name)`

In additional, the string substitution support multiple prefixes for different approaches:

[source]
----
Base64 Decoder: $(base64Decoder:SGVsbG9Xb3JsZCE=)
Base64 Encoder: $(base64Encoder:HelloWorld!)
Java Constant: $(const:java.awt.event.KeyEvent.VK_ESCAPE)
Date: $(date:yyyy-MM-dd)
DNS: $(dns:address|apache.org)
Environment Variable: $(env:USERNAME)
File Content: $(file:UTF-8:src/test/resources/document.properties)
Java: $(java:version)
Localhost: $(localhost:canonical-name)
Properties File: $(properties:src/test/resources/document.properties::mykey)
Resource Bundle: $(resourceBundle:org.example.testResourceBundleLookup:mykey)
Script: $(script:javascript:3 + 4)
System Property: $(sys:user.dir)
URL Decoder: $(urlDecoder:Hello%20World%21)
URL Encoder: $(urlEncoder:Hello World!)
URL Content (HTTP): $(url:UTF-8:http://www.apache.org)
URL Content (HTTPS): $(url:UTF-8:https://www.apache.org)
URL Content (File): $(url:UTF-8:file:///$(sys:user.dir)/src/test/resources/document.properties)
XML XPath: $(xml:src/test/resources/document.xml:/root/path/to/node)
----

=== Example

The following example demonstrates how a custom configuration that creates a new realm looks like:

.Configmap definition for a custom realm to be created when starting up keycloak.
[source,yaml]
----
apiVersion: v1
kind: ConfigMap
metadata:
name: keycloak-app1-prod-config
namespace: bigli-test
data:
keycloak-config.json: |
{
"enabled": true,
"realm": "prod-app"
}
----

.Keycloak instance with custom configuration
[source,yaml]
----
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNKeycloak
metadata:
name: keycloak-app1-prod
namespace: prod-app
spec:
parameters:
service:
customConfigurationRef: keycloak-app1-prod-config <1>
----
<1> The name of the `ConfigMap`. Must be in the same namespace as the Keycloak claim.


== Environment variables

You can pass custom environment variables to your Keycloak instance. Those can then either be used by your custom providers or by your custom configuration.

=== Example

The following example demonstrates how a custom configuration that creates a new realm and uses environment variables looks like:

.Secret containing a custom environment variable
[source,yaml]
----
apiVersion: v1
kind: Secret
metadata:
name: keycloak-app2-prod-env
namespace: prod-app
stringData:
REALM_NAME: prod-app
type: Opaque
----

.Configmap definition referencing an environmental variable
[source,yaml]
----
apiVersion: v1
kind: ConfigMap
metadata:
name: keycloak-app2-prod-config
namespace: prod-app
data:
keycloak-config.json: |
{
"enabled": true,
"$(env:REALM_NAME)"
}
----

.Keycloak instance with custom configuration and environment variables
[source,yaml]
----
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNKeycloak
metadata:
name: keycloak-app2-prod
namespace: prod-app
spec:
parameters:
service:
customConfigurationRef: keycloak-app2-prod-config <1>
customEnvVariablesRef: keycloak-app2-prod-env <2>
----
<1> The name of the `ConfigMap`. Must be in the same namespace as the Keycloak claim.
<2> The name of the `Secret` that contains the environment variables. Must be in the same namespace as the Keycloak claim.

0 comments on commit 7f97b71

Please sign in to comment.