pkg/machine: stop using a device name for UserKnownHostsFile #30054
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
mheon
What:
LocalhostSSHArgs()passesUserKnownHostsFile=+os.DevNull. On Windows that value isNUL, and because thesshbinary is resolved fromPATH, an MSYS/Cygwin build can win the race and treatNULas a relative filename — creating a real file calledNULin the caller's working directory.Why it matters:
NULis a reserved device name on Windows (withCON,PRN,AUX,COM1-9,LPT1-9). Most tools cannot open it, Explorer anddelcannot remove it, and if it is ever committed it breaksgit checkouton Windows. It appears silently in whatever directory the caller happens to be in — common for tooling that shells out topodman.The code already uses
os.DevNullrather than a hardcoded/dev/null, which is exactly why it still breaks: Go-level portability doesn't help when the consumer is whicheversshbinary thePATHresolves.Fix: use a real file —
filepath.Join(os.TempDir(), "podman-machine-known-hosts")— created up front at0600, and passed throughfilepath.ToSlash, because a backslash-separatedC:\...path is not portable between native Windows OpenSSH and Cygwin/MSYS builds.LocalhostSSHArgs()'s signature is unchanged, so bothlocalhostNativeSSHandLocalhostSSHCopyare fixed without touching their call sites or the-i/-pargument ordering.A stable per-user path rather than a fresh temp file per invocation is deliberate:
StrictHostKeyChecking=nois 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
sshOpenSSH_10.5p1 (/usr/bin/sshahead ofOpenSSH_for_Windows_9.5p2onPATH), key exchange run againstlocalhost:This is the same mechanism the bug report describes, and it is not specific to
podman machine ssh— any MSYSsshinvocation with that option creates the file.Test:
TestLocalhostSSHArgsKnownHostsIsRealFileasserts the option is set, is notos.DevNull, is absolute, contains no backslashes, and resolves to an existing non-directory file.go test ./pkg/machine/andgo vet ./pkg/machine/pass;pkg/machinealso cross-compiles forGOOS=windows, and the full Windows binary builds with-tags "containers_image_openpgp remote".Not addressed here:
StrictHostKeyChecking=noremains. 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.