Database security checklist: access, encryption, exposure and patching
A practical checklist for hardening any database server, with MongoDB and Redis examples: no public exposure, authentication, least privilege, TLS, protected backups, patching and audit.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
Most database breaches do not need clever exploits. They happen because a server listened on a public address without a password, an application account could do everything, or a backup file sat somewhere readable. Work through this list for every database you run, then repeat it after major changes.
1. Keep it off the internet
A database port should be reachable only from the hosts that need it: application servers, admin jump hosts, backup and monitoring systems. Both MongoDB and Redis document that they should run in a trusted network.
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo ss -ltnp | grep -E ':(27017|6379|5432|3306)\b' # what listens, on which address
- Bind to loopback and private interfaces only:
net.bindIpin/etc/mongod.conf,bindinredis.conf. Both default to localhost; keep it that way unless remote clients need access. - Add a host firewall rule that allows the port only from known source addresses, and a network firewall or security group in front of that.
- From a machine outside your network, confirm that the port is closed. Only scan hosts you own or are authorized to test.
- Use a VPN, SSH tunnel or bastion host for administration instead of opening ports to admin laptops.
2. Require authentication everywhere
- MongoDB: set
security.authorization: enabledand create users before opening the port. Replica set members also need internal authentication (keyfile or X.509). - Redis: protected mode is a fallback, not a control. Create ACL users, give every client its own credentials, and disable or password-protect the
defaultuser. - Generate long random secrets (for example
openssl rand -base64 32, orACL GENPASSin Redis) and keep them in a secret store, never in source control or command lines.
3. Least privilege
Each application, job and person gets its own account with only the rights it needs. If one is leaked, the damage stays small and the audit trail shows who did what.
// MongoDB: read-write on one database only
use admin
db.createUser({ user: "appuser", pwd: passwordPrompt(), roles: [ { role: "readWrite", db: "shop" } ] })
# Redis: own key prefix, no dangerous commands
ACL SETUSER appuser on >CHANGE_ME ~app:* &app:* +@all -@dangerous
- Backups use a backup-only role (
backupin MongoDB), monitoring uses a read-only one (clusterMonitor, or a Redis user limited to+info +ping). - Keep superuser accounts (
root, a full Redis admin) for emergencies, with the secret stored separately. - Review users regularly and remove the ones for retired applications and people who left.
4. Encrypt traffic and data
Without TLS, passwords and data cross the network in clear text. Enable TLS on any connection that leaves a single trusted host.
# /etc/mongod.conf
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/ca.pem
# redis.conf (Redis built with TLS support)
port 0
tls-port 6379
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
- Encrypt data at rest: database-native encryption where available, otherwise encrypted volumes (for example LUKS/dm-crypt).
- Clients must verify the server certificate. Disabling verification to make an error go away removes most of the protection.
5. Protect the backups
A backup holds the same data as the database, usually with weaker protection. Encrypt backup files, restrict who can read them, store at least one copy offline or immutable so ransomware on the database host cannot delete it, and test restores. See the 3-2-1 backup article for a full routine.
6. Patch and stay supported
- Subscribe to the vendor’s security announcements and check for CVEs regularly.
- Track the end-of-life dates of your major versions and upgrade before they expire; unsupported versions stop getting security fixes.
- Apply minor releases on a schedule, test them on staging first, and keep the OS patched too.
7. Harden the host and the service
- Run the database as a dedicated unprivileged system user (
mongodb/mongod,redis), never as root. - Restrict the data, log and configuration directories to that user. Config files that contain secrets should be mode 600.
- Turn off features you do not use: MongoDB can disable server-side JavaScript with
--noscripting; Redis ACLs can block commands such asCONFIG,DEBUGandMODULEfor everyone except admins.
8. Log, monitor and audit
- Collect authentication failures and admin actions centrally. MongoDB Enterprise includes an auditing facility; on other editions, rely on the server log and your platform’s logging.
- Alert on unusual connections, sudden drops in key or document counts, and failing backups.
- Write down who may access production data and why, and review it.
Quick self-check
- Can anyone on the internet open a TCP connection to the database port? (Must be no.)
- Does every client authenticate with its own user? (Must be yes.)
- Can the application account drop databases or change configuration? (Should be no.)
- Is traffic between application and database encrypted when it leaves the host? (Should be yes.)
- Is there a restored-and-verified backup from the last month, with a copy off the host? (Must be yes.)
- Is the server on a supported version with current security patches? (Must be yes.)
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0200 PostgreSQL roles, privileges and default privileges Create login and group roles, grant access to databases, schemas and tables, and use ALTER DEFAULT PRIVILEGES so tables created later get… Intermediate · Step by step · Linux Article Roles & administration · Security & access 15 Oct 2026
- 0201 pg_hba.conf and PostgreSQL authentication methods pg_hba.conf decides who may connect from where and how they must prove who they are. Rules are checked top to bottom and… Intermediate · Explains an idea · Linux Article Install & connect · Security & access 15 Oct 2026
- 0209 Fix: FATAL: password authentication failed for user PostgreSQL reached the server and found a matching pg_hba.conf rule, but the password check failed. Usually a wrong password, a role without… Intermediate · Fixes an error · Any system Article Roles & administration · Security & access 15 Oct 2026
- 0210 Fix: FATAL: no pg_hba.conf entry for host The server received the connection but no pg_hba.conf rule matches this client address, user, database and SSL mode. Add or correct a… Intermediate · Fixes an error · Linux Article Install & connect · Security & access 15 Oct 2026
- 0214 MySQL users and privileges: CREATE USER, GRANT and authentication plugins A MySQL account is a user name plus the host it connects from. You create it with CREATE USER, give it rights… Beginner · Step by step · Linux Article Administration · Security & access 15 Oct 2026
- 0216 MySQL vs MariaDB: what actually differs MariaDB started as a fork of MySQL and still speaks the same client protocol, but GTIDs, JSON storage, authentication and tooling have… Intermediate · Explains an idea · Linux Article Choosing a database · MySQL & MariaDB 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +5,471 chars