Skip to content

MongoDB encryption at rest: KMIP, AWS KMS, and local key files

Enable WiredTiger encryption at rest in MongoDB Enterprise with KMIP, AWS KMS, or a local keyfile — key rotation, performance impact, and the keystore that becomes your new SPOF.

MongoDB Enterprise ships native WiredTiger encryption at rest — AES-256-CBC or AES-256-GCM at the storage-engine layer, transparent to the application. Encryption uses a two-level key hierarchy: a master key managed by your key-management system, and per-database keys derived from it and stored encrypted alongside the data. This article covers the three credible key-management backends (KMIP, AWS KMS, local file), the rotation procedure, and the operational gotchas that surface when the keystore is what fails.

How to verify

Confirm encryption is enabled and check the encryption mode:

mongosh --host mongo.example.internal:27017
db.serverStatus().encryptionAtRest
db.adminCommand({ getCmdLineOpts: 1 }).parsed.security
sudo strings /var/lib/mongodb/WiredTiger.wt | head
ls -la /etc/mongodb/keystore/

encryptionAtRest.encryptionEnabled: true is the definitive answer. If the storage files contain readable strings (db.users, document content), encryption is not active despite what the config claims — the strings test is the truth.

What’s happening

WiredTiger encryption works at the page level: every block written to disk is encrypted, every block read is decrypted, with a per-database key. The master key encrypts the per-database keys; it never appears unencrypted on disk. At startup, mongod retrieves the master key from the configured backend, decrypts the database keys, and holds them in memory. If the keystore is unreachable, mongod cannot start.

Three backends are supported. KMIP (Key Management Interoperability Protocol) is the standard enterprise choice — typically backed by Thales CipherTrust, HashiCorp Vault’s KMIP secrets engine, or AWS CloudHSM with a KMIP front-end. AWS KMS native integration uses a customer-managed CMK and IAM authentication. Local keyfile stores a passphrase-protected key on the local filesystem — convenient for development, dangerous for production unless paired with disk-level encryption (LUKS) for the keyfile itself.

Performance overhead is modest with modern CPUs (AES-NI on Intel/AMD, ARMv8 crypto extensions on Graviton). Expect 3-8% CPU overhead on write-heavy workloads, less on read-heavy. The bigger operational concern is the keystore as a new SPOF — your database is fully unrecoverable without the master key.

The procedure

  1. Pick a backend and prepare its credentials. For AWS KMS, create a CMK in the same region as the MongoDB hosts and an IAM role with kms:Decrypt on the CMK.

    aws kms create-key --description "MongoDB master key prod-1" --tags TagKey=Project,TagValue=prod
  2. Configure mongod for encryption at rest. Set the options in mongod.conf before any data is written; you cannot enable encryption on an existing dataset without a full re-initialize.

    security:
      enableEncryption: true
      kmip:
        serverName: kmip.example.internal
        port: 5696
        serverCAFile: /etc/mongodb/kmip-ca.pem
        clientCertificateFile: /etc/mongodb/kmip-client.pem
  3. For AWS KMS specifically.

    security:
      enableEncryption: true
      kmip:
        kmsProvider: aws
        awsKey: "arn:aws:kms:us-east-1:123456789012:key/abcd…"
      encryptionCipherMode: AES256-GCM
  4. For a local keyfile. Use only when you cannot stand up a real KMS.

    openssl rand -base64 96 > /etc/mongodb/master.key
    chmod 600 /etc/mongodb/master.key
    chown mongodb:mongodb /etc/mongodb/master.key
    security:
      enableEncryption: true
      encryptionKeyFile: /etc/mongodb/master.key
  5. Initialize and verify. Start mongod with the new config and confirm encryption status. A clean restart with encryptionAtRest.encryptionEnabled: true confirms the wiring.

  6. Schedule master-key rotation. WiredTiger encrypts database keys with the master key; rotating the master key re-encrypts the database keys (cheap) without re-encrypting the entire dataset (expensive).

    db.adminCommand({ rotateKey: 1 })

Operational notes

  • The keystore is now in the critical path for startup. A KMIP outage prevents mongod from booting after a restart, even if the data and config are intact. Build the keystore for higher availability than the database that depends on it.
  • Backups are encrypted at rest too. A mongodump BSON file is plaintext; an LVM/filesystem snapshot of the WiredTiger files is encrypted but only readable on a mongod with access to the same master key. Plan restore procedures accordingly.
  • Key rotation does not re-encrypt data. It re-encrypts only the per-database keys. To force a full data re-encryption, you must initial-sync a new node from scratch — a deliberate operation, not an automatic one.
  • Encryption does not protect against authenticated reads. If an attacker has database credentials, encryption at rest provides zero defence. Pair with auth, RBAC, network segmentation, and audit logging.
  • The local keyfile must not live on the same disk it protects. A stolen disk image with the keyfile on it is no better than an unencrypted disk. Use disk-level LUKS on the keyfile mount, or store it on a separate disk.

Stack Harbor configures MongoDB encryption at rest as part of the security baseline for clients in regulated industries — KMIP-backed master keys, IAM-isolated KMS access, documented rotation cadence, and incident-response runbooks for keystore outages. See /en/services/managed-operations/ for how this integrates with the broader operating model.