Debian Codegraph @

docs/Configuration.md

raw
1 # Configuration
2
3 For a first deployment, follow [Getting Started](Getting%20Started). This page
4 is the complete configuration reference.
5
6 To configure openvpn-auth-oauth2, the recommended approach uses a YAML file.
7 If installed through a Linux package,
8 the file `/etc/sysconfig/openvpn-auth-oauth2` allows configuration of openvpn-auth-oauth2 through environment variables.
9
10 Take a look at the [FAQ](./FAQ) section, for common questions, issues and solutions.
11
12 ## Configuration file
13
14 openvpn-auth-oauth2 supports configuration via a YAML file. Pass the file with
15 the `--config` flag or the `OPENVPN_AUTH_OAUTH2_CONFIG_FILE` environment
16 variable.
17
18 See the [example configuration file](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/packaging/etc/openvpn-auth-oauth2/config.yaml).
19
20 ## Configuration precedence
21
22 When an option is configured in more than one place, openvpn-auth-oauth2 uses
23 the following order, from lowest to highest priority:
24
25 1. Built-in default
26 2. YAML configuration file
27 3. Environment variable
28 4. Command-line flag
29
30 Environment variable names use the `OPENVPN_AUTH_OAUTH2_` prefix. Dots and
31 dashes in the corresponding flag name both become single underscores. For
32 example, `openvpn.command-timeout` becomes
33 `OPENVPN_AUTH_OAUTH2_OPENVPN_COMMAND_TIMEOUT`.
34
35 Environment values are validated at startup. Boolean values must be exactly
36 `true` or `false`, and malformed values or unknown
37 `OPENVPN_AUTH_OAUTH2_` environment variables stop startup with an error.
38 Command-line positional arguments are not supported.
39
40 ## Supported configuration properties
41
42 <details>
43 <summary>Expand</summary>
44
45 <!-- BEGIN USAGE -->
46 ```
47 Documentation available at https://github.com/jkroepke/openvpn-auth-oauth2/wiki
48
49 Usage of openvpn-auth-oauth2:
50
51 --config string
52 path to one .yaml config file (env: OPENVPN_AUTH_OAUTH2_CONFIG_FILE)
53 --debug.listen string
54 listen address for go profiling endpoint (env: OPENVPN_AUTH_OAUTH2_DEBUG_LISTEN) (default "127.0.0.1:9001")
55 --debug.pprof
56 Enables go profiling endpoint. This should be never exposed. (env: OPENVPN_AUTH_OAUTH2_DEBUG_PPROF)
57 --http.assets-path value
58 Custom path to the assets directory. Files in this directory will be served under /assets/ and having an higher priority than the embedded assets. (env: OPENVPN_AUTH_OAUTH2_HTTP_ASSETS_PATH)
59 --http.baseurl value
60 listen addr for client listener (env: OPENVPN_AUTH_OAUTH2_HTTP_BASEURL) (default http://localhost:9000)
61 --http.cert string
62 Path to tls server certificate used for TLS listener. (env: OPENVPN_AUTH_OAUTH2_HTTP_CERT)
63 --http.check.ipaddr
64 Check if client IP in http and VPN is equal (env: OPENVPN_AUTH_OAUTH2_HTTP_CHECK_IPADDR)
65 --http.enable-proxy-headers
66 Use X-Forwarded-For http header for client ips (env: OPENVPN_AUTH_OAUTH2_HTTP_ENABLE_PROXY_HEADERS)
67 --http.key string
68 Path to tls server key used for TLS listener. (env: OPENVPN_AUTH_OAUTH2_HTTP_KEY)
69 --http.listen string
70 listen addr for client listener (env: OPENVPN_AUTH_OAUTH2_HTTP_LISTEN) (default ":9000")
71 --http.secret value
72 Random generated secret for cookie encryption. Must be 16, 24 or 32 characters. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_HTTP_SECRET)
73 --http.template value
74 Path to a HTML file which is displayed at the end of the screen. See https://github.com/jkroepke/openvpn-auth-oauth2/wiki/Layout-Customization for more information. (env: OPENVPN_AUTH_OAUTH2_HTTP_TEMPLATE)
75 --http.tls
76 enable TLS listener (env: OPENVPN_AUTH_OAUTH2_HTTP_TLS)
77 --http.trusted-proxies value
78 Trusted reverse proxy CIDRs allowed to set X-Forwarded-For. Multiple values can be provided as a comma-separated list. (env: OPENVPN_AUTH_OAUTH2_HTTP_TRUSTED_PROXIES)
79 --log.format string
80 log format. json or console (env: OPENVPN_AUTH_OAUTH2_LOG_FORMAT) (default "console")
81 --log.level value
82 log level. Can be one of: debug, info, warn, error (env: OPENVPN_AUTH_OAUTH2_LOG_LEVEL) (default INFO)
83 --log.vpn-client-ip
84 log IP of VPN client. Useful to have an identifier between OpenVPN and openvpn-auth-oauth2. (env: OPENVPN_AUTH_OAUTH2_LOG_VPN_CLIENT_IP) (default true)
85 --oauth2.auth-style value
86 Auth style represents how requests for tokens are authenticated to the server. Possible values: auto, params, header. See https://pkg.go.dev/golang.org/x/oauth2#AuthStyle (env: OPENVPN_AUTH_OAUTH2_OAUTH2_AUTH_STYLE) (default params)
87 --oauth2.authorize-params string
88 additional url query parameter to authorize endpoint (env: OPENVPN_AUTH_OAUTH2_OAUTH2_AUTHORIZE_PARAMS)
89 --oauth2.client.id string
90 oauth2 client id (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_ID)
91 --oauth2.client.private-key value
92 oauth2 client private key. Secure alternative to oauth2.client.secret. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_PRIVATE_KEY)
93 --oauth2.client.private-key-id string
94 oauth2 client private key id. If specified, JWT assertions will be generated with the specific kid header. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_PRIVATE_KEY_ID)
95 --oauth2.client.secret value
96 oauth2 client secret. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_SECRET)
97 --oauth2.endpoint.auth value
98 The flag is used to specify a custom OAuth2 authorization endpoint. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_AUTH)
99 --oauth2.endpoint.discovery value
100 The flag is used to set a custom OAuth2 discovery URL. This URL retrieves the provider's configuration details. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_DISCOVERY)
101 --oauth2.endpoint.token value
102 The flag is used to specify a custom OAuth2 token endpoint. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_TOKEN)
103 --oauth2.groups-claim string
104 Defines the claim name in the ID Token which contains the user groups. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_GROUPS_CLAIM) (default "groups")
105 --oauth2.issuer value
106 oauth2 issuer (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ISSUER)
107 --oauth2.nonce
108 If true, a nonce will be defined on the auth URL which is expected inside the token. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_NONCE) (default true)
109 --oauth2.openvpn-username string
110 CEL expression to resolve the username from the normalized identity. The expression must evaluate to a string value. Example: string(token.claims.sub). If empty, the common name is used. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_OPENVPN_USERNAME) (default "user.username")
111 --oauth2.pkce
112 If true, Proof Key for Code Exchange (PKCE) RFC 7636 is used for token exchange. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_PKCE) (default true)
113 --oauth2.provider string
114 oauth2 provider (env: OPENVPN_AUTH_OAUTH2_OAUTH2_PROVIDER) (default "generic")
115 --oauth2.refresh-nonce value
116 Controls nonce behavior on refresh token requests. Options: auto (try with nonce, retry without on error), empty (always use empty nonce), equal (use same nonce as initial auth). (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_NONCE) (default auto)
117 --oauth2.refresh.enabled
118 If true, openvpn-auth-oauth2 stores refresh tokens and will use it do an non-interaction reauth. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_ENABLED)
119 --oauth2.refresh.expires duration
120 TTL of stored oauth2 token. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_EXPIRES) (default 8h0m0s)
121 --oauth2.refresh.secret value
122 Required, if oauth2.refresh.enabled=true. Random generated secret for token encryption. Must be 16, 24 or 32 characters. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_SECRET)
123 --oauth2.refresh.use-session-id
124 If true, openvpn-auth-oauth2 will use the session_id to refresh sessions on initial auth. Requires 'auth-token-gen [lifetime] external-auth' on OpenVPN server. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_USE_SESSION_ID)
125 --oauth2.refresh.validate-user
126 If true, openvpn-auth-oauth2 will validate the user against the OIDC provider on each refresh. Usefully, if API limits are exceeded or OIDC provider can't deliver an refresh token. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_VALIDATE_USER) (default true)
127 --oauth2.scopes value
128 oauth2 token scopes. Defaults depends on oauth2.provider. Comma separated list. Example: openid,profile,email (env: OPENVPN_AUTH_OAUTH2_OAUTH2_SCOPES)
129 --oauth2.user-info
130 If true, openvpn-auth-oauth2 uses the OIDC UserInfo endpoint to fetch additional information about the user (e.g. groups). (env: OPENVPN_AUTH_OAUTH2_OAUTH2_USER_INFO)
131 --oauth2.validate.expression string
132 CEL expression for custom identity validation. The expression must evaluate to a boolean value. Example: openvpn.commonName == user.username (env: OPENVPN_AUTH_OAUTH2_OAUTH2_VALIDATE_EXPRESSION)
133 --oauth2.validate.groups value
134 oauth2 required user groups. If multiple groups are configured, the user needs to be least in one group. Comma separated list. Example: group1,group2,group3 (env: OPENVPN_AUTH_OAUTH2_OAUTH2_VALIDATE_GROUPS)
135 --openvpn.addr value
136 openvpn management interface addr. Must start with unix:// or tcp:// (env: OPENVPN_AUTH_OAUTH2_OPENVPN_ADDR) (default unix:/run/openvpn/server.sock)
137 --openvpn.auth-pending-timeout duration
138 How long OpenVPN server wait until user is authenticated (env: OPENVPN_AUTH_OAUTH2_OPENVPN_AUTH_PENDING_TIMEOUT) (default 3m0s)
139 --openvpn.auth-token-user
140 Override the username of a session with the username from the token by using auth-token-user, if the client username is empty (env: OPENVPN_AUTH_OAUTH2_OPENVPN_AUTH_TOKEN_USER) (default true)
141 --openvpn.bypass.common-names value
142 Skip OAuth authentication for client certificate common names (CNs) matching any of the given regular expressions. Multiple expressions can be provided as a comma-separated list. Regular expressions are automatically anchored (^…$) by default, so "client" matches only "client". To allow partial matches, specify explicitly (e.g. "client.*"). (env: OPENVPN_AUTH_OAUTH2_OPENVPN_BYPASS_COMMON_NAMES)
143 --openvpn.client-config.enabled
144 If true, openvpn-auth-oauth2 will read the CCD directory for additional configuration. This function mimic the client-config-dir directive in OpenVPN. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_ENABLED)
145 --openvpn.client-config.expression string
146 CEL expression that returns an ordered list of client configuration names. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_EXPRESSION)
147 --openvpn.client-config.ignore-not-found
148 Ignore missing client configuration files. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_IGNORE_NOT_FOUND) (default true)
149 --openvpn.client-config.path value
150 Path to the CCD directory. openvpn-auth-oauth2 will look for an file with an .conf suffix and returns the content back. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_PATH) (default /etc/openvpn-auth-oauth2/client-config/)
151 --openvpn.client-config.strategy value
152 Client config selection strategy. Values: [merge,user-selector]. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_STRATEGY) (default merge)
153 --openvpn.command-timeout duration
154 Maximum time to wait for a response to an OpenVPN management command. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_COMMAND_TIMEOUT) (default 10s)
155 --openvpn.common-name.environment-variable-name string
156 Name of the environment variable in the OpenVPN management interface which contains the common name. If username-as-common-name is enabled, this should be set to 'username' to use the username as common name. Other values like 'X509_0_emailAddress' are supported. See https://openvpn.net/community-resources/reference-manual-for-openvpn-2-6/#environmental-variables for more information. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_COMMON_NAME_ENVIRONMENT_VARIABLE_NAME) (default "common_name")
157 --openvpn.enforce-unique-user
158 Enforces one active OpenVPN session for the username resolved by oauth2.openvpn-username. Requires a direct OpenVPN management-interface connection; the OpenVPN plugin is not supported. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_ENFORCE_UNIQUE_USER)
159 --openvpn.override-username
160 Requires OpenVPN Server 2.7! If true, openvpn-auth-oauth2 use the override-username command to set the username in OpenVPN connection. This is useful to use real usernames in OpenVPN statistics. The username will be set after client configs are read. Read OpenVPN man page for limitations of the override-username. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_OVERRIDE_USERNAME)
161 --openvpn.pass-through.address value
162 The address of the pass-through socket. Must start with unix:// or tcp:// (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_ADDRESS) (default unix:/run/openvpn-auth-oauth2/server.sock)
163 --openvpn.pass-through.enabled
164 If true, openvpn-auth-oauth2 will setup a pass-through socket for the OpenVPN management interface. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_ENABLED)
165 --openvpn.pass-through.password value
166 The password for the pass-through socket. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_PASSWORD)
167 --openvpn.pass-through.socket-group string
168 The group for the pass-through socket. Used only, if openvpn.pass-through.address starts with unix:// If empty, the group of the process is used. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_SOCKET_GROUP)
169 --openvpn.pass-through.socket-mode value
170 The explicit four-digit octal unix file permission mode for the pass-through socket. Used only, if openvpn.pass-through.address starts with unix:// (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_SOCKET_MODE) (default 0660)
171 --openvpn.password value
172 openvpn management interface password. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASSWORD)
173 --openvpn.reauthentication
174 If set to false, openvpn-auth-oauth2 rejects all re-authentication requests. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_REAUTHENTICATION) (default true)
175 --provider.google.validate.groups-transitive
176 If true, required group membership for the Google provider is matched transitively: nested sub-groups of a configured group in oauth2.validate.groups are accepted. Requires the cloud-identity.groups.readonly scope and a Google Workspace/Cloud Identity plan that supports the Cloud Identity checkTransitiveMembership API. (env: OPENVPN_AUTH_OAUTH2_PROVIDER_GOOGLE_VALIDATE_GROUPS_TRANSITIVE)
177 --version
178 show version
179 ```
180 <!-- END USAGE -->
181
182 </details>
183
184
185 ## Read sensitive data from a file
186
187 The following parameter supports sensitive data from the file:
188
189 * http.secret
190 * openvpn.password
191 * oauth2.client.secret
192 * oauth2.refresh.secret
193
194 To read the sensitive data from the file, use the `file://` prefix, e.g. `file://path/to/secret.txt`.
195
196 ### openvpn-auth-oauth2 config
197
198 openvpn-auth-oauth2 starts an HTTP listener that the OpenVPN client must access before establishing the VPN connection.
199 By default, the HTTP listener operates on `:9000`.
200
201 It is highly recommended to place openvpn-auth-oauth2 behind a reverse proxy terminates the TLS connections.
202 Configuring `OPENVPN_AUTH_OAUTH2_HTTP_BASEURL` remains crucial because openvpn-auth-oauth2 needs to know the redirect URL.
203
204 Example:
205
206 <table>
207 <thead><tr><td>env/sysconfig configuration</td></tr></thead>
208 <tbody><tr><td>
209
210 ```ini
211 # openvpn-auth-oauth2 config file
212 OPENVPN_AUTH_OAUTH2_HTTP_LISTEN=:9000
213 OPENVPN_AUTH_OAUTH2_HTTP_BASEURL=https://login.example.com
214 ```
215 </td></tr></tbody>
216 <thead><tr><td>yaml configuration</td></tr></thead>
217 <tbody><tr><td>
218
219 ```yaml
220 http:
221 listen: ":9000"
222 baseurl: "https://login.example.com"
223 ```
224 </td></tr></tbody>
225 </table>
226
227 ### Filesystem Permissions
228
229 See [Filesystem Permissions](Filesystem%20Permissions) for more information.
230
231 ## Choose the OpenVPN integration
232
233 `openvpn-auth-oauth2` supports two production integration methods:
234
235 | Integration | Main benefit | Limitation |
236 | --- | --- | --- |
237 | [OpenVPN plugin](OpenVPN%20Plugin) | Leaves OpenVPN's management interface available for other tools | Distributed for Linux AMD64, Linux ARM64, and FreeBSD AMD64; does not support `openvpn.enforce-unique-user` |
238 | Direct management interface | Provides the full management command set and supports `openvpn.enforce-unique-user` | Occupies OpenVPN's single management client connection |
239
240 > [!NOTE]
241 > The OpenVPN plugin is stable and supported since openvpn-auth-oauth2 version
242 > 2.0. Choose between the integrations based on their capabilities, not plugin
243 > maturity.
244
245 ### OpenVPN plugin
246
247 Follow [OpenVPN Plugin](OpenVPN%20Plugin) to install the shared library and
248 configure its authentication-only TCP or Unix socket.
249
250 ### Direct management interface
251
252 To connect `openvpn-auth-oauth2` directly to OpenVPN, add the following lines:
253
254 ```ini
255 # openvpn server.conf
256 ...
257 # /etc/openvpn/password.txt is a password file where the password must be on first line
258 management /run/openvpn/server.sock unix /etc/openvpn/password.txt
259 management-client-auth
260 # management-hold holds the OpenVPN server until openvpn-auth-oauth2 has been connected.
261 # In some situation, there is a deadlock where systemd waits for OpenVPN server, not starting
262 #management-hold
263
264 # If auth-user-pass-optional is not set, the OpenVPN server requires username/password from clients
265 # and terminate the connection with an TLS error, if the client does not provide it.
266 auth-user-pass-optional
267
268 # Enable auth-token-gen to allow non-interactive session refresh
269 # Mandatory for mobile devices, because auth-token works across disconnects
270 # The lifetime of the token must be the same as the refresh token in openvpn-auth-oauth2.
271 # The token can't be extended after it has been generated. The lifetime must be the maximum lifetime of a VPN session.
272 # 8 hours = 28800 seconds
273 auth-gen-token 28800 external-auth
274 ```
275
276 #### Environment configuration
277
278 ```ini
279 # openvpn-auth-oauth2 config file
280 OPENVPN_AUTH_OAUTH2_OPENVPN_ADDR=unix:///run/openvpn/server.sock
281 OPENVPN_AUTH_OAUTH2_OPENVPN_PASSWORD=<password>
282 OPENVPN_AUTH_OAUTH2_OPENVPN_OVERRIDE_USERNAME=true # For OpenVPN 2.7+ servers
283 ```
284
285 #### YAML configuration
286
287 ```yaml
288 openvpn:
289 addr: "unix:///run/openvpn/server.sock"
290 password: "<password>"
291 override-username: true # For OpenVPN 2.7+ servers
292 ```
293
294 ## Setup OIDC Provider
295
296 See [Providers](Providers) for more information.
297
298 ## HTTPS Listener
299
300 See [HTTPS Listener](HTTPS%20Listener) for more information.
301
302 ## Custom Login Templates
303
304 See [Layout Customization](Layout%20Customization) for more information
305
306 ## Non-interactive session refresh
307
308 See [Non-interactive session refresh](Non-interactive%20session%20refresh) for more information.
309
310 ## Client specific configuration
311
312 See [Client specific configuration](Client%20specific%20configuration) for more information.
313
314 ## OpenVPN username handling
315
316 See [OpenVPN Username](OpenVPN%20Username) for more information.