mirror of
https://github.com/dangeroustech/ZeroTierBridge.git
synced 2025-12-06 00:56:58 +00:00
Merge pull request #36 from dangeroustech/general-updates
General Best Practise Updates
This commit is contained in:
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@@ -9,3 +9,12 @@ updates:
|
|||||||
- dependencies
|
- dependencies
|
||||||
- github-actions
|
- github-actions
|
||||||
|
|
||||||
|
- package-ecosystem: docker
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
labels:
|
||||||
|
- dependencies
|
||||||
|
- docker
|
||||||
|
|
||||||
|
|||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
sbom.spdx.json
|
||||||
|
results.sarif
|
||||||
13
Dockerfile
13
Dockerfile
@@ -5,8 +5,17 @@ ARG VERSION=1.12.2
|
|||||||
RUN apt-get update -qq && apt-get install -qq --no-install-recommends -y \
|
RUN apt-get update -qq && apt-get install -qq --no-install-recommends -y \
|
||||||
ca-certificates=20230311+deb12u1 \
|
ca-certificates=20230311+deb12u1 \
|
||||||
curl=7.88.1-10+deb12u14
|
curl=7.88.1-10+deb12u14
|
||||||
RUN ARCH_MAPPING=$([ "$TARGETARCH" = "amd64" ] && echo amd64 || ([ "$TARGETARCH" = "arm64" ] && echo arm64 || echo "$TARGETARCH")) \
|
RUN set -e; \
|
||||||
&& curl -sSL -o zerotier-one.deb "${PACKAGE_BASEURL}/zerotier-one_${VERSION}_${ARCH_MAPPING}.deb"
|
DETECTED_ARCH="${TARGETARCH:-}"; \
|
||||||
|
if [ -z "$DETECTED_ARCH" ]; then DETECTED_ARCH="$(dpkg --print-architecture)"; fi; \
|
||||||
|
case "$DETECTED_ARCH" in \
|
||||||
|
amd64|x86_64) ARCH_MAPPING=amd64 ;; \
|
||||||
|
arm64|aarch64) ARCH_MAPPING=arm64 ;; \
|
||||||
|
armhf|armv7*) ARCH_MAPPING=armhf ;; \
|
||||||
|
*) echo "Unsupported architecture: $DETECTED_ARCH" >&2; exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
echo "Downloading ZeroTier: arch=$ARCH_MAPPING version=$VERSION"; \
|
||||||
|
curl -fsSL -o zerotier-one.deb "${PACKAGE_BASEURL}/zerotier-one_${VERSION}_${ARCH_MAPPING}.deb"
|
||||||
|
|
||||||
FROM debian:12.6
|
FROM debian:12.6
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -20,21 +20,21 @@ You also need to add a static route into ZeroTier so that the traffic is routed
|
|||||||
|
|
||||||
### Docker Compose
|
### Docker Compose
|
||||||
|
|
||||||
**You need to edit the `ZT_NETWORKS` and `ARCH` variable in the `docker-compose.yml` file first to add your networks and make sure your acrhitecture is correct (see [this page](http://download.zerotier.com/debian/buster/pool/main/z/zerotier-one/) for examples, usually either amd64 or arm64)**
|
Edit the `ZT_NETWORKS` variable in `docker-compose.yml` to add your networks. Multi-arch images are published automatically; no architecture changes are needed.
|
||||||
|
|
||||||
Easiest way to bring up is via Docker Compose. Rename `docker-compose.yml.example` to `docker-compose.yml` and run `docker compose up -d`.
|
Easiest way to bring up is via Docker Compose. Rename `docker-compose.yml.example` to `docker-compose.yml` and run `docker compose up -d`.
|
||||||
|
|
||||||
If you want to disable bridging, set `ZT_BRIDGE=false`. This can be done after the initial networks have been joined (just change the environment variable in the `docker-compose.yml` file and run `), as the ZeroTier config persists but IPTables forwarding is done on each container startup.
|
If you want to disable bridging, set `ZT_BRIDGE=false`. This can be done after the initial networks have been joined (just change the environment variable in the `docker-compose.yml` file and restart), as the ZeroTier config persists but IPTables forwarding is done on each container startup.
|
||||||
|
|
||||||
### OG Docker
|
### OG Docker
|
||||||
|
|
||||||
`docker build -t zerotierbridge .`
|
`docker build -t zerotierbridge .`
|
||||||
|
|
||||||
`docker run --privileged -e ZT_NETWORKS=NETWORK_1 NETWORK_2 -e ZT_BRIDGE=true zerotierbridge:latest`
|
`docker run --cap-add NET_ADMIN --cap-add NET_RAW --sysctl net.ipv4.ip_forward=1 -e ZT_NETWORKS="NETWORK_1 NETWORK_2" -e ZT_BRIDGE=true zerotierbridge:latest`
|
||||||
|
|
||||||
Add your network ID(s) into the `ZT_NETWORKS` argument, space separated.
|
Add your network ID(s) into the `ZT_NETWORKS` argument, space separated.
|
||||||
|
|
||||||
Disable bridging by passing `ZT_BRIDGE=false`. This can be done after the initial networks have been joined (just rebuild the container), as the ZeroTier config persists but IPTables forwarding is done on each container startup.
|
Disable bridging by passing `ZT_BRIDGE=false`. This can be done after the initial networks have been joined (just restart the container), as the ZeroTier config persists but IPTables forwarding is done on each container startup.
|
||||||
|
|
||||||
#### Persistent Storage
|
#### Persistent Storage
|
||||||
|
|
||||||
@@ -42,8 +42,6 @@ If you would like the container to retain the same ZeroTier client ID on reboot,
|
|||||||
|
|
||||||
`docker run --privileged -e ZT_NETWORKS=NETWORK_ID_HERE ZT_BRIDGE=true -v zt_config:/var/lib/zerotier-one/ zerotierbridge:latest`
|
`docker run --privileged -e ZT_NETWORKS=NETWORK_ID_HERE ZT_BRIDGE=true -v zt_config:/var/lib/zerotier-one/ zerotierbridge:latest`
|
||||||
|
|
||||||
#### Caveat: Architecture
|
#### Notes
|
||||||
|
|
||||||
If you need to run this on a device with different architecture (a raspberry pi, for instance), then just edit line 3 of the Dockerfile.
|
If your host requires additional privileges for networking, you may need to add device and capabilities in your runtime configuration. The provided Docker Compose example includes `cap_add: [NET_ADMIN, NET_RAW]` and `sysctls` for IP forwarding.
|
||||||
|
|
||||||
If you were using a Raspberry Pi 4, you would change this to `ARCH=arm64` and the container will pull the correct ZeroTier installer.
|
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ services:
|
|||||||
container_name: zerotierbridge
|
container_name: zerotierbridge
|
||||||
image: registry.dangerous.tech/dangeroustech/zerotierbridge
|
image: registry.dangerous.tech/dangeroustech/zerotierbridge
|
||||||
restart: always
|
restart: always
|
||||||
privileged: true
|
cap_add:
|
||||||
|
- NET_ADMIN
|
||||||
|
- NET_RAW
|
||||||
|
sysctls:
|
||||||
|
net.ipv4.ip_forward: "1"
|
||||||
volumes:
|
volumes:
|
||||||
- zt_config:/var/lib/zerotier-one
|
- zt_config:/var/lib/zerotier-one
|
||||||
environment:
|
environment:
|
||||||
- ZT_NETWORKS=NETWORK_ID_1 NETWORK_ID_2 NETWORK_ID_3
|
ZT_NETWORKS: "NETWORK_ID_1 NETWORK_ID_2 NETWORK_ID_3"
|
||||||
- ZT_BRIDGE=true
|
ZT_BRIDGE: "true"
|
||||||
volumes:
|
volumes:
|
||||||
zt_config:
|
zt_config:
|
||||||
@@ -1,15 +1,22 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
grepzt() {
|
set -eu
|
||||||
(find /proc -name exe | xargs -I{} readlink {}) 2>/dev/null | grep -q zerotier-one
|
|
||||||
return $?
|
terminate() {
|
||||||
|
# Try to terminate zerotier-one gracefully
|
||||||
|
if [ -n "${ZT_PID:-}" ]; then
|
||||||
|
kill -TERM "$ZT_PID" 2>/dev/null || true
|
||||||
|
wait "$ZT_PID" 2>/dev/null || true
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
trap terminate INT TERM
|
||||||
|
|
||||||
echo "starting zerotier"
|
echo "starting zerotier"
|
||||||
setsid /usr/sbin/zerotier-one &
|
setsid /usr/sbin/zerotier-one &
|
||||||
|
ZT_PID=$!
|
||||||
|
|
||||||
while ! grepzt
|
# Wait for zerotier to be responsive
|
||||||
do
|
until zerotier-cli info >/dev/null 2>&1; do
|
||||||
echo "zerotier hasn't started, waiting a second"
|
echo "zerotier hasn't started, waiting a second"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
@@ -17,34 +24,34 @@ done
|
|||||||
# Set IPTables to allow NATting
|
# Set IPTables to allow NATting
|
||||||
sysctl -w net.ipv4.ip_forward=1 > /dev/null
|
sysctl -w net.ipv4.ip_forward=1 > /dev/null
|
||||||
|
|
||||||
echo "joining networks: $ZT_NETWORKS"
|
echo "joining networks: ${ZT_NETWORKS:-}"
|
||||||
|
|
||||||
for n in $ZT_NETWORKS
|
for n in ${ZT_NETWORKS:-}; do
|
||||||
do
|
|
||||||
echo "joining $n"
|
echo "joining $n"
|
||||||
|
|
||||||
while ! zerotier-cli join "$n"
|
until zerotier-cli join "$n"; do
|
||||||
do
|
|
||||||
echo "joining $n failed; trying again in 1s"
|
echo "joining $n failed; trying again in 1s"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$ZT_BRIDGE" = "true" ]
|
if [ "${ZT_BRIDGE:-true}" = "true" ]; then
|
||||||
then
|
ZT_IFACE=$(zerotier-cli get "$n" portDeviceName)
|
||||||
echo "Configuring iptables on $(zerotier-cli get $n portDeviceName)"
|
PHY_IFACE=eth0
|
||||||
PHY_IFACE=eth0; ZT_IFACE=$(zerotier-cli get $n portDeviceName)
|
echo "Configuring iptables on ${ZT_IFACE}"
|
||||||
|
|
||||||
iptables -t nat -A POSTROUTING -o $PHY_IFACE -j MASQUERADE
|
# idempotent rules
|
||||||
iptables -t nat -A POSTROUTING -o $ZT_IFACE -j MASQUERADE
|
iptables -t nat -C POSTROUTING -o "$PHY_IFACE" -j MASQUERADE 2>/dev/null || iptables -t nat -A POSTROUTING -o "$PHY_IFACE" -j MASQUERADE
|
||||||
iptables -A FORWARD -i $PHY_IFACE -o $ZT_IFACE -j ACCEPT
|
iptables -t nat -C POSTROUTING -o "$ZT_IFACE" -j MASQUERADE 2>/dev/null || iptables -t nat -A POSTROUTING -o "$ZT_IFACE" -j MASQUERADE
|
||||||
iptables -A FORWARD -i $ZT_IFACE -o $PHY_IFACE -j ACCEPT
|
iptables -C FORWARD -i "$PHY_IFACE" -o "$ZT_IFACE" -j ACCEPT 2>/dev/null || iptables -A FORWARD -i "$PHY_IFACE" -o "$ZT_IFACE" -j ACCEPT
|
||||||
|
iptables -C FORWARD -i "$ZT_IFACE" -o "$PHY_IFACE" -j ACCEPT 2>/dev/null || iptables -A FORWARD -i "$ZT_IFACE" -o "$PHY_IFACE" -j ACCEPT
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Give ZT a second realise it's online
|
# Give ZT a second to realise it's online
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
# Print Client Info
|
# Print Client Info
|
||||||
echo "$(zerotier-cli info)"
|
zerotier-cli info || true
|
||||||
|
|
||||||
sleep infinity
|
# Keep the container running while zerotier-one is alive
|
||||||
|
wait "$ZT_PID"
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "2.1.0",
|
|
||||||
"$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json",
|
|
||||||
"runs": [
|
|
||||||
{
|
|
||||||
"tool": {
|
|
||||||
"driver": {
|
|
||||||
"name": "Grype",
|
|
||||||
"version": "0.63.0",
|
|
||||||
"informationUri": "https://github.com/anchore/grype"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"results": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
99659
sbom.spdx.json
99659
sbom.spdx.json
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user