Repository navigation
fix: use imported host credentials for ssh -a/-u/-d on static provider - #937
Merged
Merged
Conversation
The apply-file (-a), upload (-u), and download (-d) paths built tools.Remote from viper config and CLI defaults, ignoring the credentials stored in the static inventory by `onctl import`. This caused authentication failures because remote.Username was empty (no static.vm.username in viper), the wrong private key was read (global default ~/.ssh/id_rsa), and SSHPort defaulted to 22. Export ProviderStatic.GetHost so cmd/ssh.go can look up the imported host's username, port, and key and apply them to the Remote struct before running any non-interactive SSH operation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16405d7dd3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #937 +/- ##
==========================================
- Coverage 24.03% 23.96% -0.07%
==========================================
Files 44 44
Lines 4402 4414 +12
==========================================
Hits 1058 1058
- Misses 3213 3225 +12
Partials 131 131 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Codex review on #937: imported hosts can store keys like ~/.ssh/id_ed25519, but the read path skipped the tilde expansion that getSSHKeyFilePaths applies elsewhere, silently leaving PrivateKey empty and failing SSH auth. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMNwz2nRZZSn5T6aEmUyJu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onctl -p static ssh <name> -a <script>(and-u/-d) was failing withssh: unable to authenticatebecause thetools.Remotestruct was built from viper config and CLI defaults, not the imported host's inventory entryremote.Usernamewas always empty (static.vm.usernameis never set in viper)remote.PrivateKeyused the global default key (~/.ssh/id_rsa) instead of the key specified atonctl importtimeremote.SSHPortdefaulted to 22 instead of the imported host's stored portusesImportedKeyguard only short-circuited for direct interactive SSH (isDirectSSH && usesImportedKey), so-a/-u/-dalways hit the broken pathFix
ProviderStatic.getHost→GetHostsocmd/ssh.gocan access inventory credentials!(isDirectSSH && usesImportedKey)→!usesImportedKeyto skip reading the default key for all static-provider operations when no-kflag is giventools.Remote, populateUsername,SSHPort, andPrivateKeyfrom the imported host's inventory entry (respecting explicit-k/-Pflag overrides)Test plan
onctl import ax41 --ip <ip> --user root --key ~/.ssh/id_ed25519onctl -p static ssh ax41 -a some-script.sh— should now authenticate correctlyonctl -p static ssh ax41(interactive) — should still work as beforeonctl -p static ssh ax41 -k /other/key -a script.sh— explicit-kflag should override inventory key