Security: SSH host key verification disabled (MITM risk)#11309
Security: SSH host key verification disabled (MITM risk)#11309tomaioo wants to merge 1 commit intolablup:mainfrom
Conversation
The deployment script sets `AutoAddPolicy`, which trusts unknown SSH host keys automatically. This allows man-in-the-middle attacks during deployment, potentially exposing credentials and enabling command interception/modification. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
|
|
1 similar comment
|
|
|
Thanks for the security fix — the direction is correct ( Changelog requiredThis repo uses towncrier and every PR needs a news fragment. Please add one under
While here, the PR title
Supporting referencesThis isn't just a stylistic preference —
Operational concern with
|
There was a problem hiding this comment.
Pull request overview
Improves deployment security by enforcing strict SSH host key verification to reduce man-in-the-middle (MITM) risk during static file deployment.
Changes:
- Load system known host keys before connecting via SSH.
- Switch Paramiko’s missing-host-key policy from auto-trust (
AutoAddPolicy) to strict reject (RejectPolicy).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ssh.set_missing_host_key_policy(paramiko.RejectPolicy()) | ||
|
|
||
| for ip in sys.argv[1:]: | ||
| ssh.connect(ip) |
There was a problem hiding this comment.
With RejectPolicy enabled, ssh.connect(ip) will raise a paramiko SSHException for unknown/mismatched host keys and this script will exit with a traceback. Consider catching the host-key-related exception(s) and printing a clear actionable message (e.g., how to provision/update known_hosts for the target IP) so failures are easier to diagnose during deployments.
| ssh.connect(ip) | |
| try: | |
| ssh.connect(ip) | |
| except paramiko.BadHostKeyException as exc: | |
| print( | |
| f'Failed to connect to {ip}: the host key does not match the entry in known_hosts. ' | |
| f'Remove or update the stale key for this host and retry. Details: {exc}', | |
| file=sys.stderr, | |
| ) | |
| print( | |
| f'Example: ssh-keygen -R {ip} && ssh-keyscan -H {ip} >> ~/.ssh/known_hosts', | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| except paramiko.SSHException as exc: | |
| print( | |
| f'Failed to connect to {ip}: SSH host key verification failed or the host key is not present in known_hosts. ' | |
| f'Add the correct host key for this host and retry. Details: {exc}', | |
| file=sys.stderr, | |
| ) | |
| print( | |
| f'Example: ssh-keyscan -H {ip} >> ~/.ssh/known_hosts', | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) |
Summary
Security: SSH host key verification disabled (MITM risk)
Problem
Severity:
High| File:scripts/agent/deploy-static/deploy_static_files.py:L13The deployment script sets
AutoAddPolicy, which trusts unknown SSH host keys automatically. This allows man-in-the-middle attacks during deployment, potentially exposing credentials and enabling command interception/modification.Solution
Use strict host key verification (
RejectPolicy) and pre-provision known host keys (e.g., viaload_system_host_keys()or a managed known_hosts file). Fail deployment on host key mismatch.Changes
scripts/agent/deploy-static/deploy_static_files.py(modified)