Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code refactoring for the dockerfiles. #14

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion lokinet/contrib/lokinet-auth.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#What is this ip?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make separate issues for each of these questions instead of in a git commit on a PR so they are tracked and we can close them as they get addressed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I figured out a number of things on my own but I'm not sure how to close the PR - Please do if you can.

[network]
auth=lmq
auth-lmq=tcp://10.0.3.1:5555
auth-lmq=tcp://10.0.3.1:5555
10 changes: 9 additions & 1 deletion lokinet/contrib/lokinet-authserv.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# where is logic.py coming from?
# /var/lib/lokinet-exit-provider/logic.py
# what is the format/options of /data/lokinet-exit-broker.env / what are it's default contents?
# I assume that it's an authentication server of some kind for the exit node
# I could be wrong but I believe that this is meant to behave as a separate authenticaton server
# if it is then when running without systemd, then maybe I'd want to run it in a separate container.


[Unit]
Description=Lokinet authserv: exit authentication server
Wants=network.target
Expand All @@ -12,4 +20,4 @@ ExecStart=/usr/bin/python3 -m lokinet.auth --cmd /var/lib/lokinet-exit-provider/
Restart=always

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
5 changes: 4 additions & 1 deletion lokinet/contrib/lokinet-exit-broker.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Need some clarification on what this does.


[Unit]
Description=Lokinet exit broker: exit broker webapp thing
Wants=nginx.service
Expand All @@ -12,4 +15,4 @@ ExecStart=/usr/bin/gunicorn3 exit_broker:app
Restart=always

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions lokinet/contrib/lokinet-exit-rc.local.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# wait for lokinet
# to do what? How can we tell if lokinet has done what it needs to do?
sleep 10

