security: add a filer token without copying the outgoing metadata

WithFilerToken copied the outgoing metadata twice on every filer gRPC
call to check for an authorization the caller set and to add its own.
Look the key up in place and append the token instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-04 16:25:09 -08:00
1 parent e8c58b38d7
commit a040c73fff
1 file changed
+2 -5
+2 -5
View File
@@ -189,8 +189,7 @@ func WithFilerSubscriptionToken(ctx context.Context, source FilerTokenSource) (c
// bearer with admin authority. It preserves deadlines, cancellation and all
// unrelated metadata, without modifying the original context's metadata.
func WithFilerToken(ctx context.Context, source FilerTokenSource) (context.Context, error) {
md, _ := metadata.FromOutgoingContext(ctx)
if _, supplied := md["authorization"]; supplied || source == nil {
if source == nil || metadata.ValueFromOutgoingContext(ctx, "authorization") != nil {
return ctx, nil
}
token, err := source(ctx)
@@ -200,9 +199,7 @@ func WithFilerToken(ctx context.Context, source FilerTokenSource) (context.Conte
if token == "" {
return ctx, nil
}
md = md.Copy()
md.Set("authorization", BearerPrefix+string(token))
return metadata.NewOutgoingContext(ctx, md), nil
return metadata.AppendToOutgoingContext(ctx, "authorization", BearerPrefix+string(token)), nil
}
// WithFilerClientAuth wraps a connection interface for one logical client,