Skip to content

GRPC-tunnel: fix non-bearer auth credential schemes - #133

Merged
shawnburke merged 1 commit into
mainfrom
grpc/auth-header-parity
Aug 28, 2026
Merged

GRPC-tunnel: fix non-bearer auth credential schemes#133
shawnburke merged 1 commit into
mainfrom
grpc/auth-header-parity

Conversation

@shawnburke

Copy link
Copy Markdown
Collaborator

Stack 1/3 — base main. Independent of the other two; reviewable and mergeable on its own.

The bug

Three of the four auth schemes sent the wrong credential:

scheme sent should send
token Bearer <t> Token <t>
raw raw <t> <t> — no prefix
basic with a pre-encoded token Basic Og== (base64 of ":", an empty credential) the token verbatim

The basic case is the sharp one: a rule carrying an already-encoded user:pass pair — the shape Azure Repos uses — dropped it and authenticated as nobody.

The fix

A scheme is supported exactly when authHeaderBuilders has a builder for it, so the supported set and the behaviour cannot drift. They were previously a set in one file and a switch in another, raw string literals in both — a scheme in the set with no case sends no credential while claiming support, and a case with no set entry warns about itself while working fine.

The builder bodies match snyk-broker's lib/common/utils/auth-header.ts.

An unrecognized scheme now warns and sends no header, which is what the broker's authHeader() does with one — it returns undefined. Previously it invented <scheme> <token>.

Scope

auth.go is new; applyAuth moves out of router.go whole. Nothing else in router.go is touched, and no signature changes — this is why it sits at the bottom of the stack rather than tangled into the wildcard work.

Test plan

  • router_auth_test.go covers each scheme's exact header, case-insensitive scheme lookup, basic preferring username/password when both are present, and an unknown scheme sending nothing.
  • TestEveryDeclaredAuthSchemeBuildsACredential iterates authHeaderBuilders, so a scheme added without a test fails the build rather than shipping untested.
  • test/conformance/auth_schemes.json encodes the same cases as transport-agnostic fixtures.
  • go test ./server/snykbroker/... ./common/... green.

🤖 Generated with Claude Code

`token` emitted `Bearer`, `raw` emitted `raw ` instead of the bare token,
and `basic` with a pre-encoded token dropped it and sent `Basic Og==` —
base64 of ":", an empty credential.

A scheme is now supported exactly when `authHeaderBuilders` has a builder
for it, so the set and the behaviour cannot drift. An unrecognized scheme
warns and sends no header, which is what snyk-broker's authHeader() does
with one.

The bodies match snyk-broker's lib/common/utils/auth-header.ts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@shawnburke shawnburke changed the title Build the credential snyk-broker builds Align credential support with snyk-broker Aug 28, 2026
@shawnburke shawnburke changed the title Align credential support with snyk-broker GRPC-tunnel: fix non-bearer auth credential schemes Aug 28, 2026
@shawnburke
shawnburke merged commit 4f7f669 into main Aug 28, 2026
20 checks passed
@shawnburke
shawnburke deleted the grpc/auth-header-parity branch August 28, 2026 06:33
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.

2 participants