Compare commits

...
3 Commits
Author SHA1 Message Date
christianmanivong 8e9d21c368 Merge pull request 'feat(ssh): SSHD_CONFIG_GENERATED keeps the hardening to the drop-in (#88), release 4.26.0' (#89) from fix/ssh-hardening-generated-config into main
driver / test (3.12) (push) Successful in 1m35s
driver / standard (push) Successful in 17s
driver / lint (push) Successful in 23s
driver / types (push) Successful in 2m7s
driver / test (3.13) (push) Successful in 1m41s
driver / lowest (push) Successful in 1m30s
driver / build (push) Successful in 1m5s
driver / security (push) Successful in 1m41s
driver / publish (push) Successful in 1m11s
CI / driver (push) Successful in 8m25s
2026-11-03 07:00:40 +00:00
christianmanivong 25f28297e4 chore(release): 4.26.0
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 17s
driver / types (pull_request) Successful in 2m9s
driver / test (3.13) (pull_request) Successful in 2m2s
driver / test (3.12) (pull_request) Successful in 2m10s
driver / lowest (pull_request) Successful in 36s
driver / build (pull_request) Successful in 35s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 3m28s
driver / publish (pull_request) Skipped
2026-11-03 07:56:46 +01:00
christianmanivong 847c902193 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.
2026-11-03 07:56:46 +01:00
4 changed files with 55 additions and 3 deletions

No files matched your search

+9
View File
@@ -7,6 +7,15 @@ recorded here; their history is the git log.
## [Unreleased]
## [4.26.0] - 2026-11-03
### Added
- `OpenSshServerMixin.SSHD_CONFIG_GENERATED`: a driver whose platform writes sshd_config
from its own database, but includes `/etc/ssh/sshd_config.d` (OpenMediaVault), sets it
and keeps `harden_ssh_server`. The hardening then goes only into the drop-in; a
sshd_config without that include is left alone and the result says why, since the
platform would write over a change to it on its next apply (#88, NetOrk/netork#1950).
## [4.25.0] - 2026-11-02
### Added
+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,
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-device-types"
version = "4.25.0"
version = "4.26.0"
description = "Abstract device-type base classes for NAPALM drivers"
readme = "README.md"
requires-python = ">=3.12"
+27
View File
@@ -14,6 +14,7 @@ import pytest
from napalm_device_types.channel import CommandResult
from napalm_device_types.ssh_server import (
DROPIN_DIR,
DROPIN_PATH,
MAIN_CONFIG,
OpenSshServerMixin,
@@ -401,6 +402,32 @@ def test_mixin_falls_back_to_sshd_config_without_an_include():
assert host._effective()["mac"] == ["hmac-sha2-256"]
class GeneratedConfigHost(FakeHost):
"""A platform that writes sshd_config from its own database (OpenMediaVault)."""
SSHD_CONFIG_GENERATED = True
def test_generated_sshd_config_still_gets_the_dropin():
host = GeneratedConfigHost()
result = host.harden_ssh_server({"mac": ["hmac-sha1"]})
assert result.applied
assert result.path == DROPIN_PATH
assert host.files[MAIN_CONFIG] == "Include /etc/ssh/sshd_config.d/*.conf\nPort 22\n"
def test_generated_sshd_config_without_an_include_is_left_alone():
"""The platform would write its own file over the change on its next apply."""
host = GeneratedConfigHost(main="Port 22\nMACs hmac-sha1,hmac-sha2-256\n")
result = host.harden_ssh_server({"mac": ["hmac-sha1"]})
assert not result.applied and not result.rolled_back
assert result.path is None
assert host.files[MAIN_CONFIG] == "Port 22\nMACs hmac-sha1,hmac-sha2-256\n"
assert list(host.files) == [MAIN_CONFIG]
assert host.reloads == 0
assert DROPIN_DIR in result.message
def test_mixin_restores_when_sshd_rejects_the_config():
host = FakeHost()
host.syntax_ok = False