mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +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>
174 lines
6.0 KiB
Go
174 lines
6.0 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"github.com/seaweedfs/seaweedfs/weed/util/version"
|
|
)
|
|
|
|
func (fs *FilerServer) Statistics(ctx context.Context, req *filer_pb.StatisticsRequest) (resp *filer_pb.StatisticsResponse, err error) {
|
|
|
|
var output *master_pb.StatisticsResponse
|
|
|
|
err = fs.filer.MasterClient.WithClient(ctx, false, func(masterClient master_pb.SeaweedClient) error {
|
|
grpcResponse, grpcErr := masterClient.Statistics(ctx, &master_pb.StatisticsRequest{
|
|
Replication: fs.statisticsReplication(req.Replication),
|
|
Collection: req.Collection,
|
|
Ttl: req.Ttl,
|
|
DiskType: req.DiskType,
|
|
})
|
|
if grpcErr != nil {
|
|
return grpcErr
|
|
}
|
|
|
|
output = grpcResponse
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &filer_pb.StatisticsResponse{
|
|
TotalSize: output.TotalSize,
|
|
UsedSize: output.UsedSize,
|
|
FileCount: output.FileCount,
|
|
LogicalTotalSize: output.LogicalTotalSize,
|
|
LogicalUsedSize: output.LogicalUsedSize,
|
|
}, nil
|
|
}
|
|
|
|
// statisticsReplication names the replication the caller's writes will use, so
|
|
// the master sizes free space by the right number of copies. Writes through
|
|
// this filer follow its default, not the master's, so fill that in when the
|
|
// request leaves the choice open.
|
|
func (fs *FilerServer) statisticsReplication(requested string) string {
|
|
if requested != "" {
|
|
return requested
|
|
}
|
|
return fs.option.DefaultReplication
|
|
}
|
|
|
|
// isKnownPingTarget reports whether target is a peer the filer has learned
|
|
// about from its master subscription (other filers, volume servers) or from
|
|
// its own master list. Restricting Ping prevents the RPC from being used as
|
|
// an arbitrary outbound dialer. All lookups are O(1) so the gate adds no
|
|
// noticeable overhead even in large clusters.
|
|
func (fs *FilerServer) isKnownPingTarget(ctx context.Context, target string, targetType string) bool {
|
|
addr := pb.ServerAddress(target)
|
|
switch targetType {
|
|
case cluster.FilerType:
|
|
if fs.filer != nil && fs.filer.MetaAggregator != nil && fs.filer.MetaAggregator.HasPeer(addr) {
|
|
return true
|
|
}
|
|
return false
|
|
case cluster.VolumeServerType:
|
|
if fs.filer != nil && fs.filer.MasterClient != nil {
|
|
return fs.filer.MasterClient.HasVolumeServer(addr)
|
|
}
|
|
return false
|
|
case cluster.MasterType:
|
|
key := addr.ToHttpAddress()
|
|
if fs.option != nil && fs.option.Masters != nil {
|
|
if _, ok := fs.option.Masters.GetInstancesAsMap()[string(addr)]; ok {
|
|
return true
|
|
}
|
|
// Fall back to a port-tolerant compare for callers that supply
|
|
// the http form when masters were registered with grpc suffix.
|
|
for _, master := range fs.option.Masters.GetInstances() {
|
|
if master.ToHttpAddress() == key {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
if fs.filer != nil && fs.filer.MasterClient != nil {
|
|
if _, ok := fs.filer.MasterClient.ListMasterSet()[key]; ok {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (fs *FilerServer) Ping(ctx context.Context, req *filer_pb.PingRequest) (resp *filer_pb.PingResponse, pingErr error) {
|
|
resp = &filer_pb.PingResponse{
|
|
StartTimeNs: time.Now().UnixNano(),
|
|
}
|
|
// Empty target is a self-liveness probe. In compatibility mode it remains
|
|
// available without a bearer; require-token enforcement runs before this
|
|
// handler and rejects tokenless calls.
|
|
if req.Target != "" && !fs.isKnownPingTarget(ctx, req.Target, req.TargetType) {
|
|
resp.StopTimeNs = time.Now().UnixNano()
|
|
return resp, status.Errorf(codes.InvalidArgument, "unknown ping target %s of type %s", req.Target, req.TargetType)
|
|
}
|
|
if req.TargetType == cluster.FilerType {
|
|
pingErr = pb.WithFilerClient(false, 0, pb.ServerAddress(req.Target), fs.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
|
|
pingResp, err := client.Ping(withCallerAuthContext(ctx), &filer_pb.PingRequest{})
|
|
if pingResp != nil {
|
|
resp.RemoteTimeNs = pingResp.StartTimeNs
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
if req.TargetType == cluster.VolumeServerType {
|
|
pingErr = pb.WithVolumeServerClient(false, pb.ServerAddress(req.Target), fs.volumeGrpcDialOption(), func(client volume_server_pb.VolumeServerClient) error {
|
|
pingResp, err := client.Ping(ctx, &volume_server_pb.PingRequest{})
|
|
if pingResp != nil {
|
|
resp.RemoteTimeNs = pingResp.StartTimeNs
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
if req.TargetType == cluster.MasterType {
|
|
pingErr = pb.WithMasterClient(context.Background(), false, pb.ServerAddress(req.Target), fs.masterGrpcDialOption(), false, func(client master_pb.SeaweedClient) error {
|
|
pingResp, err := client.Ping(ctx, &master_pb.PingRequest{})
|
|
if pingResp != nil {
|
|
resp.RemoteTimeNs = pingResp.StartTimeNs
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
if pingErr != nil {
|
|
pingErr = fmt.Errorf("ping %s %s: %v", req.TargetType, req.Target, pingErr)
|
|
}
|
|
resp.StopTimeNs = time.Now().UnixNano()
|
|
return
|
|
}
|
|
|
|
func (fs *FilerServer) GetFilerConfiguration(ctx context.Context, req *filer_pb.GetFilerConfigurationRequest) (resp *filer_pb.GetFilerConfigurationResponse, err error) {
|
|
|
|
t := &filer_pb.GetFilerConfigurationResponse{
|
|
Masters: fs.option.Masters.GetInstancesAsStrings(),
|
|
Collection: fs.option.Collection,
|
|
Replication: fs.option.DefaultReplication,
|
|
MaxMb: uint32(fs.option.MaxMB),
|
|
DirBuckets: fs.filer.DirBucketsPath,
|
|
Cipher: fs.filer.Cipher,
|
|
Signature: fs.filer.Signature,
|
|
MetricsAddress: fs.metricsAddress,
|
|
MetricsIntervalSec: int32(fs.metricsIntervalSec),
|
|
Version: version.Version(),
|
|
FilerGroup: fs.option.FilerGroup,
|
|
MajorVersion: version.MAJOR_VERSION,
|
|
MinorVersion: version.MINOR_VERSION,
|
|
Digest: util.Digest(),
|
|
}
|
|
|
|
glog.V(4).InfofCtx(ctx, "GetFilerConfiguration: %v", t)
|
|
|
|
return t, nil
|
|
}
|