Repository navigation
feat(proxy): let authz hooks add headers to target requests - #647
Open
sfc-gh-pkowalewski wants to merge 1 commit into
Open
sfc-gh-pkowalewski wants to merge 1 commit into
sfc-gh-pkowalewski wants to merge 1 commit into
Conversation
sfc-gh-pkowalewski
marked this pull request as ready for review
October 27, 2026 16:28
sfc-gh-pkowalewski
force-pushed
the
proxy-policy-target-metadata
branch
2 times, most recently
from
October 27, 2026 19:02
3c919c4 to
081d80b
Compare
A policy or hook can set RPCAuthInput.TargetMetadata while the proxy authorizes a call, and the proxy sends it to the target as request metadata. NewCredentialsDialer records each target's identity at the handshake, so the first request is authorized before the stream to the target opens. A later message that changes the metadata closes the stream, and the proxy binary now uses the new dialer.
sfc-gh-pkowalewski
force-pushed
the
proxy-policy-target-metadata
branch
from
October 27, 2026 19:13
081d80b to
d0b1c4f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A proxy policy can only allow or deny a call. Some setups need the policy to hand information about its decision to the target, for example which rule allowed the request, so the target can act on it. Request metadata is the natural place for that, but the proxy opens the stream to the target before it authorizes the first request, and gRPC sends metadata when a stream opens, so there is no moment where a policy result can be attached.
Solution
A policy or hook can now set
TargetMetadataon the authorization input, and the proxy sends it with the call to the target.To authorize before the stream opens, the new
NewCredentialsDialerrecords the identity each target presents during the TLS handshake, which is the same identity policies see today. The proxy authorizes the first request with it and then opens the stream with the metadata attached.Metadata cannot change once a stream is open, so a later request that produces different metadata closes the stream. The proxy binary switches to the new dialer. The existing dialer keeps its current behaviour and rejects calls whose policy sets metadata.
sequenceDiagram participant C as Client participant P as Proxy participant T as Target C->>P: Request P->>T: Connect (TLS handshake) T-->>P: Target identity Note over P: Authorize the first request.<br/>The policy may set TargetMetadata. P->>T: Open stream with TargetMetadata P->>T: First request T-->>P: Response P-->>C: Response C->>P: Later request Note over P: Authorize again. If TargetMetadata<br/>differs, close with PermissionDenied. P->>T: Later requestTesting
The existing proxy tests now run through the new dialer and pass, also with the race detector.
New tests check that the metadata reaches the target for unary, server streaming and bidirectional calls, that a client stream with no requests still works, that a mid stream change is rejected, and that the old dialer refuses calls that set metadata. Two more check that an unreachable target still reports the underlying connection error and that a cancelled call returns
Canceled. Each new test fails when the behaviour it covers is removed.I also deployed the change to a staging proxy with a hook that sets metadata on one method. The target received it on that method only, the end to end suite passed, streaming, fan out and dry run calls behaved as before, and error rates did not change.
go test ./...passes apart fromTestServerWithUnixCredentials, which fails the same way onmainon macOS because it depends on local group membership.