mongo_user.present function creates user when already exists
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
The mongo_user.present state will attempt creation of a mongo user that already exists and has correct roles.
Setup
mongo_testuser:
mongodb_user.present:
- host: localhost
- port: 12345
- name: "testuser"
- passwd: << USER-PW >>
- database: admin
- user: "root"
- password: <<CONECT-PW>>
- roles:
- userAdminAnyDatabase
- dbAdminAnyDatabase
- readWriteAnyDatabase
Please be as specific as possible and give set-up details.
- on-prem machine
Steps to Reproduce the behavior
Install pymongo python module if required (via pip - version >3.7 < 4.0)
Create a state as listed above
Run the state and expect no errors.
[INFO ] Creating user testuser
[ERROR ] Creating user testuser failed with error: User "testuser@admin" already exists
[INFO ] User testuser is already present
Expected behavior
No errors are listed or reported (these were originally noted in /var/log/salt/minion)
Versions Report
Salt Version:
Salt: 3006.4
Python Version:
Python: 3.10.13 (main, Oct 4 2023, 21:54:22) [GCC 11.2.0]
Dependency Versions:
cffi: 1.14.6
cherrypy: 18.6.1
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.2
libgit2: Not Installed
looseversion: 1.0.2
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 22.0
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.9.8
pygit2: Not Installed
python-gnupg: 0.4.8
PyYAML: 6.0.1
PyZMQ: 23.2.0
relenv: 0.13.12
smmap: Not Installed
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: debian 11 bullseye
locale: utf-8
machine: x86_64
release: 5.10.0-13-amd64
system: Linux
version: Debian GNU/Linux 11 bullseye```
</details>
**Additional context**
I think this is related to the indenting of this call - it is not included in the conditional above so the mongodb.user_create is called regardless of the roles being correct.
https://github.com/saltstack/salt/blob/fd05f3876c2cba1f5485e69e58ea43f1b2247cdf/salt/states/mongodb_user.py#L133
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
Start in salt/states/mongodb_user.py around line 133, where the issue reports that the user creation call is outside the relevant conditional. Reproduce the provided state with an existing MongoDB user and verify that a correct user produces no creation error or duplicate creation attempt.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases, devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100