From 7e32ced67df251285f88da4b5d97c4d77d4f9257 Mon Sep 17 00:00:00 2001 From: Isha Agarwal Date: Sun, 4 Oct 2026 18:54:25 +0000 Subject: [PATCH 1/2] [kafka] Fix Debian 11 security repo and backports cleanup in Kafka init actions --- kafka/kafka-manager.sh | 32 ++++++++++++++++---------------- kafka/kafka.sh | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/kafka/kafka-manager.sh b/kafka/kafka-manager.sh index a5acb28bc..83c714531 100755 --- a/kafka/kafka-manager.sh +++ b/kafka/kafka-manager.sh @@ -95,34 +95,34 @@ function remove_old_backports { oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}'); stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}'); - matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list*)" + matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list* || true)" if [[ -n "$matched_files" ]]; then for filename in "$matched_files"; do grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \ sed -i -e 's/^.*-backports.*$//' "$filename" done fi + + local security_files=( $(grep -rsil 'bullseye-security' /etc/apt/sources.list*||:) ) + if [[ ${#security_files[@]} -gt 0 ]]; then + local security_mirror="https://snapshot.debian.org/archive/debian-security/20260830T000000Z" + if curl -fsSLI --connect-timeout 5 --max-time 10 "https://archive.debian.org/debian-security/dists/bullseye-security/InRelease" >/dev/null 2>&1; then + security_mirror="https://archive.debian.org/debian-security" + fi + for filename in "${security_files[@]}"; do + sed -i "s|https\?://[^/]\+/debian-security|${security_mirror}|g" "${filename}" + done + echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until + fi } function main(){ local java_major_version=$(java -version 2>&1 | grep -oP 'version "?(1\.)?\K\d+' || true) OS=$(. /etc/os-release && echo "${ID}") - # The remove_old_backports function is breaking the init action on - # Dataproc 2.1 (Debian 11) images. - # - # The function's logic fetches the current Debian stable (Trixie) and - # oldstable (Bookworm) codenames and deletes any backports repository - # that does not match. - # - # This incorrectly removes the essential bullseye-backports repository - # on Debian 11 systems, as "bullseye" is no longer stable or oldstable. - # This change disables the function to prevent it from damaging the - # system's valid apt configuration. - # - # if [[ ${OS} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then - # remove_old_backports - # fi + if [[ ${OS} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then + remove_old_backports + fi if [[ ${java_major_version} -lt 11 ]]; then echo "Error: Java 11 or higher is required for CMAK" >&2 diff --git a/kafka/kafka.sh b/kafka/kafka.sh index ece51eefc..e56e186ac 100755 --- a/kafka/kafka.sh +++ b/kafka/kafka.sh @@ -52,7 +52,8 @@ function recv_keys() { mkdir -p /etc/apt/trusted.gpg.d gpg --export B7B3B788A8D3785C > /etc/apt/trusted.gpg.d/mysql-repo.gpg else - retry_apt_command "apt-get install -y gnupg2 && \ + retry_apt_command "(apt-get update || true) && \ + apt-get install -y gnupg2 && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C" fi } @@ -212,13 +213,25 @@ function remove_old_backports { oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}'); stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}'); - matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list*)" + matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list* || true)" if [[ -n "$matched_files" ]]; then for filename in "$matched_files"; do grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \ sed -i -e 's/^.*-backports.*$//' "$filename" done fi + + local security_files=( $(grep -rsil 'bullseye-security' /etc/apt/sources.list*||:) ) + if [[ ${#security_files[@]} -gt 0 ]]; then + local security_mirror="https://snapshot.debian.org/archive/debian-security/20260830T000000Z" + if curl -fsSLI --connect-timeout 5 --max-time 10 "https://archive.debian.org/debian-security/dists/bullseye-security/InRelease" >/dev/null 2>&1; then + security_mirror="https://archive.debian.org/debian-security" + fi + for filename in "${security_files[@]}"; do + sed -i "s|https\?://[^/]\+/debian-security|${security_mirror}|g" "${filename}" + done + echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until + fi } function main() { From 8c749a5bac05a1c333e5f7800e2033d7459610bc Mon Sep 17 00:00:00 2001 From: Isha Agarwal Date: Fri, 4 Dec 2026 09:42:57 +0000 Subject: [PATCH 2/2] Address review comments: iterate matched_files as array and remove subshell parens --- kafka/kafka-manager.sh | 6 +++--- kafka/kafka.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kafka/kafka-manager.sh b/kafka/kafka-manager.sh index 83c714531..aa575bfd3 100755 --- a/kafka/kafka-manager.sh +++ b/kafka/kafka-manager.sh @@ -95,9 +95,9 @@ function remove_old_backports { oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}'); stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}'); - matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list* || true)" - if [[ -n "$matched_files" ]]; then - for filename in "$matched_files"; do + local matched_files=( $(grep -rsil '\-backports' /etc/apt/sources.list* || true) ) + if [[ ${#matched_files[@]} -gt 0 ]]; then + for filename in "${matched_files[@]}"; do grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \ sed -i -e 's/^.*-backports.*$//' "$filename" done diff --git a/kafka/kafka.sh b/kafka/kafka.sh index e56e186ac..4cac8fd7b 100755 --- a/kafka/kafka.sh +++ b/kafka/kafka.sh @@ -52,7 +52,7 @@ function recv_keys() { mkdir -p /etc/apt/trusted.gpg.d gpg --export B7B3B788A8D3785C > /etc/apt/trusted.gpg.d/mysql-repo.gpg else - retry_apt_command "(apt-get update || true) && \ + retry_apt_command "apt-get update || true && \ apt-get install -y gnupg2 && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C" fi @@ -213,9 +213,9 @@ function remove_old_backports { oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}'); stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}'); - matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list* || true)" - if [[ -n "$matched_files" ]]; then - for filename in "$matched_files"; do + local matched_files=( $(grep -rsil '\-backports' /etc/apt/sources.list* || true) ) + if [[ ${#matched_files[@]} -gt 0 ]]; then + for filename in "${matched_files[@]}"; do grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \ sed -i -e 's/^.*-backports.*$//' "$filename" done