Mongo: Authentication failed when using environment variables

Created on 14 May 2020  路  2Comments  路  Source: docker-library/mongo

Hello,

I using mongo latest on rancher/k8s with config as below:
image

image

I can't authentication when use "mongo -u mongoadmin -p secret --authenticationDatabase admin"
image

2020-05-14T15:02:09.450+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-05-14T15:02:09.455+0000 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-05-14T15:02:09.456+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=mongo-1-7448bf88c4-4jwgn
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] db version v4.2.6
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] git version: 20364840b8f1af16917e4c23c1b5f5efd8b352f8
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] allocator: tcmalloc
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] modules: none
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] build environment:
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] distarch: x86_64
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] target_arch: x86_64
2020-05-14T15:02:09.457+0000 I CONTROL [initandlisten] options: { net: { bindIp: "0.0.0.0" }, security: { authorization: "enabled" } }
2020-05-14T15:02:09.458+0000 I STORAGE [initandlisten]
2020-05-14T15:02:09.458+0000 I STORAGE [initandlisten] * WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-05-14T15:02:09.458+0000 I STORAGE [initandlisten] *
See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-05-14T15:02:09.458+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7507M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2020-05-14T15:02:10.570+0000 I STORAGE [initandlisten] WiredTiger message [1589468530:570844][1:0x7f9bbf946b00], txn-recover: Set global recovery timestamp: (0, 0)
2020-05-14T15:02:10.753+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2020-05-14T15:02:10.930+0000 I STORAGE [initandlisten] Timestamp monitor starting
2020-05-14T15:02:10.996+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-05-14T15:02:10.996+0000 I CONTROL [initandlisten]
2020-05-14T15:02:10.998+0000 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: ce784610-bf27-45e9-a7f0-e3dc165b8a89 and options: { uuid: UUID("ce784610-bf27-45e9-a7f0-e3dc165b8a89") }
2020-05-14T15:02:11.119+0000 I INDEX [initandlisten] index build: done building index _id_ on ns admin.system.version
2020-05-14T15:02:11.120+0000 I SHARDING [initandlisten] Marking collection admin.system.version as collection version:
2020-05-14T15:02:11.120+0000 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.2
2020-05-14T15:02:11.120+0000 I SHARDING [initandlisten] Marking collection local.system.replset as collection version:
2020-05-14T15:02:11.121+0000 I STORAGE [initandlisten] Flow Control is enabled on this deployment.
2020-05-14T15:02:11.121+0000 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version:
2020-05-14T15:02:11.122+0000 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: bfbf11ff-f98c-4e35-9a35-9fb4f9aa5677 and options: { capped: true, size: 10485760 }
2020-05-14T15:02:11.290+0000 I INDEX [initandlisten] index build: done building index _id_ on ns local.startup_log
2020-05-14T15:02:11.291+0000 I SHARDING [initandlisten] Marking collection local.startup_log as collection version:
2020-05-14T15:02:11.295+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2020-05-14T15:02:11.303+0000 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version:
2020-05-14T15:02:11.304+0000 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
2020-05-14T15:02:11.304+0000 I NETWORK [listener] Listening on /tmp/mongodb-27017.sock
2020-05-14T15:02:11.304+0000 I STORAGE [LogicalSessionCacheRefresh] createCollection: config.system.sessions with provided UUID: b5b491c4-e372-4eaa-9a9c-65c204d8b9a3 and options: { uuid: UUID("b5b491c4-e372-4eaa-9a9c-65c204d8b9a3") }
2020-05-14T15:02:11.304+0000 I NETWORK [listener] Listening on 0.0.0.0
2020-05-14T15:02:11.304+0000 I NETWORK [listener] waiting for connections on port 27017
2020-05-14T15:02:11.458+0000 I INDEX [LogicalSessionCacheRefresh] index build: done building index _id_ on ns config.system.sessions
2020-05-14T15:02:11.596+0000 I INDEX [LogicalSessionCacheRefresh] index build: starting on config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 } using method: Hybrid
2020-05-14T15:02:11.596+0000 I INDEX [LogicalSessionCacheRefresh] build may temporarily use up to 200 megabytes of RAM
2020-05-14T15:02:11.597+0000 I INDEX [LogicalSessionCacheRefresh] index build: collection scan done. scanned 0 total records in 0 seconds
2020-05-14T15:02:11.599+0000 I INDEX [LogicalSessionCacheRefresh] index build: inserted 0 keys from external sorter into index in 0 seconds
2020-05-14T15:02:11.622+0000 I INDEX [LogicalSessionCacheRefresh] index build: done building index lsidTTLIndex on ns config.system.sessions
2020-05-14T15:02:11.658+0000 I COMMAND [LogicalSessionCacheRefresh] command config.system.sessions command: createIndexes { createIndexes: "system.sessions", indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ], $db: "config" } numYields:0 reslen:114 locks:{ ParallelBatchWriterMode: { acquireCount: { r: 2 } }, ReplicationStateTransition: { acquireCount: { w: 3 } }, Global: { acquireCount: { r: 1, w: 2 } }, Database: { acquireCount: { r: 1, w: 2, W: 1 } }, Collection: { acquireCount: { r: 4, w: 1, R: 1, W: 2 } }, Mutex: { acquireCount: { r: 3 } } } flowControl:{ acquireCount: 1, timeAcquiringMicros: 3 } storage:{} protocol:op_msg 354ms
2020-05-14T15:02:12.001+0000 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version:
2020-05-14T15:02:15.826+0000 I NETWORK [listener] connection accepted from 127.0.0.1:42108 #1 (1 connection now open)
2020-05-14T15:02:15.828+0000 I SHARDING [conn1] Marking collection admin.system.users as collection version:
2020-05-14T15:02:15.828+0000 I ACCESS [conn1] note: no users configured in admin.system.users, allowing localhost access
2020-05-14T15:02:15.829+0000 I NETWORK [conn1] received client metadata from 127.0.0.1:42108 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "4.2.6" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }
2020-05-14T15:02:15.829+0000 I ACCESS [conn1] Supported SASL mechanisms requested for unknown user 'mongoadmin@admin'
2020-05-14T15:02:15.830+0000 I ACCESS [conn1] SASL SCRAM-SHA-1 authentication failed for mongoadmin on admin from client 127.0.0.1:42108 ; UserNotFound: Could not find user "mongoadmin" for db "admin"
2020-05-14T15:02:15.832+0000 I NETWORK [conn1] end connection 127.0.0.1:42108 (0 connections now open)

Please help me.

question

All 2 comments

UserNotFound: Could not find user "mongoadmin" for db "admin"

You're overwriting the entrypoint script that processes the environment variables among other things https://github.com/docker-library/mongo/blob/master/4.2/docker-entrypoint.sh
Just leave that blank but you can keep the command, or if you have to put something: https://github.com/docker-library/mongo/blob/112494a28df43cd3c867f7487bcb825d9e176a7c/4.2/Dockerfile#L105

UserNotFound: Could not find user "mongoadmin" for db "admin"

You're overwriting the entrypoint script that processes the environment variables among other things https://github.com/docker-library/mongo/blob/master/4.2/docker-entrypoint.sh
Just leave that blank but you can keep the command, or if you have to put something:

https://github.com/docker-library/mongo/blob/112494a28df43cd3c867f7487bcb825d9e176a7c/4.2/Dockerfile#L105

It worked, thank you ;)

Was this page helpful?
0 / 5 - 0 ratings