Skip to content

security: enable SSH host key verification for remote collection - #22

Merged
OkiriGabriel merged 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/12-ssh-strict-host-key
Jul 16, 2026
Merged

OkiriGabriel merged 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/12-ssh-strict-host-key

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Summary

Closes the man-in-the-middle exposure caused by StrictHostKeyChecking=no in remote SSH collection.

What changed

  • collectors/server.py
    • Removed StrictHostKeyChecking=no from the SSH command used to collect remote server diagnostics.
    • Switched from asyncio.create_subprocess_shell to asyncio.create_subprocess_exec for the SSH argv, removing local shell injection risk for the remote path.
  • tools/executor.py
    • Removed StrictHostKeyChecking=no from the SSH command used by run_shell_command against remote hosts.
    • Same create_subprocess_exec change as above.
  • .env.example
    • Documented SSH_KNOWN_HOSTS and the requirement to mount a known_hosts file.
    • Clarified SSH_REMOTE_USER usage.
  • docs/CENTRALIZED_DEPLOYMENT.md
    • Updated SSH config, Docker run example, Kubernetes volume example, and .env checklist to reflect strict host-key verification and known_hosts mounting.
  • tests/test_ssh_remote.py
    • Asserts the constructed SSH argv does not contain StrictHostKeyChecking=no.
    • Asserts SSH_KNOWN_HOSTS is passed as UserKnownHostsFile.
    • Asserts SSH_REMOTE_USER produces the user@host form and does not override an explicit user@host.
    • Covers both collectors/server.py and tools/executor.py without opening real SSH connections.

Operational consequence (by design)

Remote SSH collection now relies on OpenSSH's default strict host-key checking. Deployments that previously depended on the insecure StrictHostKeyChecking=no behavior must mount or populate a known_hosts file and set SSH_KNOWN_HOSTS, or SSH connections to remote servers will fail. This is intentional — it prevents MITM attacks.

Tests / gates

python3 -m pytest tests/ -q

Result: 80 passed, 1 warning in 1.13s

Closes #12

Prepared with AI assistance (Kimi K2.7 Code), human-reviewed before submission.

Remove StrictHostKeyChecking=no from collectors/server.py and tools/executor.py.

Default to OpenSSH's strict host-key checking and add support for:

- SSH_KNOWN_HOSTS (sets UserKnownHostsFile)

- SSH_REMOTE_USER (prepends user@ when host has no user prefix)

Document known_hosts mounting in .env.example and docs/CENTRALIZED_DEPLOYMENT.md.

Add tests asserting the SSH argv no longer contains StrictHostKeyChecking=no,

and that the new env vars are wired correctly for both call sites.

Closes open-devops-agent#12

Co-Authored-By: Kimi K2.7 Code <[email protected]>
@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Thanks @Nitjsefnie! SSH host key verification is already covered in PR #20 (merged on feat/add-mcp). Closing as duplicate — appreciate the contribution.

@OkiriGabriel
OkiriGabriel merged commit bd7c592 into open-devops-agent:main Jul 16, 2026
3 of 11 checks passed
OkiriGabriel added a commit that referenced this pull request Jul 16, 2026
Consolidate SSH argv construction in tools/ssh_utils.build_ssh_argv and
wire collectors/server.py and tools/executor.py to create_subprocess_exec
instead of shell strings. Removes duplicate unused _build_ssh_args helpers.

Fixes 7 failing tests from Nitjsefnie PR #22 merge on main.

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove StrictHostKeyChecking=no from remote SSH collection

2 participants