Skip to content

Trim whitespace from provider secret auth values - #1447

Open
Skavya-06 wants to merge 1 commit into
fluxcd:mainfrom
Skavya-06:fix/trim-secret-auth
Open

Skavya-06 wants to merge 1 commit into
fluxcd:mainfrom
Skavya-06:fix/trim-secret-auth

Conversation

@Skavya-06

Copy link
Copy Markdown

What this PR does / why we need it:

Provider Secrets created with kubectl create secret generic --from-file (or any tool that preserves the trailing newline) end up with token, username and password values that carry surrounding whitespace. prepareNotifier already trims providerSecret.Data[secrets.KeyToken] when merging the provider-token, but the values that flow through extractAuthFromSecret were passed to the notifier verbatim, so Alertmanager-style notifiers would send Authorization: Bearer <token>\n and get rejected by upstreams.

This trims token, username and password in extractAuthFromSecret, matching the existing treatment in prepareNotifier.

Fixes #1445

Special notes for your reviewer:

Added TestExtractAuthFromSecretTrimsWhitespace, which builds the notifier from the extracted options and asserts the credentials are trimmed. It fails against main and passes with the change.

Validated locally with make tidy fmt vet and go test ./internal/server/.

Checklist

  • Local tests pass (make tidy fmt vet && go test ./...)
  • Tests have been added for the change
  • Commit is signed off per the DCO

Authentication values read from provider Secrets are now whitespace-trimmed before being passed to notifiers, matching the treatment already applied to provider secrets elsewhere in prepareNotifier. Trailing newlines from kubectl-created secrets no longer break token or basic auth.

Signed-off-by: Kavya Srivastava <skavya12669@gmail.com>
Assisted-by: Qoder

@IsuruDilhan IsuruDilhan 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.

This fixes the same two lines as #1446 (opened 6 minutes earlier against the same root cause, #1445): trimming authMethods.Token, authMethods.Basic.Username and authMethods.Basic.Password in extractAuthFromSecret. Both PRs will conflict/duplicate if merged separately, so it's probably worth consolidating into one.

On the test itself: TestExtractAuthFromSecretTrimsWhitespace here calls extractAuthFromSecret directly and asserts on the Alertmanager notifier's exported Token/Username/Password fields. That's a fine unit check, but it stops one layer short of the actual regression - it doesn't verify what ends up on the wire.

#1446's equivalent test (TestCreateNotifierTrimsSecretCredentials) goes through prepareNotifier -> createNotifier -> Post() against a real httptest.Server and asserts on the captured Authorization header directly. That's strictly more end-to-end: it would also catch a regression in how Alertmanager.Post/Slack.Post build the header (e.g. the SetBasicAuth base64 encoding), not just whether the struct fields are trimmed.

Given the production change is identical, I'd suggest picking #1446 (more thorough test, filed first) and closing this one, or alternatively pulling its HTTP-level assertion style into this PR's test.

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.

Provider secret token is not trimmed since v1.7.0: a trailing newline breaks the Authorization header

2 participants