fix(collector): SSH private key ignored when password is also configured (#4409) by Madhav-Rakhonde · Pull Request #4470 · apache/hertzbeat · GitHub
Skip to content

fix(collector): SSH private key ignored when password is also configured (#4409) - #4470

Open
Madhav-Rakhonde wants to merge 1 commit into
apache:masterfrom
Madhav-Rakhonde:fix/issue-4409-ssh-private-key-ignored-when-password-set
Open

Madhav-Rakhonde wants to merge 1 commit into
apache:masterfrom
Madhav-Rakhonde:fix/issue-4409-ssh-private-key-ignored-when-password-set

Conversation

@Madhav-Rakhonde

Copy link
Copy Markdown
Contributor

What's changed?

In SshHelper.addIdentity(), an early return was executed immediately after registering the password identity:

if (StringUtils.hasText(password)) {
    clientSession.addPasswordIdentity(password);
    return;          // <-- key never loaded
}

…red (apache#4409)

SshHelper.addIdentity() contained an early return after registering the
password identity:

    if (StringUtils.hasText(password)) {
        clientSession.addPasswordIdentity(password);
        return;          // <-- key never loaded
    }

This meant that whenever a Linux SSH monitor had both a password and a
private key configured, only the password was added to the MINA SSHD
client session. If the target server had PasswordAuthentication disabled
(public-key only), the connection always failed even though a valid
private key was present.

Fix: remove the early return so that both credentials are registered.
MINA SSHD will then attempt each method in order and succeed with
whichever the server accepts.

Changes:
- Removed the premature return in SshHelper.addIdentity() so that the
  private key is always loaded when privateKey is non-empty, regardless
  of whether a password is also set.
- Added regression test bothPasswordAndPrivateKeyAreRegisteredWhenBothConfigured
  in SshHelperTest that verifies both addPasswordIdentity and
  addPublicKeyIdentity are called on the client session when both
  credentials are supplied.

Fixes apache#4409
Copilot AI balanced review requested due to automatic review settings October 17, 2026 18:53

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants