@@ -37,7 +37,9 @@ import (
3737 "d7y.io/dragonfly/v2/pkg/net/ip"
3838 pkgredis "d7y.io/dragonfly/v2/pkg/redis"
3939 "d7y.io/dragonfly/v2/pkg/rpc"
40+ "d7y.io/dragonfly/v2/pkg/rpc/auth"
4041 managerclient "d7y.io/dragonfly/v2/pkg/rpc/manager/client"
42+ "d7y.io/dragonfly/v2/pkg/types"
4143 "d7y.io/dragonfly/v2/scheduler/announcer"
4244 "d7y.io/dragonfly/v2/scheduler/config"
4345 "d7y.io/dragonfly/v2/scheduler/job"
@@ -97,6 +99,13 @@ func New(ctx context.Context, cfg *config.Config, d dfpath.Dfpath) (*Server, err
9799
98100 // Initialize dial options of manager grpc client.
99101 managerDialOptions := []grpc.DialOption {grpc .WithStatsHandler (otelgrpc .NewClientHandler ())}
102+ // Attach JWT per-RPC creds for inter-component calls if a key is provided.
103+ if key := cfg .Auth .JWT .Key ; key != "" {
104+ claims := auth .DurationClaims (types .SchedulerName , types .ManagerName , 10 * time .Minute )
105+ if token , err := auth .SignHS256 (key , claims ); err == nil {
106+ managerDialOptions = append (managerDialOptions , grpc .WithPerRPCCredentials (auth .NewPerRPCCreds (token )))
107+ }
108+ }
100109 if cfg .Manager .TLS != nil {
101110 clientTransportCredentials , err := rpc .NewClientCredentials (cfg .Manager .TLS .CACert , cfg .Manager .TLS .Cert , cfg .Manager .TLS .Key )
102111 if err != nil {
0 commit comments