Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

ARG KC_HEALTH_ENABLED=true
ARG KC_METRICS_ENABLED=true
ARG KC_FEATURES=token-exchange
ARG KC_DB=postgres
ARG KC_HTTP_RELATIVE_PATH=/auth

Expand All @@ -27,36 +26,31 @@
# Configure build options
ARG KC_HEALTH_ENABLED
ARG KC_METRICS_ENABLED
ARG KC_FEATURES
ARG KC_DB
ARG KC_HTTP_RELATIVE_PATH
ENV KC_HEALTH_ENABLED=$KC_HEALTH_ENABLED
ENV KC_METRICS_ENABLED=$KC_METRICS_ENABLED
ENV KC_FEATURES=$KC_FEATURES
ENV KC_DB=$KC_DB
ENV KC_HTTP_RELATIVE_PATH=$KC_HTTP_RELATIVE_PATH

# Install custom providers
COPY --chown=keycloak:keycloak build/image/openremote-theme-provider.jar /opt/keycloak/providers
COPY --chown=keycloak:keycloak build/image/openremote-issuer-provider.jar /opt/keycloak/providers
COPY --chown=keycloak:keycloak build/image/openremote-self-register-configure-event-listener.jar /opt/keycloak/providers

WORKDIR /opt/keycloak

# Build custom image and copy into this new image
RUN /opt/keycloak/bin/kc.sh build --spi-initializer-provider=issuer
RUN /opt/keycloak/bin/kc.sh build

FROM keycloak/keycloak:${VERSION}

# Reinstate build args in case starting in dev mode
ARG KC_HEALTH_ENABLED
ARG KC_METRICS_ENABLED
ARG KC_FEATURES
ARG KC_DB
ARG KC_HTTP_RELATIVE_PATH
ENV KC_HEALTH_ENABLED=$KC_HEALTH_ENABLED
ENV KC_METRICS_ENABLED=$KC_METRICS_ENABLED
ENV KC_FEATURES=$KC_FEATURES
ENV KC_DB=$KC_DB
ENV KC_HTTP_RELATIVE_PATH=$KC_HTTP_RELATIVE_PATH

Expand All @@ -82,17 +76,17 @@
ENV KC_DB_URL_DATABASE=openremote
ENV KC_DB_SCHEMA=public
ENV KC_DB_USERNAME=postgres
ENV KC_DB_PASSWORD=postgres

Check warning on line 79 in Dockerfile

View workflow job for this annotation

GitHub Actions / CI/CD

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "KC_DB_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV KC_HTTP_ENABLED=true
ENV KC_LOG_CONSOLE_FORMAT='%-5p [%c] (%t) %s%e%n'
ENV KC_PROXY_HEADERS=xforwarded
ENV KC_LOG_LEVEL=info
ENV KC_BOOTSTRAP_ADMIN_USERNAME=admin
ENV KC_BOOTSTRAP_ADMIN_PASSWORD=secret

Check warning on line 85 in Dockerfile

View workflow job for this annotation

GitHub Actions / CI/CD

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "KC_BOOTSTRAP_ADMIN_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV KEYCLOAK_SELF_REGISTERED_USER_ROLES="{ }"

HEALTHCHECK --interval=3s --timeout=3s --start-period=30s --retries=120 CMD curl --head -fsS http://localhost:9000/auth/health/ready || exit 1

EXPOSE 8080

ENTRYPOINT exec /opt/keycloak/bin/kc.sh ${KEYCLOAK_START_COMMAND:-start --optimized} --spi-initializer-issuer-base-uri=${KEYCLOAK_ISSUER_BASE_URI:-} --spi-events-listener-self-register-user-configure-self-registered-user-roles="${KEYCLOAK_SELF_REGISTERED_USER_ROLES:-}" ${KEYCLOAK_START_OPTS:-}
ENTRYPOINT exec /opt/keycloak/bin/kc.sh ${KEYCLOAK_START_COMMAND:-start} --spi-events-listener-self-register-user-configure-self-registered-user-roles="${KEYCLOAK_SELF_REGISTERED_USER_ROLES:-}" ${KEYCLOAK_START_OPTS:-}

Check warning on line 92 in Dockerfile

View workflow job for this annotation

GitHub Actions / CI/CD

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for ENTRYPOINT to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ Keycloak docker image built for `postgres` with:

* Default env variable values to assume running behind a reverse proxy sending `X-Forwarded-*` headers (env variables can be changed see keycloak documentation)
* Enables metrics and health endpoints by default
* Adds custom functionality to allow token 'issuer' to be fixed by setting `KEYCLOAK_ISSUER_BASE_URI` (e.g. `KEYCLOAK_ISSUER_BASE_URI: https://192.168.1.2/auth`)
this is to allow a private deployment to be accessed over a reverse tunnel, when using this you also need to set the following but precaution should be taken to validate the `Host` header in the reverse proxy:
* `KC_HOSTNAME: `
* `KC_HOSTNAME_STRICT: false`
* OpenRemote theme embedded and set as default (login and email templates only)
* Request path to `/auth` (like older versions of Keycloak to simplify usage behind a reverse proxy)
* Listener to configure roles of self-registered users. Roles are set using `KEYCLOAK_SELF_REGISTERED_USER_ROLES` environment variable,
Expand All @@ -33,13 +29,13 @@ This can be done e.g. by piping to `jq -c | sed 's/"/\\"/g'`, which would result
The listener is not enabled by default. In Keycloak, in the `Realm settings` - `Events` - `Event listeners` admin screen, `self-register-user-configure` should be added to the list.

## Working on the OpenRemote theme
The openremote theme template files are located in `src/main/resources/theme/openremote`; to work on the OpenRemote theme use (ensure you are in the repo root dir first):
The OpenRemote theme template files are located in `theme/src/main/resources/theme/openremote`; to work on the OpenRemote theme use (ensure you are in the repo root dir first and change port as required):

```shell
docker run --rm -p 8081:8080 -e KC_HOSTNAME_PORT=8081 -e KEYCLOAK_START_COMMAND=start-dev -e KEYCLOAK_START_OPTS="--spi-theme-static-max-age=-1 --spi-theme-cache-themes=false --spi-theme-cache-templates=false" --mount type=bind,src=$PWD/theme/src/main/resources/theme/openremote,dst=/deployment/keycloak/themes/dev openremote/keycloak:latest
docker run --rm -p 8081:8080 -e KC_DB="dev-mem" -e KC_HOSTNAME="localhost" -e KEYCLOAK_START_OPTS="--spi-theme-static-max-age=-1 --spi-theme-cache-themes=false --spi-theme-cache-templates=false" --mount type=bind,src=$PWD/theme/src/main/resources/theme/openremote,dst=/deployment/keycloak/themes/dev openremote/keycloak:develop
```

Then access http://localhost:8081/auth/ then change the template used for a realm to the `dev` template then try and login to that realm via http://localhost:8081/auth/admin/REALM_NAME/console and any changes made to the template files can be reloaded in realtime by just refreshing the window.
Then access http://localhost:8081/auth/ then create a new realm and change the template used for the realm to the `dev` template then try and login to that realm via http://localhost:8081/auth/admin/REALM_NAME/console and any changes made to the template files can be reloaded in realtime by just refreshing the window.

To get the standard themes for reference use the following (replace `${VERSION}` with actual keycloak version used):
```shell
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'base'
}
41 changes: 0 additions & 41 deletions fixed-issuer/build.gradle

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
include 'fixed-issuer'
include 'self-register-user-configure'
include 'theme'
Loading