Skip to content
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

[Bug]: Cannot connect to RabbitMQ (module) #1702

Closed
abemedia opened this issue Sep 30, 2023 · 13 comments · Fixed by #1905 or #2051
Closed

[Bug]: Cannot connect to RabbitMQ (module) #1702

abemedia opened this issue Sep 30, 2023 · 13 comments · Fixed by #1905 or #2051
Labels
bug An issue with the library

Comments

@abemedia
Copy link
Contributor

Testcontainers version

v0.25.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

x86

Go version

1.21

Docker version

n/a

Docker info

n/a

What happened?

The rabbitmq module is essentially broken as the admin account can only connect from localhost (see log output from container). The following example fails with the error Exception (403) Reason: "username or password not allowed"

	c, err := rabbitmq.RunContainer(ctx)
	if err != nil {
		log.Fatal(err)
	}

	url, err := c.AmqpURL(ctx)
	if err != nil {
		log.Fatal(err)
	}

	conn, err := amqp091.Dial(url)
	if err != nil {
		log.Fatal(err)
	}

It might be a good idea to add a test that attempts to connect to the created container via the Go client library.

Relevant log output

2023-09-30 10:10:55.927 [info] <0.245.0> Running boot step pre_boot defined by app rabbit
2023-09-30 10:10:55.927 [info] <0.245.0> Running boot step rabbit_core_metrics defined by app rabbit
2023-09-30 10:10:55.928 [info] <0.245.0> Running boot step rabbit_alarm defined by app rabbit
2023-09-30 10:10:55.930 [info] <0.251.0> Memory high watermark set to 6285 MiB (6590391910 bytes) of 15712 MiB (16475979776 bytes) total
2023-09-30 10:10:55.933 [info] <0.253.0> Enabling free disk space monitoring
2023-09-30 10:10:55.933 [info] <0.253.0> Disk free limit set to 50MB
2023-09-30 10:10:55.935 [info] <0.245.0> Running boot step code_server_cache defined by app rabbit
2023-09-30 10:10:55.935 [info] <0.245.0> Running boot step file_handle_cache defined by app rabbit
2023-09-30 10:10:55.935 [info] <0.256.0> Limiting to approx 1048476 file handles (943626 sockets)
2023-09-30 10:10:55.935 [info] <0.257.0> FHC read buffering:  OFF
2023-09-30 10:10:55.936 [info] <0.257.0> FHC write buffering: ON
2023-09-30 10:10:55.936 [info] <0.245.0> Running boot step worker_pool defined by app rabbit
2023-09-30 10:10:55.936 [info] <0.246.0> Will use 8 processes for default worker pool
2023-09-30 10:10:55.936 [info] <0.246.0> Starting worker pool 'worker_pool' with 8 processes in it
2023-09-30 10:10:55.936 [info] <0.245.0> Running boot step database defined by app rabbit
2023-09-30 10:10:55.937 [info] <0.245.0> Node database directory at /var/lib/rabbitmq/mnesia/rabbit@eb241ba09bcd is empty. Assuming we need to join an existing cluster or initialise from scratch...
2023-09-30 10:10:55.937 [info] <0.245.0> Configured peer discovery backend: rabbit_peer_discovery_classic_config
2023-09-30 10:10:55.937 [info] <0.245.0> Will try to lock with peer discovery backend rabbit_peer_discovery_classic_config
2023-09-30 10:10:55.937 [info] <0.245.0> Peer discovery backend does not support locking, falling back to randomized delay
2023-09-30 10:10:55.937 [info] <0.245.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping randomized startup delay.
2023-09-30 10:10:55.937 [info] <0.245.0> All discovered existing cluster peers: 
2023-09-30 10:10:55.937 [info] <0.245.0> Discovered no peer nodes to cluster with
2023-09-30 10:10:55.939 [info] <0.44.0> Application mnesia exited with reason: stopped
2023-09-30 10:10:56.076 [info] <0.245.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2023-09-30 10:10:56.111 [info] <0.245.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2023-09-30 10:10:56.157 [info] <0.245.0> Waiting for Mnesia tables for 30000 ms, 9 retries left
2023-09-30 10:10:56.157 [info] <0.245.0> Peer discovery backend rabbit_peer_discovery_classic_config does not support registration, skipping registration.
2023-09-30 10:10:56.158 [info] <0.245.0> Running boot step database_sync defined by app rabbit
2023-09-30 10:10:56.158 [info] <0.245.0> Running boot step feature_flags defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step codec_correctness_check defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step external_infrastructure defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step rabbit_registry defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step rabbit_auth_mechanism_cr_demo defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step rabbit_queue_location_random defined by app rabbit
2023-09-30 10:10:56.159 [info] <0.245.0> Running boot step rabbit_event defined by app rabbit
2023-09-30 10:10:56.160 [info] <0.245.0> Running boot step rabbit_auth_mechanism_amqplain defined by app rabbit
2023-09-30 10:10:56.160 [info] <0.245.0> Running boot step rabbit_auth_mechanism_plain defined by app rabbit
2023-09-30 10:10:56.160 [info] <0.245.0> Running boot step rabbit_exchange_type_direct defined by app rabbit
2023-09-30 10:10:56.160 [info] <0.245.0> Running boot step rabbit_exchange_type_fanout defined by app rabbit
2023-09-30 10:10:56.160 [info] <0.245.0> Running boot step rabbit_exchange_type_headers defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_exchange_type_topic defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_mirror_queue_mode_all defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_mirror_queue_mode_exactly defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_mirror_queue_mode_nodes defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_priority_queue defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Priority queues enabled, real BQ is rabbit_variable_queue
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_queue_location_client_local defined by app rabbit
2023-09-30 10:10:56.161 [info] <0.245.0> Running boot step rabbit_queue_location_min_masters defined by app rabbit
2023-09-30 10:10:56.162 [info] <0.245.0> Running boot step kernel_ready defined by app rabbit
2023-09-30 10:10:56.162 [info] <0.245.0> Running boot step rabbit_sysmon_minder defined by app rabbit
2023-09-30 10:10:56.162 [info] <0.245.0> Running boot step rabbit_epmd_monitor defined by app rabbit
2023-09-30 10:10:56.165 [info] <0.429.0> epmd monitor knows us, inter-node communication (distribution) port: 25672
2023-09-30 10:10:56.165 [info] <0.245.0> Running boot step guid_generator defined by app rabbit
2023-09-30 10:10:56.170 [info] <0.245.0> Running boot step rabbit_node_monitor defined by app rabbit
2023-09-30 10:10:56.171 [info] <0.435.0> Starting rabbit_node_monitor
2023-09-30 10:10:56.172 [info] <0.245.0> Running boot step delegate_sup defined by app rabbit
2023-09-30 10:10:56.173 [info] <0.245.0> Running boot step rabbit_memory_monitor defined by app rabbit
2023-09-30 10:10:56.173 [info] <0.245.0> Running boot step core_initialized defined by app rabbit
2023-09-30 10:10:56.173 [info] <0.245.0> Running boot step upgrade_queues defined by app rabbit
2023-09-30 10:10:56.210 [info] <0.245.0> message_store upgrades: 1 to apply
2023-09-30 10:10:56.210 [info] <0.245.0> message_store upgrades: Applying rabbit_variable_queue:move_messages_to_vhost_store
2023-09-30 10:10:56.211 [info] <0.245.0> message_store upgrades: No durable queues found. Skipping message store migration
2023-09-30 10:10:56.211 [info] <0.245.0> message_store upgrades: Removing the old message store data
2023-09-30 10:10:56.211 [info] <0.245.0> message_store upgrades: All upgrades applied successfully
2023-09-30 10:10:56.255 [info] <0.245.0> Running boot step rabbit_connection_tracking defined by app rabbit
2023-09-30 10:10:56.255 [info] <0.245.0> Running boot step rabbit_connection_tracking_handler defined by app rabbit
2023-09-30 10:10:56.256 [info] <0.245.0> Running boot step rabbit_exchange_parameters defined by app rabbit
2023-09-30 10:10:56.256 [info] <0.245.0> Running boot step rabbit_mirror_queue_misc defined by app rabbit
2023-09-30 10:10:56.258 [info] <0.245.0> Running boot step rabbit_policies defined by app rabbit
2023-09-30 10:10:56.259 [info] <0.245.0> Running boot step rabbit_policy defined by app rabbit
2023-09-30 10:10:56.259 [info] <0.245.0> Running boot step rabbit_queue_location_validator defined by app rabbit
2023-09-30 10:10:56.259 [info] <0.245.0> Running boot step rabbit_vhost_limit defined by app rabbit
2023-09-30 10:10:56.259 [info] <0.245.0> Running boot step rabbit_mgmt_reset_handler defined by app rabbitmq_management
2023-09-30 10:10:56.259 [info] <0.245.0> Running boot step rabbit_mgmt_db_handler defined by app rabbitmq_management_agent
2023-09-30 10:10:56.259 [info] <0.245.0> Management plugin: using rates mode 'basic'
2023-09-30 10:10:56.260 [info] <0.245.0> Running boot step recovery defined by app rabbit
2023-09-30 10:10:56.261 [info] <0.245.0> Running boot step load_definitions defined by app rabbitmq_management
2023-09-30 10:10:56.261 [info] <0.245.0> Running boot step empty_db_check defined by app rabbit
2023-09-30 10:10:56.261 [info] <0.245.0> Adding vhost '/'
2023-09-30 10:10:56.302 [info] <0.476.0> Making sure data directory '/var/lib/rabbitmq/mnesia/rabbit@eb241ba09bcd/msg_stores/vhosts/628WB79CIFDYO9LJI6DKMI09L' for vhost '/' exists
2023-09-30 10:10:56.310 [info] <0.476.0> Starting message stores for vhost '/'
2023-09-30 10:10:56.311 [info] <0.480.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_transient": using rabbit_msg_store_ets_index to provide index
2023-09-30 10:10:56.312 [info] <0.476.0> Started message store of type transient for vhost '/'
2023-09-30 10:10:56.313 [info] <0.483.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent": using rabbit_msg_store_ets_index to provide index
2023-09-30 10:10:56.313 [warning] <0.483.0> Message store "628WB79CIFDYO9LJI6DKMI09L/msg_store_persistent": rebuilding indices from scratch
2023-09-30 10:10:56.315 [info] <0.476.0> Started message store of type persistent for vhost '/'
2023-09-30 10:10:56.317 [info] <0.245.0> Creating user 'guest'
2023-09-30 10:10:56.322 [info] <0.245.0> Setting user tags for user 'guest' to [administrator]
2023-09-30 10:10:56.327 [info] <0.245.0> Setting permissions for 'guest' in '/' to '.*', '.*', '.*'
2023-09-30 10:10:56.331 [info] <0.245.0> Running boot step rabbit_looking_glass defined by app rabbit
2023-09-30 10:10:56.331 [info] <0.245.0> Running boot step rabbit_core_metrics_gc defined by app rabbit
2023-09-30 10:10:56.332 [info] <0.245.0> Running boot step background_gc defined by app rabbit
2023-09-30 10:10:56.332 [info] <0.245.0> Running boot step connection_tracking defined by app rabbit
2023-09-30 10:10:56.339 [info] <0.245.0> Setting up a table for connection tracking on this node: tracked_connection_on_node_rabbit@eb241ba09bcd
2023-09-30 10:10:56.346 [info] <0.245.0> Setting up a table for per-vhost connection counting on this node: tracked_connection_per_vhost_on_node_rabbit@eb241ba09bcd
2023-09-30 10:10:56.346 [info] <0.245.0> Running boot step routing_ready defined by app rabbit
2023-09-30 10:10:56.346 [info] <0.245.0> Running boot step pre_flight defined by app rabbit
2023-09-30 10:10:56.346 [info] <0.245.0> Running boot step notify_cluster defined by app rabbit
2023-09-30 10:10:56.346 [info] <0.245.0> Running boot step networking defined by app rabbit
2023-09-30 10:10:56.349 [info] <0.529.0> started TCP listener on [::]:5672
2023-09-30 10:10:56.349 [info] <0.245.0> Running boot step cluster_name defined by app rabbit
2023-09-30 10:10:56.350 [info] <0.245.0> Running boot step direct_client defined by app rabbit
2023-09-30 10:10:56.350 [info] <0.245.0> Running boot step os_signal_handler defined by app rabbit
2023-09-30 10:10:56.350 [info] <0.531.0> Swapping OS signal event handler (erl_signal_server) for our own
2023-09-30 10:10:56.392 [info] <0.581.0> Management plugin: HTTP (non-TLS) listener started on port 15672
2023-09-30 10:10:56.392 [info] <0.687.0> Statistics database started.
2023-09-30 10:10:56.392 [info] <0.686.0> Starting worker pool 'management_worker_pool' with 3 processes in it
 completed with 3 plugins.
