Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension/bearertokenauth] Fix the RPC credential updates #35653

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions extension/bearertokenauthextension/bearertokenauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
var _ credentials.PerRPCCredentials = (*PerRPCAuth)(nil)

// PerRPCAuth is a gRPC credentials.PerRPCCredentials implementation that returns an 'authorization' header.
// NOTE: Needs a function instead of static values so the data can be refreshed
type PerRPCAuth struct {
metadata map[string]string
renderMetadata func() map[string]string
}

// GetRequestMetadata returns the request metadata to be used with the RPC.
func (c *PerRPCAuth) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
return c.metadata, nil
// Call the render function to get the latest data
return c.renderMetadata(), nil
}

// RequireTransportSecurity always returns true for this implementation. Passing bearer tokens in plain-text connections is a bad idea.
Expand Down Expand Up @@ -170,9 +172,12 @@ func (b *BearerTokenAuth) Shutdown(_ context.Context) error {

// PerRPCCredentials returns PerRPCAuth an implementation of credentials.PerRPCCredentials that
func (b *BearerTokenAuth) PerRPCCredentials() (credentials.PerRPCCredentials, error) {
// Create a function that will return the request metadata when called later
return &PerRPCAuth{
metadata: map[string]string{"authorization": b.authorizationValue()},
}, nil
renderMetadata: func() map[string]string {
return map[string]string{"authorization": b.authorizationValue()}
},
}, nil
}

// RoundTripper is not implemented by BearerTokenAuth
Expand Down