Skip to content

Fix known_hosts race condition with concurrent clush SSH connections#2137

Open
berendt wants to merge 1 commit intomainfrom
fix-clush
Open

Fix known_hosts race condition with concurrent clush SSH connections#2137
berendt wants to merge 1 commit intomainfrom
fix-clush

Conversation

@berendt
Copy link
Member

@berendt berendt commented Mar 15, 2026

Add UserKnownHostsFile=/dev/null to clush ssh_options to prevent multiple parallel SSH connections (fanout: 64) from colliding on hard link updates to /root/.ssh/known_hosts.

AI-assisted: Claude Code

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Using UserKnownHostsFile=/dev/null avoids the race but fully disables host key persistence; consider whether pointing to an isolated temporary known_hosts file (per run or per user) would give you the same concurrency safety with better security properties.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `UserKnownHostsFile=/dev/null` avoids the race but fully disables host key persistence; consider whether pointing to an isolated temporary known_hosts file (per run or per user) would give you the same concurrency safety with better security properties.

## Individual Comments

### Comment 1
<location path="files/clustershell/clush.conf" line_range="10" />
<code_context>
 node_count: yes
 verbosity: 1
-ssh_options: -o IdentityFile=/ansible/secrets/id_rsa.operator -o StrictHostKeyChecking=no -o LogLevel=ERROR
+ssh_options: -o IdentityFile=/ansible/secrets/id_rsa.operator -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR
</code_context>
<issue_to_address>
**🚨 issue (security):** Using UserKnownHostsFile=/dev/null removes host key persistence and may hide MITM issues.

Combined with `StrictHostKeyChecking=no`, this effectively disables SSH host key verification. If this is only for ephemeral or non-production use, please scope it more narrowly (e.g., limited inventories or an explicit opt‑in flag) and ensure it cannot be reused in production or other sensitive contexts.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Use a per-invocation temporary known_hosts file instead of /dev/null
to prevent parallel SSH connections (fanout: 64) from colliding on
hard link updates, while still maintaining host key persistence
during the session. The temp file is seeded from /share/known_hosts
so existing host keys are verified.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New security issues found

Comment on lines +215 to +220
subprocess.call(
f'/usr/local/bin/clush -l {settings.OPERATOR_USER}'
f' -o "-o UserKnownHostsFile={tmp_known_hosts}"'
f' -g {host}',
shell=True,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'call' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

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.

1 participant