nixos/openldap: refactor the openldap module to make it safer and more versatile#141240
nixos/openldap: refactor the openldap module to make it safer and more versatile#141240poscat0x04 wants to merge 13 commits intoNixOS:masterfrom
Conversation
2dcdb11 to
0f9895c
Compare
There was a problem hiding this comment.
- Run OpenLDAP in foreground
I don't think this is a good idea, for reasons mentioned inline.
- Change the default config directory to /var/lib/openldap/slapd.d
Why this change? Generally, system configuration lives in /etc, and this seems like system configuration...
- Use systemd's StateDirectory to create configuration dir (if it is the default config dir), and database dirs (if they are located under /var/lib/openldap)
Makes sense for database dirs, but I'm not sure about the configuration dir. See inline comment as well.
- Forbid setting declarativeContents for database whos directory is not under /var/lib/openldap to avoid accidentally rm -rf of the whole directory
- Run both the prestart script and slapd as unprivileged user instead of root
I like these, these are good improvements.
| ]); | ||
| Type = "forking"; | ||
| PIDFile = cfg.settings.attrs.olcPidFile; | ||
| StateDirectory = [ "openldap/slapd.d" ] ++ additionalStateDirectories; |
There was a problem hiding this comment.
Can we use ConfigurationDirectory for the configuration? IMO it makes sense for it to be separate from the rest of the state.
There was a problem hiding this comment.
It depends... when an application manages its own configuration we often call that "state" in NixOS land.
This module allows either the application or NixOS to manage the configuration (and maybe both?)
One argument for using StateDirectory is that the ownership allows you to run the application as non root entirely - ConfigurationDirectory does not allow this.
Good points on both side.
There was a problem hiding this comment.
Yeah, openldap is a bit weird with this. Because on the one hand, the OLC configuration can be changed at run-time, by writing to the appropriate directory via LDAP. OTOH, we nuke those settings every restart, with the declarative settings. This was a conscious choice, since it seems the most nix-y.
IMO it would be nice to deny writes to the configuration directory entirely, so that we don't surprise users by dropping settings after they are applied. I think this would require running the pre-start script as root, but the process could still be non-root (as it just needs read access)?
|
Looks like good improvements to maintainability, especially this one:
That was kind of dangerous before! Sorry for the delay in reviewing, I meant to do it last weekend but was busier than I expected. |
I mean the purpose of OLC (on-line configuration) is to make the configuration more like a database than a static config file so that configuration can be changed (via LDAP) without restarting the server. I think it makes sense to put the configuration database, which is stateful, in |
|
I can confirm that OpenLDAP has been working on my machine for two weeks now (running alongside postfix and dovecot). |
|
NixOS tests has been fixed |
|
I think OLC doesn't fit well with the general NIxOS philosophy, of having declarative configuration entirely controlled by NixOS modules, because the actual system configuration might diverge over time from what is configured through the modules. However, it is a powerful feature, and might be necessary for some people, and we don't want to block them from using NixOS. IMO, the best solution would be to have this depend on the |
|
I still don't think it's a good idea to put the OLC database in |
|
I would leave reviewing of this PR to you (@kwohlfahrt) and just do a final test on my infrastructure once it is ready. |
That's a good approach, can we move the current |
I tried to implement this this today, and it looks like it might not be workable. Unfortunately, file includes (like
I disagree on this - knowing that my configuration exactly matches what is declared in the module (and won't change when I redeploy the service) is a big benefit for me. I can implement this and open a PR against your branch, then we can merge this? |
|
Sure. |
|
Just in case you missed it, I opened a PR here: poscat0x04#1 - let me know what you think! |
Motivation for this change
Changes
StateDirectoryto create configuration dir (if it is the default config dir), and database dirs (if they are located under/var/lib/openldap)/var/lib/openldapto avoid accidentallyrm -rfof the whole directory/var/lib/openldap/slapd.dcc @kwohlfahrt
Todos
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)