Skip to content

Commit 93258e4

Browse files
committed
fix: write Erlang cookie to disk for CLI tool authentication
1 parent 8096c06 commit 93258e4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

rabbitmq/entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export RABBITMQ_MANAGEMENT_PORT="${RABBITMQ_MANAGEMENT_PORT:-15672}"
4747
unset RABBITMQ_DEFAULT_PASS_FILE
4848
unset RABBITMQ_ERLANG_COOKIE_FILE
4949

50+
# Write the cookie to disk so CLI tools (rabbitmqctl, rabbitmq-diagnostics)
51+
# invoked via "docker compose exec" can authenticate with the broker.
52+
# The env var is only visible to PID 1; exec'd shells read the file.
53+
# The file may already exist read-only (0400) from a previous run, so
54+
# widen permissions before overwriting, then lock back down.
55+
cookie_file="${RABBITMQ_MNESIA_DIR:-/var/lib/rabbitmq}/.erlang.cookie"
56+
if [ -f "${cookie_file}" ]; then
57+
chmod 600 "${cookie_file}" 2>/dev/null || true
58+
fi
59+
printf '%s' "${cookie}" > "${cookie_file}"
60+
chmod 400 "${cookie_file}"
61+
5062
entrypoint="/opt/rabbitmq/sbin/docker-entrypoint.sh"
5163
if [ ! -x "${entrypoint}" ]; then
5264
entrypoint="$(command -v docker-entrypoint.sh || true)"

0 commit comments

Comments
 (0)