feat(ssh): SSHD_CONFIG_GENERATED keeps the hardening to the drop-in (#88)

A platform that writes sshd_config from its own database (OpenMediaVault)
had to opt out of harden_ssh_server altogether. Where that generated file
includes /etc/ssh/sshd_config.d, the drop-in is safe; only the fallback
that rewrites sshd_config itself would be undone on the next apply. With
SSHD_CONFIG_GENERATED set, a sshd_config without the include is left alone
and the result says why.
This commit is contained in:
christianmanivong committed 2026-11-03 07:56:46 +01:00
1 parent fdf2f89115
commit 847c902193
3 files changed
+52 -2

No files matched your search

+18 -2
View File
@@ -15,7 +15,9 @@ accident.
``/etc/ssh/sshd_config.d/*.conf`` -- Debian and Ubuntu do, at the top -- the
lists go to :data:`DROPIN_PATH`, which sorts first and so wins. sshd_config
stays as the distribution shipped it, and removing the file undoes the change.
Only without such an ``Include`` is sshd_config itself rewritten, after a copy.
Only without such an ``Include`` is sshd_config itself rewritten, after a copy --
and not at all on a platform that generates it
(:attr:`OpenSshServerMixin.SSHD_CONFIG_GENERATED`).
**Nobody is locked out, by three checks.**
@@ -426,9 +428,16 @@ class OpenSshServerMixin:
whose platform writes sshd_config itself (an appliance that regenerates it
from its own database) must not inherit this, or must opt out with
``harden_ssh_server = None``: its file would be overwritten on the next
apply.
apply. Where that generated file still includes the drop-in directory, the
driver sets :attr:`SSHD_CONFIG_GENERATED` instead and keeps the hardening.
"""
#: True where the platform writes sshd_config from its own database
#: (OpenMediaVault): only the drop-in directory is written, and a
#: sshd_config that does not include it is left alone, since the platform
#: would write over a change to it on its next apply.
SSHD_CONFIG_GENERATED: bool = False
if TYPE_CHECKING: # pragma: no cover - declared for type checkers only
def run_command(
@@ -565,6 +574,13 @@ class OpenSshServerMixin:
main = self._ssh_read(MAIN_CONFIG)
if main is None:
raise RuntimeError(f"cannot read {MAIN_CONFIG}")
if self.SSHD_CONFIG_GENERATED and not has_dropin_include(main):
result.message = (
f"Not changed: {MAIN_CONFIG} does not include {DROPIN_DIR}, and this"
" platform writes it from its own settings."
)
say(result.message)
return result
restore = self._write_change(plan, main, result, say)
return self._apply_or_restore(
result,