emeraldpay / dshackle

Fault Tolerant Load Balancer for Ethereum and Bitcoin APIs
Apache License 2.0
298 stars 65 forks source link

Support for basic authentication as part of the URL #261

Open barnabasbusa opened 9 months ago

barnabasbusa commented 9 months ago

Looks like basic authentication is not supported in dshackle.

Is there any quick way to enable this?

Example: config:

cluster:
      upstreams:
        - id: "geth-lighthouse"
          chain: ethereum
          connection:
            ethereum:
              rpc:
                url: "https://username:pass@rpc.lighthouse-geth-001.srv.holesky.ethpandaops.io"

dshackle logs:

2023-28-09 13:58:51.821 | INFO  |  ConfiguredUpstreams | Using Ethereum upstream, at https://username:pass@rpc.lighthouse-geth-001.srv.holesky.ethpandaops.io
2023-28-09 13:58:52.120 | WARN  |  EthereumRpcUpstream | Setting up upstream geth-lighthouse with RPC-only access, less effective than WS+RPC
2023-28-09 13:58:52.131 | INFO  |  EthereumRpcUpstream | Configured for Ethereum
2023-28-09 13:58:52.727 | INFO  | entMultistreamHolder | Upstream geth-lighthouse with chain ETHEREUM has been added
2023-28-09 13:58:52.741 | WARN  |         AbstractHead | Restarting the Head...
2023-28-09 13:58:53.635 | INFO  |            StarterKt | Started StarterKt in 16.031 seconds (JVM running for 18.811)
2023-28-09 13:59:07.726 | INFO  |          Multistream | State of ETH: height=?, status=[UNAVAILABLE/1], lag=[0], weak=[geth-lighthouse]

Raw curl to the rpc endpoint

curl --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST  https://username:password@rpc.lighthouse-geth-001.srv.holesky.ethpandaops.io

response:

{"jsonrpc":"2.0","id":1,"result":"0x207"}
splix commented 9 months ago

Did you try to specify it as basic-auth option? https://github.com/emeraldpay/dshackle/blob/master/docs/reference-configuration.adoc#ethereum-connection-options

PS I guess it's possible to extract from the URL as well, but at this time I could suggest to use the config option

barnabasbusa commented 9 months ago

Yeah,I wasn't aware of this field. Thanks it is working using this extra field, but indeed it would be great if the standard method with the prefixed username:pass method would also be supported out of the box.

barnabasbusa commented 9 months ago

Also it would be great if custom auth headers could also be passed, not just basic auth. For example something like this: https://developers.cloudflare.com/cloudflare-one/identity/service-tokens/#connect-your-service-to-access