Protecting Ethereum JSON-RPC API with passwordBy Mikko Ohtamaa 2 years ago. Tagged under parity, go-ethereum, geth, nginx http, dapp, json-rpc, cppethereum, security, linux. PrefaceThis blog post is aimed to smart contract application developers and discusses how to securely run your Ethereum nodes behind a password for secure exposure over Internet. Go Ethereum (geth) is the most popular software for Ethereum node. The other popular Ethereum implementations are Parity and cpp-ethereum. Distributed applications (Dapps) are JavaScript coded web pages that connect to any of these Ethereum node softwares over JSON-RPC API protocol that is self runs on the top of HTTP protocol. geth or none of the node softwares themselves doesn't provide secure networking. It is not safe to expose Ethereum JSON-RPC API to public Internet as even with private APIs disabled this opens a door for trivial denial of service attacks. Node softwares themselves don't need to provide secure networking primitives, as this kind of built-in functionality would increase complexity and add attack surface to critical blockchain node software. Dapps themselve are pure client side HTML and JavaScript, don't need any servers and they can run in any web browser, including mobile and embedded ones, like one inside Mist wallet. Using Nginx proxy as HTTP Basic AuthenticatorThere are several ways to protect access to a HTTP API. The most common methods include API token in the HTTP header, cookie based authentication or HTTP Basic Access Authentication. HTTP Basic Authentication is a very old feature of HTTP protocol where a web browser opens a native pop dialog asking for username and password. It is limited in nature, but very easy to implement and perfect for use cases where one needs to expose a private Dapp for a limited Internet audience. These use cases include showing a Dapp demo, private and permissioned blockchain applications or exposing Ethereum functionality as a part of your software-as-a-service solution. NginxNginx is one of the most popular open source web server applications. We show how to set up Nginx web server, so that it servers your Dapp (HTML files) and geth JSON-RPC API privately using HTTP Basic Auth. We assume Ubuntu 14.04 of newer Linux server. The file locations may depend on the used Linux distribution. Installing NginxInstall Nginx on Ubuntu Linux 14.04 or newer:
Configuring NginxWe assume we edit the default website configuration file
Create HTTP Basic Auth user demo with a password:
Configuring gethThe easiest way to get started with daemonized geth is to run it in a UNIX screen:
Exit See geth private testnet instructions. Configuring DappIn your Dapp, make web3.js to use
Deploying DappCopy your DApp files to Bonus - a deployment shell script example:
Restart NginxDo a hard restart for Nginx:
Test and iterateVisit website and see if your Dapp connects to proxied Geth. Check /eth endpoint make sure a geth is properly running as a background process on the server
|
|
來(lái)自: quasiceo > 《數(shù)字幣》