Add TOR docker

This commit is contained in:
nicolas.dorier 2019-03-05 23:50:02 +09:00
parent 601b3c6edd
commit 28a74e69dc
3 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
exec "$@"

View File

@ -0,0 +1,88 @@
# Thanks to https://hub.docker.com/r/chriswayg/tor-alpine/dockerfile (Christian chriswayg@gmail.com)
# Dockerfile for Tor Relay Server with obfs4proxy (Multi-Stage build)
FROM golang:alpine3.7 AS go-build
# Build /go/bin/obfs4proxy & /go/bin/meek-server
RUN apk --no-cache add --update git \
&& go get -v git.torproject.org/pluggable-transports/obfs4.git/obfs4proxy \
&& go get -v git.torproject.org/pluggable-transports/meek.git/meek-server \
&& cp -rv /go/bin /usr/local/
FROM alpine:3.7 AS tor-build
ARG TOR_GPG_KEY=0x6AFEE6D49E92B601
ENV TOR_VERSION=0.3.5.8
# Install prerequisites
RUN apk --no-cache add --update \
gnupg \
build-base \
libevent \
libevent-dev \
libressl \
libressl-dev \
xz-libs \
xz-dev \
zlib \
zlib-dev \
zstd \
zstd-dev \
# Install Tor from source, incl. GeoIP files (get latest release version number from Tor ReleaseNotes)
&& TOR_TARBALL_NAME="tor-${TOR_VERSION}.tar.gz" \
&& TOR_TARBALL_LINK="https://dist.torproject.org/${TOR_TARBALL_NAME}" \
&& wget -q $TOR_TARBALL_LINK \
&& wget $TOR_TARBALL_LINK.asc \
# Reliably fetch the TOR_GPG_KEY
&& found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
ipv4.pool.sks-keyservers.net \
keys.gnupg.net \
pgp.mit.edu \
; do \
echo "Fetching GPG key $TOR_GPG_KEY from $server"; \
gpg --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$TOR_GPG_KEY" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $TOR_GPG_KEY" && exit 1; \
gpg --verify $TOR_TARBALL_NAME.asc \
&& tar xf $TOR_TARBALL_NAME \
&& cd tor-$TOR_VERSION \
&& ./configure \
&& make install \
&& ls -R /usr/local/
# Main files created (plus docs):
# /usr/local/bin/tor
# /usr/local/bin/tor-gencert
# /usr/local/bin/tor-resolve
# /usr/local/bin/torify
# /usr/local/share/tor/geoip
# /usr/local/share/tor/geoip6
# /usr/local/etc/tor/torrc.sample
FROM alpine:3.7
# Installing dependencies of Tor and pwgen
RUN apk --no-cache add --update \
libevent \
libressl \
xz-libs \
zlib \
zstd \
pwgen
# Copy obfs4proxy & meek-server
COPY --from=go-build /usr/local/bin/ /usr/local/bin/
# Copy Tor
COPY --from=tor-build /usr/local/ /usr/local/
# Persist data
VOLUME /etc/tor /var/lib/tor
COPY docker-entrypoint.sh /entrypoint.sh
# ORPort, DirPort, SocksPort, ObfsproxyPort, MeekPort
EXPOSE 9001 9030 9050 54444 7002
ENTRYPOINT ["./entrypoint.sh"]
CMD ["tor"]

View File

@ -0,0 +1,73 @@
FROM debian:stretch-slim as qemu-download
RUN set -ex \
&& apt-get update \
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget \
qemu qemu-user-static qemu-user binfmt-support
FROM debian:stretch-slim as tor-build
ARG TOR_GPG_KEY=0x6AFEE6D49E92B601
ENV TOR_VERSION=0.3.5.8
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates perl autoconf automake build-essential git libtool python python3 wget gnupg dirmngr git \
libc6-armhf-cross gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
ENV target_host=arm-linux-gnueabihf
ENV AR=${target_host}-ar \
AS=${target_host}-as \
CC=${target_host}-gcc \
CXX=${target_host}-g++ \
LD=${target_host}-ld \
STRIP=${target_host}-strip \
QEMU_LD_PREFIX=/usr/${target_host} \
HOST=${target_host}
RUN wget -q https://zlib.net/zlib-1.2.11.tar.gz \
&& tar xvf zlib-1.2.11.tar.gz \
&& cd zlib-1.2.11 \
&& ./configure --prefix=$QEMU_LD_PREFIX \
&& make \
&& make install && cd .. && rm zlib-1.2.11.tar.gz && rm -rf zlib-1.2.11
RUN wget -q https://github.com/openssl/openssl/archive/OpenSSL_1_0_2r.tar.gz \
&& tar xvf OpenSSL_1_0_2r.tar.gz \
&& cd openssl-OpenSSL_1_0_2r \
&& ./Configure --prefix=$QEMU_LD_PREFIX linux-armv4 -march=armv7 no-shared no-dso no-zlib no-asm \
&& make \
&& make install && cd .. && rm OpenSSL_1_0_2r.tar.gz && rm -rf openssl-OpenSSL_1_0_2r
RUN wget -q https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz \
&& tar xvf libevent-2.1.8-stable.tar.gz \
&& cd libevent-2.1.8-stable \
&& ./autogen.sh \
&& ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-shared --enable-static --with-pic --disable-samples --disable-libevent-regress \
&& make \
&& make install && cd .. && rm libevent-2.1.8-stable.tar.gz && rm -rf libevent-2.1.8-stable
RUN wget -q https://www.torproject.org/dist/tor-0.3.5.8.tar.gz \
&& tar xvf tor-0.3.5.8.tar.gz \
&& cd tor-0.3.5.8 \
&& ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-gcc-hardening --disable-system-torrc --disable-asciidoc \
--enable-static-tor \
--enable-static-libevent --with-libevent-dir=$QEMU_LD_PREFIX \
--enable-static-openssl --with-openssl-dir=$QEMU_LD_PREFIX \
--enable-static-zlib --with-zlib-dir=$QEMU_LD_PREFIX \
--disable-systemd --disable-lzma --disable-seccomp --disable-unittests --disable-zstd-advanced-apis \
&& make \
&& make install && cd .. && rm tor-0.3.5.8.tar.gz && rm -rf tor-0.3.5.8
FROM arm32v7/debian:stretch-slim
COPY --from=qemu-download /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static
COPY --from=tor-build /usr/arm-linux-gnueabihf/bin/tor* /usr/bin/
# Persist data
VOLUME /etc/tor /var/lib/tor
COPY docker-entrypoint.sh /entrypoint.sh
# ORPort, DirPort, SocksPort, ObfsproxyPort, MeekPort
EXPOSE 9001 9030 9050 54444 7002
ENTRYPOINT ["./entrypoint.sh"]
CMD ["tor"]