Skip to content

fix: use imported host credentials for ssh -a/-u/-d on static provider - #937

Merged
cdalar merged 2 commits into
mainfrom
fix/static-ssh-apply-credentials
Jun 27, 2026
Merged

cdalar merged 2 commits into
mainfrom
fix/static-ssh-apply-credentials

Conversation

@cdalar

@cdalar cdalar commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • onctl -p static ssh <name> -a <script> (and -u/-d) was failing with ssh: unable to authenticate because the tools.Remote struct was built from viper config and CLI defaults, not the imported host's inventory entry
  • remote.Username was always empty (static.vm.username is never set in viper)
  • remote.PrivateKey used the global default key (~/.ssh/id_rsa) instead of the key specified at onctl import time
  • remote.SSHPort defaulted to 22 instead of the imported host's stored port
  • The usesImportedKey guard only short-circuited for direct interactive SSH (isDirectSSH && usesImportedKey), so -a/-u/-d always hit the broken path

Fix

  • Export ProviderStatic.getHost → GetHost so cmd/ssh.go can access inventory credentials
  • Change the key-read guard from !(isDirectSSH && usesImportedKey) → !usesImportedKey to skip reading the default key for all static-provider operations when no -k flag is given
  • After building tools.Remote, populate Username, SSHPort, and PrivateKey from the imported host's inventory entry (respecting explicit -k/-P flag overrides)

Test plan

  • onctl import ax41 --ip <ip> --user root --key ~/.ssh/id_ed25519
  • onctl -p static ssh ax41 -a some-script.sh — should now authenticate correctly
  • onctl -p static ssh ax41 (interactive) — should still work as before
  • onctl -p static ssh ax41 -k /other/key -a script.sh — explicit -k flag should override inventory key

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread cmd/ssh.go Resolved
@codecov

codecov Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.96%. Comparing base (57a69e3) to head (916baf0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/ssh.go 0.00% 13 Missing ⚠️
pkg/cloud/static.go 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
@cdalar
cdalar merged commit dd2fb89 into main Jun 27, 2026
17 checks passed
@cdalar
cdalar deleted the fix/static-ssh-apply-credentials branch August 19, 2026 13:53
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.

2 participants

⌂ 换网址