From a040c73fffdcb0c98249224fec23c7a7910b3fe8 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 4 Dec 2026 16:25:09 -0800 Subject: [PATCH] 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 --- weed/security/filer_client_auth.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/weed/security/filer_client_auth.go b/weed/security/filer_client_auth.go index 8349392ac7..72142fedb5 100644 --- a/weed/security/filer_client_auth.go +++ b/weed/security/filer_client_auth.go @@ -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,