2023-09-30 10:10:56.497 [info] <0.9.0> Server startup complete; 3 plugins started.
 * rabbitmq_management
 * rabbitmq_web_dispatch
 * rabbitmq_management_agent
2023-09-30 10:11:01.597 [info] <0.697.0> accepting AMQP connection <0.697.0> (172.17.0.1:55776 -> 172.17.0.3:5672)
2023-09-30 10:11:01.629 [error] <0.697.0> Error on AMQP connection <0.697.0> (172.17.0.1:55776 -> 172.17.0.3:5672, state: starting):
PLAIN login refused: user 'guest' can only connect via localhost

Additional information

No response

@abemedia abemedia added the bug An issue with the library label Sep 30, 2023
@abemedia abemedia changed the title [Bug]: Cannot connect to RabbitMQ [Bug]: Cannot connect to RabbitMQ (module) Sep 30, 2023
@mdelapenya
Copy link
Member

It might be a good idea to add a test that attempts to connect to the created container via the Go client library.

Isn't it this one? https://github.com/testcontainers/testcontainers-go/blob/main/modules/rabbitmq/examples_test.go#L48-L85

@abemedia
Copy link
Contributor Author

abemedia commented Oct 1, 2023

Oh I missed that. So is this run in CI? I wonder why my simple example above doesn't work then...

