(feature) Add host key scanning for SSH credentials
Add a host detail action that scans the target SSH host key with ssh-keyscan and stores it on the selected SSH credential. Merge scanned known_hosts entries without duplicates and let the existing runtime config pass them through as UserKnownHostsFile for unattended rsync over SSH. Extend host checks to warn when the selected credential has no known_hosts entries, making host key verification failures actionable from Django.
This commit is contained in:
@@ -10,6 +10,7 @@ from django.test import SimpleTestCase, TestCase, override_settings
|
||||
|
||||
from pobsync_backend.forms import normalize_private_key, validate_ssh_private_key
|
||||
from pobsync_backend.models import GlobalConfig, SshCredential
|
||||
from pobsync_backend.ssh_keys import merge_known_hosts
|
||||
|
||||
|
||||
class SshCredentialValidationTests(SimpleTestCase):
|
||||
@@ -60,3 +61,14 @@ class SshCredentialManagementTests(TestCase):
|
||||
|
||||
global_config.refresh_from_db()
|
||||
self.assertEqual(global_config.default_ssh_credential.name, "default")
|
||||
|
||||
def test_merge_known_hosts_appends_unique_entries(self) -> None:
|
||||
merged = merge_known_hosts(
|
||||
"web-01.example.test ssh-ed25519 AAAAOLD\n",
|
||||
"web-01.example.test ssh-ed25519 AAAAOLD\nweb-01.example.test ssh-rsa AAAANEW\n",
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
merged,
|
||||
"web-01.example.test ssh-ed25519 AAAAOLD\nweb-01.example.test ssh-rsa AAAANEW\n",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user