Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ssh_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from pathlib import Path


# sshd keeps the first value it reads, so the drop-in must sort before others such as 50-cloud-init.conf.
DEFAULT_CONFIG = Path("C:/ProgramData/ssh/sshd_config") if os.name == "nt" else Path("/etc/ssh/sshd_config")
DEFAULT_DROPIN = Path("C:/ProgramData/ssh/sshd_config.d/99-dispersal-wolves.conf") if os.name == "nt" else Path("/etc/ssh/sshd_config.d/99-dispersal-wolves.conf")
DEFAULT_DROPIN = Path("C:/ProgramData/ssh/sshd_config.d/00-dispersal-wolves.conf") if os.name == "nt" else Path("/etc/ssh/sshd_config.d/00-dispersal-wolves.conf")

POLICY = {
"permitrootlogin": ("no", "Root login should be disabled."),
Expand Down
12 changes: 11 additions & 1 deletion tests/test_ssh_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from pathlib import Path

from ssh_guard import audit, install_dropin, parse_config, parse_effective_output
from ssh_guard import DEFAULT_DROPIN, HARDENED_DROPIN, audit, install_dropin, parse_config, parse_effective_output


class SshGuardTests(unittest.TestCase):
Expand All @@ -18,6 +18,16 @@ def test_effective_output_and_audit(self):
self.assertEqual(findings["permitrootlogin"].status, "pass")
self.assertEqual(findings["maxauthtries"].status, "pass")

def test_default_dropin_overrides_earlier_dropins(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "sshd_config.d").mkdir()
(root / "sshd_config.d" / "50-cloud-init.conf").write_text("PasswordAuthentication yes\n", encoding="utf-8")
(root / "sshd_config.d" / DEFAULT_DROPIN.name).write_text(HARDENED_DROPIN, encoding="utf-8")
config = root / "sshd_config"
config.write_text("Include sshd_config.d/*.conf\n", encoding="utf-8")
self.assertEqual(parse_config(config)["passwordauthentication"], "no")

def test_apply_requires_confirmation(self):
with tempfile.TemporaryDirectory() as directory:
ok, message = install_dropin(Path(directory) / "sshd_config", Path(directory) / "dropin", False)
Expand Down
Loading