Repository navigation
feat(roles/mongodb): store the dump login as a systemd credential - #526
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 credentialmongodb-dump-login.json./etc/credstore.encrypted/;mongodb-dump.servicegetsLoadCredentialEncrypted=mongodb-dump-login.json, and bothmongodump --configand mongosh read$CREDENTIALS_DIRECTORY/mongodb-dump-login.json./etc/credstore/(root, 0600); the script falls back to it via${CREDENTIALS_DIRECTORY:-/etc/credstore}./etc/mongodb-dump-login.jsonand itsbackup: truecopies are removed.mongodb__dump_user, the credential is removed (state: absent); the dump then logs in without a password, as before./usr/local/sbinto/usr/local/libexec, since onlymongodb-dump.servicegets the decrypted login; started directly, it aborts with a hint to usesystemctl start mongodb-dump.service. The old/usr/local/sbin/mongodb-dumpis removed.systemctl starthint, the TPM2/Secure Boot caveat. CONTRIBUTING:mongodblisted as a second reference implementation.Deviation from the documented pattern: the credential is built inline with
to_jsoninstead of from a template belowtemplates/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 withlookup('template')and withlookup('template') | string; only an expression ending into_jsonsurvives. 2.21.5 renders all variants correctly. The exception is documented in CONTRIBUTING ("Secrets for systemd Services");mariadb_serveris not affected, its INI content does not start with{.Verified with Molecule
mongodbon 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, andverify.ymlgreps all of/etcfor it: no match on systemd >= 251, only/etc/credstore/mongodb-dump-login.jsonbelow. 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.