mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
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:
1 parent
e8c58b38d7
commit
a040c73fff
1 file changed
+2
-5
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user