-
-
Notifications
You must be signed in to change notification settings - Fork 511
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]: Error when using WithUsername and WithPassword with the WithReplicaSet option #2755
Comments
I faced same issue and I would like to work on this bug. {
name: "With Replica set, WithUsername, WithPassword and mongo:6",
img: "mongo:6",
opts: []testcontainers.ContainerCustomizer{
mongodb.WithReplicaSet("rs"),
mongodb.WithUsername("tester"),
mongodb.WithPassword("testpass"),
},
} The test failed with below error. === RUN TestMongoDB
=== RUN TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
=== PAUSE TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
=== CONT TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
mongodb_test.go:80:
Error Trace: ~/testcontainers-go/modules/mongodb/mongodb_test.go:80
Error: Received unexpected error:
generic container: start container: started hook: container exec create: Error response from daemon: Container 37d341411e5c383c4718f8108f99ea63265418208ffe887db14fc881bb55d4c3 is not running
all exposed ports, [27017/tcp], were not mapped in 5s: port 27017/tcp is not mapped yet
wait until ready: check target: retries: 1, port: "", last err: container exited with code 2
Test: TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
--- FAIL: TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6 (89.00s) |
It seems when root username and password are set in mongodb containers then security.keyfile must be passed.
Adding keyfile inside container is not very straight forward. The keyfile requires specific permission and should be read only by mongodb user or group members. @mdelapenya Can you suggest if there is a way to add file to containers with specific ownership. Also it is worth solving this problem. I think another approach is to allow replicaset without username passwords. |
@abhipranay thanks for your support in identifying the root cause, I'm happy to review your work when sent. 👏 We do not have a way to define permissions in copied files unless you define a postStart hook running CopyToContainer(ctx context.Context, fileContent []byte, containerFilePath string, fileMode int64) error
CopyDirToContainer(ctx context.Context, hostDirPath string, containerParentPath string, fileMode int64) error
CopyFileToContainer(ctx context.Context, hostFilePath string, containerFilePath string, fileMode int64) error In any case, I'm not against the change offering a deprecation path. Wdyt? |
@mdelapenya Thanks for the details. I agree as well on deprecation path for mongo module. Given the usecases for testcontainer is in test environments, it doesn't seem a good idea to aim to provide support for all types of configurations as many of them make sense for production environments. For more advanced use cases where user really care about security configs, testcontainer I will raise PR for deprecating |
@abhipranay my interest in the deprecation was not for the replicaset but for the copy APIs in the core library, as the replicaset is used test production scenarios. And deprecating them with an alternative method, that we should discuss the name, something like |
@mdelapenya I have another approach to tackle the problem. You may check the PR. Core idea in PR is to use a wrapper entrypoint which creates keyfile inside container with correct ownership and permissions before starting mongo daemon. To make the changes safer the custom entrypoint is used only when needed. |
Testcontainers version
v0.33.0
Using the latest Testcontainers version?
Yes
Host OS
MacOS
Host arch
ARM
Go version
1.23.0
Docker version
Client: Cloud integration: v1.0.35+desktop.13 Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:14:46 2024 OS/Arch: darwin/arm64 Context: desktop-linux Server: Docker Desktop 4.29.0 (145265) Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:18:02 2024 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
Docker info
What happened?
When running the following code, I consistently receive the error message stated in the log output. I tried different mongo versions and with/without wait strategies and it's the same result.
mongo, err := mongodb.Run(ctx, "mongo:latest", mongodb.WithReplicaSet("rs0"), mongodb.WithUsername("root"), mongodb.WithPassword("example"), testcontainers.WithWaitStrategy(wait.ForLog("Waiting for connections")), )
Relevant log output
Additional information
No response
The text was updated successfully, but these errors were encountered: