mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
master: sign a LookupVolume token for the file id asked for (#13300)
* 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>
This commit is contained in:
1 parent
dc15685282
commit
5c36ee70ee
3 files changed
+51
-3
No files matched your search
@@ -267,7 +267,7 @@ func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupV
|
||||
}
|
||||
var auth string
|
||||
if commaSep > 0 { // this is a file id
|
||||
auth = string(security.GenJwtForVolumeServer(ms.guard.SigningKey(), ms.guard.ExpiresAfterSec(), result.VolumeOrFileId))
|
||||
auth = string(security.GenJwtForVolumeServer(ms.guard.SigningKey(), ms.guard.ExpiresAfterSec(), baseFid(volumeOrFileId)))
|
||||
}
|
||||
if result.NotFound {
|
||||
notFoundCount++
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
@@ -292,9 +292,9 @@ func (ms *MasterServer) maybeAddJwtAuthorization(w http.ResponseWriter, fileId s
|
||||
}
|
||||
var encodedJwt security.EncodedJwt
|
||||
if isWrite {
|
||||
encodedJwt = security.GenJwtForVolumeServer(ms.guard.SigningKey(), ms.guard.ExpiresAfterSec(), fileId)
|
||||
encodedJwt = security.GenJwtForVolumeServer(ms.guard.SigningKey(), ms.guard.ExpiresAfterSec(), baseFid(fileId))
|
||||
} else {
|
||||
encodedJwt = security.GenJwtForVolumeServer(ms.guard.ReadSigningKey(), ms.guard.ReadExpiresAfterSec(), fileId)
|
||||
encodedJwt = security.GenJwtForVolumeServer(ms.guard.ReadSigningKey(), ms.guard.ReadExpiresAfterSec(), baseFid(fileId))
|
||||
}
|
||||
if encodedJwt == "" {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user