← Back to Pull requests

pkg/machine: stop using a device name for UserKnownHostsFile #30054

Closed
unknown closed this pull request without merging on Oct 28, 2026 12:11 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 19:15 UTC
Author

What: LocalhostSSHArgs() passes UserKnownHostsFile= + os.DevNull. On Windows that value is NUL, and because the ssh binary is resolved from PATH, an MSYS/Cygwin build can win the race and treat NUL as a relative filename — creating a real file called NUL in the caller's working directory.

Why it matters: NUL is a reserved device name on Windows (with CON, PRN, AUX, COM1-9, LPT1-9). Most tools cannot open it, Explorer and del cannot remove it, and if it is ever committed it breaks git checkout on Windows. It appears silently in whatever directory the caller happens to be in — common for tooling that shells out to podman.

The code already uses os.DevNull rather than a hardcoded /dev/null, which is exactly why it still breaks: Go-level portability doesn't help when the consumer is whichever ssh binary the PATH resolves.

Fix: use a real file — filepath.Join(os.TempDir(), "podman-machine-known-hosts") — created up front at 0600, and passed through filepath.ToSlash, because a backslash-separated C:\... path is not portable between native Windows OpenSSH and Cygwin/MSYS builds.

LocalhostSSHArgs()'s signature is unchanged, so both localhostNativeSSH and LocalhostSSHCopy are fixed without touching their call sites or the -i/-p argument ordering.

A stable per-user path rather than a fresh temp file per invocation is deliberate: StrictHostKeyChecking=no is still in effect, so the file only ever receives host keys we have already decided not to verify. Per-invocation temp files would buy no additional safety and would require threading a cleanup function through both call sites, adding failure modes for no gain. Happy to switch if reviewers prefer.

Verification — Windows 11 26300.9711, MSYS ssh OpenSSH_10.5p1 (/usr/bin/ssh ahead of OpenSSH_for_Windows_9.5p2 on PATH), key exchange run against localhost:

UserKnownHostsFile=NUL                                    -> 91-byte file named NUL in the cwd
UserKnownHostsFile=C:/.../Temp/podman-machine-known-hosts  -> cwd untouched, key written to that file

This is the same mechanism the bug report describes, and it is not specific to podman machine ssh — any MSYS ssh invocation with that option creates the file.

Test: TestLocalhostSSHArgsKnownHostsIsRealFile asserts the option is set, is not os.DevNull, is absolute, contains no backslashes, and resolves to an existing non-directory file. go test ./pkg/machine/ and go vet ./pkg/machine/ pass; pkg/machine also cross-compiles for GOOS=windows, and the full Windows binary builds with -tags "containers_image_openpgp remote".

Not addressed here: StrictHostKeyChecking=no remains. This change removes the stray-file symptom, not the decision to skip verification of a VM we created ourselves. Seeding the machine's real key and dropping the option would be the durable fix; it is a larger behavioural change and probably belongs in its own issue/PR.

Fixes #30026

---

AI assistance: the patch and its regression test were drafted with AI coding agents (CodingFleet). The reproduction on Windows, the A/B verification, the review responses and this description were directed and checked by me — I'm accountable for the change.

Diff: 410 lines (+307 / -103) across 5 files Reviewer: mheon Review duration: 1015m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 410 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.360
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #30054"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 44.9% (MEDIUM) · Higher = larger blast radius
44.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.7% · Safe to merge
17.7%