Skip to content

Redact private key material from SSH error messages - #38543

Closed
SebTardif wants to merge 2 commits into
hashicorp:mainfrom
SebTardif:fix/redact-private-key-errors
Closed

Redact private key material from SSH error messages#38543
SebTardif wants to merge 2 commits into
hashicorp:mainfrom
SebTardif:fix/redact-private-key-errors

Conversation

@SebTardif

@SebTardif SebTardif commented May 8, 2026

Copy link
Copy Markdown

signCertWithPrivateKey() in the SSH communicator formats private key
content, certificate content, and parsed key structs into error messages
using %q. These error strings propagate to terminal output and CI logs
(GitHub Actions, Jenkins, etc.), exposing credential material to anyone
with log access.

This commit removes the sensitive values from the four fmt.Errorf calls
in the function. The underlying golang.org/x/crypto/ssh error (still
included via %s) already describes the failure cause (malformed PEM,
unsupported algorithm, key/cert type mismatch), so no diagnostic
information is lost. The four distinct error prefixes still identify
which step failed.

The sibling function readPrivateKey() was already safe (it only formats
err, not the key content).

Related redaction work in this repo:

Similar fix in other projects:

Target Release

1.16.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Yes. This change prevents private key material from being exposed in error
messages that appear in terminal output and CI/CD logs.

CHANGELOG entry

  • This change is not user-facing.

Remove private key content, certificate content, and parsed key structs
from error messages in signCertWithPrivateKey(). These values were
formatted with %q into error strings that appear in terminal output
and CI logs, exposing credential material.

The underlying crypto library error (preserved via %s) already describes
the failure cause (malformed PEM, unsupported algorithm, etc.), so no
diagnostic information is lost.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@crw

crw commented May 8, 2026

Copy link
Copy Markdown
Contributor

@SebTardif Please see our Contributing.md, particularly the sections Proposing a Change and AI Usage. One of our requirements is disclosure of AI usage. Thanks for this submission.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@crw crw closed this May 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants