| 1 |
# OpenVPN Plugin |
| 2 |
|
| 3 |
> [!NOTE] |
| 4 |
> The OpenVPN plugin is stable and supported since openvpn-auth-oauth2 version |
| 5 |
> 2.0. It is a production deployment option, not an experimental feature. |
| 6 |
|
| 7 |
The plugin connects OpenVPN Server to the `openvpn-auth-oauth2` service through |
| 8 |
OpenVPN's plugin API. It exposes the authentication events that |
| 9 |
`openvpn-auth-oauth2` needs without occupying OpenVPN's management interface. |
| 10 |
Monitoring, administration, or other management clients can continue using the |
| 11 |
real management interface. |
| 12 |
|
| 13 |
## When to use the plugin |
| 14 |
|
| 15 |
Use the plugin when: |
| 16 |
|
| 17 |
- the OpenVPN server runs on Linux AMD64, Linux ARM64, or FreeBSD AMD64; |
| 18 |
- another tool needs OpenVPN's management interface; or |
| 19 |
- you prefer to isolate authentication from general management commands. |
| 20 |
|
| 21 |
Use the [direct management interface](Configuration#direct-management-interface) |
| 22 |
instead when `openvpn.enforce-unique-user` is required. |
| 23 |
|
| 24 |
| Capability | Plugin | |
| 25 |
| --- | --- | |
| 26 |
| Browser-based OIDC authentication | Supported | |
| 27 |
| Non-interactive session refresh | Supported | |
| 28 |
| `openvpn.override-username` | Supported on OpenVPN 2.7 or later | |
| 29 |
| Built-in client-specific configuration | Supported | |
| 30 |
| `openvpn.enforce-unique-user` | Not supported; use the direct management interface | |
| 31 |
| General OpenVPN management commands | Use OpenVPN's separate, real management interface | |
| 32 |
|
| 33 |
> [!IMPORTANT] |
| 34 |
> `openvpn.enforce-unique-user` does not work through the plugin. The setting |
| 35 |
> queries `status 3` and sends `client-kill` before accepting a connection. The |
| 36 |
> plugin socket deliberately implements only the authentication-related |
| 37 |
> management protocol, so `openvpn-auth-oauth2` rejects this combination during |
| 38 |
> startup. |
| 39 |
|
| 40 |
## Architecture |
| 41 |
|
| 42 |
```text |
| 43 |
┌─────────────────────────┐ |
| 44 |
│ OpenVPN Server │ |
| 45 |
│ │ |
| 46 |
│ Real management socket │<── monitoring or administration tools |
| 47 |
└────────────┬────────────┘ |
| 48 |
│ OpenVPN plugin API |
| 49 |
┌────────────▼────────────┐ |
| 50 |
│ openvpn-auth-oauth2.so │ |
| 51 |
└────────────┬────────────┘ |
| 52 |
│ Auth-only TCP or Unix socket |
| 53 |
┌────────────▼────────────┐ |
| 54 |
│ openvpn-auth-oauth2 │ |
| 55 |
└─────────────────────────┘ |
| 56 |
``` |
| 57 |
|
| 58 |
## Requirements |
| 59 |
|
| 60 |
- OpenVPN Community Server 2.6.2 or later. |
| 61 |
- Linux AMD64, Linux ARM64, or FreeBSD AMD64 for a prebuilt plugin artifact. |
| 62 |
- glibc 2.17 or later on Linux. The prebuilt Linux plugin dynamically links to |
| 63 |
`libc.so.6`, `libresolv.so.2`, and `libpthread.so.0`. |
| 64 |
- The `openvpn-auth-oauth2` binary and plugin from the same release. |
| 65 |
- A dedicated password shared by the OpenVPN plugin and |
| 66 |
`openvpn-auth-oauth2`. |
| 67 |
|
| 68 |
> [!IMPORTANT] |
| 69 |
> The prebuilt Linux plugin does not support musl-based distributions such as |
| 70 |
> Alpine Linux. Alpine's `gcompat` and `libc6-compat` packages do not provide |
| 71 |
> all glibc ABI and thread-local storage behavior required by Go shared |
| 72 |
> libraries loaded with `dlopen`. This is a known |
| 73 |
> [Go runtime limitation](https://github.com/golang/go/issues/54805). Run |
| 74 |
> OpenVPN on a glibc-based distribution or use the |
| 75 |
> [direct management interface](Configuration#direct-management-interface) |
| 76 |
> instead. |
| 77 |
|
| 78 |
> [!NOTE] |
| 79 |
> Release archives contain the plugin for Linux AMD64, Linux ARM64, and FreeBSD |
| 80 |
> AMD64. Linux AMD64 and ARM64 DEB/RPM packages also contain the matching |
| 81 |
> plugin. The `openvpn-auth-oauth2` service itself is released for more operating |
| 82 |
> systems and architectures; those other artifacts do not include the plugin. |
| 83 |
|
| 84 |
## 1. Install the plugin |
| 85 |
|
| 86 |
Linux DEB and RPM packages install the shared library that matches the package |
| 87 |
architecture. On every supported platform, the shared library is named |
| 88 |
`openvpn-auth-oauth2.so`. Release archives contain the plugin beside the service |
| 89 |
binary, and Linux packages install it at: |
| 90 |
|
| 91 |
```text |
| 92 |
/usr/lib/openvpn/openvpn-auth-oauth2.so |
| 93 |
``` |
| 94 |
|
| 95 |
If you use the release archive, extract the matching `.so` file and place it in |
| 96 |
a directory that OpenVPN can read. Keep the plugin and service versions aligned. |
| 97 |
|
| 98 |
## 2. Create the connection password |
| 99 |
|
| 100 |
Package installations confine OpenVPN and `openvpn-auth-oauth2` differently. |
| 101 |
Use two files with identical contents so each process can read its own file |
| 102 |
without broadening filesystem access: |
| 103 |
|
| 104 |
```bash |
| 105 |
sudo install -m 0600 -o root -g root /dev/null \ |
| 106 |
/etc/openvpn/management-password.txt |
| 107 |
sudo install -m 0640 -o root -g openvpn-auth-oauth2 /dev/null \ |
| 108 |
/etc/openvpn-auth-oauth2/management-password.txt |
| 109 |
plugin_password="$(openssl rand -hex 32)" |
| 110 |
printf '%s\n' "$plugin_password" \ |
| 111 |
| sudo tee /etc/openvpn/management-password.txt \ |
| 112 |
/etc/openvpn-auth-oauth2/management-password.txt >/dev/null |
| 113 |
unset plugin_password |
| 114 |
``` |
| 115 |
|
| 116 |
> [!WARNING] |
| 117 |
> The plugin socket controls authentication decisions. Do not expose it to an |
| 118 |
> untrusted network, and do not make either password file readable by unrelated |
| 119 |
> users. |
| 120 |
|
| 121 |
## 3. Configure OpenVPN |
| 122 |
|
| 123 |
### TCP loopback socket |
| 124 |
|
| 125 |
TCP loopback avoids Unix socket ownership differences between OpenVPN packages: |
| 126 |
|
| 127 |
```ini |
| 128 |
plugin /usr/lib/openvpn/openvpn-auth-oauth2.so "tcp://127.0.0.1:9002" "/etc/openvpn/management-password.txt" |
| 129 |
auth-user-pass-optional |
| 130 |
``` |
| 131 |
|
| 132 |
### Unix socket |
| 133 |
|
| 134 |
A Unix socket avoids allocating a TCP port: |
| 135 |
|
| 136 |
```ini |
| 137 |
plugin /usr/lib/openvpn/openvpn-auth-oauth2.so "unix:///run/openvpn/openvpn-auth-oauth2.sock" "/etc/openvpn/management-password.txt" |
| 138 |
auth-user-pass-optional |
| 139 |
``` |
| 140 |
|
| 141 |
> [!IMPORTANT] |
| 142 |
> For a Unix socket, OpenVPN must be able to create the socket before dropping |
| 143 |
> privileges and remove it during shutdown. The runtime user therefore needs |
| 144 |
> write and search permissions on the parent directory. |
| 145 |
|
| 146 |
The plugin directive accepts three values: |
| 147 |
|
| 148 |
1. Path to the shared library. |
| 149 |
2. TCP or Unix address on which the plugin listens for |
| 150 |
`openvpn-auth-oauth2`. |
| 151 |
3. Path to the password file that OpenVPN can read. |
| 152 |
|
| 153 |
Restart the applicable OpenVPN server unit after changing its configuration. |
| 154 |
|
| 155 |
## 4. Configure openvpn-auth-oauth2 |
| 156 |
|
| 157 |
Set `openvpn.addr` to the same address as the plugin and read the matching |
| 158 |
password copy. |
| 159 |
|
| 160 |
### YAML configuration |
| 161 |
|
| 162 |
```yaml |
| 163 |
openvpn: |
| 164 |
addr: "tcp://127.0.0.1:9002" |
| 165 |
password: "file:///etc/openvpn-auth-oauth2/management-password.txt" |
| 166 |
``` |
| 167 |
|
| 168 |
### Environment configuration |
| 169 |
|
| 170 |
```ini |
| 171 |
OPENVPN_AUTH_OAUTH2_OPENVPN_ADDR=tcp://127.0.0.1:9002 |
| 172 |
OPENVPN_AUTH_OAUTH2_OPENVPN_PASSWORD=file:///etc/openvpn-auth-oauth2/management-password.txt |
| 173 |
``` |
| 174 |
|
| 175 |
For a Unix socket, replace the address in both configurations with the same |
| 176 |
`unix://` value. |
| 177 |
|
| 178 |
> [!TIP] |
| 179 |
> To avoid browser logins during TLS reauthentication and reconnects, configure |
| 180 |
> [non-interactive session refresh](Non-interactive%20session%20refresh). The |
| 181 |
> plugin supports refresh tokens and OpenVPN session IDs. |
| 182 |
|
| 183 |
## 5. Verify the connection |
| 184 |
|
| 185 |
Start or restart `openvpn-auth-oauth2`, then inspect both services: |
| 186 |
|
| 187 |
```bash |
| 188 |
sudo systemctl restart openvpn-auth-oauth2 |
| 189 |
sudo systemctl status openvpn-auth-oauth2 |
| 190 |
sudo journalctl -u openvpn-auth-oauth2 --no-pager -n 100 |
| 191 |
``` |
| 192 |
|
| 193 |
The `openvpn-auth-oauth2` log should report a connection to the configured |
| 194 |
address. The OpenVPN log should show that the plugin loaded without an address, |
| 195 |
password-file, or permission error. |
| 196 |
|
| 197 |
If the connection fails, verify that: |
| 198 |
|
| 199 |
- OpenVPN loaded the `.so` from the expected path; |
| 200 |
- both configurations use the same TCP or Unix address; |
| 201 |
- the two password files contain the same value; and |
| 202 |
- each process can read its password file and access every parent directory. |