-
Notifications
You must be signed in to change notification settings - Fork 0
fix: write Erlang cookie to disk for CLI tool authentication #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,18 @@ export RABBITMQ_MANAGEMENT_PORT="${RABBITMQ_MANAGEMENT_PORT:-15672}" | |||||||||||||||||||
| unset RABBITMQ_DEFAULT_PASS_FILE | ||||||||||||||||||||
| unset RABBITMQ_ERLANG_COOKIE_FILE | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Write the cookie to disk so CLI tools (rabbitmqctl, rabbitmq-diagnostics) | ||||||||||||||||||||
| # invoked via "docker compose exec" can authenticate with the broker. | ||||||||||||||||||||
| # The env var is only visible to PID 1; exec'd shells read the file. | ||||||||||||||||||||
| # The file may already exist read-only (0400) from a previous run, so | ||||||||||||||||||||
| # widen permissions before overwriting, then lock back down. | ||||||||||||||||||||
| cookie_file="${RABBITMQ_MNESIA_DIR:-/var/lib/rabbitmq}/.erlang.cookie" | ||||||||||||||||||||
| if [ -f "${cookie_file}" ]; then | ||||||||||||||||||||
| chmod 600 "${cookie_file}" 2>/dev/null || true | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suppressing errors from
Suggested change
|
||||||||||||||||||||
| fi | ||||||||||||||||||||
| printf '%s' "${cookie}" > "${cookie_file}" | ||||||||||||||||||||
| chmod 400 "${cookie_file}" | ||||||||||||||||||||
|
Comment on lines
+58
to
+60
|
||||||||||||||||||||
| fi | |
| printf '%s' "${cookie}" > "${cookie_file}" | |
| chmod 400 "${cookie_file}" | |
| fi | |
| old_umask=$(umask) | |
| umask 077 | |
| printf '%s' "${cookie}" > "${cookie_file}" | |
| chmod 400 "${cookie_file}" | |
| umask "${old_umask}" |
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the cookie file already exists and you chmod it to 0600, then a subsequent failure while writing (disk full, permission issue, etc.) will cause the script to exit (set -e) and leave the cookie less restricted than intended. Consider writing via a temporary file + atomic rename and/or using a trap to always restore permissions to 0400 on exit.
| if [ -f "${cookie_file}" ]; then | |
| chmod 600 "${cookie_file}" 2>/dev/null || true | |
| fi | |
| printf '%s' "${cookie}" > "${cookie_file}" | |
| chmod 400 "${cookie_file}" | |
| tmp_cookie_file="${cookie_file}.tmp.$$" | |
| printf '%s' "${cookie}" > "${tmp_cookie_file}" | |
| chmod 400 "${tmp_cookie_file}" | |
| mv -f "${tmp_cookie_file}" "${cookie_file}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cookie location: Erlang CLI tools generally read the cookie from the invoking user’s home directory ("$HOME/.erlang.cookie"). Using RABBITMQ_MNESIA_DIR here can write the cookie somewhere else if that env var is set, which would still break
docker compose exec rabbitmqctl .... Consider basing the path on $HOME (or explicitly /var/lib/rabbitmq) instead of the mnesia dir.