Skip to content

feat(roles/mongodb): store the dump login as a systemd credential - #526

Merged
NavidSassan merged 2 commits into
mainfrom
feat/mongodb-dump-credential
Oct 29, 2026
Merged

NavidSassan merged 2 commits into
mainfrom
feat/mongodb-dump-credential

Conversation

@NavidSassan

Copy link
Copy Markdown
Member

Second consumer of linuxfabrik.lfops.systemd_credential, following the pattern of #522: the password of the dump user moves from /etc/mongodb-dump-login.json (plain text, since #518) to the systemd credential mongodb-dump-login.json.

  • systemd >= 251 (RHEL 9/10, Debian 12, Ubuntu 24.04): encrypted in /etc/credstore.encrypted/; mongodb-dump.service gets LoadCredentialEncrypted=mongodb-dump-login.json, and both mongodump --config and mongosh read $CREDENTIALS_DIRECTORY/mongodb-dump-login.json.
  • RHEL 8 (239), Ubuntu 22.04 (249): plain text in /etc/credstore/ (root, 0600); the script falls back to it via ${CREDENTIALS_DIRECTORY:-/etc/credstore}.
  • The old /etc/mongodb-dump-login.json and its backup: true copies are removed.
  • Without authorization or mongodb__dump_user, the credential is removed (state: absent); the dump then logs in without a password, as before.
  • The dump script moves from /usr/local/sbin to /usr/local/libexec, since only mongodb-dump.service gets the decrypted login; started directly, it aborts with a hint to use systemctl start mongodb-dump.service. The old /usr/local/sbin/mongodb-dump is removed.
  • mongosh gets the path of the login file through the environment instead of having it quoted into the JavaScript.
  • README: where the password lives per platform, the systemctl start hint, the TPM2/Secure Boot caveat. CONTRIBUTING: mongodb listed as a second reference implementation.

Deviation from the documented pattern: the credential is built inline with to_json instead of from a template below templates/etc/credstore/. ansible-core before 2.19 turns a rendered string that starts with { into a dict, so the module stored its Python repr ({'password': ...}) and mongosh / mongodump could not parse it. Reproduced locally: ansible-core 2.16.19 breaks with lookup('template') and with lookup('template') | string; only an expression ending in to_json survives. 2.21.5 renders all variants correctly. The exception is documented in CONTRIBUTING ("Secrets for systemd Services"); mariadb_server is not affected, its INI content does not start with {.

Verified with Molecule mongodb on Rocky 8, 9, 10, Debian 12, Ubuntu 22.04 and 24.04 (ansible-core 2.16.19): converge, verify, idempotence, verify. The scenario's dump password carries a marker, and verify.yml greps all of /etc for it: no match on systemd >= 251, only /etc/credstore/mongodb-dump-login.json below. The dump (mongodump and the file-based method with fsyncLock as the dump user) runs through the unit, so it proves that both mongodump and mongosh read the credential.

Not tested: the upgrade path from a host with the old /etc/mongodb-dump-login.json* and /usr/local/sbin/mongodb-dump.

NavidSassan and others added 2 commits October 29, 2026 11:43
Also moves the dump script to /usr/local/libexec, since only
mongodb-dump.service gets the decrypted login.

The credential is built inline with to_json instead of from a template:
ansible-core before 2.19 turns a rendered '{...}' string into a dict, and
the module then stored its Python repr. Verified with ansible-core 2.16.19
and 2.21.5; Molecule mongodb green on Rocky 8/9/10, Debian 12, Ubuntu
22.04/24.04.
@NavidSassan
NavidSassan merged commit 278a672 into main Oct 29, 2026
13 checks passed
@NavidSassan
NavidSassan deleted the feat/mongodb-dump-credential branch October 29, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant