| 1 |
# Client specific configuration |
| 2 |
|
| 3 |
openvpn-auth-oauth2 can load OpenVPN client configuration snippets from a |
| 4 |
configured directory and send the merged result through the OpenVPN management |
| 5 |
interface. |
| 6 |
|
| 7 |
Enable the feature with `--openvpn.client-config.enabled` and set |
| 8 |
`--openvpn.client-config.path` to the directory that contains the configuration |
| 9 |
files. |
| 10 |
|
| 11 |
When `openvpn.client-config.enabled` is false, no client configuration file is |
| 12 |
loaded, including `DEFAULT.conf`. |
| 13 |
|
| 14 |
Each resolved config name loads `<name>.conf` from that directory. Filenames |
| 15 |
must satisfy Go's `fs.ValidPath`; absolute paths and `.` or `..` path elements |
| 16 |
are rejected. Config names containing `<`, `>`, `"`, `'`, `&`, `` ` ``, or |
| 17 |
control characters are rejected because names can also be rendered in the |
| 18 |
browser-based profile selector. Symbolic links are followed only when their |
| 19 |
targets remain inside the configured client config directory. |
| 20 |
|
| 21 |
If the expression returns an empty list, openvpn-auth-oauth2 loads |
| 22 |
`DEFAULT.conf`, matching OpenVPN's `client-config-dir` default-file pattern. If |
| 23 |
a returned `<name>.conf` file is not found, the default behavior is to ignore the |
| 24 |
missing file and continue. Set `openvpn.client-config.ignore-not-found: false` |
| 25 |
to deny the client instead. |
| 26 |
|
| 27 |
## Resolver |
| 28 |
|
| 29 |
Client config names are resolved with |
| 30 |
`openvpn.client-config.expression`. The expression is [CEL](CEL%20Language%20Features.md) and must return |
| 31 |
an ordered string list. |
| 32 |
|
| 33 |
The resolver receives the same normalized context as the other CEL settings. |
| 34 |
The most useful fields are: |
| 35 |
|
| 36 |
- `user.username`: the resolved OpenVPN username. |
| 37 |
- `user.groups`: the normalized provider groups. |
| 38 |
- `user.roles`: the normalized provider roles. |
| 39 |
- `openvpn.commonName`: the OpenVPN user common name. |
| 40 |
- `token.claims`: the raw OAuth2 ID token claims. |
| 41 |
|
| 42 |
The `auth`, `openvpn`, `token`, and `user` namespaces are all available. See |
| 43 |
[CEL Language Features](CEL%20Language%20Features.md) for the complete |
| 44 |
contract. |
| 45 |
|
| 46 |
Example: |
| 47 |
|
| 48 |
```yaml |
| 49 |
oauth2: |
| 50 |
openvpn-username: user.username |
| 51 |
validate: |
| 52 |
groups: |
| 53 |
- GRP-VPN |
| 54 |
|
| 55 |
openvpn: |
| 56 |
override-username: true |
| 57 |
client-config: |
| 58 |
enabled: true |
| 59 |
path: /etc/openvpn-auth-oauth2/client-config |
| 60 |
expression: | |
| 61 |
user.groups.filter(g, g in [ |
| 62 |
"GRP-VPN", |
| 63 |
"GRP-ADMIN", |
| 64 |
"GRP-NETWORK" |
| 65 |
]) + |
| 66 |
[user.username] |
| 67 |
``` |
| 68 |
|
| 69 |
For `[email protected]` with `GRP-VPN` and `GRP-ADMIN`, this loads: |
| 70 |
|
| 71 |
1. `GRP-VPN.conf` |
| 72 |
2. `GRP-ADMIN.conf` |
| 73 |
3. `[email protected]` |
| 74 |
|
| 75 |
## Strategy |
| 76 |
|
| 77 |
`openvpn.client-config.strategy` controls how resolved config names are applied. |
| 78 |
|
| 79 |
The default is `merge`. |
| 80 |
|
| 81 |
### merge |
| 82 |
|
| 83 |
`merge` loads all resolved config files in resolver order. |
| 84 |
|
| 85 |
Duplicate config names are loaded once. Duplicate config lines are sent once, |
| 86 |
preserving the first occurrence. Missing config files are skipped when |
| 87 |
`openvpn.client-config.ignore-not-found` is true, so authorization must still be |
| 88 |
enforced with `oauth2.validate.groups` or `oauth2.validate.expression`. |
| 89 |
This lets the expression return every valid role or group name and leave |
| 90 |
unconfigured names without a matching `.conf` file. |
| 91 |
|
| 92 |
```yaml |
| 93 |
openvpn: |
| 94 |
client-config: |
| 95 |
enabled: true |
| 96 |
path: /etc/openvpn-auth-oauth2/client-config |
| 97 |
strategy: merge |
| 98 |
expression: | |
| 99 |
(["base-vpn"] + user.roles).distinct() |
| 100 |
``` |
| 101 |
|
| 102 |
With this configuration, a role named `admin-routes` loads |
| 103 |
`admin-routes.conf`. A role without a matching file is ignored while |
| 104 |
`openvpn.client-config.ignore-not-found` is true. |
| 105 |
|
| 106 |
Groups can also map to several shared config files. This is useful when |
| 107 |
different groups should receive overlapping route sets: |
| 108 |
|
| 109 |
```yaml |
| 110 |
openvpn: |
| 111 |
client-config: |
| 112 |
enabled: true |
| 113 |
path: /etc/openvpn-auth-oauth2/client-config |
| 114 |
strategy: merge |
| 115 |
expression: | |
| 116 |
user.groups |
| 117 |
.map(g, { |
| 118 |
"GRP-VPN": ["base-vpn"], |
| 119 |
"GRP-ADMIN": ["base-vpn", "admin-routes"], |
| 120 |
"GRP-NETWORK": ["base-vpn", "network-routes"] |
| 121 |
}[g]) |
| 122 |
.flatten() |
| 123 |
.distinct() |
| 124 |
``` |
| 125 |
|
| 126 |
The map returns a list of config names for each group. `flatten()` converts the |
| 127 |
list of lists into one ordered list, and `distinct()` removes repeated entries |
| 128 |
such as `base-vpn`. |
| 129 |
|
| 130 |
Use this pattern when every input group is expected to exist in the map. If the |
| 131 |
token can contain unrelated groups, prefer returning the group names directly and |
| 132 |
let `openvpn.client-config.ignore-not-found` skip missing files. |
| 133 |
|
| 134 |
### user-selector |
| 135 |
|
| 136 |
`user-selector` shows the profile selector when the resolver returns more than |
| 137 |
one config name. If the resolver returns one config name, that config is used |
| 138 |
directly. If the resolver returns an empty list, `DEFAULT.conf` is used. |
| 139 |
|
| 140 |
```yaml |
| 141 |
openvpn: |
| 142 |
client-config: |
| 143 |
enabled: true |
| 144 |
path: /etc/openvpn-auth-oauth2/client-config |
| 145 |
strategy: user-selector |
| 146 |
expression: | |
| 147 |
["corporate", "guest"] + |
| 148 |
user.groups.filter(g, g.startsWith("vpn-profile-")) |
| 149 |
``` |