| 1 |
# Getting Started |
| 2 |
|
| 3 |
This guide takes you from an existing OpenVPN Community Server to a first OIDC |
| 4 |
login. It uses the Linux package and a reverse proxy on the same host as |
| 5 |
`openvpn-auth-oauth2`. You can connect OpenVPN through the stable plugin or |
| 6 |
directly through its management interface. |
| 7 |
|
| 8 |
If you only want to evaluate the login flow, use the self-contained |
| 9 |
[Docker Compose demo](Demo). For other deployment layouts, follow this guide to |
| 10 |
understand the required connections, then use the linked reference pages. |
| 11 |
|
| 12 |
## What you need |
| 13 |
|
| 14 |
- OpenVPN Community Server 2.6.2 or later and a |
| 15 |
[WebAuth-compatible client](OpenVPN). |
| 16 |
- Administrator access to an OIDC provider. |
| 17 |
- Root access to the OpenVPN server. |
| 18 |
- A short public HTTPS URL, such as `https://vpn-login.example.com`, that VPN |
| 19 |
clients can reach. |
| 20 |
- A TLS certificate or reverse proxy for that URL. |
| 21 |
|
| 22 |
You will configure three connections: |
| 23 |
|
| 24 |
```text |
| 25 |
OpenVPN client -> public HTTPS URL -> openvpn-auth-oauth2 |
| 26 |
| |
| 27 |
+-> OIDC provider |
| 28 |
| |
| 29 |
OpenVPN server <--- plugin or management ---+ |
| 30 |
``` |
| 31 |
|
| 32 |
## 1. Choose the public URL |
| 33 |
|
| 34 |
In the examples below, the public URL is `https://vpn-login.example.com`. The |
| 35 |
OIDC redirect URI is always the public URL followed by `/oauth2/callback`: |
| 36 |
|
| 37 |
```text |
| 38 |
https://vpn-login.example.com/oauth2/callback |
| 39 |
``` |
| 40 |
|
| 41 |
The public URL must resolve from the user's browser. It does not have to match |
| 42 |
the OpenVPN server hostname. |
| 43 |
|
| 44 |
## 2. Install openvpn-auth-oauth2 |
| 45 |
|
| 46 |
On a Debian-based system, install the current release from the project's APT |
| 47 |
repository: |
| 48 |
|
| 49 |
```bash |
| 50 |
curl -L https://raw.githubusercontent.com/jkroepke/openvpn-auth-oauth2/refs/heads/main/packaging/apt/openvpn-auth-oauth2.sources \ |
| 51 |
| sudo tee /etc/apt/sources.list.d/openvpn-auth-oauth2.sources |
| 52 |
sudo apt update |
| 53 |
sudo apt install openvpn-auth-oauth2 |
| 54 |
``` |
| 55 |
|
| 56 |
For RPM packages or a source build, see [Installation](Installation). Do not |
| 57 |
start the service yet; it requires the OIDC and OpenVPN settings from the next |
| 58 |
steps. |
| 59 |
|
| 60 |
## 3. Register the OIDC application |
| 61 |
|
| 62 |
Create an application in your OIDC provider with the redirect URI from step 1. |
| 63 |
Keep these values for the service configuration: |
| 64 |
|
| 65 |
- issuer URL; |
| 66 |
- client ID; |
| 67 |
- client secret; |
| 68 |
- provider name, scopes, or additional settings required by that provider. |
| 69 |
|
| 70 |
Follow the matching section in [Providers](Providers) for exact registration |
| 71 |
steps and configuration. If your provider is not listed, use the `generic` |
| 72 |
provider with its OIDC issuer URL. |
| 73 |
|
| 74 |
## 4. Choose the OpenVPN integration |
| 75 |
|
| 76 |
Both integration methods support browser authentication, token refresh, |
| 77 |
username overrides, and client-specific configuration. |
| 78 |
|
| 79 |
| Integration | Choose it when | Trade-off | |
| 80 |
| --- | --- | --- | |
| 81 |
| [OpenVPN plugin](OpenVPN%20Plugin) | Your OpenVPN server uses Linux AMD64, Linux ARM64, or FreeBSD AMD64 | Keeps OpenVPN's management interface available, but cannot enforce one active session per OIDC username | |
| 82 |
| Direct management interface | You need `openvpn.enforce-unique-user` or cannot use the plugin | Supports the full management command set, but occupies OpenVPN's single management client connection | |
| 83 |
|
| 84 |
> [!NOTE] |
| 85 |
> The OpenVPN plugin is stable and supported since openvpn-auth-oauth2 version |
| 86 |
> 2.0. It is not an experimental integration. |
| 87 |
|
| 88 |
## 5. Configure the OpenVPN server |
| 89 |
|
| 90 |
Add the configuration for the integration selected in step 4 to the existing |
| 91 |
OpenVPN server configuration. Keep the server's current network, TLS, and PKI |
| 92 |
settings. |
| 93 |
|
| 94 |
Create a password for the connection between OpenVPN and |
| 95 |
`openvpn-auth-oauth2`. Both processes must use the same value. |
| 96 |
|
| 97 |
```bash |
| 98 |
sudo install -m 0600 -o root -g root /dev/null \ |
| 99 |
/etc/openvpn/management-password.txt |
| 100 |
sudo install -m 0640 -o root -g openvpn-auth-oauth2 /dev/null \ |
| 101 |
/etc/openvpn-auth-oauth2/management-password.txt |
| 102 |
management_password="$(openssl rand -hex 32)" |
| 103 |
printf '%s\n' "$management_password" \ |
| 104 |
| sudo tee /etc/openvpn/management-password.txt \ |
| 105 |
/etc/openvpn-auth-oauth2/management-password.txt >/dev/null |
| 106 |
unset management_password |
| 107 |
``` |
| 108 |
|
| 109 |
### Option A: OpenVPN plugin |
| 110 |
|
| 111 |
Linux AMD64 and ARM64 DEB and RPM packages install the plugin at |
| 112 |
`/usr/lib/openvpn/openvpn-auth-oauth2.so`. Add it to the OpenVPN server |
| 113 |
configuration: |
| 114 |
|
| 115 |
```ini |
| 116 |
plugin /usr/lib/openvpn/openvpn-auth-oauth2.so "tcp://127.0.0.1:9002" "/etc/openvpn/management-password.txt" |
| 117 |
auth-user-pass-optional |
| 118 |
``` |
| 119 |
|
| 120 |
The plugin listens on the loopback address for `openvpn-auth-oauth2` and leaves |
| 121 |
OpenVPN's real management interface available for other tools. See |
| 122 |
[OpenVPN Plugin](OpenVPN%20Plugin) for Unix socket configuration, package and |
| 123 |
architecture limitations, and troubleshooting. |
| 124 |
|
| 125 |
> [!IMPORTANT] |
| 126 |
> Do not enable `openvpn.enforce-unique-user` with the plugin. The setting needs |
| 127 |
> the `status 3` and `client-kill` commands from OpenVPN's direct management |
| 128 |
> interface, which the plugin's authentication-only protocol does not expose. |
| 129 |
|
| 130 |
### Option B: Direct management interface |
| 131 |
|
| 132 |
Add the following directives to the OpenVPN server configuration: |
| 133 |
|
| 134 |
```ini |
| 135 |
management /run/openvpn/server.sock unix /etc/openvpn/management-password.txt |
| 136 |
management-client-auth |
| 137 |
auth-user-pass-optional |
| 138 |
``` |
| 139 |
|
| 140 |
> [!WARNING] |
| 141 |
> The management interface accepts only one client. If another tool needs that |
| 142 |
> connection, use the [OpenVPN plugin](OpenVPN%20Plugin) or |
| 143 |
> [management interface pass-through](Management%20Interface%20pass-through). |
| 144 |
|
| 145 |
By default, OpenVPN continues to require the client certificates from the |
| 146 |
existing server configuration. If browser-based OIDC authentication should |
| 147 |
replace client-certificate authentication, add this directive for either |
| 148 |
integration: |
| 149 |
|
| 150 |
```ini |
| 151 |
verify-client-cert none |
| 152 |
``` |
| 153 |
|
| 154 |
> [!TIP] |
| 155 |
> To avoid another browser login during TLS reauthentication or reconnects, |
| 156 |
> configure both the OpenVPN `auth-gen-token` directive and |
| 157 |
> [non-interactive session refresh](Non-interactive%20session%20refresh). |
| 158 |
|
| 159 |
Restart the applicable OpenVPN server unit after changing its configuration. |
| 160 |
Unit names vary by distribution and instance, so use the name for your existing |
| 161 |
server. With the direct management integration, confirm that |
| 162 |
`/run/openvpn/server.sock` exists after the restart. |
| 163 |
|
| 164 |
## 6. Configure openvpn-auth-oauth2 |
| 165 |
|
| 166 |
Generate a cookie-encryption secret. The value must contain exactly 16, 24, or |
| 167 |
32 characters; this command generates 32: |
| 168 |
|
| 169 |
```bash |
| 170 |
sudo install -m 0640 -o root -g openvpn-auth-oauth2 /dev/null \ |
| 171 |
/etc/openvpn-auth-oauth2/http-secret.txt |
| 172 |
openssl rand -hex 16 \ |
| 173 |
| sudo tee /etc/openvpn-auth-oauth2/http-secret.txt >/dev/null |
| 174 |
``` |
| 175 |
|
| 176 |
Edit `/etc/openvpn-auth-oauth2/config.yaml` and add the minimum configuration |
| 177 |
below. Replace every value in angle brackets and merge any extra settings from |
| 178 |
your provider's documentation. |
| 179 |
|
| 180 |
```yaml |
| 181 |
http: |
| 182 |
listen: "127.0.0.1:9000" |
| 183 |
baseurl: "https://vpn-login.example.com" |
| 184 |
secret: "file:///etc/openvpn-auth-oauth2/http-secret.txt" |
| 185 |
|
| 186 |
oauth2: |
| 187 |
issuer: "<oidc-issuer-url>" |
| 188 |
client: |
| 189 |
id: "<oidc-client-id>" |
| 190 |
secret: "<oidc-client-secret>" |
| 191 |
|
| 192 |
openvpn: |
| 193 |
# OpenVPN plugin: |
| 194 |
addr: "tcp://127.0.0.1:9002" |
| 195 |
password: "file:///etc/openvpn-auth-oauth2/management-password.txt" |
| 196 |
``` |
| 197 |
|
| 198 |
> [!TIP] |
| 199 |
> When using the direct management interface, set `openvpn.addr` to |
| 200 |
> `unix:///run/openvpn/server.sock` instead. |
| 201 |
|
| 202 |
The package also reads `/etc/sysconfig/openvpn-auth-oauth2`; values there |
| 203 |
override the YAML file. The [Configuration](Configuration) reference explains |
| 204 |
all settings, precedence, and how to read secrets from files. |
| 205 |
|
| 206 |
## 7. Add HTTPS |
| 207 |
|
| 208 |
Configure your reverse proxy to serve `https://vpn-login.example.com` and |
| 209 |
forward requests to `http://127.0.0.1:9000`. The public URL must match |
| 210 |
`http.baseurl` exactly. |
| 211 |
|
| 212 |
See [HTTPS Listener](HTTPS%20Listener) for reverse-proxy guidance or for using |
| 213 |
the service's native TLS listener. Do not expose the plain HTTP listener to an |
| 214 |
untrusted network. |
| 215 |
|
| 216 |
## 8. Start and verify the service |
| 217 |
|
| 218 |
Enable the service and inspect its startup logs: |
| 219 |
|
| 220 |
```bash |
| 221 |
sudo systemctl enable --now openvpn-auth-oauth2 |
| 222 |
sudo systemctl status openvpn-auth-oauth2 |
| 223 |
sudo journalctl -u openvpn-auth-oauth2 --no-pager -n 100 |
| 224 |
``` |
| 225 |
|
| 226 |
Startup must complete without configuration, OIDC discovery, socket, or |
| 227 |
permission errors. If the service cannot read a secret or connect to the Unix |
| 228 |
socket, see [Filesystem Permissions](Filesystem%20Permissions). |
| 229 |
|
| 230 |
## 9. Test a VPN login |
| 231 |
|
| 232 |
1. Import the OpenVPN profile into a [supported client](OpenVPN). |
| 233 |
2. Connect to the VPN. |
| 234 |
3. Confirm that the client opens the public URL in a browser. |
| 235 |
4. Sign in at the OIDC provider. |
| 236 |
5. Confirm that the browser reports success and the VPN connection completes. |
| 237 |
|
| 238 |
If the browser does not open, authentication loops, or the connection times |
| 239 |
out, start with [Troubleshooting](Debugging%20Errors) and the [FAQ](FAQ). Check |
| 240 |
the OpenVPN server and `openvpn-auth-oauth2` logs together because the flow |
| 241 |
crosses both services. |
| 242 |
|
| 243 |
## Production checklist |
| 244 |
|
| 245 |
After the first successful login: |
| 246 |
|
| 247 |
- Review the [security considerations](Security%20considerations), especially |
| 248 |
IP-address validation and trusted reverse proxies. |
| 249 |
- Configure [token validation](Client%20token%20validation) or provider-side |
| 250 |
assignments so only intended users can connect. |
| 251 |
- Decide whether users need |
| 252 |
[non-interactive session refresh](Non-interactive%20session%20refresh). |
| 253 |
- Review [OpenVPN username handling](OpenVPN%20Username) if logs, status output, |
| 254 |
or per-user policy must use the OIDC identity. |
| 255 |
- If only one session per OIDC username is allowed, review the |
| 256 |
[`openvpn.enforce-unique-user` limitations](OpenVPN%20Username#limiting-a-username-to-one-active-session) |
| 257 |
before choosing the OpenVPN integration. |
| 258 |
- Keep the HTTP, OIDC client, management, and refresh secrets out of source |
| 259 |
control and restrict their filesystem permissions. |