mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* master: sign a LookupVolume token for the file id asked for LookupVolume signed the token with the bare volume id, and the volume server checks the token's fid against vid,key, so every token it handed out was refused. /dir/lookup signs the file id. operation.LookupJwt goes through LookupVolume, so the expired-token renewals of the S3 PutObject and copy cleanup deletes, the admin file browser and weed benchmark all got a token the volume server refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * master: sign lookup tokens for the base file id The volume server checks a token's fid against the file id with its _<delta> suffix stripped, so a token minted for vid,key_N, over gRPC or /dir/lookup, was refused. Sign baseFid of the file id in both paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.9 KiB
Go
49 lines
1.9 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
)
|
|
|
|
// A token looked up for a file id, over gRPC or /dir/lookup, must pass the
|
|
// volume server's check for that file, a file id with a "_<delta>" suffix
|
|
// included.
|
|
func TestLookupVolumeTokenAuthorizesTheFileId(t *testing.T) {
|
|
ms := newLeaderMaster()
|
|
ms.guard = security.NewGuard(nil, "write-key", 10, "", 0, "", "")
|
|
node := ms.Topo.GetOrCreateDataCenter("dc1").GetOrCreateRack("rack1").
|
|
GetOrCreateDataNode("127.0.0.1", 8080, 18080, "127.0.0.1", "node1", map[string]uint32{"": 10})
|
|
ms.Topo.SyncDataNodeRegistration([]*master_pb.VolumeInformationMessage{{Id: 7, Size: 100}}, node)
|
|
|
|
for _, fileId := range []string{"7,01637037d6", "7,01637037d6_1"} {
|
|
resp, err := ms.LookupVolume(context.Background(), &master_pb.LookupVolumeRequest{VolumeOrFileIds: []string{fileId}})
|
|
if err != nil {
|
|
t.Fatalf("lookup %s: %v", fileId, err)
|
|
}
|
|
if len(resp.VolumeIdLocations) != 1 || resp.VolumeIdLocations[0].Auth == "" {
|
|
t.Fatalf("lookup %s answer = %+v, want one location with a token", fileId, resp.VolumeIdLocations)
|
|
}
|
|
if !volumeAccepts(resp.VolumeIdLocations[0].Auth, fileId) {
|
|
t.Errorf("the volume server refuses the gRPC token looked up for %s", fileId)
|
|
}
|
|
|
|
w := httptest.NewRecorder()
|
|
ms.maybeAddJwtAuthorization(w, fileId, true)
|
|
if token := strings.TrimPrefix(w.Header().Get("Authorization"), security.BearerPrefix); !volumeAccepts(token, fileId) {
|
|
t.Errorf("the volume server refuses the /dir/lookup token for %s", fileId)
|
|
}
|
|
}
|
|
}
|
|
|
|
func volumeAccepts(token, fileId string) bool {
|
|
vid, fid, _ := strings.Cut(fileId, ",")
|
|
r := httptest.NewRequest("DELETE", "/"+fileId, nil)
|
|
r.Header.Set("Authorization", security.BearerPrefix+token)
|
|
return (&VolumeServer{}).checkJwtAuthorizationWithKey(r, vid, fid, security.SigningKey("write-key"), nil)
|
|
}
|