upgrade-keycloak.sh: Use readiness endpoint and derive expected issuer from Keycloak config

The post-upgrade check compared the issuer against FQHN_HOSTNAME, which
can differ from Keycloak's public 'hostname' setting, so a healthy
Keycloak was reported as failed.

- Wait for /health/ready on the management port (fall back to the
  well-known endpoint if health is not enabled), timeout 120s.
- Derive the expected issuer from 'hostname' in the new keycloak.conf,
  falling back to FQHN_HOSTNAME.
- Report an issuer mismatch as a warning instead of aborting.
- Keep the curl error instead of overwriting it with the journal output.

Also fix missing comma in .claude/settings.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrisandClaude Opus 5.5 committed 2026-11-18 18:19:11 +01:00
1 parent 386c0a44cb
commit c1382d3f04
2 files changed
+40 -13

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
"Bash(scp * iam-nd.oopen.de:*)", "Bash(scp * iam-nd.oopen.de:*)",
"Bash(scp iam-nd.oopen.de:* *)", "Bash(scp iam-nd.oopen.de:* *)",
"Bash(rsync * iam-nd.oopen.de:*)", "Bash(rsync * iam-nd.oopen.de:*)",
"Bash(rsync iam-nd.oopen.de:* *)" "Bash(rsync iam-nd.oopen.de:* *)",
"Bash(ssh keycloak-nd.oopen.de)", "Bash(ssh keycloak-nd.oopen.de)",
"Bash(ssh keycloak-nd.oopen.de *)", "Bash(ssh keycloak-nd.oopen.de *)",
"Bash(scp * keycloak-nd.oopen.de:*)", "Bash(scp * keycloak-nd.oopen.de:*)",
+39 -12
View File
@@ -913,24 +913,37 @@ echo
echo -e "\033[37m\033[1mSome post-installation stuff..\033[m" echo -e "\033[37m\033[1mSome post-installation stuff..\033[m"
echo echo
# Readiness check: prefer the health endpoint on the management interface
# (requires 'health-enabled=true'), otherwise fall back to the OIDC
# well-known endpoint of the master realm.
#
NEW_KC_CONF="${KEYCLOAK_INSTALL_DIR}/conf/keycloak.conf"
if grep -Eq '^[[:space:]]*health-enabled[[:space:]]*=[[:space:]]*true' "${NEW_KC_CONF}" 2>/dev/null ; then
_ready_url="http://127.0.0.1:9000/health/ready"
else
_ready_url="http://127.0.0.1:8080/realms/master/.well-known/openid-configuration"
fi
# Expected issuer: derived from 'hostname' in Keycloak's keycloak.conf (may be
# a full URL or a bare hostname), falling back to FQHN_HOSTNAME.
#
_kc_hostname="$(sed -n -E 's/^[[:space:]]*hostname[[:space:]]*=[[:space:]]*([^[:space:]]+).*/\1/p' "${NEW_KC_CONF}" 2>/dev/null | tail -n 1)"
[[ -z "${_kc_hostname}" ]] && _kc_hostname="${FQHN_HOSTNAME}"
[[ "${_kc_hostname}" =~ ^https?:// ]] || _kc_hostname="https://${_kc_hostname}"
_kc_hostname="${_kc_hostname%/}"
_expected_issuer="${_kc_hostname}/realms/master"
_issuer_host="${_kc_hostname#*://}"
_issuer_host="${_issuer_host%%/*}"
echononl "Wait until the Keycloak service has started completely." echononl "Wait until the Keycloak service has started completely."
echo_wait echo_wait
declare -i index=0 declare -i index=0
declare -i _max_secs_waiting=60 declare -i _max_secs_waiting=120
keycloak_service_started=false keycloak_service_started=false
while true ; do while true ; do
# Try to establish a connection to localhost:8080
#
if systemctl is-active --quiet keycloak.service && \ if systemctl is-active --quiet keycloak.service && \
curl --fail --silent --show-error \ curl --fail --silent --show-error -o /dev/null "${_ready_url}" > "${LOCK_DIR}/ready-check.err" 2>&1 ; then
-H "Host: ${FQHN_HOSTNAME}" \
-H "X-Forwarded-Host: ${FQHN_HOSTNAME}" \
-H "X-Forwarded-Proto: https" \
"http://127.0.0.1:8080/realms/master/.well-known/openid-configuration" \
-o "${LOCK_DIR}/openid-configuration.json" 2> "$log_file" && \
grep -Eq '"issuer"[[:space:]]*:[[:space:]]*"https://'"${FQHN_HOSTNAME//./\.}"'/realms/master"' \
"${LOCK_DIR}/openid-configuration.json" ; then
echo_ok echo_ok
keycloak_service_started=true keycloak_service_started=true
break break
@@ -938,10 +951,24 @@ while true ; do
if [[ ${index} -ge ${_max_secs_waiting} ]]; then if [[ ${index} -ge ${_max_secs_waiting} ]]; then
echo_failed echo_failed
journalctl -u keycloak.service -n 50 --no-pager > "$log_file" 2>&1 journalctl -u keycloak.service -n 50 --no-pager > "$log_file" 2>&1
fatal "Keycloak did not become healthy within ${_max_secs_waiting} seconds or returned an unexpected issuer. The old installation remains at '${CUR_INSTALL_DIR}'. Do not start it against a possibly migrated database without checking compatibility or restoring '${DB_DUMP_FILE}'. Last log messages:\n$(cat "$log_file")" fatal "Keycloak did not become ready within ${_max_secs_waiting} seconds (checked: ${_ready_url}). Last check error: $(cat "${LOCK_DIR}/ready-check.err" 2>/dev/null). The old installation remains at '${CUR_INSTALL_DIR}'. Do not start it against a possibly migrated database without checking compatibility or restoring '${DB_DUMP_FILE}'. Last log messages:\n$(cat "$log_file")"
fi fi
(( index++ )) (( index++ ))
sleep 1 sleep 1
done done
echononl "Check issuer of realm 'master' (${_expected_issuer}).."
_issuer="$(curl --fail --silent --show-error \
-H "Host: ${_issuer_host}" \
-H "X-Forwarded-Host: ${_issuer_host}" \
-H "X-Forwarded-Proto: https" \
"http://127.0.0.1:8080/realms/master/.well-known/openid-configuration" 2> "$log_file" \
| sed -n -E 's/.*"issuer"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/p')"
if [[ "${_issuer}" == "${_expected_issuer}" ]]; then
echo_ok
else
echo_failed
warn "Unexpected issuer for realm 'master'.\n\n\tExpected: ${_expected_issuer}\n\tReturned: ${_issuer:-<none>}\n\n\t$(cat "$log_file")\n\n\tKeycloak is running; please check 'hostname' in '${NEW_KC_CONF}' and FQHN_HOSTNAME in '${conf_file}'."
fi
clean_up 0 clean_up 0