Skip to content

Offer only the deployment key when ssh-ing to instances - #67

Open
wayneeseguin wants to merge 1 commit into
cloudfoundry:masterfrom
fivetwenty-io:ssh-identities-only
Open

Offer only the deployment key when ssh-ing to instances#67
wayneeseguin wants to merge 1 commit into
cloudfoundry:masterfrom
fivetwenty-io:ssh-identities-only

Conversation

@wayneeseguin

Copy link
Copy Markdown

The failure

Direct ssh examples (the os tagged service configuration specs, and anything else going through BoshHelper#ssh) die with:

Net::SSH::Disconnect: disconnected: Too many authentication failures (2)

It looks intermittent, because whether it fires depends on how many identities happen to be loaded on the machine running BATs, and an RSA key is offered once per signature algorithm. bosh ssh is unaffected, since the CLI passes -o IdentitiesOnly=yes.

The cause

BoshHelper#ssh sets :key_data and leaves every other identity source at its default, so Net::SSH adds two more:

  • ~/.ssh/config. Net::SSH.start merges the parsed config under the caller's options, so IdentityFile entries in a Host * block land in :keys, which is offered before :key_data.

  • The ssh-agent, which contributes every loaded identity. SSH_AUTH_SOCK is not the only way it is found, so clearing that variable does not settle it either.

Enough identities and the server hits MaxAuthTries and disconnects. Note :keys_only alone does not fix this. It gates agent identities only (key_manager.rb:134); the ones that came from the config file are still offered.

The fix

Clear :keys, set :keys_only, and turn the agent off, so the only identity offered is the key BATs was handed. Parsing of ~/.ssh/config stays enabled, so directives such as ProxyJump, Port, and HostName keep working; only the identity sources are pinned.

The gateway path dups ssh_options after these lines, so it inherits them and still substitutes :gateway_private_key for :key_data as before.

Evidence

Counting the identities each option set would offer, using the real KeyManager on a machine with a Host * block and a loaded agent:

Options Identities offered
current code (key_data only) 190
keys_only: true 3
keys: [] + keys_only: true + use_agent: false (this PR) 1

And connecting to a real sshd with a key it accepts, all four in one run:

A. upstream today (key_data only)
    AUTH-FAIL: Net::SSH::Disconnect: disconnected: Too many authentication failures (2)
B. keys_only only
    AUTH-FAIL: Net::SSH::Disconnect: disconnected: Too many authentication failures (2)
C. config:false + keys_only + use_agent:false
    AUTH-OK: 26a28701-6c76-43fa-40be-1289c94e51d6
D. keys:[] + keys_only + use_agent:false        <-- this PR
    AUTH-OK: 26a28701-6c76-43fa-40be-1289c94e51d6

Variant C, which offers the same single identity as D but by disabling config parsing outright, is the form that ran the full suite green (47 examples, 0 failures, 11 pending) on a Proxmox VE lab: run report. D is submitted here instead because it fixes the same failure without silently dropping ~/.ssh/config directives that other users may depend on.

Tests

Adds a #ssh example asserting the identity set. It fails on master and passes with the fix. bundle exec rspec spec/bat: 42 examples, 0 failures.

Related: #66 adds a Proxmox VE cloud config template. The two are independent; this fix stands on its own on any IaaS.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 19, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: wayneeseguin / name: Wayne E Seguin (861ab8f)

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 168ee961-976c-4deb-b94f-f6ab785c17f4

📥 Commits

Reviewing files that changed from the base of the PR and between 31057b3 and 861ab8f.

📒 Files selected for processing (2)
  • lib/bat/bosh_helper.rb
  • spec/bat/bosh_helper_spec.rb

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

BoshHelper#ssh now restricts Net::SSH authentication to the supplied deployment key. It clears configured identities, enables keys_only, and disables SSH-agent authentication. Specs stub Net::SSH.start and verify the key data and authentication options.

Suggested reviewers: fmoehler, a-hassanin

Merge Risk: ⚪ Minimal · up to 861ab

The change limits direct SSH connections to the intended deployment key while preserving SSH configuration directives, with targeted tests covering the behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: restricting SSH authentication to the deployment key.
Description check ✅ Passed The description directly explains the authentication failure, its cause, the fix, preserved SSH configuration behavior, and test results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aramprice

aramprice commented Aug 19, 2026

Copy link
Copy Markdown
Member

@wayne - can you please sign the CLA, or re-trigger with /easycla if this is an error.

@wayneeseguin

Copy link
Copy Markdown
Author

OK should be an error as I signed before I'll retriever

@wayneeseguin

Copy link
Copy Markdown
Author

I think it's because this is my personal GH, re-signing

@wayneeseguin

Copy link
Copy Markdown
Author

Let's try that again I have 2 accounts,

/eazycla

Net::SSH fills in identity sources the caller does not name: every
IdentityFile from ~/.ssh/config, which it tries ahead of :key_data, and
every identity held by a reachable ssh-agent. On a workstation with a
'Host *' block or a loaded agent that is enough extra identities to
exhaust the target sshd's MaxAuthTries, so the server disconnects and
the example dies with 'Too many authentication failures'.

Pin the identity set to the key BATs was given. :keys_only on its own
does not do it: it filters agent identities but leaves the ones the
config file contributed, so :keys has to be cleared as well. Parsing of
~/.ssh/config stays on, so directives such as ProxyJump and Port keep
working.
@wayneeseguin

Copy link
Copy Markdown
Author

Figured it out, was a stupid Forking error 🤪

@aramprice
aramprice requested review from a team, a-hassanin and fmoehler and removed request for a team August 19, 2026 17:08
@aramprice aramprice moved this from Inbox to Pending Review | Discussion in Foundational Infrastructure Working Group Aug 19, 2026
@rkoster
rkoster requested a balanced review from Copilot August 20, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Restricts direct Net::SSH connections to the deployment-provided key, preventing authentication failures caused by extra SSH config and agent identities.

Changes:

  • Clears configured identities and disables agent identities.
  • Adds a regression test for the resulting SSH options.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/bat/bosh_helper.rb Pins SSH authentication to the supplied key.
spec/bat/bosh_helper_spec.rb Verifies exclusive identity options.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-project-automation github-project-automation Bot moved this from Pending Review | Discussion to Pending Merge | Prioritized in Foundational Infrastructure Working Group Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending Merge | Prioritized

Development

Successfully merging this pull request may close these issues.

3 participants