forked from cerc-io/plugeth
cmd/geth: make authrpc listening address settable from command line (#24522)
The default listening address "localhost" is not sufficient when running geth in Docker.
This commit is contained in:
parent
65ed1a6871
commit
5079e3c6e5
@ -165,6 +165,7 @@ var (
|
|||||||
utils.HTTPListenAddrFlag,
|
utils.HTTPListenAddrFlag,
|
||||||
utils.HTTPPortFlag,
|
utils.HTTPPortFlag,
|
||||||
utils.HTTPCORSDomainFlag,
|
utils.HTTPCORSDomainFlag,
|
||||||
|
utils.AuthHostFlag,
|
||||||
utils.AuthPortFlag,
|
utils.AuthPortFlag,
|
||||||
utils.JWTSecretFlag,
|
utils.JWTSecretFlag,
|
||||||
utils.HTTPVirtualHostsFlag,
|
utils.HTTPVirtualHostsFlag,
|
||||||
|
@ -136,7 +136,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
utils.IPCDisabledFlag,
|
utils.IPCDisabledFlag,
|
||||||
utils.IPCPathFlag,
|
utils.IPCPathFlag,
|
||||||
utils.JWTSecretFlag,
|
|
||||||
utils.HTTPEnabledFlag,
|
utils.HTTPEnabledFlag,
|
||||||
utils.HTTPListenAddrFlag,
|
utils.HTTPListenAddrFlag,
|
||||||
utils.HTTPPortFlag,
|
utils.HTTPPortFlag,
|
||||||
@ -150,6 +149,9 @@ var AppHelpFlagGroups = []flags.FlagGroup{
|
|||||||
utils.WSApiFlag,
|
utils.WSApiFlag,
|
||||||
utils.WSPathPrefixFlag,
|
utils.WSPathPrefixFlag,
|
||||||
utils.WSAllowedOriginsFlag,
|
utils.WSAllowedOriginsFlag,
|
||||||
|
utils.JWTSecretFlag,
|
||||||
|
utils.AuthHostFlag,
|
||||||
|
utils.AuthPortFlag,
|
||||||
utils.GraphQLEnabledFlag,
|
utils.GraphQLEnabledFlag,
|
||||||
utils.GraphQLCORSDomainFlag,
|
utils.GraphQLCORSDomainFlag,
|
||||||
utils.GraphQLVirtualHostsFlag,
|
utils.GraphQLVirtualHostsFlag,
|
||||||
|
@ -522,11 +522,16 @@ var (
|
|||||||
Usage: "Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)",
|
Usage: "Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)",
|
||||||
Value: ethconfig.Defaults.RPCTxFeeCap,
|
Value: ethconfig.Defaults.RPCTxFeeCap,
|
||||||
}
|
}
|
||||||
// Authenticated port settings
|
// Authenticated RPC HTTP settings
|
||||||
|
AuthHostFlag = cli.StringFlag{
|
||||||
|
Name: "authrpc.host",
|
||||||
|
Usage: "Listening address for authenticated APIs",
|
||||||
|
Value: node.DefaultConfig.AuthHost,
|
||||||
|
}
|
||||||
AuthPortFlag = cli.IntFlag{
|
AuthPortFlag = cli.IntFlag{
|
||||||
Name: "authrpc.port",
|
Name: "authrpc.port",
|
||||||
Usage: "Listening port for authenticated APIs",
|
Usage: "Listening port for authenticated APIs",
|
||||||
Value: node.DefaultAuthPort,
|
Value: node.DefaultConfig.AuthPort,
|
||||||
}
|
}
|
||||||
JWTSecretFlag = cli.StringFlag{
|
JWTSecretFlag = cli.StringFlag{
|
||||||
Name: "authrpc.jwtsecret",
|
Name: "authrpc.jwtsecret",
|
||||||
@ -965,6 +970,9 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
|
|||||||
cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
|
cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.GlobalIsSet(AuthHostFlag.Name) {
|
||||||
|
cfg.AuthHost = ctx.GlobalString(AuthHostFlag.Name)
|
||||||
|
}
|
||||||
if ctx.GlobalIsSet(AuthPortFlag.Name) {
|
if ctx.GlobalIsSet(AuthPortFlag.Name) {
|
||||||
cfg.AuthPort = ctx.GlobalInt(AuthPortFlag.Name)
|
cfg.AuthPort = ctx.GlobalInt(AuthPortFlag.Name)
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,6 @@ type Config struct {
|
|||||||
// for ephemeral nodes).
|
// for ephemeral nodes).
|
||||||
HTTPPort int `toml:",omitempty"`
|
HTTPPort int `toml:",omitempty"`
|
||||||
|
|
||||||
// Authport is the port number on which the authenticated API is provided.
|
|
||||||
AuthPort int `toml:",omitempty"`
|
|
||||||
|
|
||||||
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
||||||
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
||||||
// useless for custom HTTP clients.
|
// useless for custom HTTP clients.
|
||||||
@ -142,6 +139,12 @@ type Config struct {
|
|||||||
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
||||||
HTTPPathPrefix string `toml:",omitempty"`
|
HTTPPathPrefix string `toml:",omitempty"`
|
||||||
|
|
||||||
|
// AuthHost is the listening address on which authenticated APIs are provided.
|
||||||
|
AuthHost string `toml:",omitempty"`
|
||||||
|
|
||||||
|
// AuthPort is the port number on which authenticated APIs are provided.
|
||||||
|
AuthPort int `toml:",omitempty"`
|
||||||
|
|
||||||
// WSHost is the host interface on which to start the websocket RPC server. If
|
// 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.
|
// this field is empty, no websocket API endpoint will be started.
|
||||||
WSHost string
|
WSHost string
|
||||||
|
@ -50,6 +50,7 @@ var (
|
|||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
DataDir: DefaultDataDir(),
|
DataDir: DefaultDataDir(),
|
||||||
HTTPPort: DefaultHTTPPort,
|
HTTPPort: DefaultHTTPPort,
|
||||||
|
AuthHost: DefaultAuthHost,
|
||||||
AuthPort: DefaultAuthPort,
|
AuthPort: DefaultAuthPort,
|
||||||
HTTPModules: []string{"net", "web3"},
|
HTTPModules: []string{"net", "web3"},
|
||||||
HTTPVirtualHosts: []string{"localhost"},
|
HTTPVirtualHosts: []string{"localhost"},
|
||||||
|
@ -419,6 +419,7 @@ func (n *Node) startRPC() error {
|
|||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
initWS := func(apis []rpc.API, port int) error {
|
initWS := func(apis []rpc.API, port int) error {
|
||||||
server := n.wsServerForPort(port, false)
|
server := n.wsServerForPort(port, false)
|
||||||
if err := server.setListenAddr(n.config.WSHost, port); err != nil {
|
if err := server.setListenAddr(n.config.WSHost, port); err != nil {
|
||||||
@ -438,7 +439,7 @@ func (n *Node) startRPC() error {
|
|||||||
initAuth := func(apis []rpc.API, port int, secret []byte) error {
|
initAuth := func(apis []rpc.API, port int, secret []byte) error {
|
||||||
// Enable auth via HTTP
|
// Enable auth via HTTP
|
||||||
server := n.httpAuth
|
server := n.httpAuth
|
||||||
if err := server.setListenAddr(DefaultAuthHost, port); err != nil {
|
if err := server.setListenAddr(n.config.AuthHost, port); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := server.enableRPC(apis, httpConfig{
|
if err := server.enableRPC(apis, httpConfig{
|
||||||
@ -453,7 +454,7 @@ func (n *Node) startRPC() error {
|
|||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
// Enable auth via WS
|
// Enable auth via WS
|
||||||
server = n.wsServerForPort(port, true)
|
server = n.wsServerForPort(port, true)
|
||||||
if err := server.setListenAddr(DefaultAuthHost, port); err != nil {
|
if err := server.setListenAddr(n.config.AuthHost, port); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := server.enableWS(apis, wsConfig{
|
if err := server.enableWS(apis, wsConfig{
|
||||||
@ -467,6 +468,7 @@ func (n *Node) startRPC() error {
|
|||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up HTTP.
|
// Set up HTTP.
|
||||||
if n.config.HTTPHost != "" {
|
if n.config.HTTPHost != "" {
|
||||||
// Configure legacy unauthenticated HTTP.
|
// Configure legacy unauthenticated HTTP.
|
||||||
|
Loading…
Reference in New Issue
Block a user