ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
480 stars 188 forks source link

403 Forbidden #15

Closed ekkis closed 8 years ago

ekkis commented 8 years ago

I'm using the new Docker-for-Mac to run the daemon like this:

$docker run -d --name bitcoind -e BITCOIN_DATA=/data \
    -v ${PWD}/bitcoind:/data -p 8332:8332 seegno/bitcoind:latest \
    -server -rpcuser=test -rpcpassword=nopass -rpcallowip=192.168.1.67 \
    -printtoconsole -debug=rpc

where the IP address I allow is my default:

$ ifconfig |grep inet |grep -v inet6
    inet 127.0.0.1 nitmask 0xff000000 
    inet 192.168.1.67 netmask 0xffffff00 broadcast 192.168.1.255

I then run my app:

var BTC = require('bitcoin-core');

var opts = { 
    host: 'localhost',
    port: 8332,
    username: 'test',
    password: 'nopass'
};
btc = new BTC(opts);
btc.getNewAddress().then(function(s) {
    console.log(s);
});

and get:

Unhandled rejection RpcError: 403 Forbidden at get (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/parser.js:34:11) at Client.rpc (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/parser.js:81:14) at Request.self.callback (/Users/ekkis/Development/Test/www/node_modules/request/request.js:200:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (/Users/ekkis/Development/Test/www/node_modules/request/request.js:1067:10) at emitOne (events.js:82:20) at Request.emit (events.js:169:7) at IncomingMessage. (/Users/ekkis/Development/Test/www/node_modules/request/request.js:988:12) From previous event: at /Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/index.js:163:21 From previous event: at Client.command (/Users/ekkis/Development/Test/www/node_modules/bitcoin-core/dist/src/index.js:152:34) at apply (/Users/ekkis/Development/Test/www/node_modules/lodash/lodash.js:409:27) at Client.wrapper as getNewAddress at Object. (/Users/ekkis/Development/Test/www/t:12:5) at Module._compile (module.js:425:26) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Function.Module.runMain (module.js:457:10) at startup (node.js:136:18) at node.js:972:3

though I seem able to connect to the server:

$ telnet localhost 8332
Trying ::1...
Connected to localhost.
Escape character is '^]'.

it doesn't hang up on me with a connection error... what am I missing?

ekkis commented 8 years ago

well... if I run the daemon with -logips and make my attempt I see:

2016-07-09 18:32:26 Received a POST request for / from 172.17.0.1:50262

instead of the IP address I expected. I gather it's the IP address of the VM that Docker runs, that somehow gets routed to the container. so now the question is: how do I discover that IP address from my node app so I can whitelist it?

ekkis commented 8 years ago

and... (drumroll) the answer seems to be that I can pick it up from the docker inspect NetworkSettings.Gateway key. but... in fact, I can bake it into the CLI because for this image the gateway is always the same

sahityakumarsuman commented 4 years ago

@ekkis are you able to solve this problem, I am running my docker image on was and trying to connect with it. While the RPC client method of bitcoin-core gives me a 403 Forbidden error I am able to connect with same port with telnet.

const wallet1 = new Rpc_client({
    network: 'regtest',
    username: 'someusername',
    wallet: 'somewallet.dat',
    host : '1X.1X1.X3X.2X7',
    port : '18332',
    password: 'somepassword',
});

I am running a docker bitcoin-core with the following docker image

`docker run -d -p 18332:18332 ruimarinho/bitcoin-core:0.15-alpine -printtoconsole -server -rpcauth='someusername:somepassword -regtest -wallet=somewallet.dat -rpcallowip=172.17.0.0/16 -txindex

`

Help me to resolve this error

ekkis commented 4 years ago

see the comment I closed this issue with for a solution

sahityakumarsuman commented 4 years ago

What I did is

docker run -d -p 18332:18332 ruimarinho/bitcoin-core:0.15-alpine -printtoconsole -server -rpcauth='someusername:somepassword -regtest -wallet=somewallet.dat -rpcallowip=0.0.0.0/0 -txindex
const wallet = new Rpc_client({
    network: 'regtest',
    username: 'someusername',
    wallet: 'somewallet.dat',
    host : '1X.1X1.X3X.2X7',
    port : '18332',
    password: 'somepassword',
}, true);

now successfully able to connect, I know there is some security issue in here but i am checking for testnetwork. Would be great if anyone going for mainnet and give a secure method to connect

@ekkis thanks for your reply but i tried that and found no file also i am new to docker so not able to put that in action. would be a great help if you can tell me for mainnet