@eddumelendez
Copy link
Member

Looking at the rabbitmq docs

These variables were available previously in the docker-specific entrypoint shell script but are now available in RabbitMQ directly.

So, testcontainers-go and testcontainers-java are not taking that into account for versions lower than 3.9. env vars were added in rabbitmq 3.9.

@abemedia if you switch to 3.9-management-alpine image then it should work

@abemedia
Copy link
Contributor Author

abemedia commented Oct 9, 2023

It seems adding the following fixes it:

rabbitmq.WithAdminUsername("admin"),
rabbitmq.WithAdminPassword("password"),

Using the module without these options is definitely broken though...

@eddumelendez
Copy link
Member

I found the issue. In both cases, declaring or not the admin credentials when container is created are guest/guest, can be verified by inspecting the container. So, when setting admin/password, those values are only used in AmqpURL(ctx). What's not clear for me is why in these case the access is not denied.

@sambarnes
Copy link

Was running into similar issues here -- the default config in the docs isn't runnable as is. Upgrading to 3.9 def solved some issues

Separately (don't mean to hijack the thread, but since this is the open RabbitMQ ticket already) feels kinda odd that these config types like Exchange are hidden inside the rabbitmq_test package, rather than exported from the rabbitmq package to be usable with the rest of the setup.

type Exchange struct {

Might make sense to remove their references in the docs if we're not supposed to use em?

@mdelapenya
Copy link
Member

Might make sense to remove their references in the docs if we're not supposed to use em?

@sambarnes thanks for raising your concerns on this. I had the same feeling adding them to the test files. I intentionally want to hide them from the public APIs, but still wanted to create examples for users to follow. This allowed us to decouple from the RabbitMQ implementation if it changes in the future.

I now see the docs are not clear at all about that. Or maybe I'm creating a different expectation on those types, as I created them only for demonstration purposes, as examples.

How would you do it to make it more evident that they are for reference, not usable at all?

@eddumelendez
Copy link
Member

Probably, just using raw commands would be enough for the sake of examples.

@mdelapenya
Copy link
Member

mdelapenya commented Oct 11, 2023

Indeed. There are some examples that are complex enough to create an abstraction, like this one:

func (b Binding) AsCommand() []string {
cmd := []string{"rabbitmqadmin"}
if b.VHost != "" {
cmd = append(cmd, fmt.Sprintf("--vhost=%s", b.VHost))
}
cmd = append(cmd, "declare", "binding", fmt.Sprintf("source=%s", b.Source), fmt.Sprintf("destination=%s", b.Destination))
if b.DestinationType != "" {
cmd = append(cmd, fmt.Sprintf("destination_type=%s", b.DestinationType))
}
if b.RoutingKey != "" {
cmd = append(cmd, fmt.Sprintf("routing_key=%s", b.RoutingKey))
}
if len(b.Args) > 0 {
bytes, err := json.Marshal(b.Args)
if err != nil {
return cmd
}
cmd = append(cmd, "arguments="+string(bytes))
}
return cmd
}

That's why I decided to encapsulate them into a struct, not making the tests less readable with the build of the raw commands.

@sambarnes
Copy link

Yeah i was about to suggest the same^. I think raw string commands for examples would be a solid starting point.

Could maybe expose a default struct that just does the simple string case for testcontainers.Executable? Like testcontainers.NewBasicExecutable(cmd []string) where its .AsCommand() impl simply returns the original arg

Then a footnote linking to that test file for ppl with more complex needs with custom structs?


just thinking out loud here, this morning is the first i tried the rabbit example for testcontainers, so i'm not as familiar as y'all :)

@mdelapenya
Copy link
Member

@sambarnes added here: #1905

@abemedia
Copy link
Contributor Author

abemedia commented Nov 6, 2023

@mdelapenya that PR doesn't actually fix the issue the ticket was about.

@mdelapenya
Copy link
Member

@abemedia let's reopen it then until we get to it.

But I'd like to understand better the bug in here: is it because the credentials should be there in order to make it work? #1702 (comment)

If so, we can update the module to always offer defaults, and/or improve the docs to make it explicit. Would that fix that for you? In any case, please share here your thoughts 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
4 participants