Debian Codegraph @

docs/HTTPS Listener.md

raw
1 # HTTPS Listener
2
3 > [!IMPORTANT]
4 > Remember to set `OPENVPN_AUTH_OAUTH2_HTTP_BASEURL` correctly. It should start with `https://` following your public domain name plus port.
5
6 Some SSO Provider like Entra ID requires `https://` based redirect URL.
7 In the default configuration, openvpn-auth-oauth2 listen on `http://`.
8 There are two common ways to set up an HTTPS listener
9
10 # Reverse proxy (nginx, traefik)
11
12 You can use one of your favorite http reverse proxies.
13 Configure HTTPS on reverse proxy and proxy to an HTTP instance of openvpn-auth-oauth2.
14 For beginners, [traefik](https://traefik.io/traefik/) is recommended since it [natively](https://doc.traefik.io/traefik/https/acme/)
15 supports [Let's Encrypt](https://letsencrypt.org/) where you can get public SSL certificates for free.
16
17 # Using native HTTPS support
18
19 openvpn-auth-oauth2 supports HTTPS out of the box.
20 If openvpn-auth-oauth2 runs as systemd service, the HTTPS certificates must place in `/etc/openvpn-auth-oauth2/` with
21 the owner `root` and the group `openvpn-auth-oauth2`. See [Filesystem Permissions](Filesystem%20Permissions) for more information.
22
23 <table>
24 <thead><tr><td>env/sysconfig configuration</td></tr></thead>
25 <tbody><tr><td>
26
27 ```ini
28 OPENVPN_AUTH_OAUTH2_HTTP_TLS=true
29 OPENVPN_AUTH_OAUTH2_HTTP_KEY=/etc/openvpn-auth-oauth2/server.key
30 OPENVPN_AUTH_OAUTH2_HTTP_CERT=/etc/openvpn-auth-oauth2/server.crt
31 ```
32 </td></tr></tbody>
33 <thead><tr><td>yaml configuration</td></tr></thead>
34 <tbody><tr><td>
35
36 ```yaml
37 http:
38 tls: true
39 key: /etc/openvpn-auth-oauth2/server.key
40 cert: /etc/openvpn-auth-oauth2/server.crt
41 ```
42 </td></tr></tbody>
43 </table>
44
45 ## Self-signed certificate
46
47 To set up a self-signed certificate, you can use the command below:
48
49 ```bash
50 export DOMAIN_NAME=vpn.example.com
51 openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
52 -keyout /etc/openvpn-auth-oauth2/server.key \
53 -out /etc/openvpn-auth-oauth2/server.crt \
54 -subj "/CN=$DOMAIN_NAME" -addext "subjectAltName=DNS:$DOMAIN_NAME"
55 chown root:openvpn-auth-oauth2 /etc/openvpn-auth-oauth2/server.key /etc/openvpn-auth-oauth2/server.crt
56 chmod 640 /etc/openvpn-auth-oauth2/server.key /etc/openvpn-auth-oauth2/server.crt
57 ```
58
59 You can also use [Let's Encrypt](https://letsencrypt.org/) to get public SSL certificates for free.
60 The [certbot](https://certbot.eff.org/instructions) is a recommended tool to get SSL certificates.
61 Alternatively, can use [acme.sh](https://acme.sh/), which is a pure Unix shell script implementing ACME client protocol.
62
63 openvpn-auth-oauth2 requires a [`SIGHUP` signal](https://en.wikipedia.org/wiki/SIGHUP) to reload the TLS certificate.
64
65 ## Signing certificates with certbot via dns-challenge
66
67 You need to install `certbot` and suitable for you `DNS plugin`. More information on supported by certbot DNS plugins and how to config them you may find [here](https://eff-certbot.readthedocs.io/en/stable/using.html#dns-plugins). It's up to you to define what ACME server to use for verification. By default it's set to letsencrypt, you may change it with `--server` [option](https://eff-certbot.readthedocs.io/en/stable/using.html#changing-the-acme-server). Also, take a look at [RFC 8555](https://datatracker.ietf.org/doc/html/rfc8555) about ACME Protocol.
68
69 You can create certs with command below and than copy them to `/etc/openvpn-auth-oauth2/` directory or create a link to files. Do not forget to set right permissions.
70
71 The command below uses certbot to create a free SSL certificate for a domain hosted on Cloudflare.
72
73 ```bash
74 certbot certonly --noninteractive --verbose \
75 --force-renewal \
76 --dns-cloudflare \
77 --dns-cloudflare-credentials /path/to/your/cloudflare.ini \
78 --agree-tos \
79 --email [email protected] \
80 --key-type rsa \
81 --rsa-key-size 2048 \
82 --domains this.is.example.domain \
83 --preferred-challenges dns-01 \
84 --server "https://acme-v02.api.letsencrypt.org/directory"
85 ```
86
87
88
89 ## Run HTTPS listener on 443 port
90
91 Running openvpn-auth-oauth2 on port 443 requires special permissions.
92
93 Create a new file `/etc/systemd/system/openvpn-auth-oauth2.service.d/override.conf` with the following content:
94
95 ```ini
96 [Service]
97 AmbientCapabilities=CAP_NET_BIND_SERVICE
98 CapabilityBoundingSet=CAP_NET_BIND_SERVICE
99 PrivateUsers=false
100 ```
101
102 Then, run the following commands:
103
104 ```bash
105 echo "capability net_bind_service," > /etc/apparmor.d/local/usr.bin.openvpn-auth-oauth2
106 systemctl restart apparmor
107 systemctl daemon-reload
108 systemctl restart openvpn-auth-oauth2
109 ```