| 1 |
services: |
| 2 |
openvpn: |
| 3 |
container_name: openvpn |
| 4 |
init: true |
| 5 |
image: openvpn-auth-oauth2/openvpn |
| 6 |
build: |
| 7 |
context: . |
| 8 |
args: |
| 9 |
GIT_BRANCH: release/2.6 |
| 10 |
#language=dockerfile |
| 11 |
dockerfile_inline: | |
| 12 |
# renovate: docker=ubuntu |
| 13 |
FROM ubuntu:26.04 |
| 14 |
ARG GIT_BRANCH |
| 15 |
ARG DEBIAN_FRONTEND=noninteractive |
| 16 |
RUN apt update -qqy \ |
| 17 |
&& apt install -qqy curl gnupg ifupdown iproute2 iptables iputils-ping net-tools git \ |
| 18 |
build-essential autoconf automake libtool pkg-config libnl-genl-3-dev libcap-ng-dev \ |
| 19 |
libssl-dev liblz4-dev liblzo2-dev libpam0g-dev python3-docutils easy-rsa |
| 20 |
|
| 21 |
WORKDIR /build/ |
| 22 |
|
| 23 |
RUN git clone --depth 1 https://github.com/OpenVPN/openvpn.git --branch $${GIT_BRANCH} --single-branch . |
| 24 |
RUN autoreconf -i -v -f |
| 25 |
RUN ./configure |
| 26 |
RUN make |
| 27 |
RUN make install |
| 28 |
cap_add: |
| 29 |
- NET_ADMIN |
| 30 |
networks: |
| 31 |
openvpn-auth-oauth2: |
| 32 |
aliases: |
| 33 |
- openvpn |
| 34 |
devices: |
| 35 |
- /dev/net/tun |
| 36 |
ports: |
| 37 |
- "1196:1196/udp" |
| 38 |
volumes: |
| 39 |
- openvpn:/etc/openvpn/server |
| 40 |
- ./config/client/:/etc/openvpn/client/ |
| 41 |
- ./openvpn-server.conf:/etc/openvpn/openvpn.conf |
| 42 |
environment: |
| 43 |
EASYRSA: /usr/share/easy-rsa/ |
| 44 |
EASYRSA_PKI: /etc/openvpn/server/pki |
| 45 |
EASYRSA_BATCH: 1 |
| 46 |
EASYRSA_NO_VARS: 1 |
| 47 |
EASYRSA_NO_PASS: 1 |
| 48 |
EASYRSA_ALGO: "ed" |
| 49 |
EASYRSA_CURVE: "ed25519" |
| 50 |
EASYRSA_DN: "cn_only" |
| 51 |
entrypoint: |
| 52 |
- /bin/sh |
| 53 |
- -ec |
| 54 |
#language=shell script |
| 55 |
- |- |
| 56 |
if [ ! -f /etc/openvpn/server/pki/ca.crt ]; then |
| 57 |
/usr/share/easy-rsa/easyrsa init-pki nopass |
| 58 |
/usr/share/easy-rsa/easyrsa build-ca nopass |
| 59 |
/usr/share/easy-rsa/easyrsa build-server-full server nopass |
| 60 |
/usr/share/easy-rsa/easyrsa build-server-full client nopass |
| 61 |
fi |
| 62 |
if [ ! -f /etc/openvpn/server/ta.key ]; then |
| 63 |
openvpn --genkey tls-crypt-v2-server /etc/openvpn/server/ta.key |
| 64 |
openvpn --tls-crypt-v2 /etc/openvpn/server/ta.key --genkey tls-crypt-v2-client /etc/openvpn/server/ta-client.key |
| 65 |
fi |
| 66 |
|
| 67 |
if [ ! -f /etc/openvpn/server/password.txt ]; then |
| 68 |
printf password > /etc/openvpn/server/password.txt |
| 69 |
chmod 400 /etc/openvpn/server/password.txt |
| 70 |
fi |
| 71 |
|
| 72 |
cat > "/etc/openvpn/client/client.ovpn" <<EOF |
| 73 |
client |
| 74 |
dev tun |
| 75 |
persist-tun |
| 76 |
|
| 77 |
cipher AES-256-GCM |
| 78 |
|
| 79 |
nobind |
| 80 |
|
| 81 |
remote 127.0.0.1 1196 udp4 |
| 82 |
remote-cert-tls server |
| 83 |
resolv-retry infinite |
| 84 |
|
| 85 |
tls-cert-profile preferred |
| 86 |
tls-version-min 1.3 |
| 87 |
auth SHA512 |
| 88 |
|
| 89 |
auth-nocache |
| 90 |
tun-mtu 1420 |
| 91 |
mssfix 1300 |
| 92 |
|
| 93 |
<ca> |
| 94 |
$(cat /etc/openvpn/server/pki/ca.crt) |
| 95 |
</ca> |
| 96 |
|
| 97 |
<key> |
| 98 |
$(cat /etc/openvpn/server/pki/private/client.key) |
| 99 |
</key> |
| 100 |
<cert> |
| 101 |
$(openssl x509 -in /etc/openvpn/server/pki/issued/client.crt) |
| 102 |
</cert> |
| 103 |
|
| 104 |
<tls-crypt-v2> |
| 105 |
$(cat /etc/openvpn/server/ta-client.key) |
| 106 |
</tls-crypt-v2> |
| 107 |
EOF |
| 108 |
|
| 109 |
iptables -t nat -I POSTROUTING 1 -s 10.8.0.0/23 -o eth0 -j MASQUERADE |
| 110 |
iptables -I INPUT 1 -i tun0 -j ACCEPT |
| 111 |
iptables -I FORWARD 1 -i eth0 -o tun0 -j ACCEPT |
| 112 |
iptables -I FORWARD 1 -i tun0 -o eth0 -j ACCEPT |
| 113 |
iptables -I INPUT 1 -i eth0 -p udp --dport 1196 -j ACCEPT |
| 114 |
|
| 115 |
exec openvpn --config "/etc/openvpn/openvpn.conf" |
| 116 |
openvpn-auth-oauth2: |
| 117 |
container_name: openvpn-auth-oauth2 |
| 118 |
image: openvpn-auth-oauth2/openvpn-auth-oauth2 |
| 119 |
build: |
| 120 |
context: . |
| 121 |
args: |
| 122 |
GIT_BRANCH: release/2.6 |
| 123 |
#language=dockerfile |
| 124 |
dockerfile_inline: | |
| 125 |
# renovate: docker=golang |
| 126 |
FROM golang:1.27-alpine |
| 127 |
|
| 128 |
RUN go install github.com/jkroepke/openvpn-auth-oauth2@latest |
| 129 |
restart: unless-stopped |
| 130 |
depends_on: |
| 131 |
openvpn: |
| 132 |
condition: service_started |
| 133 |
keycloak: |
| 134 |
condition: service_healthy |
| 135 |
networks: |
| 136 |
openvpn-auth-oauth2: |
| 137 |
aliases: |
| 138 |
- openvpn-auth-oauth2 |
| 139 |
environment: |
| 140 |
OPENVPN_AUTH_OAUTH2_HTTP_LISTEN: ":9000" |
| 141 |
OPENVPN_AUTH_OAUTH2_HTTP_BASEURL: "http://localhost:9000/" |
| 142 |
OPENVPN_AUTH_OAUTH2_HTTP_SECRET: "1jd93h5b6s82lf03jh5b2hf9" |
| 143 |
OPENVPN_AUTH_OAUTH2_OPENVPN_ADDR: "tcp://openvpn:8081" |
| 144 |
OPENVPN_AUTH_OAUTH2_OPENVPN_PASSWORD: "password" |
| 145 |
OPENVPN_AUTH_OAUTH2_OAUTH2_ISSUER: "http://localhost:8080/realms/openvpn-auth-oauth2" |
| 146 |
OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_DISCOVERY: "http://keycloak:8080/realms/openvpn-auth-oauth2/.well-known/openid-configuration" |
| 147 |
OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_ENABLED: "true" |
| 148 |
OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_SECRET: "1jd93h5b6s82lf03jh5b2hf9" |
| 149 |
OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_ID: "openvpn-auth-oauth2" |
| 150 |
OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_SECRET: "zSkHo6iq8AEZ9W725JqomqkZGhfOG8jL" |
| 151 |
ports: |
| 152 |
- "9000:9000/tcp" |
| 153 |
- "9092:9092/tcp" |
| 154 |
command: |
| 155 |
- /go/bin/openvpn-auth-oauth2 |
| 156 |
keycloak: |
| 157 |
image: quay.io/keycloak/keycloak:latest |
| 158 |
environment: |
| 159 |
KEYCLOAK_ADMIN: admin |
| 160 |
KEYCLOAK_ADMIN_PASSWORD: insecure |
| 161 |
KC_HOSTNAME_STRICT: "false" |
| 162 |
KC_FILE: "/openvpn-auth-oauth2-realm.json" |
| 163 |
networks: |
| 164 |
openvpn-auth-oauth2: |
| 165 |
aliases: |
| 166 |
- keycloak |
| 167 |
healthcheck: |
| 168 |
test: >- |
| 169 |
exec 5<>/dev/tcp/127.0.0.1/8080 |
| 170 |
&& echo -e "HEAD /realms/openvpn-auth-oauth2/.well-known/openid-configuration HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n" >&5 |
| 171 |
&& grep -q "HTTP/1.1 200 OK" - <&5 |
| 172 |
interval: 30s |
| 173 |
timeout: 10s |
| 174 |
retries: 4 |
| 175 |
start_period: 30s |
| 176 |
start_interval: 5s |
| 177 |
user: "1000" |
| 178 |
volumes: |
| 179 |
- keycloak:/opt/keycloak/data/ |
| 180 |
- ./keycloak-realm.json:/opt/keycloak/data/import/openvpn-auth-oauth2-realm.json |
| 181 |
ports: |
| 182 |
- "8080:8080/tcp" |
| 183 |
command: |
| 184 |
- start-dev |
| 185 |
- --import-realm |
| 186 |
|
| 187 |
volumes: |
| 188 |
openvpn: {} |
| 189 |
keycloak: {} |
| 190 |
|
| 191 |
networks: |
| 192 |
openvpn-auth-oauth2: {} |