Repository navigation
Conversation
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
left a comment
There was a problem hiding this comment.
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.
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 withtoken,usernameandpasswordvalues that carry surrounding whitespace.prepareNotifieralready trimsproviderSecret.Data[secrets.KeyToken]when merging the provider-token, but the values that flow throughextractAuthFromSecretwere passed to the notifier verbatim, so Alertmanager-style notifiers would sendAuthorization: Bearer <token>\nand get rejected by upstreams.This trims token, username and password in
extractAuthFromSecret, matching the existing treatment inprepareNotifier.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 againstmainand passes with the change.Validated locally with
make tidy fmt vetandgo test ./internal/server/.Checklist
make tidy fmt vet && go test ./...)