Support basic auth in JSON RPC endpoint (#6897)

* Support basic auth in JSON RPC endpoint

* Review comment: Allow blank password in basi auth of JSON RPC endpoint

* Reuse basic auth configuration function

---------

Co-authored-by: sl1depengwyn <max.pengwyn@gmail.com>
pull/6922/head
Victor Baranov 2 years ago committed by GitHub
parent 7a704d8420
commit 65d7ad5b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 11
      apps/explorer/config/dev/arbitrum.exs
  3. 11
      apps/explorer/config/dev/besu.exs
  4. 11
      apps/explorer/config/dev/erigon.exs
  5. 11
      apps/explorer/config/dev/ganache.exs
  6. 11
      apps/explorer/config/dev/geth.exs
  7. 11
      apps/explorer/config/dev/nethermind.exs
  8. 11
      apps/explorer/config/dev/rsk.exs
  9. 11
      apps/explorer/config/prod/arbitrum.exs
  10. 11
      apps/explorer/config/prod/besu.exs
  11. 11
      apps/explorer/config/prod/erigon.exs
  12. 11
      apps/explorer/config/prod/ganache.exs
  13. 11
      apps/explorer/config/prod/geth.exs
  14. 11
      apps/explorer/config/prod/nethermind.exs
  15. 11
      apps/explorer/config/prod/rsk.exs
  16. 8
      apps/indexer/config/dev/arbitrum.exs
  17. 8
      apps/indexer/config/dev/besu.exs
  18. 8
      apps/indexer/config/dev/erigon.exs
  19. 8
      apps/indexer/config/dev/ganache.exs
  20. 11
      apps/indexer/config/dev/geth.exs
  21. 10
      apps/indexer/config/dev/nethermind.exs
  22. 8
      apps/indexer/config/dev/rsk.exs
  23. 8
      apps/indexer/config/prod/arbitrum.exs
  24. 8
      apps/indexer/config/prod/besu.exs
  25. 8
      apps/indexer/config/prod/erigon.exs
  26. 8
      apps/indexer/config/prod/ganache.exs
  27. 11
      apps/indexer/config/prod/geth.exs
  28. 8
      apps/indexer/config/prod/nethermind.exs
  29. 8
      apps/indexer/config/prod/rsk.exs
  30. 14
      config/config_helper.exs
  31. 2
      rel/config.exs

@ -4,6 +4,8 @@
### Features
- [#6897](https://github.com/blockscout/blockscout/pull/6897) - Support basic auth in JSON RPC endpoint
### Fixes
- [#6912](https://github.com/blockscout/blockscout/pull/6912) - Docker compose fix exposed ports

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :explorer,
json_rpc_named_arguments: [

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -11,7 +17,7 @@ config :indexer,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545",
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Arbitrum
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -17,7 +23,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545",
trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545"
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Besu
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -17,7 +23,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545",
trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545"
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Erigon
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -11,7 +17,7 @@ config :indexer,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545",
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Ganache
],

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -17,7 +23,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545",
trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545"
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Nethermind
],
@ -33,7 +39,7 @@ config :indexer,
# trace_block: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545",
# trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545"
# ],
# http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
# http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts]
# ],
# variant: EthereumJSONRPC.Nethermind
# ]

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
blocks_concurrency: 1,
@ -18,7 +24,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545",
trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545"
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.RSK
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -11,7 +17,7 @@ config :indexer,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545",
http_options: [recv_timeout: :timer.minutes(5), timeout: :timer.minutes(5), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(5), timeout: :timer.minutes(5), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Arbitrum
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -16,7 +22,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"),
trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL")
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Besu
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -16,7 +22,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"),
trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL")
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Erigon
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -11,7 +17,7 @@ config :indexer,
transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545",
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Ganache
],

@ -1,13 +1,10 @@
import Config
hackney_opts_base = [pool: :ethereum_jsonrpc]
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts =
if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do
[:insecure] ++ hackney_opts_base
else
hackney_opts_base
end
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
json_rpc_named_arguments: [
@ -16,7 +22,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"),
trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL")
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.Nethermind
],

@ -1,5 +1,11 @@
import Config
~w(config config_helper.exs)
|> Path.join()
|> Code.eval_file()
hackney_opts = ConfigHelper.hackney_options()
config :indexer,
block_interval: :timer.seconds(5),
blocks_concurrency: 1,
@ -18,7 +24,7 @@ config :indexer,
trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"),
trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL")
],
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts]
],
variant: EthereumJSONRPC.RSK
],

@ -0,0 +1,14 @@
defmodule ConfigHelper do
def hackney_options() do
basic_auth_user = System.get_env("ETHEREUM_JSONRPC_USER", "")
basic_auth_pass = System.get_env("ETHEREUM_JSONRPC_PASSWORD", nil)
hackney_opts =
[pool: :ethereum_jsonrpc]
|> (&if(System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true", do: [:insecure] ++ &1, else: &1)).()
|> (&if(basic_auth_user != "" && !is_nil(basic_auth_pass),
do: [basic_auth: {basic_auth_user, basic_auth_pass}] ++ &1,
else: &1
)).()
end
end

@ -71,7 +71,7 @@ end
# will be used by default
release :blockscout do
set version: "1.2.0-beta"
set version: "5.1.0-beta"
set applications: [
:runtime_tools,
block_scout_web: :permanent,

Loading…
Cancel
Save