# Configuration
For a first deployment, follow [Getting Started](Getting%20Started). This page
is the complete configuration reference.
To configure openvpn-auth-oauth2, the recommended approach uses a YAML file.
If installed through a Linux package,
the file `/etc/sysconfig/openvpn-auth-oauth2` allows configuration of openvpn-auth-oauth2 through environment variables.
Take a look at the [FAQ](./FAQ) section, for common questions, issues and solutions.
## Configuration file
openvpn-auth-oauth2 supports configuration via a YAML file. Pass the file with
the `--config` flag or the `OPENVPN_AUTH_OAUTH2_CONFIG_FILE` environment
variable.
See the [example configuration file](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/packaging/etc/openvpn-auth-oauth2/config.yaml).
## Configuration precedence
When an option is configured in more than one place, openvpn-auth-oauth2 uses
the following order, from lowest to highest priority:
1. Built-in default
2. YAML configuration file
3. Environment variable
4. Command-line flag
Environment variable names use the `OPENVPN_AUTH_OAUTH2_` prefix. Dots and
dashes in the corresponding flag name both become single underscores. For
example, `openvpn.command-timeout` becomes
`OPENVPN_AUTH_OAUTH2_OPENVPN_COMMAND_TIMEOUT`.
Environment values are validated at startup. Boolean values must be exactly
`true` or `false`, and malformed values or unknown
`OPENVPN_AUTH_OAUTH2_` environment variables stop startup with an error.
Command-line positional arguments are not supported.
## Supported configuration properties
Expand
```
Documentation available at https://github.com/jkroepke/openvpn-auth-oauth2/wiki
Usage of openvpn-auth-oauth2:
--config string
path to one .yaml config file (env: OPENVPN_AUTH_OAUTH2_CONFIG_FILE)
--debug.listen string
listen address for go profiling endpoint (env: OPENVPN_AUTH_OAUTH2_DEBUG_LISTEN) (default "127.0.0.1:9001")
--debug.pprof
Enables go profiling endpoint. This should be never exposed. (env: OPENVPN_AUTH_OAUTH2_DEBUG_PPROF)
--http.assets-path value
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)
--http.baseurl value
listen addr for client listener (env: OPENVPN_AUTH_OAUTH2_HTTP_BASEURL) (default http://localhost:9000)
--http.cert string
Path to tls server certificate used for TLS listener. (env: OPENVPN_AUTH_OAUTH2_HTTP_CERT)
--http.check.ipaddr
Check if client IP in http and VPN is equal (env: OPENVPN_AUTH_OAUTH2_HTTP_CHECK_IPADDR)
--http.enable-proxy-headers
Use X-Forwarded-For http header for client ips (env: OPENVPN_AUTH_OAUTH2_HTTP_ENABLE_PROXY_HEADERS)
--http.key string
Path to tls server key used for TLS listener. (env: OPENVPN_AUTH_OAUTH2_HTTP_KEY)
--http.listen string
listen addr for client listener (env: OPENVPN_AUTH_OAUTH2_HTTP_LISTEN) (default ":9000")
--http.secret value
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)
--http.template value
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)
--http.tls
enable TLS listener (env: OPENVPN_AUTH_OAUTH2_HTTP_TLS)
--http.trusted-proxies value
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)
--log.format string
log format. json or console (env: OPENVPN_AUTH_OAUTH2_LOG_FORMAT) (default "console")
--log.level value
log level. Can be one of: debug, info, warn, error (env: OPENVPN_AUTH_OAUTH2_LOG_LEVEL) (default INFO)
--log.vpn-client-ip
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)
--oauth2.auth-style value
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)
--oauth2.authorize-params string
additional url query parameter to authorize endpoint (env: OPENVPN_AUTH_OAUTH2_OAUTH2_AUTHORIZE_PARAMS)
--oauth2.client.id string
oauth2 client id (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_ID)
--oauth2.client.private-key value
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)
--oauth2.client.private-key-id string
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)
--oauth2.client.secret value
oauth2 client secret. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_CLIENT_SECRET)
--oauth2.endpoint.auth value
The flag is used to specify a custom OAuth2 authorization endpoint. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_AUTH)
--oauth2.endpoint.discovery value
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)
--oauth2.endpoint.token value
The flag is used to specify a custom OAuth2 token endpoint. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ENDPOINT_TOKEN)
--oauth2.groups-claim string
Defines the claim name in the ID Token which contains the user groups. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_GROUPS_CLAIM) (default "groups")
--oauth2.issuer value
oauth2 issuer (env: OPENVPN_AUTH_OAUTH2_OAUTH2_ISSUER)
--oauth2.nonce
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)
--oauth2.openvpn-username string
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")
--oauth2.pkce
If true, Proof Key for Code Exchange (PKCE) RFC 7636 is used for token exchange. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_PKCE) (default true)
--oauth2.provider string
oauth2 provider (env: OPENVPN_AUTH_OAUTH2_OAUTH2_PROVIDER) (default "generic")
--oauth2.refresh-nonce value
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)
--oauth2.refresh.enabled
If true, openvpn-auth-oauth2 stores refresh tokens and will use it do an non-interaction reauth. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_ENABLED)
--oauth2.refresh.expires duration
TTL of stored oauth2 token. (env: OPENVPN_AUTH_OAUTH2_OAUTH2_REFRESH_EXPIRES) (default 8h0m0s)
--oauth2.refresh.secret value
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)
--oauth2.refresh.use-session-id
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)
--oauth2.refresh.validate-user
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)
--oauth2.scopes value
oauth2 token scopes. Defaults depends on oauth2.provider. Comma separated list. Example: openid,profile,email (env: OPENVPN_AUTH_OAUTH2_OAUTH2_SCOPES)
--oauth2.user-info
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)
--oauth2.validate.expression string
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)
--oauth2.validate.groups value
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)
--openvpn.addr value
openvpn management interface addr. Must start with unix:// or tcp:// (env: OPENVPN_AUTH_OAUTH2_OPENVPN_ADDR) (default unix:/run/openvpn/server.sock)
--openvpn.auth-pending-timeout duration
How long OpenVPN server wait until user is authenticated (env: OPENVPN_AUTH_OAUTH2_OPENVPN_AUTH_PENDING_TIMEOUT) (default 3m0s)
--openvpn.auth-token-user
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)
--openvpn.bypass.common-names value
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)
--openvpn.client-config.enabled
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)
--openvpn.client-config.expression string
CEL expression that returns an ordered list of client configuration names. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_EXPRESSION)
--openvpn.client-config.ignore-not-found
Ignore missing client configuration files. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_IGNORE_NOT_FOUND) (default true)
--openvpn.client-config.path value
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/)
--openvpn.client-config.strategy value
Client config selection strategy. Values: [merge,user-selector]. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_CLIENT_CONFIG_STRATEGY) (default merge)
--openvpn.command-timeout duration
Maximum time to wait for a response to an OpenVPN management command. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_COMMAND_TIMEOUT) (default 10s)
--openvpn.common-name.environment-variable-name string
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")
--openvpn.enforce-unique-user
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)
--openvpn.override-username
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)
--openvpn.pass-through.address value
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)
--openvpn.pass-through.enabled
If true, openvpn-auth-oauth2 will setup a pass-through socket for the OpenVPN management interface. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASS_THROUGH_ENABLED)
--openvpn.pass-through.password value
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)
--openvpn.pass-through.socket-group string
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)
--openvpn.pass-through.socket-mode value
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)
--openvpn.password value
openvpn management interface password. If argument starts with file:// it reads the secret from a file. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_PASSWORD)
--openvpn.reauthentication
If set to false, openvpn-auth-oauth2 rejects all re-authentication requests. (env: OPENVPN_AUTH_OAUTH2_OPENVPN_REAUTHENTICATION) (default true)
--provider.google.validate.groups-transitive
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)
--version
show version
```
| env/sysconfig configuration |
| ```ini # openvpn-auth-oauth2 config file OPENVPN_AUTH_OAUTH2_HTTP_LISTEN=:9000 OPENVPN_AUTH_OAUTH2_HTTP_BASEURL=https://login.example.com ``` |
| yaml configuration |
| ```yaml http: listen: ":9000" baseurl: "https://login.example.com" ``` |