# flush iptables
Expand All @@ -18,6 +19,8 @@ if_range=$(ip addr show $if_name | grep inet\ | sed 's/inet //' | cut -d' ' -f5
# add ipv4 forward rule
iptables -t nat -A POSTROUTING -s $if_range -o $exit_if -j MASQUERADE


#I'm not sure what the loop below is supposed to do. It only runs once on port 25?
# drop outbound ports
for port in 25 ; do
iptables -A FORWARD -p tcp --dport $port -j REJECT --reject-with tcp-reset -s $if_range
Expand Down
9 changes: 8 additions & 1 deletion lokinet/contrib/lokinet-exit-sysctl.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# This file can become redundant when using compose.
# sysctls:
# - net.ipv4.ip_forward=1
# - net.ipv6.conf.all.forwarding=1
#


# ip forwarding allowed
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.forwarding=1
4 changes: 4 additions & 0 deletions lokinet/contrib/lokinet-exit.crontab
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This file could become redundant together with the usage of cron; since it's repeating continously - why not use an infinite loop for the address update?
#
# lokinet-kill-scans.sh script seems like a bad idea .. details in the file

# lokinet exit cronjobs

SHELL=/bin/bash
Expand Down
6 changes: 5 additions & 1 deletion lokinet/contrib/lokinet-exit.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This file could also become redundant if we have a script generate run time values based on arguments/env variables/docker secrets
# I am not sure what other options can be configured.


[network]
exit=true
keyfile=/data/exit.private
Expand All @@ -6,4 +10,4 @@ paths=8

[router]
min-connections=18
max-connections=20
max-connections=20
8 changes: 8 additions & 0 deletions lokinet/contrib/lokinet-firewall.crontab
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# it seems that the purpose of this cronjob is to download/apply a block list through iptables
# This is problematic for several reasons
# 1. Some legit IPs could be blocked and would be hard to find
# 2. Running it is not optional
# 3. Rather than run in the 'container', it should run separately inside a privileged container using the host namespace, the reason being
# that the container is attached to DOCKER-USER chain instead of INPUT, the rules will be applied only to containers.
# any packets coming into the INPUT chain will bypass these rules that now reside under the FORWARD chain.

# lokinet firewall cronjobs

SHELL=/bin/bash
Expand Down
7 changes: 6 additions & 1 deletion lokinet/contrib/lokinet-kill-scans.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash
#
# run every minute with cron
#
# If I understand correctly, this script is responsible for blocking IPs that are attempting to DDOS the server with SYN FLOOD type attacks.
# There are some issues with this script, it would be much better to implement it using fail2ban with an expiry time, ability to whitelist and notify
# I could be wrong but it could cause an issue if the SYN/ACK packets are coming from IPs masquerading as legit SNs as a way to impact the network?
# https://serverfault.com/questions/640873/how-to-ban-syn-flood-attacks-using-fail2ban
# This seems like a more elegant solution


for ip in $( conntrack -p tcp -L | grep SYN_SENT | cut -d'=' -f 2 | cut -d' ' -f 1 | sort | uniq -c | awk '$1 > 1000 { print $2 ; }' ) ; do
echo "banning $ip"
Expand Down
2 changes: 2 additions & 0 deletions lokinet/contrib/lokinet-nginx.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#What is the purpose of this file?

[network]
keyfile=/data/nginx.private
3 changes: 3 additions & 0 deletions lokinet/contrib/lokinet-update-exit-address.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# what is the purpose of the lokinet-addr.txt file?
# what process uses it?

#!/bin/bash
print-lokinet-address.sh > /data/lokinet-addr.txt
chmod 444 /data/lokinet-addr.txt
2 changes: 2 additions & 0 deletions lokinet/contrib/lokinet-update-firewall.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# There's definitely a better way to do this.

# get lokinet's address
if_name=lokitun0
if_range=$(ip addr show $if_name | grep inet\ | sed 's/inet //' | cut -d' ' -f5)
Expand Down
37 changes: 23 additions & 14 deletions lokinet/lokinet-base.dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
FROM debian:stable AS lokinet-base
#use argument instead of lsb-release
ARG DEBIAN_RELEASE=bullseye

FROM debian:${DEBIAN_RELEASE}-slim AS lokinet-base
ENV container docker

ENV RELEASE=${DEBIAN_RELEASE:-bullseye}
#Add oxen public key
ADD --chmod=644 --chown=_apt https://deb.oxen.io/pub.gpg /etc/apt/trusted.gpg.d/lokinet.gpg

# set up packages
RUN /bin/bash -c 'echo "man-db man-db/auto-update boolean false" | debconf-set-selections'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y --no-install-recommends ca-certificates curl iptables dnsutils lsb-release systemd systemd-sysv cron conntrack iproute2 python3-pip wget'
RUN /bin/bash -c 'curl -so /etc/apt/trusted.gpg.d/lokinet.gpg https://deb.oxen.io/pub.gpg'
RUN /bin/bash -c 'echo "deb https://deb.oxen.io $(lsb_release -sc) main" > /etc/apt/sources.list.d/lokinet.list'
RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y --no-install-recommends lokinet'
RUN DEBIAN_FRONTEND=noninteractive \
&& echo "deb https://deb.oxen.io ${RELEASE} main" > /etc/apt/sources.list.d/lokinet.list \
&& echo "man-db man-db/auto-update boolean false" | debconf-set-selections \
&& apt-get update -y \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends ca-certificates iptables dnsutils systemd systemd-sysv cron conntrack iproute2 \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends lokinet \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
majestrate marked this conversation as resolved.
Show resolved Hide resolved
&& mkdir -p /var/lib/lokinet/conf.d \
&& mkdir /data && chown _lokinet:_loki /data

# make config dir for lokinet
RUN /bin/bash -c 'mkdir -p /var/lib/lokinet/conf.d'
# set up private data dir for lokinet
RUN /bin/bash -c 'mkdir /data && chown _lokinet:_loki /data'

# print lokinet util
COPY contrib/print-lokinet-address.sh /usr/local/bin/print-lokinet-address.sh
RUN /bin/bash -c 'chmod 700 /usr/local/bin/print-lokinet-address.sh'
COPY --chmod=755 contrib/print-lokinet-address.sh /usr/local/bin/print-lokinet-address.sh

# dns
COPY contrib/lokinet.resolveconf.txt /etc/resolv.conf
RUN /bin/bash -c 'chmod 644 /etc/resolv.conf'
COPY --chmod=644 contrib/lokinet.resolveconf.txt /etc/resolv.conf

STOPSIGNAL SIGRTMIN+3
ENTRYPOINT ["/sbin/init", "verbose", "systemd.unified_cgroup_hierarchy=0", "systemd.legacy_systemd_cgroup_controller=0"]
2 changes: 1 addition & 1 deletion lokinet/lokinet-exit-custom.dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM registry.oxen.rocks/lokinet-exit:latest

RUN /bin/bash -c 'ln -s /var/lib/lokinet/conf.d/custom.ini /data/custom.ini'
RUN ln -s /var/lib/lokinet/conf.d/custom.ini /data/custom.ini
16 changes: 5 additions & 11 deletions lokinet/lokinet-exit.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ COPY contrib/lokinet-exit.ini /var/lib/lokinet/conf.d/exit.ini

# set up system configs
COPY contrib/lokinet-exit-sysctl.conf /etc/sysctl.d/00-lokinet-exit.conf
COPY contrib/lokinet-exit-rc.local.sh /etc/rc.local
RUN /bin/bash -c 'chmod 700 /etc/rc.local'

COPY contrib/print-lokinet-address.sh /usr/local/bin/print-lokinet-address.sh
RUN /bin/bash -c 'chmod 700 /usr/local/bin/print-lokinet-address.sh'
COPY --chmod=700 contrib/lokinet-exit-rc.local.sh /etc/rc.local

# setup cron jobs
COPY contrib/lokinet-kill-scans.sh /usr/local/bin/lokinet-kill-scans.sh
RUN /bin/bash -c 'chmod 700 /usr/local/bin/lokinet-kill-scans.sh'
COPY contrib/lokinet-update-exit-address.sh /usr/local/bin/lokinet-update-exit-address.sh
RUN /bin/bash -c 'chmod 700 /usr/local/bin/lokinet-update-exit-address.sh'
COPY --chmod=700 contrib/lokinet-kill-scans.sh /usr/local/sbin/lokinet-kill-scans.sh
COPY --chmod=700 contrib/lokinet-update-exit-address.sh /usr/local/sbin/lokinet-update-exit-address.sh

COPY --chmod=644 contrib/lokinet-exit.crontab /etc/cron.d/lokinet-exit

COPY contrib/lokinet-exit.crontab /etc/cron.d/lokinet-exit
RUN /bin/bash -c 'chmod 644 /etc/cron.d/lokinet-exit'
5 changes: 4 additions & 1 deletion lokinet/lokinet-nginx.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM registry.oxen.rocks/lokinet-base:latest

RUN /bin/bash -c 'apt-get -o=Dpkg::Use-Pty=0 -q update && apt-get -o=Dpkg::Use-Pty=0 -q dist-upgrade -y && apt-get -o=Dpkg::Use-Pty=0 -q install -y --no-install-recommends nginx'
RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get dist-upgrade -y \
&& apt-get install -y --no-install-recommends nginx

# set up configs for lokinet nginx
COPY contrib/lokinet-nginx.ini /var/lib/lokinet/conf.d/nginx.ini