auth failed when start mongo with --auth
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.5k
- Forks
- 787
- PR merge metrics
- No merged PRs in 30d
Description
SUMMARY
when i set a password for mongo with
MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD
docker run -d --network some-network --name some-mongo
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin
-e MONGO_INITDB_ROOT_PASSWORD=secret
mongo
and i add username and password in st2.conf
[database]
host = mongo
connection_retry_max_delay_m = 1
connection_retry_backoff_mul = 1
connection_timeout = 3000
username = mongoadmin
password = secret
but the st2 run with auth error
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/mongo_client.py", line 781, in _cache_credentials
st2api | sock_info.authenticate(credentials)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/pool.py", line 810, in authenticate
st2api | auth.authenticate(credentials, self)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/auth.py", line 673, in authenticate
st2api | auth_func(credentials, sock_info)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/auth.py", line 591, in _authenticate_default
st2api | return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/auth.py", line 295, in _authenticate_scram
st2api | res = sock_info.command(source, cmd)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/pool.py", line 694, in command
st2api | exhaust_allowed=exhaust_allowed)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/network.py", line 161, in command
st2api | parse_write_concern_error=parse_write_concern_error)
st2api | File "/opt/stackstorm/st2/lib/python3.6/site-packages/pymongo/helpers.py", line 164, in _check_command_response
st2api | raise OperationFailure(errmsg, code, response, max_wire_version)
st2api | pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
STACKSTORM VERSION
3.6.0
OS, environment, install method
docker-compose
i think the root cause is missing authentication_source='admin' when connect to mongodb, but i can't find where to set this config.
i checked the source code, and found the code not use this parameter.
in this file, line 188
st2-3.6.0/st2common/st2common/models/db/init.py
should add authentication_source parameter
connection = mongoengine.connection.connect(
db_name,
host=db_host,
port=db_port,
tz_aware=True,
username=username,
password=password,
connectTimeoutMS=connection_timeout,
serverSelectionTimeoutMS=connection_timeout,
**ssl_kwargs,
**compressor_kwargs,
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue points to st2common/st2common/models/db/init.py and its mongoengine.connection.connect call; start by tracing how the [database] values in st2.conf reach that call. Check the MongoDB authentication behavior described in the issue and the surrounding database tests or entry points. Done means a MongoDB instance initialized with the documented root credentials can authenticate successfully through StackStorm.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- authentication, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100