[rpc] listen to localhost by default

for security reason, node program should only listen to localhost for rpc request by default.

-rpc_ip  option is introduced to listen to any port for rpc service

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1614/head
Leo Chen 5 years ago
parent b08d56c95d
commit 967fec9056
  1. 2
      cmd/harmony/main.go
  2. 11
      internal/configs/node/config.go
  3. 5
      node/rpc.go

@ -66,6 +66,7 @@ func printVersion() {
var ( var (
ip = flag.String("ip", "127.0.0.1", "ip of the node") ip = flag.String("ip", "127.0.0.1", "ip of the node")
rcpIP = flag.String("rpc_ip", "127.0.0.1", "listening ip of the node for rpc service")
port = flag.String("port", "9000", "port of the node.") port = flag.String("port", "9000", "port of the node.")
logFolder = flag.String("log_folder", "latest", "the folder collecting the logs of this execution") logFolder = flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
logMaxSize = flag.Int("log_max_size", 100, "the max size in megabytes of the log file before it gets rotated") logMaxSize = flag.Int("log_max_size", 100, "the max size in megabytes of the log file before it gets rotated")
@ -147,6 +148,7 @@ func initSetup() {
// Set port and ip to global config. // Set port and ip to global config.
nodeconfig.GetDefaultConfig().Port = *port nodeconfig.GetDefaultConfig().Port = *port
nodeconfig.GetDefaultConfig().IP = *ip nodeconfig.GetDefaultConfig().IP = *ip
nodeconfig.GetDefaultConfig().SetRPCIP(*ip)
// Setup mem profiling. // Setup mem profiling.
memprofiling.GetMemProfiling().Config() memprofiling.GetMemProfiling().Config()

@ -76,6 +76,7 @@ type ConfigType struct {
role Role // Role of the node role Role // Role of the node
Port string // Port of the node. Port string // Port of the node.
IP string // IP of the node. IP string // IP of the node.
rpcIP string // IP of the node listen on RPC service
MetricsFlag bool // collect and upload metrics flag MetricsFlag bool // collect and upload metrics flag
PushgatewayIP string // metrics pushgateway prometheus ip PushgatewayIP string // metrics pushgateway prometheus ip
@ -238,6 +239,16 @@ func (conf *ConfigType) GetNetworkType() NetworkType {
return conf.networkType return conf.networkType
} }
// SetRPCIP sets the IP of RPC service
func (conf *ConfigType) SetRPCIP(ip string) {
conf.rpcIP = ip
}
// GetRPCIP gets the IP of the RPC srevice
func (conf *ConfigType) GetRPCIP() string {
return conf.rpcIP
}
// SetVersion set the version of the node binary // SetVersion set the version of the node binary
func SetVersion(ver string) { func SetVersion(ver string) {
version = ver version = ver

@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/harmony-one/harmony/hmy" "github.com/harmony-one/harmony/hmy"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/hmyapi" "github.com/harmony-one/harmony/internal/hmyapi"
"github.com/harmony-one/harmony/internal/hmyapi/filters" "github.com/harmony-one/harmony/internal/hmyapi/filters"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
@ -56,12 +57,12 @@ func (node *Node) StartRPC(nodePort string) error {
port, _ := strconv.Atoi(nodePort) port, _ := strconv.Atoi(nodePort)
httpEndpoint = fmt.Sprintf(":%v", port+rpcHTTPPortOffset) httpEndpoint = fmt.Sprintf("%v:%v", nodeconfig.GetDefaultConfig().GetRPCIP(), port+rpcHTTPPortOffset)
if err := node.startHTTP(httpEndpoint, apis, httpModules, httpOrigins, httpVirtualHosts, httpTimeouts); err != nil { if err := node.startHTTP(httpEndpoint, apis, httpModules, httpOrigins, httpVirtualHosts, httpTimeouts); err != nil {
return err return err
} }
wsEndpoint = fmt.Sprintf(":%v", port+rpcWSPortOffset) wsEndpoint = fmt.Sprintf("%v:%v", nodeconfig.GetDefaultConfig().GetRPCIP(), port+rpcWSPortOffset)
if err := node.startWS(wsEndpoint, apis, wsModules, wsOrigins, true); err != nil { if err := node.startWS(wsEndpoint, apis, wsModules, wsOrigins, true); err != nil {
node.stopHTTP() node.stopHTTP()
return err return err

Loading…
Cancel
Save