[SERVER-33649] Can't create a user immediately after running rs.initiate() Created: 03/Mar/18  Updated: 27/Oct/23  Resolved: 05/Mar/18

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 3.7.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mykola Yashchenko Assignee: Ramon Fernandez Marina
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

1. Start mongod with the following command: mongod --auth --replSet
2. Initiate replica set: mongo admin --eval "rs.initiate();"
3. Create admin user: mongo admin --eval "db.createUser({user: '$MONGODB_ADMIN_USER', pwd: '$MONGODB_ADMIN_PASS', roles:[{role:'root',db:'admin'}]});"

Participants:

 Description   

I caught this bug during working with official docker image (v 3.7.2)

mongo_1              | => Creating admin user with a password in MongoDB
mongo_1              | 2018-03-03T11:22:09.246+0000 I NETWORK  [conn2] end connection 127.0.0.1:57942 (0 connections now open)
mongo_1              | 2018-03-03T11:22:09.250+0000 I REPL     [rsSync] transition to SECONDARY from RECOVERING
mongo_1              | 2018-03-03T11:22:09.263+0000 I REPL     [rsSync] conducting a dry run election to see if we could be elected. current term: 0
mongo_1              | MongoDB shell version v3.7.2
mongo_1              | 2018-03-03T11:22:09.268+0000 I REPL     [replexec-0] dry election run succeeded, running for election in term 1
mongo_1              | 2018-03-03T11:22:09.284+0000 I STORAGE  [replexec-0] createCollection: local.replset.election with generated UUID: c4afa21d-93d0-4935-98e1-4e2e126a3801
mongo_1              | connecting to: mongodb://127.0.0.1:27017/admin
mongo_1              | 2018-03-03T11:22:09.350+0000 I NETWORK  [listener] connection accepted from 127.0.0.1:57944 #3 (1 connection now open)
mongo_1              | 2018-03-03T11:22:09.351+0000 I NETWORK  [conn3] received client metadata from 127.0.0.1:57944 conn3: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.7.2" }, os: { type: "Linux", name: "PRETTY_NAME="Debian GNU/Linux 8 (jessie)"", architecture: "x86_64", version: "Kernel 4.9.60-linuxkit-aufs" } }
mongo_1              | MongoDB server version: 3.7.2
mongo_1              | 2018-03-03T11:22:09.358+0000 E QUERY    [thread1] Error: couldn't add user: Cache Reader No keys found for HMAC that is valid for time: { ts: Timestamp(1520076129, 1) } with id: 0 :
mongo_1              | _getErrorWithCode@src/mongo/shell/utils.js:25:13
mongo_1              | DB.prototype.createUser@src/mongo/shell/db.js:1437:15
mongo_1              | @(shell eval):1:1



 Comments   
Comment by Ramon Fernandez Marina [ 05/Mar/18 ]

I'm able to reproduce this behavior when I try to create users before rs.initiate() has finished running, so you need to wait for the replica set to be configured to be able to successfully add users.

Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group. See also our Technical Support page for additional support resources.

Regards,
Ramón.

Generated at Thu Feb 08 04:34:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.