Skip to content

Honor separately-configured user_name/password in AMQP connections - #13

Closed
vson-ic wants to merge 1 commit into
mainfrom
fix/amqp-credentials-from-server-config
Closed

vson-ic wants to merge 1 commit into
mainfrom
fix/amqp-credentials-from-server-config

Conversation

@vson-ic

@vson-ic vson-ic commented Sep 18, 2026

Copy link
Copy Markdown

Context

Found while tracking down dchbx/edi_journal#194 — a consumer app was misusing connection_uri (a display-only, credential-free string) to open a manual Bunny connection. While tracing why the correct API (connection_params) is guaranteed to work, found a real gap underneath it.

The bug

BunnyConnectionProxy.connection_credentials_from_server only ever pulled credentials from userinfo embedded in the server's url (amqp://user:pass@host:port/vhost). But EventSource.configure's own DSL explicitly supports configuring credentials as separate fields:

config.servers do |server|
  server.amqp do |rabbitmq|
    rabbitmq.url       = ENV["RABBITMQ_URL_EVENT_SOURCE"]
    rabbitmq.user_name = ENV["RABBITMQ_USERNAME"]
    rabbitmq.password  = ENV["RABBITMQ_PASSWORD"]
  end
end

Whenever url was also present (which it almost always is), those separately-configured user_name/password fields were silently ignored, and the real connection fell back to ConnectDefaults' guest/guest unless url also happened to embed working credentials. That means connection_params (and the actual Bunny connection built from it) only worked correctly by coincidence in some environments, and would silently authenticate as guest/guest in others — no error raised, just a connection that may or may not be to the right account.

The fix

server[:user_name]/server[:password] now take precedence when both are present, falling back to URL-embedded credentials otherwise. Existing URL-embedded-credential behavior is unchanged — the existing "given a url with non-default credentials" spec still passes.

connection_uri is untouched — it stays a display-only, credential-free string (used for logging and as the connection registry key in ConnectionManager), so nothing about what gets logged changes, and there's no risk of leaking credentials into logs.

Test plan

  • Added a spec covering separate user_name/password fields with a credential-free url.
  • Verified in isolation (all three cases: URL-embedded credentials, separate fields, and no credentials/defaults) since this repo's full test suite doesn't currently install cleanly against Ruby 3.4 (unrelated nio4r/Rails 6.1 native-extension issue on this Gemfile.lock).
  • Run full spec suite in CI / an environment matching the pinned Ruby version before merge.

🤖 Generated with Claude Code

connection_credentials_from_server only ever extracted credentials
from userinfo embedded in the server's url (e.g.
"amqp://user:pass@host:port/vhost"). When an app instead configures
credentials as separate fields, as EventSource.configure's DSL
explicitly supports:

  config.servers do |server|
    server.amqp do |rabbitmq|
      rabbitmq.url       = ENV["RABBITMQ_URL_EVENT_SOURCE"]
      rabbitmq.user_name = ENV["RABBITMQ_USERNAME"]
      rabbitmq.password  = ENV["RABBITMQ_PASSWORD"]
    end
  end

...those fields were silently ignored whenever url was also present,
and the real Bunny connection fell back to ConnectDefaults' guest/guest
unless the url happened to also embed working credentials. This made
connection_params (and the real running connection) look correct in
some environments purely by coincidence, and wrong in others with no
error raised.

Now server[:user_name]/server[:password] take precedence when both are
present, falling back to url-embedded credentials otherwise. Existing
url-embedded-credential behavior is unchanged (see the "given a url
with non-default credentials" spec, still passing).

connection_uri is untouched by this change - it stays a display-only,
credential-free string (used for logging and as the connection
registry key), so nothing about what gets logged changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vson-ic vson-ic closed this Sep 18, 2026
@vson-ic
vson-ic deleted the fix/amqp-credentials-from-server-config branch September 18, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant