Add an OpenLDAP database hook for dumping and restoring OpenLDAP databases with slapcat and slapadd (#1137). #1346
No reviewers
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic!1346
Loading…
Reference in a new issue
No description provided.
Delete branch "ebuzerdrmz44/borgmatic:openldap-hook"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Adds an
openldap_databases:hook. Dumps with slapcat, restores with slapadd,streamed through a named pipe like the other database hooks.
nameis an LDAP suffix, passed to-b.all. slapcat without-bdumps only the first database, so the schemarejects
alland you get a validation error instead of a backup that failspartway through.
cn=configis listed like any other suffix and isn't special-cased. The docssay to restore it first, in its own run.
ownership are left to
commands:withwhen: [restore].The command parts don't go through
shlex.quote, unlike the other hooks. There'sno shell involved (slapcat writes to the pipe with
-l, slapadd reads stdin), andquoting would break suffixes containing spaces such as
o=Example Corp,dc=example,dc=com. Two tests cover this.Closes #1137
Partial review. This is looking really good! I still need to get to docs and tests.
@ -1,4 +1,7 @@2.1.8.dev0* #1346: Add an OpenLDAP database hook for dumping and restoring OpenLDAP databases with slapcatand slapadd. See the documentation for more information:https://torsion.org/borgmatic/reference/configuration/data-sources/openldap/Thanks for adding this to the changelog!
@ -2397,0 +2403,4 @@properties:name:type: stringnot: {enum: ['all']}Interesting. Does this give a clear enough error message to the user? I'm just wondering if borgmatic giving a more hand-crafted warning/error might be clearer. I assume you've seen
borgmatic/hooks/data_source/sqlite.py:66. Maybe the difference with LDAP is thatallisn't a legitimate database name, whereas it would be for SQLite...?I do not feel strongly here.
I guess jsonschema can't attach a custom message to not, so a better one means checking it in apply_logical_validation(), which puts LDAP knowledge in config/validate.py. Your call. Happy to write it, or leave the schema as is.
Probably fine as is. You've documented it, so hopefully this schema restriction is just a backstop.
@ -0,0 +49,4 @@database['name'],'-l',dump_filename,)Might be nice to include
-d whateverto increase the log level when the borgmatic/Python log level is high enough. Seeborgmatic/borg/repo_create.py:111-112for some examples. Could also be applied toslapaddusage.Do not feel strongly.
Added, modeled on repo_create.py. There's a make_debug_flags() helper now, and both command builders splat it in:
I also pinned the log level in the existing command tests, so they can't pick up debug flags by surprise.
Awesome, thanks!
@ -0,0 +174,4 @@port,container,label,),You don't need this last
dump.make_data_source_dump_filename(). Theborgmatic_source_directorypattern is for compatibility with archives containing old dumps made before borgmatic's switch to theborgmatic_runtime_directory—so there will be exactly zero old OpenLDAP dumps made before that point because the OpenLDAP hook is brand new!right , removed it .
Great docs and tests! A few minor suggestions, and then I think this is ready to merge.
@ -113,2 +113,3 @@The SQLite hook in particular does not consider "all" a special database name.The SQLite hook in particular does not consider "all" a special database name,and the OpenLDAP hook doesn't accept it at all.You could also add OpenLDAP configuration to some of the examples in this file if you want. (See above.)
Do not feel strongly.
I added it to the involved example, right after sqlite_databases , that hook is local-only too, so a local hook in that block has precedent. Used cn=config plus a data suffix, since that's the pairing most people will actually want. Left it out of the "all databases" example for obvious reasons.
Great, thanks!
@ -0,0 +50,4 @@- name: dc=example,dc=com````cn=config` gets dumped and restored just like any other suffix. When restoring,Is there also an LDAP config file that should be backed up (separately, say in
source_directories)? Or doescn=configcover that?Checked the manual for this (slapd-config(5)): the root is hardcoded to cn=config with cn=Schema under it, so schema is in the dump . verified here, it comes back as cn=schema,cn=config. What's not in it is files the config only points at, like olcTLSCertificateFile, which is just a path. And with a legacy slapd.conf there's no config database at all: slapcat -f slapd.conf -b cn=config exits 1 with "could not open database". Both cases go in source_directories, I documented it on the reference page.
Awesome!
@ -0,0 +84,4 @@def test_dump_data_sources_logs_and_skips_if_dump_already_exists():databases = [{'name': 'dc=example,dc=com'}]flexmock(module).should_receive('make_dump_path').and_return('/run/borgmatic')I recommend also mocking out
build_dump_command()in these tests, so that you're not reliant on the behavior of a second unit (and subject to changes in it).done. Three of them stub it out; in the skip test it's a .never(), since that path returns before the builder is reached.
@ -0,0 +298,4 @@insert_logging_mock(logging.WARNING)flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)I recommend also mocking
build_restore_command()in these test functions.applied
@ -0,0 +269,4 @@)def test_build_restore_command_with_info_log_level_includes_stats_debug_flag():Normally I would recommend testing the
make_debug_flags()function separately (with its own unit tests) and then mocking it out in tests of any units that call it (likebuild_restore_command()).Do not feel strongly, as it is a pretty minor function. But it would allow you to cut out a couple tests at the cost of some additional mocking.
done. it has its own three tests now and is mocked in the
build_*tests. I kept one test per builder with the mock returning('-d', '256'), just so the splat into the command stays pinned.Thanks for all your hard work here. Merged!
Released in borgmatic 2.1.8!