Skip to content

Improve error message for encrypted SSH keys without password#2013

Open
ogulcanaydogan wants to merge 1 commit intofluxcd:mainfrom
ogulcanaydogan:fix/802-ssh-password-error-message
Open

Improve error message for encrypted SSH keys without password#2013
ogulcanaydogan wants to merge 1 commit intofluxcd:mainfrom
ogulcanaydogan:fix/802-ssh-password-error-message

Conversation

@ogulcanaydogan
Copy link

Description

When users provide a password-protected SSH private key in their Secret but forget the password field, the current error is misleading:

error: error creating SSH agent: "SSH agent requested but SSH_AUTH_SOCK not-specified"

This doesn't hint at the actual problem. The fix detects encrypted keys early by parsing the identity with ssh.ParseRawPrivateKey and checking for ssh.PassphraseMissingError. When detected, the error now reads:

SSH identity key is encrypted but no 'password' field was provided in the secret 'namespace/secret-name'

Changes

  • internal/controller/gitrepository_controller.go: Added encrypted key check in getAuthOpts() after SSH auth options are constructed. Uses golang.org/x/crypto/ssh.ParseRawPrivateKey + PassphraseMissingError detection.

How it works

  1. After git.NewAuthOptions() returns with SSH transport
  2. If Identity is present but Password is empty
  3. Try parsing the raw private key — if it returns PassphraseMissingError, the key is encrypted
  4. Return a clear error with the secret name so users know exactly what to fix

No behavior change for unencrypted keys or when password is provided.

Fixes #802

When a password-protected SSH private key is provided without the
'password' field in the Secret, the error message was misleading:
"SSH agent requested but SSH_AUTH_SOCK not-specified"

This change detects encrypted SSH keys early by attempting to parse
the identity with ssh.ParseRawPrivateKey and checking for
PassphraseMissingError. When detected, a clear error is returned
pointing the user to add the 'password' field to their Secret.

Fixes fluxcd#802

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
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.

Improve error message when users don't configure the password for password-protected SSH keys

1 participant