feat(settings): add SSH host key checking option#209
feat(settings): add SSH host key checking option#209water-sucks merged 2 commits intonix-community:mainfrom
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis PR introduces SSH host key verification configuration to control how unknown or changed host keys are handled. A new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.4)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/system/ssh.go (1)
348-358:⚠️ Potential issue | 🟡 MinorChanged host keys are always rejected before the
host_key_verificationmode is evaluated.When
len(keyErr.Want) > 0(indicating a host key has changed from what's recorded in known_hosts), the function returns an error at line 349 before reaching thehostKeyVerificationswitch at line 360. This meansHostKeyVerificationOffmode cannot accept a changed key—the mode only applies to unknown keys.This appears intentional as a security measure (treating key changes as potential MITM attacks), but it deviates from OpenSSH's
StrictHostKeyChecking=no, which would permit changed keys. If this stricter behavior is by design, consider documenting this explicitly in code comments to clarify that all host key verification modes reject changed keys unconditionally.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/system/ssh.go` around lines 348 - 358, The current check for changed host keys (len(keyErr.Want) > 0) unconditionally returns an error and prevents the subsequent host_key_verification switch (including HostKeyVerificationOff) from being applied; either update the logic to consult hostKeyVerification before rejecting changed keys (i.e., move or gate this conditional so HostKeyVerificationOff/HostKeyVerificationAcceptChanged can allow replacement) or—if the stricter rejection is intentional—add an explicit code comment immediately above the len(keyErr.Want) check documenting that changed keys are always treated as fatal (references: keyErr.Want, hostKeyVerification, HostKeyVerificationOff, knownHostsPath, ssh.FingerprintSHA256) so future readers understand the deliberate deviation from OpenSSH StrictHostKeyChecking behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@internal/system/ssh.go`:
- Around line 348-358: The current check for changed host keys (len(keyErr.Want)
> 0) unconditionally returns an error and prevents the subsequent
host_key_verification switch (including HostKeyVerificationOff) from being
applied; either update the logic to consult hostKeyVerification before rejecting
changed keys (i.e., move or gate this conditional so
HostKeyVerificationOff/HostKeyVerificationAcceptChanged can allow replacement)
or—if the stricter rejection is intentional—add an explicit code comment
immediately above the len(keyErr.Want) check documenting that changed keys are
always treated as fatal (references: keyErr.Want, hostKeyVerification,
HostKeyVerificationOff, knownHostsPath, ssh.FingerprintSHA256) so future readers
understand the deliberate deviation from OpenSSH StrictHostKeyChecking behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 87f5c43c-ec27-48b1-8c49-7d725baf521e
📒 Files selected for processing (4)
cmd/apply/apply.gointernal/settings/completion.gointernal/settings/settings.gointernal/system/ssh.go
Mimics the behavior of the OpenSSH option StrictHostKeyChecking.
7a747f6 to
83ce475
Compare
To further enable non-interactive
applyworkflows, this PR creates a new SSHknown_hostskey policy setting that mostly corresponds to the functionality of OpenSSH'sStrictHostKeyCheckingsetting.By default, it is set to
ask(the previous behavior as well), but it can be changed toaccept-newto always accept host keys,offto disable host key checking entirely, andstrictto deny unknown host keys. Any-yflags or disabling of confirmation prompts will change the defaultaskbehavior toaccept-newto allow for non-interactive execution ofnixos-cliwith new/unknown host keys.Summary by CodeRabbit