From b099f8dde4eccfd892233731244bcaf68bd2ea4c Mon Sep 17 00:00:00 2001 From: Andrey Kolkov Date: Tue, 11 Aug 2026 14:04:01 +0400 Subject: [PATCH] fix(kafka): fail closed when listing topics for an all-topics backup In the empty-TOPICS (back up all non-internal topics) branch, the topic list was resolved with a single pipeline under set -eu without pipefail: TLIST=$(kafka-topics.sh --list | grep -v '^_' || true) The pipeline's exit status is grep's alone, so a real broker error (unreachable / auth) that emits no stdout makes grep exit 1, || true swallows it, and TLIST is empty - indistinguishable from 'no non-internal topics'. The backup then drains nothing, tars an empty dir, PUTs it and reports success: a silent empty backup a later restore would treat as authoritative. Split the --list into its own command substitution so a broker error aborts the Pod under set -e; filter internal topics only afterwards, so an empty TLIST means genuinely no user topics. Signed-off-by: Andrey Kolkov Assisted-by: LLM --- examples/backups/kafka/01-create-strategy.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/backups/kafka/01-create-strategy.sh b/examples/backups/kafka/01-create-strategy.sh index 487a319b6..c9c7ddd37 100755 --- a/examples/backups/kafka/01-create-strategy.sh +++ b/examples/backups/kafka/01-create-strategy.sh @@ -156,7 +156,15 @@ spec: if [ -n "\${TOPICS}" ]; then TLIST=\$(printf '%s' "\${TOPICS}" | tr ', ' ' ') else - TLIST=\$("\${BIN}"/kafka-topics.sh --bootstrap-server "\${BOOT}" --list | grep -v '^_' || true) + # Fail closed: run --list as its own command so a broker + # error (unreachable / auth) aborts the Pod under set -e + # instead of the pipe masking the exit status to grep's and + # || true swallowing it. Only then filter internal topics, so + # an empty TLIST means genuinely no non-internal topics - + # never a silently swallowed failure that would PUT an empty + # tarball and report success. + raw=\$("\${BIN}"/kafka-topics.sh --bootstrap-server "\${BOOT}" --list) + TLIST=\$(printf '%s\n' "\${raw}" | grep -v '^_' || true) fi echo "backing up topics [\${TLIST}] from \${BOOT}" MANIFEST="\${WORK}/manifest.txt"