mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
* security: reuse the filer admin token signed in the same second An admin token's only claim is its expiry, which jwt truncates to the second, so every token signed with one key in one second is the same. Each filer gRPC call from a client with a filer signing key signed a new one: about 4us and 40 allocations per call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> * s3api: canonicalize the scrubbed internal header names once scrubInternalHeaders runs on every request, and Header.Del canonicalized each of its nine names again; five are not in canonical form, so each request allocated their canonical forms anew. Delete the precomputed canonical keys instead: 775ns and 5 allocations down to 120ns and none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * security: benchmark the token path with a fixed key, test the reuse itself Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * security: keep GenJwtForFilerAdmin's doc comment on the function Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package s3api
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
)
|
|
|
|
func TestScrubInternalHeadersDropsClientValues(t *testing.T) {
|
|
keys := []string{
|
|
s3_constants.SeaweedFSPrincipalHeader,
|
|
s3_constants.SeaweedFSSessionTokenHeader,
|
|
s3_constants.ExtObjectLockModeKey,
|
|
s3_constants.ExtRetentionUntilDateKey,
|
|
s3_constants.ExtLegalHoldKey,
|
|
s3_constants.ExtVersionIdKey,
|
|
s3_constants.SeaweedFSSSEKMSBaseIVHeader,
|
|
s3_constants.SeaweedFSSSES3BaseIVHeader,
|
|
s3_constants.SeaweedFSSSES3KeyDataHeader,
|
|
}
|
|
r, _ := http.NewRequest(http.MethodPut, "http://localhost/b/k", nil)
|
|
for _, key := range keys {
|
|
r.Header.Set(key, "client")
|
|
}
|
|
r.Header.Set("X-Amz-Date", "20261205T000000Z")
|
|
scrubInternalHeaders(r)
|
|
for _, key := range keys {
|
|
if got := r.Header.Get(key); got != "" {
|
|
t.Errorf("%s kept %q", key, got)
|
|
}
|
|
}
|
|
if r.Header.Get("X-Amz-Date") == "" {
|
|
t.Error("scrub dropped a client header")
|
|
}
|
|
}
|
|
|
|
func BenchmarkScrubInternalHeaders(b *testing.B) {
|
|
r, _ := http.NewRequest(http.MethodPut, "http://localhost/b/k", nil)
|
|
r.Header.Set("Authorization", "AWS4-HMAC-SHA256 Credential=x")
|
|
r.Header.Set("X-Amz-Date", "20261205T000000Z")
|
|
r.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
scrubInternalHeaders(r)
|
|
}
|
|
}
|