From ff20e940326b946ea1899792654931bfeafc166b Mon Sep 17 00:00:00 2001 From: Benjamin Dweck Date: Wed, 5 Jan 2022 09:32:46 +0200 Subject: [PATCH] Added existing project files --- Dockerfile | 20 ++++++++++++++++++++ README.md | 26 ++++++++++++++++++++++++++ svc-hostname | 8 ++++++++ tor.sh | 10 ++++++++++ 4 files changed, 64 insertions(+) create mode 100644 Dockerfile create mode 100755 svc-hostname create mode 100755 tor.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c1519a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM alpine + +ARG SVC_LISTEN_PORT +ARG SVC_TARGET_HOST +ARG SVC_TARGET_PORT + +WORKDIR /etc/tor + +RUN apk add --no-cache curl tor && \ + echo -e "HiddenServiceDir /var/lib/tor/svc/\nHiddenServicePort $SVC_LISTEN_PORT $SVC_TARGET_HOST:$SVC_TARGET_PORT" > ./torrc + +HEALTHCHECK --interval=60s --timeout=15s --start-period=20s \ + CMD curl -s --socks5 127.0.0.1:9050 'https://check.torproject.org/' | grep -qm1 Congratulations + +COPY tor.sh /usr/local/bin/ +COPY svc-hostname /usr/local/bin/ + +#USER tor + +CMD [ "tor.sh", "$SVC_TARGET_HOST" ] diff --git a/README.md b/README.md index e69de29..5e91e29 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,26 @@ +Tor Proxy +=========================== + +This is a Tor Proxy Docker container for "torifying" other Docker-based services in a Docker Compose project. It creates a Tor Hidden Service with an onion hostname that persists as long as it's underlying storage volume. The Tor Hidden Service listens on the specified port and proxies traffice to the specified target host:port. + +### Example Usage + +`docker-compose.yml`: +``` +... + + mysvc_tor_proxy: + build: + context: ./tor + args: + - SVC_LISTEN_PORT=80 + - SVC_TARGET_HOST=mysvc + - SVC_TARGET_PORT=8080 + volumes: + - mysvc_config:/var/lib/tor + depends_on: + - mysvc + restart: unless-stopped + +... +``` diff --git a/svc-hostname b/svc-hostname new file mode 100755 index 0000000..b9842d1 --- /dev/null +++ b/svc-hostname @@ -0,0 +1,8 @@ +#!/bin/sh + +while ! curl -s -N --socks5 127.0.0.1:9050 'https://check.torproject.org/' | grep -qm1 Congratulations +do + sleep 0.5 +done + +echo $(cat /var/lib/tor/svc/hostname) diff --git a/tor.sh b/tor.sh new file mode 100755 index 0000000..da08c90 --- /dev/null +++ b/tor.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +HOSTNAME=$1 + +IP_ADDR=$(nslookup $HOSTNAME | awk '/^Address: / { print $2 }' | tail -n1 | sed -e 's/[[:space:]]//g') +sed -i "s/$HOSTNAME/$IP_ADDR/g" /etc/tor/torrc + +echo "*** Service Hostname: $(/usr/local/bin/svc-hostname)" & + +tor