mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* filer: require bearer tokens for configured gRPC calls * filer: authenticate owned peer RPCs with per-call admin tokens * filer: retain scoped forwarding refusals with required authentication * filer: preserve tokenless HTTP forwarding outside require mode * filer: honor clock tolerance for gRPC admin fallback * filer: preserve caller token on lock owner forwards * filer: forward caller auth on target ping * filer: authenticate startup peer digest checks * filer: verify required subscription bearers independently of mTLS * filer: assert exact caller bearer on forwarded ping * filer: sign peer tokens with the gRPC verification key peerContext signed filer-owned RPCs with jwt.filer_signing.key only. With grpc_key as the only key and require-mode on, peer calls went out tokenless and were refused. With both keys set, peers that verify with grpc_key and lack the shared-key admin fallback refused the shared-key token even with require-mode off. Sign with the key filesystem gRPC verifies, and keep the shared key for metadata subscriptions, whose verifier accepts admin tokens signed only with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep a subscription token's scope over mTLS in require-mode Require-mode admitted a dedicated subscription bearer without the mTLS shortcut, but the handler re-checked it with the certificate, which granted the full stream past the token's prefixes and expiry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: delete uploaded chunks when the write owner refuses authentication A forwarded HTTP append or offset write that the owner refused as Unauthenticated kept its new chunks as if the outcome were unknown, orphaning them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: hand the admitted subscription scope to the handler The handler re-verified a dedicated subscription token after reading the request. If the token expired in between, an mTLS peer fell back to the certificate and got an unrestricted stream. The interceptor now passes the scope it admitted, and the handler refuses it once expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: accept grpc_key admin tokens on metadata subscriptions A filer with only grpc_key signs peer subscriptions with it, but the subscription verifier checked admin tokens against the shared key only, so with a subscribe key set the aggregator's peer streams were refused. An unscoped grpc_key token already has full filer gRPC access. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: delete the generated manifest when the write owner refuses authentication A forwarded HTTP append that crossed the manifest threshold left the manifest blob it had uploaded orphaned when the owner refused the call as Unauthenticated. The blob alone is deleted, since the manifest also lists committed chunks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.0 KiB
Go
106 lines
4.0 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
const pingForwardingKey = "ping-forwarding-test-key"
|
|
|
|
func newPingFilers(t *testing.T, requireToken bool) (*twoFilers, security.SigningKey) {
|
|
t.Helper()
|
|
c := newTwoFilers(t, func(fs *FilerServer) {
|
|
fs.filerGuard = security.NewGuard(nil, pingForwardingKey, 60, "", 0, "", "")
|
|
fs.grpcScope = newFilerGrpcScope(scopeConfig{
|
|
signingKey: fs.filerGuard.SigningKey,
|
|
verificationKeys: func() (security.SigningKey, security.SigningKey) { return fs.filerGuard.VerificationKeys(true) },
|
|
requireToken: func() bool { return requireToken },
|
|
}, fs)
|
|
})
|
|
|
|
// The fixture does not run the normal master peer subscription. Treat B as
|
|
// a known peer so A's real target gate admits the probe without starting a
|
|
// subscription goroutine solely for this test.
|
|
ma := filer.NewMetaAggregator(c.fsA.filer, c.addrB, nil)
|
|
c.fsA.filer.MetaAggregator = ma
|
|
t.Cleanup(ma.Shutdown)
|
|
return c, security.SigningKey(pingForwardingKey)
|
|
}
|
|
|
|
func TestFilerPingForwardsCallerBearerToRequireModePeer(t *testing.T) {
|
|
c, key := newPingFilers(t, true)
|
|
caller := peerAdminToken(key)
|
|
client := peerClient(t, c, c.addrA, caller)
|
|
|
|
_, err := client.Ping(context.Background(), &filer_pb.PingRequest{Target: string(c.addrB), TargetType: cluster.FilerType})
|
|
if err != nil {
|
|
t.Fatalf("target filer Ping: %v", err)
|
|
}
|
|
assertForwardedPingBearer(t, c.callsB, caller)
|
|
}
|
|
|
|
func assertForwardedPingBearer(t *testing.T, calls *receivedUpdates, caller string) {
|
|
t.Helper()
|
|
calls.mu.Lock()
|
|
defer calls.mu.Unlock()
|
|
if len(calls.pingAuthorizations) != 1 {
|
|
t.Fatalf("receiving filer saw %d Ping calls, want one", len(calls.pingAuthorizations))
|
|
}
|
|
if !slices.Equal(calls.pingAuthorizations[0], []string{"Bearer " + caller}) {
|
|
t.Fatal("receiving filer did not get exactly the caller's bearer")
|
|
}
|
|
}
|
|
|
|
func TestFilerPingRejectsTokenlessCallerInRequireMode(t *testing.T) {
|
|
c, _ := newPingFilers(t, true)
|
|
client := peerClient(t, c, c.addrA, "")
|
|
|
|
_, err := client.Ping(context.Background(), &filer_pb.PingRequest{Target: string(c.addrB), TargetType: cluster.FilerType})
|
|
if status.Code(err) != codes.Unauthenticated {
|
|
t.Fatalf("tokenless target Ping error=%v, want Unauthenticated", err)
|
|
}
|
|
}
|
|
|
|
func TestFilerPingDoesNotMintPeerAdminForTokenlessCaller(t *testing.T) {
|
|
c, _ := newPingFilers(t, false)
|
|
c.fsB.grpcScope.cfg.requireToken = func() bool { return true }
|
|
client := peerClient(t, c, c.addrA, "")
|
|
|
|
_, err := client.Ping(context.Background(), &filer_pb.PingRequest{Target: string(c.addrB), TargetType: cluster.FilerType})
|
|
if err == nil || !strings.Contains(err.Error(), "filer: gRPC token authentication is required") {
|
|
t.Fatalf("tokenless target Ping against require-mode peer error=%v, want remote Unauthenticated", err)
|
|
}
|
|
}
|
|
|
|
func TestFilerPingPreservesTokenlessCompatibilityWhenRequireModeOff(t *testing.T) {
|
|
c, _ := newPingFilers(t, false)
|
|
client := peerClient(t, c, c.addrA, "")
|
|
|
|
if _, err := client.Ping(context.Background(), &filer_pb.PingRequest{Target: string(c.addrB), TargetType: cluster.FilerType}); err != nil {
|
|
t.Fatalf("tokenless target Ping in compatibility mode: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestFilerPingReplacesStaleOutgoingAuthorization(t *testing.T) {
|
|
c, key := newPingFilers(t, true)
|
|
caller := peerAdminToken(key)
|
|
stale := peerAdminToken(security.SigningKey("stale-ping-key"))
|
|
ctx := metadata.NewIncomingContext(context.Background(), metadata.Pairs("authorization", "Bearer "+caller))
|
|
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs("authorization", "Bearer "+stale))
|
|
|
|
if _, err := c.fsA.Ping(ctx, &filer_pb.PingRequest{Target: string(c.addrB), TargetType: cluster.FilerType}); err != nil {
|
|
t.Fatalf("target filer Ping with stale outgoing authorization: %v", err)
|
|
}
|
|
assertForwardedPingBearer(t, c.callsB, caller)
|
|
}
|