Skip to content

Commit

Permalink
7667 cli params vhost (#7669)
Browse files Browse the repository at this point in the history
This change adds 'any' as an alternate wildcard to '*'.

I have updated all doc references in the main erigon repo - let me know
if there is anywhere else that needs changing.
  • Loading branch information
mh0lt authored Jun 9, 2023
1 parent 614769f commit 62b2375
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ http.api : ["eth","debug","net"]
Erigon can be used as an Execution Layer (EL) for Consensus Layer clients (CL). Default configuration is OK.

If your CL client is on a different device, add `--authrpc.addr 0.0.0.0` ([Engine API] listens on localhost by default)
as well as `--authrpc.vhosts <CL host>`.
as well as `--authrpc.vhosts <CL host>` where `<CL host>` is your source host or `any`.

[Engine API]: https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md

Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ var (
}
HTTPVirtualHostsFlag = cli.StringFlag{
Name: "http.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts 'any' or '*' as wildcard.",
Value: strings.Join(nodecfg.DefaultConfig.HTTPVirtualHosts, ","),
}
AuthRpcVirtualHostsFlag = cli.StringFlag{
Name: "authrpc.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept Engine API requests (server enforced). Accepts '*' wildcard.",
Usage: "Comma separated list of virtual hostnames from which to accept Engine API requests (server enforced). Accepts 'any' or '*' as wildcard.",
Value: strings.Join(nodecfg.DefaultConfig.HTTPVirtualHosts, ","),
}
HTTPApiFlag = cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ services:
<<: *default-erigon-service
entrypoint: rpcdaemon
command: |
${RPCDAEMON_FLAGS-} --http.addr=0.0.0.0 --http.vhosts=* --http.corsdomain=* --ws
${RPCDAEMON_FLAGS-} --http.addr=0.0.0.0 --http.vhosts=any --http.corsdomain=* --ws
--private.api.addr=erigon:9090 --txpool.api.addr=txpool:9094 --datadir=/home/erigon/.local/share/erigon
ports: [ "8545:8545" ]

Expand Down
2 changes: 1 addition & 1 deletion k8s/google-kubernetes-engine/statefulset-erigon-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- '--http.addr=0.0.0.0'
- '--http.api=eth,erigon,web3,net,debug,ots,trace,txpool'
- '--http.corsdomain=*'
- '--http.vhosts=*'
- '--http.vhosts=any'
- '--log.console.verbosity=1'
- '--log.json'
- '--metrics'
Expand Down
6 changes: 5 additions & 1 deletion node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.next.ServeHTTP(w, r)
return
}
if _, exist := h.vhosts[host]; exist {
if _, exist := h.vhosts["any"]; exist {
h.next.ServeHTTP(w, r)
return
}
if _, exist := h.vhosts[strings.ToLower(host)]; exist {
h.next.ServeHTTP(w, r)
return
}
Expand Down
17 changes: 16 additions & 1 deletion node/rpcstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCorsHandler(t *testing.T) {
assert.Equal(t, "", resp2.Header.Get("Access-Control-Allow-Origin"))
}

// TestVhosts makes sure vhosts are properly handled on the http server.
// TestVhosts makes sure vhosts is properly handled on the http server.
func TestVhosts(t *testing.T) {
srv := createAndStartServer(t, &httpConfig{Vhosts: []string{"test"}}, false, &wsConfig{})
defer srv.stop()
Expand All @@ -65,6 +65,21 @@ func TestVhosts(t *testing.T) {
assert.Equal(t, resp2.StatusCode, http.StatusForbidden)
}

// TestVhostsAny makes sure vhosts any is properly handled on the http server.
func TestVhostsAny(t *testing.T) {
srv := createAndStartServer(t, &httpConfig{Vhosts: []string{"any"}}, false, &wsConfig{})
defer srv.stop()
url := "http://" + srv.listenAddr()

resp := rpcRequest(t, url, "host", "test")
defer resp.Body.Close()
assert.Equal(t, resp.StatusCode, http.StatusOK)

resp2 := rpcRequest(t, url, "host", "bad")
defer resp2.Body.Close()
assert.Equal(t, resp.StatusCode, http.StatusOK)
}

type originTest struct {
spec string
expOk []string
Expand Down
4 changes: 2 additions & 2 deletions tests/automated-testing/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
image: thorax/erigon:$ERIGON_TAG
entrypoint: rpcdaemon
command: |
--private.api.addr=erigon:9090 --http.api=admin,eth,erigon,web3,net,debug,trace,txpool,parity --http.addr=0.0.0.0 --http.vhosts=* --http.corsdomain=* --http.port=8545 --graphql --log.dir.path=/logs/node1
--private.api.addr=erigon:9090 --http.api=admin,eth,erigon,web3,net,debug,trace,txpool,parity --http.addr=0.0.0.0 --http.vhosts=any --http.corsdomain=* --http.port=8545 --graphql --log.dir.path=/logs/node1
volumes:
- ./logdir:/logs
user: ${DOCKER_UID}:${DOCKER_GID}
Expand All @@ -47,7 +47,7 @@ services:
image: thorax/erigon:$ERIGON_TAG
entrypoint: rpcdaemon
command: |
--private.api.addr=erigon-node2:9090 --http.api=admin,eth,erigon,web3,net,debug,trace,txpool,parity --http.addr=0.0.0.0 --http.vhosts=* --http.corsdomain=* --http.port=8545 --log.dir.path=/logs/node2
--private.api.addr=erigon-node2:9090 --http.api=admin,eth,erigon,web3,net,debug,trace,txpool,parity --http.addr=0.0.0.0 --http.vhosts=any --http.corsdomain=* --http.port=8545 --log.dir.path=/logs/node2
volumes:
- ./logdir:/logs
user: ${DOCKER_UID}:${DOCKER_GID}
Expand Down

0 comments on commit 62b2375

Please sign in to comment.