From 3ff6a88d8e6da8e43197214294c1274c41e73c89 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Thu, 3 Oct 2019 06:00:45 +0200 Subject: [PATCH] Add tor relay fragment (#190) * Add tor relay fragment * remove extra , * use same tor container for relay * remove \ns * use own container for tor relay because of https://trac.torproject.org/projects/tor/ticket/8742 * be explicit with ports * fix container name * fix duplicate config * fix config clash * do not set daemon config item * add info about tor requirements and legal implications --- Generated/torrc-relay.tmpl | 12 +++++++ Generated/torrc.tmpl | 4 +++ README.md | 3 ++ btcpay-setup.sh | 4 +++ .../docker-fragments/opt-add-tor-relay.yml | 33 +++++++++++++++++++ helpers.sh | 4 ++- 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Generated/torrc-relay.tmpl create mode 100644 docker-compose-generator/docker-fragments/opt-add-tor-relay.yml diff --git a/Generated/torrc-relay.tmpl b/Generated/torrc-relay.tmpl new file mode 100644 index 0000000..8e5a988 --- /dev/null +++ b/Generated/torrc-relay.tmpl @@ -0,0 +1,12 @@ +ORPort 9001 +DirPort 9030 +ExitPolicy reject *:* +CookieAuthentication 1 + +Nickname {{ $.Env.TOR_RELAY_NICKNAME}} +ContactInfo {{ $.Env.TOR_RELAY_EMAIL}} + + +{{ if $.Env.ADDITIONAL_TORRC_CONFIG }} +{{ $.Env.ADDITIONAL_TORRC_CONFIG}} +{{ end }} \ No newline at end of file diff --git a/Generated/torrc.tmpl b/Generated/torrc.tmpl index b97696a..c17853b 100644 --- a/Generated/torrc.tmpl +++ b/Generated/torrc.tmpl @@ -27,4 +27,8 @@ HiddenServicePort {{ $virtualPort }} {{ $containerNetwork.IP }}:{{ $port }} {{ end }} {{ end }} {{ end }} +{{ end }} + +{{ if $.Env.ADDITIONAL_TORRC_CONFIG }} +{{ $.Env.ADDITIONAL_TORRC_CONFIG}} {{ end }} \ No newline at end of file diff --git a/README.md b/README.md index 617808a..5044d9a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ You can read [the article](https://medium.com/@BtcpayServer/hosting-btcpay-serve * `BTCPAYGEN_DOCKER_IMAGE`: Optional, Specify which generator image to use if you have customized the C# generator. Set to `btcpayserver/docker-compose-generator:local` to build the generator locally at runtime. * `BTCPAY_IMAGE`: Optional, Specify which btcpayserver image to use if you have a customized btcpayserver. * `BTCPAYGEN_EXCLUDE_FRAGMENTS`: Semicolon-separated list of fragments you want to forcefully exclude (eg. `litecoin-clightning`) +* `TOR_RELAY_NICKNAME`: If tor relay is activated with opt-add-tor-relay, the relay nickname +* `TOR_RELAY_EMAIL`: If tor relay is activated with opt-add-tor-relay, the email for Tor to contact you regarding your relay Additionally, there are specific environment variables for some addons: @@ -153,6 +155,7 @@ Available `BTCPAYGEN_ADDITIONAL_FRAGMENTS` currently are: * [opt-add-btctransmuter](docker-compose-generator/docker-fragments/opt-add-btctransmuter.yml), for a self-hosted IFTTT style service for crypto services such as fiat settlement. * [opt-txindex](docker-compose-generator/docker-fragments/opt-txindex.yml), to enable txindex=1 in bitcoin.conf if you require txindexing for Bisq, DOJO, Esplora, etc. * [opt-unsafe-expose](docker-compose-generator/docker-fragments/opt-unsafe-expose.yml), to unsafely expose bitcoind P2P port 8333 if you require P2P for Bisq, DOJO, Esplora, etc. WARNING: ONLY USE ON TRUSTED LAN OR WITH FIREWALL RULES WHITELISTING SPECIFIC HOSTS +* [opt-add-tor-relay](docker-compose-generator/docker-fragments/opt-add-tor-relay.yml), for a non-exit tor relay. Make sure to have ports 9001 and 9030 accessible externally. [Please read the legal implications of running a tor relay](https://www.eff.org/torchallenge/faq.html) and [what resources are used to operate the relay](https://trac.torproject.org/projects/tor/wiki/TorRelayGuide#RelayRequirements). You can also create your own [custom fragments](#how-can-i-customize-the-generated-docker-compose-file). diff --git a/btcpay-setup.sh b/btcpay-setup.sh index af3c4f2..d597305 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -104,6 +104,8 @@ Add-on specific variables: WOOCOMMERCE_HOST: If woocommerce is activated with opt-add-woocommerce, the hostname of your woocommerce website (eg. store.example.com) BTCPAYGEN_EXCLUDE_FRAGMENTS: Semicolon-separated list of fragments you want to forcefully exclude (eg. litecoin-clightning) BTCTRANSMUTER_HOST: If btc transmuter is activated with opt-add-btctransmuter, the hostname of your btc transmuter website (eg. store.example.com) + TOR_RELAY_NICKNAME: If tor relay is activated with opt-add-tor-relay, the relay nickname + TOR_RELAY_EMAIL: If tor relay is activated with opt-add-tor-relay, the email for Tor to contact you regarding your relay END } START="" @@ -301,6 +303,8 @@ BTCPAYGEN_ADDITIONAL_FRAGMENTS:$BTCPAYGEN_ADDITIONAL_FRAGMENTS BTCPAYGEN_EXCLUDE_FRAGMENTS:$BTCPAYGEN_EXCLUDE_FRAGMENTS BTCPAY_IMAGE:$BTCPAY_IMAGE ACME_CA_URI:$ACME_CA_URI +TOR_RELAY_NICKNAME: $TOR_RELAY_NICKNAME +TOR_RELAY_EMAIL: $TOR_RELAY_EMAIL ---------------------- Additional exported variables: BTCPAY_DOCKER_COMPOSE=$BTCPAY_DOCKER_COMPOSE diff --git a/docker-compose-generator/docker-fragments/opt-add-tor-relay.yml b/docker-compose-generator/docker-fragments/opt-add-tor-relay.yml new file mode 100644 index 0000000..cd07803 --- /dev/null +++ b/docker-compose-generator/docker-fragments/opt-add-tor-relay.yml @@ -0,0 +1,33 @@ +version: "3" +services: + tor-relay-gen: + restart: unless-stopped + image: btcpayserver/docker-gen:0.7.6 + container_name: tor-relay-gen + volumes: + - "/var/run/docker.sock:/tmp/docker.sock:ro" + - "./torrc-relay.tmpl:/etc/docker-gen/templates/torrc.tmpl:ro" + - "tor_relay_torrcdir:/usr/local/etc/tor" + entrypoint: /usr/local/bin/docker-gen -notify-sighup tor-relay -watch -wait 5s:30s /etc/docker-gen/templates/torrc.tmpl /usr/local/etc/tor/torrc-2 + links: + - tor-relay + environment: + TOR_RELAY_NICKNAME: ${TOR_RELAY_NICKNAME} + TOR_RELAY_EMAIL: ${TOR_RELAY_EMAIL} + + tor-relay: + restart: unless-stopped + image: btcpayserver/tor:0.4.1.5 + container_name: tor-relay + environment: + TOR_PASSWORD: btcpayserver + TOR_ADDITIONAL_CONFIG: /usr/local/etc/tor/torrc-2 + volumes: + - "tor_relay_datadir:/home/tor/.tor" + - "tor_relay_torrcdir:/usr/local/etc/tor" + ports: + - "9001:9001" + - "9030:9030" +volumes: + tor_relay_datadir: + tor_relay_torrcdir: \ No newline at end of file diff --git a/helpers.sh b/helpers.sh index 43a3964..811f10a 100755 --- a/helpers.sh +++ b/helpers.sh @@ -87,7 +87,9 @@ BTCPAY_SSHAUTHORIZEDKEYS=$BTCPAY_SSHAUTHORIZEDKEYS LIBREPATRON_HOST=$LIBREPATRON_HOST BTCTRANSMUTER_HOST=$BTCTRANSMUTER_HOST BTCPAY_CRYPTOS=$BTCPAY_CRYPTOS -WOOCOMMERCE_HOST=$WOOCOMMERCE_HOST" > $BTCPAY_ENV_FILE +WOOCOMMERCE_HOST=$WOOCOMMERCE_HOST +TOR_RELAY_NICKNAME=$TOR_RELAY_NICKNAME +TOR_RELAY_EMAIL=$TOR_RELAY_EMAIL" > $BTCPAY_ENV_FILE } btcpay_up() {