diff --git a/cmd/platon/main.go b/cmd/platon/main.go index 47a116e4f7..cfb64af141 100644 --- a/cmd/platon/main.go +++ b/cmd/platon/main.go @@ -124,6 +124,9 @@ var ( utils.HTTPListenAddrFlag, utils.HTTPPortFlag, utils.HTTPCORSDomainFlag, + utils.AuthListenFlag, + utils.AuthPortFlag, + utils.AuthVirtualHostsFlag, utils.JWTSecretFlag, utils.HTTPVirtualHostsFlag, utils.GraphQLEnabledFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 619a0d6744..ff80010918 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -384,6 +384,25 @@ var ( Value: ethconfig.Defaults.RPCTxFeeCap, Category: flags.APICategory, } + // Authenticated RPC HTTP settings + AuthListenFlag = &cli.StringFlag{ + Name: "authrpc.addr", + Usage: "Listening address for authenticated APIs", + Value: node.DefaultConfig.AuthAddr, + Category: flags.APICategory, + } + AuthVirtualHostsFlag = &cli.StringFlag{ + Name: "authrpc.vhosts", + Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.", + Value: strings.Join(node.DefaultConfig.AuthVirtualHosts, ","), + Category: flags.APICategory, + } + AuthPortFlag = &cli.IntFlag{ + Name: "authrpc.port", + Usage: "Listening port for authenticated APIs", + Value: node.DefaultConfig.AuthPort, + Category: flags.APICategory, + } JWTSecretFlag = &cli.StringFlag{ Name: "authrpc.jwtsecret", Usage: "Path to a JWT secret to use for authenticated RPC endpoints", @@ -1022,6 +1041,15 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) { if ctx.Bool(HTTPEnabledEthCompatibleFlag.Name) { types2.HttpEthCompatible = true } + if ctx.IsSet(AuthListenFlag.Name) { + cfg.AuthAddr = ctx.String(AuthListenFlag.Name) + } + if ctx.IsSet(AuthPortFlag.Name) { + cfg.AuthPort = ctx.Int(AuthPortFlag.Name) + } + if ctx.IsSet(AuthVirtualHostsFlag.Name) { + cfg.AuthVirtualHosts = SplitAndTrim(ctx.String(AuthVirtualHostsFlag.Name)) + } if ctx.IsSet(HTTPVirtualHostsFlag.Name) { cfg.HTTPVirtualHosts = SplitAndTrim(ctx.String(HTTPVirtualHostsFlag.Name)) } diff --git a/node/config.go b/node/config.go index c69045c8c2..df073e5d21 100644 --- a/node/config.go +++ b/node/config.go @@ -136,12 +136,16 @@ type Config struct { // HTTPPathPrefix specifies a path prefix on which http-rpc is to be served. HTTPPathPrefix string `toml:",omitempty"` - // AuthHost is the listening address on which authenticated APIs are provided. - AuthHost string `toml:",omitempty"` + // AuthAddr is the listening address on which authenticated APIs are provided. + AuthAddr string `toml:",omitempty"` // AuthPort is the port number on which authenticated APIs are provided. AuthPort int `toml:",omitempty"` + // AuthVirtualHosts is the list of virtual hostnames which are allowed on incoming requests + // for the authenticated api. This is by default {'localhost'}. + AuthVirtualHosts []string `toml:",omitempty"` + // WSHost is the host interface on which to start the websocket RPC server. If // this field is empty, no websocket API endpoint will be started. WSHost string diff --git a/node/defaults.go b/node/defaults.go index b5cc2bf2d4..69faaca480 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -50,8 +50,9 @@ var ( var DefaultConfig = Config{ DataDir: DefaultDataDir(), HTTPPort: DefaultHTTPPort, - AuthHost: DefaultAuthHost, + AuthAddr: DefaultAuthHost, AuthPort: DefaultAuthPort, + AuthVirtualHosts: DefaultAuthVhosts, HTTPModules: []string{"net", "web3"}, HTTPVirtualHosts: []string{"localhost"}, HTTPTimeouts: rpc.DefaultHTTPTimeouts, diff --git a/node/node.go b/node/node.go index 187c04f506..94dac21bb3 100644 --- a/node/node.go +++ b/node/node.go @@ -450,12 +450,12 @@ func (n *Node) startRPC() error { initAuth := func(apis []rpc.API, port int, secret []byte) error { // Enable auth via HTTP server := n.httpAuth - if err := server.setListenAddr(n.config.AuthHost, port); err != nil { + if err := server.setListenAddr(n.config.AuthAddr, port); err != nil { return err } if err := server.enableRPC(apis, httpConfig{ CorsAllowedOrigins: DefaultAuthCors, - Vhosts: DefaultAuthVhosts, + Vhosts: n.config.AuthVirtualHosts, Modules: DefaultAuthModules, prefix: DefaultAuthPrefix, jwtSecret: secret, @@ -465,7 +465,7 @@ func (n *Node) startRPC() error { servers = append(servers, server) // Enable auth via WS server = n.wsServerForPort(port, true) - if err := server.setListenAddr(n.config.AuthHost, port); err != nil { + if err := server.setListenAddr(n.config.AuthAddr, port); err != nil { return err } if err := server.enableWS(apis, wsConfig{