Skip to content

Commit e857203

Browse files
chore: disable flag on unsafe/test RPCs (backport #736) (#742)
<hr>This is an automatic backport of pull request #736 done by [Mergify](https://mergify.com). Co-authored-by: Lazar <[email protected]>
1 parent 30df1b0 commit e857203

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4646
* [#732](https://github.com/babylonlabs-io/finality-provider/pull/732) feat: add version metric
4747
* [#734](https://github.com/babylonlabs-io/finality-provider/pull/734) chore: rm unused cfg val
4848
* [#735](https://github.com/babylonlabs-io/finality-provider/pull/735) chore: use counter prometeus
49+
* [#736](https://github.com/babylonlabs-io/finality-provider/pull/736) chore: disable flag on unsafe/test RPCs
4950

5051
## v2.0.0-rc.5
5152

eotsmanager/config/config.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ var (
3737
)
3838

3939
type Config struct {
40-
LogLevel string `long:"loglevel" description:"Logging level for all subsystems" choice:"trace" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"fatal"`
41-
KeyringBackend string `long:"keyring-type" description:"Type of keyring to use"`
42-
RPCListener string `long:"rpclistener" description:"the listener for RPC connections, e.g., 127.0.0.1:1234"`
43-
HMACKey string `long:"hmackey" description:"The HMAC key for authentication with FPD. If not provided, will use HMAC_KEY environment variable."`
44-
Metrics *metrics.Config `group:"metrics" namespace:"metrics"`
45-
GRPCMaxContentLength int `long:"grpcmaxcontentlength" description:"The maximum size of the gRPC message in bytes."`
40+
LogLevel string `long:"loglevel" description:"Logging level for all subsystems" choice:"trace" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"fatal"`
41+
KeyringBackend string `long:"keyring-type" description:"Type of keyring to use"`
42+
RPCListener string `long:"rpclistener" description:"the listener for RPC connections, e.g., 127.0.0.1:1234"`
43+
HMACKey string `long:"hmackey" description:"The HMAC key for authentication with FPD. If not provided, will use HMAC_KEY environment variable."`
44+
DisableUnsafeEndpoints bool `long:"disable-unsafe-endpoints" description:"Disable unsafe RPC endpoints (e.g., UnsafeSignEOTS) that bypass slashing protection. Recommended for production."`
45+
Metrics *metrics.Config `group:"metrics" namespace:"metrics"`
46+
GRPCMaxContentLength int `long:"grpcmaxcontentlength" description:"The maximum size of the gRPC message in bytes."`
4647

4748
DatabaseConfig *DBConfig `group:"dbconfig" namespace:"dbconfig"`
4849
}
@@ -138,12 +139,13 @@ func DefaultConfigWithHomePath(homePath string) *Config {
138139

139140
func DefaultConfigWithHomePathAndPorts(homePath string, rpcPort, metricsPort int) *Config {
140141
cfg := &Config{
141-
LogLevel: defaultLogLevel,
142-
KeyringBackend: defaultKeyringBackend,
143-
DatabaseConfig: DefaultDBConfigWithHomePath(homePath),
144-
RPCListener: defaultRpcListener,
145-
Metrics: metrics.DefaultEotsConfig(),
146-
GRPCMaxContentLength: defaultMaxGRPCContentLength,
142+
LogLevel: defaultLogLevel,
143+
KeyringBackend: defaultKeyringBackend,
144+
DatabaseConfig: DefaultDBConfigWithHomePath(homePath),
145+
RPCListener: defaultRpcListener,
146+
DisableUnsafeEndpoints: false, // default to false for backward compatibility
147+
Metrics: metrics.DefaultEotsConfig(),
148+
GRPCMaxContentLength: defaultMaxGRPCContentLength,
147149
}
148150
cfg.RPCListener = fmt.Sprintf("%s:%d", DefaultRPCHost, rpcPort)
149151
cfg.Metrics.Port = metricsPort

eotsmanager/service/rpcserver.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"google.golang.org/grpc/codes"
1212

1313
"github.com/babylonlabs-io/finality-provider/eotsmanager"
14+
"github.com/babylonlabs-io/finality-provider/eotsmanager/config"
1415
"github.com/babylonlabs-io/finality-provider/eotsmanager/proto"
1516
"github.com/babylonlabs-io/finality-provider/eotsmanager/types"
1617
)
@@ -20,15 +21,18 @@ import (
2021
type rpcServer struct {
2122
proto.UnimplementedEOTSManagerServer
2223

23-
em *eotsmanager.LocalEOTSManager
24+
em *eotsmanager.LocalEOTSManager
25+
cfg *config.Config
2426
}
2527

2628
// newRPCServer creates a new RPC sever from the set of input dependencies.
2729
func newRPCServer(
2830
em *eotsmanager.LocalEOTSManager,
31+
cfg *config.Config,
2932
) *rpcServer {
3033
return &rpcServer{
31-
em: em,
34+
em: em,
35+
cfg: cfg,
3236
}
3337
}
3438

@@ -89,6 +93,11 @@ func (r *rpcServer) SignEOTS(_ context.Context, req *proto.SignEOTSRequest) (
8993
// UnsafeSignEOTS only used for testing purposes. Doesn't offer slashing protection!
9094
func (r *rpcServer) UnsafeSignEOTS(_ context.Context, req *proto.SignEOTSRequest) (
9195
*proto.SignEOTSResponse, error) {
96+
if r.cfg.DisableUnsafeEndpoints {
97+
return nil, status.Error(codes.PermissionDenied, //nolint:wrapcheck
98+
"UnsafeSignEOTS endpoint is disabled in configuration for security reasons")
99+
}
100+
92101
sig, err := r.em.UnsafeSignEOTS(req.Uid, req.ChainId, req.Msg, req.Height)
93102
if err != nil {
94103
return nil, fmt.Errorf("failed to sign EOTS: %w", err)

eotsmanager/service/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewEOTSManagerServer(cfg *config.Config, l *zap.Logger, em *eotsmanager.Loc
3737
return &Server{
3838
cfg: cfg,
3939
logger: l,
40-
rpcServer: newRPCServer(em),
40+
rpcServer: newRPCServer(em, cfg),
4141
db: db,
4242
quit: make(chan struct{}, 1),
4343
}

0 commit comments

Comments
 (0)