mirror of
https://github.com/cmehay/docker-tor-hidden-service.git
synced 2025-04-19 21:39:13 +00:00
Using pyentrypoint
This commit is contained in:
parent
7f16f43cdf
commit
ccfdb851cc
8 changed files with 59 additions and 93 deletions
19
Dockerfile
19
Dockerfile
|
@ -1,23 +1,20 @@
|
|||
FROM debian:jessie
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV HOME /var/lib/tor
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
tor \
|
||||
python3 \
|
||||
git \
|
||||
ca-certificates
|
||||
python3-pip
|
||||
|
||||
ADD assets/docker-entrypoint.sh /
|
||||
ADD assets/tor_config.py /
|
||||
RUN pip3 install pyentrypoint==0.2.1
|
||||
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
RUN git clone https://github.com/cmehay/python-docker-tool.git /docker --branch=old
|
||||
RUN touch /docker/__init__.py
|
||||
ADD assets/entrypoint-config.yml /
|
||||
ADD assets/display_onions.py /
|
||||
ADD assets/torrc /etc/tor/torrc
|
||||
|
||||
VOLUME ["/var/lib/tor/hidden_service/"]
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
ENTRYPOINT ["pyentrypoint"]
|
||||
|
||||
CMD ["tor"]
|
||||
|
|
|
@ -19,3 +19,9 @@ $ docker run -ti --link something --volume /path/to/keys:/var/lib/tor/hidden_ser
|
|||
```
|
||||
|
||||
Look at the `docker-compose.yml` file to see own to use it.
|
||||
|
||||
### pyentrypoint
|
||||
|
||||
This container is using [`pyentrypoint`](https://github.com/cmehay/pyentrypoint) to generate its setup.
|
||||
|
||||
If you need to use the legacy version, please checkout to the `legacy` branch or pull `goldy/tor-hidden-service:legacy`.
|
||||
|
|
13
assets/display_onions.py
Normal file
13
assets/display_onions.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import os
|
||||
|
||||
for root, dirs, _ in os.walk("/var/lib/tor/hidden_service/", topdown=False):
|
||||
for service in dirs:
|
||||
filename = "{root}{service}/hostname".format(
|
||||
service=service,
|
||||
root=root
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
print('{service}: {onion}'.format(
|
||||
service=service,
|
||||
onion=hostfile.read()
|
||||
))
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "${1:0:1}" == '-' ]; then
|
||||
set -- tor $@
|
||||
fi
|
||||
|
||||
if [ "$1" == "tor" ]; then
|
||||
# Set config
|
||||
python3 ./tor_config.py
|
||||
|
||||
# set rights on keys
|
||||
chown -R debian-tor:debian-tor /var/lib/tor/hidden_service/
|
||||
chmod -R 700 /var/lib/tor/hidden_service/
|
||||
|
||||
# Switch user
|
||||
|
||||
set -- su debian-tor -s /bin/sh -c "$@"
|
||||
fi
|
||||
|
||||
exec "$@"
|
14
assets/entrypoint-config.yml
Normal file
14
assets/entrypoint-config.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
command: tor
|
||||
|
||||
user: debian-tor
|
||||
group: debian-tor
|
||||
|
||||
config_files:
|
||||
- /etc/tor/torrc
|
||||
|
||||
post_conf_commands:
|
||||
- timeout 3s tor > /dev/null || true
|
||||
- python3 /display_onions.py
|
||||
- chown -R debian-tor:debian-tor $HOME
|
||||
|
||||
debug: false
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from docker import docker
|
||||
from subprocess import call
|
||||
|
||||
# Generate conf for tor hidden service
|
||||
def set_conf():
|
||||
rtn = []
|
||||
links = docker.get_links()
|
||||
with open("/etc/tor/torrc", "a") as conf:
|
||||
for link in links:
|
||||
path = "/var/lib/tor/hidden_service/{service}".format(service=link)
|
||||
env_port = links[link]['environment'].get('PORT')
|
||||
# Test if link has ports
|
||||
if len(links[link]['ports']) == 0 and not env_port:
|
||||
print("{link} has no port")
|
||||
continue
|
||||
conf.write('HiddenServiceDir {path}\n'.format(path=path))
|
||||
rtn.append(link)
|
||||
for port in links[link]['ports']:
|
||||
if links[link]['ports'][port]['protocol'] == 'UDP':
|
||||
continue
|
||||
service = '{port} {ip}:{port}'.format(
|
||||
port=port, ip=links[link]['ip']
|
||||
)
|
||||
conf.write('HiddenServicePort {service}\n'.format(
|
||||
service=service
|
||||
))
|
||||
if env_port:
|
||||
service = '80 {ip}:{port}'.format(
|
||||
port=env_port, ip=links[link]['ip']
|
||||
)
|
||||
conf.write('HiddenServicePort {service}\n'.format(
|
||||
service=service
|
||||
))
|
||||
# set relay if enabled in env (not so secure)
|
||||
if 'RELAY' in os.environ:
|
||||
conf.write("ORPort 9001\n")
|
||||
# Disable local socket
|
||||
conf.write("SocksPort 0\n")
|
||||
return rtn
|
||||
|
||||
def gen_host(services):
|
||||
# Run tor to generate keys if they doesn't exist
|
||||
call(["sh", "-c", "timeout 3s tor > /dev/null"])
|
||||
for service in services:
|
||||
filename = "/var/lib/tor/hidden_service/{service}/hostname".format(
|
||||
service=service
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
print('{service}: {onion}'.format(
|
||||
service=service,
|
||||
onion=hostfile.read()
|
||||
))
|
||||
|
||||
if __name__ == '__main__':
|
||||
services = set_conf()
|
||||
gen_host(services)
|
12
assets/torrc
Normal file
12
assets/torrc
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% for container in containers %}
|
||||
HiddenServiceDir /var/lib/tor/hidden_service/{{container.names[0]}}
|
||||
{% for link in container.links %}
|
||||
HiddenServicePort {{link.port}} {{link.ip}}:{{link.port}}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% if 'RELAY' in environ %}
|
||||
ORPort 9001
|
||||
{% endif %}
|
||||
|
||||
SocksPort 0
|
|
@ -4,7 +4,12 @@ tor:
|
|||
image: goldy/tor-hidden-service
|
||||
links:
|
||||
- hello
|
||||
- world
|
||||
|
||||
hello:
|
||||
image: tutum/hello-world
|
||||
hostname: hello-world
|
||||
hostname: hello
|
||||
|
||||
world:
|
||||
image: tutum/hello-world
|
||||
hostname: world
|
||||
|
|
Loading…
Add table
Reference in a new issue