Skip to content

Database audit fix · Authentication

How to Enable Access Control and MongoDB Authorization

MongoDB ships with access control off, so until security.authorization is set to enabled every client that reaches the port is a full administrator. Add authorization: enabled under security: in /etc/mongod.conf and restart mongod.

Hiren KalariyaHiren KalariyaLast reviewed mongodb-authorization
CtrlOpsMongoDB AuthorizationHIGH

What did your audit say?

FAIL · when the audit printed

Not found

As configured, every client that can reach the port has full admin access to every database.

Severity
High
Needs root or sudo
Yes
Results it can return
FAIL · WARN · SKIP · PASS
Check in this audit
7 of 8

Every threshold on this page is transcribed from the database-security-authentication audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 8 Authentication checks, or how the audit runs.

Greps /etc/mongod.conf for a line matching ^[[:space:]]*authorization:[[:space:]]*enabled (the security.authorization YAML key), reading the file through the script's root helper because it is not world-readable. The pattern is anchored to the start of the line but allows leading whitespace, so the normal indented form under security: matches while a commented-out # authorization: enabled does not. One matching line is the PASS; no match anywhere in the file is the FAIL.

Runs only when MongoDB is detected (HAS_MG=1: a mongod binary, a running mongod, or /etc/mongod.conf). It then needs /etc/mongod.conf to exist at that exact path (MGCONF) - any other config location yields WARN - and root/sudo to read it, otherwise SKIP. This is a config-file grep only: the script never connects to the server, so authorization enabled by a command-line flag or by a replica-set keyFile is not seen.

What each result means
ResultWhenWhat it means
SKIPMongoDB not installedNothing was checked. No mongod binary, process or config file was found on this host.
WARNmongod present but /etc/mongod.conf missingMongoDB is here but its config was not, so authorization is unconfirmed in either direction. Check whichever file your instance actually loads.
PASSauthorization: enabled foundThe config on disk demands credentials. Confirm mongod was restarted after the line was added.
FAILNot foundAs configured, every client that can reach the port has full admin access to every database.
SKIPNo root to read the fileNothing was read. The file is there but was unreadable, so this is not a pass.

MongoDB ships with access control disabled. Without security.authorization: enabled every client that reaches the port has full admin rights. This, combined with binding to 0.0.0.0, produced the 2017 "MongoDB ransom" wave where tens of thousands of databases were wiped. MongoDB Security Checklist item 1: "Enable Access Control and Enforce Authentication". CIS MongoDB: "Ensure authentication is enabled".

  • Server started with mongod --auth on the command line (systemd unit override) or with --keyFile/security.keyFile in a replica set: both enforce authorization but are not matched by the grep. False FAIL.
  • Config at a non-default path (/etc/mongodb.conf, /opt/mongo/mongod.conf) gives WARN "not found". Check ps -o args -C mongod for -f/--config.
  • Commented-out # authorization: enabled is correctly ignored.
  • Indented under security: is the normal form and is matched.
  1. Create the MongoDB admin user first

    Do this while authorization is still off, otherwise you lock yourself out.

    javascript
    use admindb.createUser({user:"admin", pwd: passwordPrompt(), roles:[{role:"userAdminAnyDatabase",db:"admin"},"readWriteAnyDatabase"]})

  2. Enable MongoDB authorization

    In /etc/mongod.conf:

    yaml
    security:  authorization: enabled

    Then systemctl restart mongod, because the check reads the file but the server only enforces what it loaded at startup.

  3. Give Redis a credential

    Redis on the same host has the same default and is worth doing in the same change. Set a requirepass in /etc/redis/redis.conf, or an ACL with a user line or an aclfile, then systemctl restart redis.

    ini
    requirepass a-long-random-string-not-a-word

  4. Update every client

    Both changes break existing connections the moment the service restarts, so update application connection strings first, not after. Then confirm the credential works:

    sh
    mongosh -u admin --authenticationDatabase admin

sh
# Ask the running server, which is authoritative:mongosh --quiet --eval 'db.adminCommand({getParameter:1, authenticationMechanisms:1})'# On an auth-enabled server an unauthenticated admin command is refused:mongosh --quiet --eval 'db.adminCommand({listDatabases:1})'# expected: MongoServerError ... requires authentication# And an authenticated connection works:mongosh -u admin --authenticationDatabase admin --quiet --eval 'db.adminCommand({listDatabases:1})'

Debugging

  • Confirm with command -v mongod; pgrep -a mongod; ls /etc/mongod.conf.
  • The file exists but the audit account cannot read it. sudo grep -n authorization /etc/mongod.conf.
  • The server uses a different config path. Find the real one with ps -o args= -C mongod and look for -f/--config. The check only ever reads /etc/mongod.conf, so a server configured elsewhere cannot produce PASS.
  • This is the known blind spot. If mongod is started with --auth, or the replica set uses security.keyFile (which implies authorization), the grep finds nothing. Confirm real enforcement with the mongosh command above and record the finding as a false positive. Setting security.authorization: enabled explicitly in /etc/mongod.conf both documents the intent and clears the check.
  • The config was changed and not restarted. systemctl restart mongod, then retest with mongosh.

Sources

Next

Re-run the Authentication audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 8 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

Download for MacDownload for WindowsAll 8 Authentication fixes

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google Analytics cookies and live chat stay off until you allow them. Cookie policy