安全地公开您的网络,使任何人都可以访问您的智能合约

Expose securely your network to make possible anyone can hit your smart contract

我正在使用 go-ethereum 实现以太坊 PoA 网络

我在网络上部署了一个 ERC20 令牌,想法是网络 必须从互联网上的任何钱包访问 (即 metamask、myetherwallet 等)

这个网络的想法是:

为了实现这一点,我创建了 2 个负责密封块的完整节点。

我运行那些节点是这样的:

geth --datadir sealer1/  --syncmode 'full' --port 30351 --rpc --rpcaddr 'localhost' --rpcport 8502 --rpcapi='admin,personal,db,eth,net,web3,txpool,miner' --networkid 20 --gasprice '1' -unlock 'someaccount' --password s2/password.txt --mine

如您所见,关于这些节点有一些重要的事情:

  1. 解锁帐户
  2. 只能从本地主机访问(注意 rpcaddres)
  3. 那些节点是矿工

如果我将这样的节点暴露在互联网上(允许从任何来源进行 RPC 访问),任何黑客都可以将以太币发送到另一个帐户,因此,我创建了第三个节点,一个标准节点,它不暴露 rpc api但允许端口 8545 上的连接(以便从 metamask、myetherwallet 等访问)

我运行节点用这个命令:

geth --datadir standard1/ --syncmode 'full' --port 30352 --rpc --rpcport 8545--rpccorsdomain '*' --rpcaddr 'SERVER_PUBLIC_IP' --networkid 20 --gasprice '1'  

你可以看到这个节点:

  1. 不解锁帐户
  2. 允许从任何来源访问 rpc
  3. 不公开个人、管理员等 rpc api

我的问题是:

为什么我会有这些问题

因为有很多地方不建议开放RPC端口,所以我不安全如果:

足以安全地公开我的节点。

以下是与打开 RPC 访问相关的一些问题:

https://blog.blockdaemon.com/ethereum-geth-configuration-made-in-ireland-7ba2e876c6e3 https://www.reddit.com/r/ethereum/comments/4z0mvi/ethereum_nodes_with_insecure_rpc_settings_are/

https://www.reddit.com/r/ethereum/comments/3ird55/holy_shit_my_eth_accounts_been_hacked/

https://www.reddit.com/r/ethereum/comments/4jav5u/mist_wallet_has_2_sec_vulnerability_for_rpc/

https://blog.3or.de/internet-wide-ethereum-json-rpc-scans.html

https://www.bokconsulting.com.au/blog/7218-ethers-stolen-from-miner-with-rpc-port-open/

https://blog.ethereum.org/2015/08/29/security-alert-insecurely-configured-geth-can-make-funds-remotely-accessible/

这里推荐以太坊团队负责人:

Ok, your setup seems insanely dangerous. --rpcaddr=external_address essentially opens up the node to anyone in the world to access it. Forthermore, --rpcapi 'admin,personal,db,eth,net,web3,txpool,miner' permits anyone with access to do absolutely anything. I can imagine someone from the internet is brute forcing the passwords.

https://github.com/ethereum/go-ethereum/issues/17417#issuecomment-413877558

is this approach secure?

大体思路是对的,但还有改进的余地。

  1. 首先,我永远不会 运行 一个同时使用 -unlock 启用 personal API 的节点,这使任何人都可以永久访问该帐户可以访问您的节点。所以想象一下,有人通过其他途径获得了对您节点的访问权限,他们将能够立即从该帐户中花费您的资金,从本地主机产生交易。请考虑仅在该节点上公开 safe API 或完全删除 unlock 语句。
  2. 如果您坚持按上述配置密封节点,请添加一些加固。有多种选择,您可以使用强大的防火墙规则集基本上阻止来自外部网络的所有内容,除了端口 30351 上的节点通信。或者,我会做的是隐藏完全断开此节点与 public Internet 的连接并且仅将 p2p 流量从该节点连接到其他 proxy 节点,该节点连接到您的节点和互联网上的其他节点。不过,这可能会带来网络稳定性方面的缺陷。

Is there another way to allow anyone in the world to use Metamask to hit my smartcontract without open the RPC access on the standard node?

您是否考虑过研究 public PoA 网络,例如 poa.net?这基本上允许您的用户将 metamask 或 mycrypto 连接到现有的 POA 基础设施。