Skip to content

Commit

Permalink
Remove kcmadm login session when Keycloak service restarts unless usi…
Browse files Browse the repository at this point in the history
…ng persistent sessions
  • Loading branch information
treydock committed Nov 18, 2024
1 parent f291300 commit ac65098
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion files/kcadm-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=/dev/null
. /opt/keycloak/conf/kcadm-wrapper.conf

EXPIRES=$(/usr/bin/sed -n -r 's|.*"refreshExpiresAt" : ([0-9]*).*|\1|p' "$CONFIG" || echo "0")
EXPIRES=$(/usr/bin/sed -n -r 's|.*"refreshExpiresAt" : ([0-9]*).*|\1|p' "$CONFIG" 2>/dev/null || echo "0")
NOW=$(/usr/bin/date +%s%3N)

if [ ! -f "$CONFIG" ] || [ "$EXPIRES" -lt "$NOW" ]; then
Expand Down
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$wrapper_conf = {
'KCADM' => "${keycloak::install_base}/bin/kcadm.sh",
'CONFIG' => "${keycloak::conf_dir}/kcadm.config",
'CONFIG' => $keycloak::login_config,
'SERVER' => $keycloak::wrapper_server,
'REALM' => 'master',
'ADMIN_USER' => $keycloak::admin_user,
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
$providers_dir = "${install_base}/providers"
$wrapper_path = "${keycloak::install_base}/bin/kcadm-wrapper.sh"
$wrapper_conf = "${conf_dir}/kcadm-wrapper.conf"
$login_config = "${conf_dir}/kcadm.config"

$default_config = {
'hostname' => $hostname,
Expand Down
4 changes: 4 additions & 0 deletions templates/keycloak.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Environment='JAVA_HOME=<%= scope['keycloak::java_home'] %>'
User=<%= scope['keycloak::user'] %>
Group=<%= scope['keycloak::group'] %>
ExecStart=<%= scope['keycloak::service_start_cmd'] %>
# TODO: remove once upgraded from Keycloak 25 to 26
<% unless (scope['keycloak::features'] || []).include?('persistent-user-sessions') -%>
ExecStartPost=-/usr/bin/rm -f <%= scope['keycloak::login_config'] %>
<% end -%>
TimeoutStartSec=600
TimeoutStopSec=600
SuccessExitStatus=0 143
Expand Down

0 comments on commit ac65098

Please sign in to comment.