Skip to content

Commit

Permalink
node: make authenticated port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Feb 25, 2022
1 parent cb6c8d4 commit f0471df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
11 changes: 10 additions & 1 deletion cmd/utils/flags.go
Expand Up @@ -520,7 +520,7 @@ var (
}
JWTSecretFlag = cli.StringFlag{
Name: "jwt-secret",
Usage: "JWT secret to use for authenticated RPC endpoints",
Usage: "JWT secret (or path to a jwt secret) to use for authenticated RPC endpoints",
}
// Logging and debug settings
EthStatsURLFlag = cli.StringFlag{
Expand Down Expand Up @@ -558,6 +558,11 @@ var (
Usage: "HTTP-RPC server listening port",
Value: node.DefaultHTTPPort,
}
HTTPAuthPortFlag = cli.IntFlag{
Name: "http.authport",
Usage: "HTTP-RPC server listening port for authenticated api's",
Value: node.DefaultAuthPort,
}
HTTPCORSDomainFlag = cli.StringFlag{
Name: "http.corsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Expand Down Expand Up @@ -955,6 +960,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
}

if ctx.GlobalIsSet(HTTPAuthPortFlag.Name) {
cfg.AuthPort = ctx.GlobalInt(HTTPAuthPortFlag.Name)
}

if ctx.GlobalIsSet(HTTPCORSDomainFlag.Name) {
cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(HTTPCORSDomainFlag.Name))
}
Expand Down
5 changes: 4 additions & 1 deletion node/config.go
Expand Up @@ -113,6 +113,9 @@ type Config struct {
// for ephemeral nodes).
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
// clients. Please be aware that CORS is a browser enforced security, it's fully
// useless for custom HTTP clients.
Expand Down Expand Up @@ -252,7 +255,7 @@ func (c *Config) HTTPEndpoint() string {

// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
func DefaultHTTPEndpoint() string {
config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort}
config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort, AuthPort: DefaultAuthPort}
return config.HTTPEndpoint()
}

Expand Down
2 changes: 2 additions & 0 deletions node/defaults.go
Expand Up @@ -34,12 +34,14 @@ const (
DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
DefaultGraphQLHost = "localhost" // Default host interface for the GraphQL server
DefaultGraphQLPort = 8547 // Default TCP port for the GraphQL server
DefaultAuthPort = 8551 // Default port for the authenticated apis
)

// DefaultConfig contains reasonable default settings.
var DefaultConfig = Config{
DataDir: DefaultDataDir(),
HTTPPort: DefaultHTTPPort,
AuthPort: DefaultAuthPort,
HTTPModules: []string{"net", "web3"},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Expand Up @@ -443,7 +443,7 @@ func (n *Node) startRPC() error {
}
// Configure authenticated HTTP (if needed).
if len(open) != len(all) {
if err := initHttp(n.httpAuth, all, 8551, jwtSecret); err != nil {
if err := initHttp(n.httpAuth, all, n.config.AuthPort, jwtSecret); err != nil {
return err
}
}
Expand All @@ -456,7 +456,7 @@ func (n *Node) startRPC() error {
}
// authenticated
if len(open) != len(all) {
if err := initWS(all, 8551, jwtSecret); err != nil {
if err := initWS(all, n.config.AuthPort, jwtSecret); err != nil {
return err
}
}
Expand Down

0 comments on commit f0471df

Please sign in to comment.