From ccf7a5e71faf25b169706c27594efcf8afb40838 Mon Sep 17 00:00:00 2001 From: Eric Chang Date: Wed, 10 Dec 2025 19:05:40 +0800 Subject: [PATCH] [DOCKER] fix randomString for macOS compatibility Use /dev/urandom with proper base64 encoding instead of /dev/random which blocks on macOS. Generate URL-safe base64 cluster ID per KIP-78. --- docker/docker_build_common.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker/docker_build_common.sh b/docker/docker_build_common.sh index 433991645..6d24c7c6e 100644 --- a/docker/docker_build_common.sh +++ b/docker/docker_build_common.sh @@ -56,9 +56,12 @@ function generateControllerPort() { fi } -# don't change the length as it is expected 16 bytes of a base64-encoded UUID +# Kafka cluster ID is a 22-char URL-safe base64-encoded UUID (16 bytes encoded = 22 chars) +# KIP-78 specifies allowed chars are [a-zA-Z0-9_\-]+ +# https://cwiki.apache.org/confluence/display/KAFKA/KIP-78:+Cluster+Id +# tr '+/' '-_' converts standard base64 to URL-safe base64 for Kafka compatibility function randomString() { - echo $(cat /dev/random | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 22 | head -n 1) + head -c 16 /dev/urandom | base64 | tr '+/' '-_' | tr -d '=' | head -c 22 } function checkDocker() {