From d31b49e30d1c8c87fea547e7f7cf02c30f0c36f0 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 20 Oct 2026 18:55:13 +0200 Subject: [PATCH] fix(keycloak,friendica): keep shipped scripts off the caller's terminal Three jobs of run 39186571513 hung and were killed by the outer timeout 9000: Friendica#1 at 9003.17s, OpenTalk#0 at 9004.66s, Agent-Broker#0 at 9006.62s, each after idling 1h37m to 2h22m. Two stopped at the same inner task, web-app-keycloak's realm design sync; the third at Friendica's addon sync. Not slowness. In the same OpenTalk job the same keycloak task also ran in the outer deploy over the local connection and finished in 4.90s. The chain is three parts, each of which is ordinary on its own: ansible.builtin.script passes no in_data, so ansible adds -tt and the remote shell gets a pty (connection/ssh.py checks 'not in_data'); container exec wraps docker in coreutils timeout, which without --foreground calls setpgid; docker exec -i then reads that controlling tty from a background process group, takes SIGTTIN and stops forever. A sibling Friendica task running the same container exec -i through the shell module passed in 0.6s, because shell carries its module payload as in_data and therefore never gets -tt. Nothing rescued it: SYS_TIMEOUT_CONTAINER_EXEC is 7d, so the OS-level kill was a week away and the CI budget arrived first. In the field, following the published instructions, it simply hangs. Closing stdin in the script removes the read. The -i stays on the exec prefixes: of the six execution sites behind KEYCLOAK_EXEC_CONTAINER, ensure_realm_user.sh pipes a credential document into reset-password -f -, and four more sites behind the derived KEYCLOAK_EXEC_KCADM pipe as well, so dropping -i would reset passwords from an empty document without erroring. Safe for every script here: none reads its own stdin. The three while-read loops are fed from files, two reads use here-strings, both piped execs override fd 0 themselves, and the nested sh -lc bodies travel as argv. Three exec sites already carried an inline --- .../web-app-friendica/files/shell/patch_ldapauth_autocreate.sh | 2 ++ roles/web-app-friendica/files/shell/sync_addon.sh | 2 ++ .../shell/per_app_mapper/delete_default_ldap_roles_mapper.sh | 2 ++ .../files/shell/per_app_mapper/ensure_app_group.sh | 2 ++ .../files/shell/per_app_mapper/purge/app_subgroups.sh | 2 ++ .../files/shell/per_app_mapper/purge/root_orphans.sh | 2 ++ .../files/shell/per_app_mapper/resolve_root_group_id.sh | 2 ++ .../files/shell/per_app_mapper/sync_app_mapper.sh | 2 ++ .../files/shell/per_app_mapper/upsert_app_mapper.sh | 2 ++ .../files/shell/rbac_realm/ensure_group_path_members.sh | 2 ++ roles/web-app-keycloak/files/shell/set_email_verified.sh | 2 ++ roles/web-app-keycloak/files/shell/sync_realm_design.sh | 2 ++ 12 files changed, 24 insertions(+) diff --git a/roles/web-app-friendica/files/shell/patch_ldapauth_autocreate.sh b/roles/web-app-friendica/files/shell/patch_ldapauth_autocreate.sh index 9fa9f95ba1..4c49711b63 100644 --- a/roles/web-app-friendica/files/shell/patch_ldapauth_autocreate.sh +++ b/roles/web-app-friendica/files/shell/patch_ldapauth_autocreate.sh @@ -28,6 +28,8 @@ set -euo pipefail EXEC="$1" P="$2" +exec &1 || true # nocheck: shell-or-true -- grandfathered: worked in practice; TODO: sharpen to catch only the exact tolerated error $CMD addon enable "$ADDON" 2>&1 || true # nocheck: shell-or-true -- grandfathered: worked in practice; TODO: sharpen to catch only the exact tolerated error diff --git a/roles/web-app-keycloak/files/shell/per_app_mapper/delete_default_ldap_roles_mapper.sh b/roles/web-app-keycloak/files/shell/per_app_mapper/delete_default_ldap_roles_mapper.sh index e5c39c52fb..3b9c93b8ab 100755 --- a/roles/web-app-keycloak/files/shell/per_app_mapper/delete_default_ldap_roles_mapper.sh +++ b/roles/web-app-keycloak/files/shell/per_app_mapper/delete_default_ldap_roles_mapper.sh @@ -14,6 +14,8 @@ set -o pipefail : "${KC_REALM:?KC_REALM is required}" : "${LDAP_COMPONENT_ID:?LDAP_COMPONENT_ID is required}" +exec &1 diff --git a/roles/web-app-keycloak/files/shell/per_app_mapper/upsert_app_mapper.sh b/roles/web-app-keycloak/files/shell/per_app_mapper/upsert_app_mapper.sh index 15f085cfff..5d60ba3cb6 100755 --- a/roles/web-app-keycloak/files/shell/per_app_mapper/upsert_app_mapper.sh +++ b/roles/web-app-keycloak/files/shell/per_app_mapper/upsert_app_mapper.sh @@ -23,6 +23,8 @@ set -o pipefail : "${PAYLOAD_FILE:?PAYLOAD_FILE is required}" [ -r "$PAYLOAD_FILE" ] || { echo "PAYLOAD_FILE not readable: $PAYLOAD_FILE" >&2; exit 1; } +exec