Back to Oauth2 Proxy

Overview

docs/versioned_docs/version-7.14.x/configuration/overview.md

7.15.273.3 KB
Original Source

oauth2-proxy can be configured via command line options, environment variables or config file (in decreasing order of precedence, i.e. command line options will overwrite environment variables and environment variables will overwrite configuration file settings).

To generate a strong cookie secret use one of the below commands:

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

<Tabs defaultValue="python"> <TabItem value="python" label="Python">
shell
python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())'
</TabItem> <TabItem value="bash" label="Bash">
shell
dd if=/dev/urandom bs=32 count=1 2>/dev/null | base64 | tr -d -- '\n' | tr -- '+/' '-_' ; echo
</TabItem> <TabItem value="openssl" label="OpenSSL">
shell
openssl rand -base64 32 | tr -- '+/' '-_'
</TabItem> <TabItem value="powershell" label="PowerShell">
powershell
# Add System.Web assembly to session, just in case
Add-Type -AssemblyName System.Web
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes([System.Web.Security.Membership]::GeneratePassword(32,4))).Replace("+","-").Replace("/","_")
</TabItem> <TabItem value="terraform" label="Terraform">
hcl
# Valid 32 Byte Base64 URL encoding set that will decode to 24 []byte AES-192 secret
resource "random_password" "cookie_secret" {
  length           = 32
  override_special = "-_"
}
</TabItem> </Tabs>

Config File

Every command line argument can be specified in a config file by replacing hyphens (-) with underscores (_). If the argument can be specified multiple times, the config option should be plural (trailing s).

An example oauth2-proxy.cfg config file is in the contrib directory. It can be used by specifying --config=/etc/oauth2-proxy.cfg

Config Options

Command Line Options

FlagDescription
--configpath to config file
--versionprint version string

General Provider Options

Provider specific options can be found on their respective subpages.

Flag / Config FieldTypeDescriptionDefault
flag: --acr-values
toml: acr_valuesstringoptional, see docs""
flag: --allowed-group
toml: allowed_groupsstring | listRestrict login to members of a group or list of groups. Furthermore, if you aren't setting the scope and use allowed_groups with the generic OIDC provider the scope groups gets added implicitly.
flag: --approval-prompt
toml: approval_promptstringOAuth approval_prompt"force"
flag: --backend-logout-url
toml: backend_logout_urlstringURL to perform backend logout, if you use {id_token} in the url it will be replaced by the actual id_token of the user session
flag: --client-id
toml: client_idstringthe OAuth Client ID, e.g. "123456.apps.googleusercontent.com"
flag: --client-secret-file
toml: client_secret_filestringthe file with OAuth Client Secret. The file must contain the secret only, with no trailing newline
flag: --client-secret
toml: client_secretstringthe OAuth Client Secret
flag: --code-challenge-method
toml: code_challenge_methodstringuse PKCE code challenges with the specified method. Either 'plain' or 'S256' (recommended)
flag: --insecure-oidc-allow-unverified-email
toml: insecure_oidc_allow_unverified_emailbooldon't fail if an email address in an id_token is not verifiedfalse
flag: --insecure-oidc-skip-issuer-verification
toml: insecure_oidc_skip_issuer_verificationboolallow the OIDC issuer URL to differ from the expected (currently required for Azure multi-tenant compatibility)false
flag: --insecure-oidc-skip-nonce
toml: insecure_oidc_skip_nonceboolskip verifying the OIDC ID Token's nonce claimtrue
flag: --jwt-key-file
toml: jwt_key_filestringpath to the private key file in PEM format used to sign the JWT so that you can say something like --jwt-key-file=/etc/ssl/private/jwt_signing_key.pem: required by login.gov
flag: --jwt-key
toml: jwt_keystringprivate key in PEM format used to sign JWT, so that you can say something like --jwt-key="${OAUTH2_PROXY_JWT_KEY}": required by login.gov
flag: --login-url
toml: login_urlstringAuthentication endpoint
flag: --auth-request-response-mode
toml: auth-request-response-modestringResponse mode to ask for during authentication request
flag: --oidc-audience-claim
toml: oidc_audience_claimsstringwhich OIDC claim contains the audience"aud"
flag: --oidc-email-claim
toml: oidc_email_claimstringwhich OIDC claim contains the user's email"email"
flag: --oidc-extra-audience
toml: oidc_extra_audiencesstring | listadditional audiences which are allowed to pass verification"[]"
flag: --oidc-groups-claim
toml: oidc_groups_claimstringwhich OIDC claim contains the user groups"groups"
flag: --oidc-issuer-url
toml: oidc_issuer_urlstringthe OpenID Connect issuer URL, e.g. "https://accounts.google.com"
flag: --oidc-jwks-url
toml: oidc_jwks_urlstringOIDC JWKS URI for token verification; required if OIDC discovery is disabled and public key files are not provided
flag: --oidc-public-key-file
toml: oidc_public_key_filesstringPath to public key file in PEM format to use for verifying JWT tokens (may be given multiple times). Required if OIDC discovery is disabled na JWKS URL isn't providedstring | list
flag: --profile-url
toml: profile_urlstringProfile access endpoint
flag: --prompt
toml: promptstringOIDC prompt; if present, approval-prompt is ignored""
flag: --provider-ca-file
toml: provider_ca_filesstring | listPaths to CA certificates that should be used when connecting to the provider. If not specified, the default Go trust sources are used instead.
flag: --provider-display-name
toml: provider_display_namestringOverride the provider's name with the given string; used for the sign-in page(depends on provider)
flag: --provider
toml: providerstringOAuth providergoogle
flag: --pubjwk-url
toml: pubjwk_urlstringJWK pubkey access endpoint: required by login.gov
flag: --redeem-url
toml: redeem_urlstringToken redemption endpoint
flag: --scope
toml:scopestringOAuth scope specification. Every provider has a default list of scopes which will be used in case no scope is configured.
flag: --skip-claims-from-profile-url
toml: skip_claims_from_profile_urlboolskip request to Profile URL for resolving claims not present in id_tokenfalse
flag: --skip-oidc-discovery
toml: skip_oidc_discoveryboolbypass OIDC endpoint discovery. --login-url, --redeem-url and --oidc-jwks-url must be configured in this casefalse
flag: --use-system-trust-store
toml: use_system_trust_storeboolDetermines if provider-ca-file files and the system trust store are used. If set to true, your custom CA files and the system trust store are used otherwise only your custom CA files.false
flag: --validate-url
toml: validate_urlstringAccess token validation endpoint
Flag / Config FieldTypeDescriptionDefault
flag: --cookie-csrf-expire
toml: cookie_csrf_expiredurationexpire timeframe for CSRF cookie15m
flag: --cookie-csrf-per-request
toml:cookie_csrf_per_requestboolEnable having different CSRF cookies per request, making it possible to have parallel requests.false
flag: --cookie-csrf-per-request-limit
toml: cookie_csrf_per_request_limitintSets a limit on the number of CSRF requests cookies that oauth2-proxy will create. The oldest cookie will be removed. Useful if users end up with 431 Request headers too large status codes. Only effective if --cookie-csrf-per-request is true"infinite"
flag: --cookie-domain
toml: cookie_domainsstring | listOptional cookie domains to force cookies to (e.g. .yourcompany.com). The longest domain matching the request's host will be used (or the shortest cookie domain if there is no match).
flag: --cookie-expire
toml: cookie_expiredurationexpire timeframe for cookie. If set to 0, cookie becomes a session-cookie which will expire when the browser is closed.168h0m0s
flag: --cookie-httponly
toml: cookie_httponlyboolset HttpOnly cookie flagtrue
flag: --cookie-name
toml: cookie_namestringthe name of the cookie that the oauth_proxy creates. Should be changed to use a cookie prefix (__Host- or __Secure-) if --cookie-secure is set."_oauth2_proxy"
flag: --cookie-path
toml: cookie_pathstringan optional cookie path to force cookies to (e.g. /poc/)"/"
flag: --cookie-refresh
toml: cookie_refreshdurationrefresh the cookie after this duration; 0 to disable; not supported by all providers 1
flag: --cookie-samesite
toml: cookie_samesitestringset SameSite cookie attribute ("lax", "strict", "none", or "").""
flag: --cookie-secret
toml: cookie_secretstringthe seed string for secure cookies (optionally base64 encoded)
flag: --cookie-secret-file
toml: cookie_secret_filestringFile containing the cookie secret (must be raw binary, exactly 16, 24, or 32 bytes). Use dd if=/dev/urandom bs=32 count=1 > cookie.secret to generate
flag: --cookie-secure
toml: cookie_secureboolset secure (HTTPS only) cookie flagtrue

Header Options

Flag / Config FieldTypeDescriptionDefault
flag: --basic-auth-password
toml: basic_auth_passwordstringthe password to set when passing the HTTP Basic Auth header
flag: --set-xauthrequest
toml: set_xauthrequestboolset X-Auth-Request-User, X-Auth-Request-Groups, X-Auth-Request-Email and X-Auth-Request-Preferred-Username response headers (useful in Nginx auth_request mode). When used with --pass-access-token, X-Auth-Request-Access-Token is added to response headers.false
flag: --set-authorization-header
toml: set_authorization_headerboolset Authorization Bearer response header (useful in Nginx auth_request mode)false
flag: --set-basic-auth
toml: set_basic_authboolset HTTP Basic Auth information in response (useful in Nginx auth_request mode)false
flag: --skip-auth-strip-headers
toml: skip_auth_strip_headersboolstrips X-Forwarded-* style authentication headers & Authorization header if they would be set by oauth2-proxytrue
flag: --pass-access-token
toml: pass_access_tokenboolpass OAuth access_token to upstream via X-Forwarded-Access-Token header. When used with --set-xauthrequest this adds the X-Auth-Request-Access-Token header to the responsefalse
flag: --pass-authorization-header
toml: pass_authorization_headerboolpass OIDC IDToken to upstream via Authorization Bearer headerfalse
flag: --pass-basic-auth
toml: pass_basic_authboolpass HTTP Basic Auth, X-Forwarded-User, X-Forwarded-Email and X-Forwarded-Preferred-Username information to upstreamtrue
flag: --prefer-email-to-user
toml: prefer_email_to_userboolPrefer to use the Email address as the Username when passing information to upstream. Will only use Username if Email is unavailable, e.g. htaccess authentication. Used in conjunction with --pass-basic-auth and --pass-user-headersfalse
flag: --pass-user-headers
toml: pass_user_headersboolpass X-Forwarded-User, X-Forwarded-Groups, X-Forwarded-Email and X-Forwarded-Preferred-Username information to upstreamtrue

Logging Options

Flag / Config FieldTypeDescriptionDefault
flag: --auth-logging-format
toml: auth_logging_formatstringTemplate for authentication log linessee Logging Configuration
flag: --auth-logging
toml: auth_loggingboolLog authentication attemptstrue
flag: --errors-to-info-log
toml: errors_to_info_logboolredirects error-level logging to default log channel instead of stderrfalse
flag: --exclude-logging-path
toml: exclude_logging_pathsstringcomma separated list of paths to exclude from logging, e.g. "/ping,/path2""" (no paths excluded)
flag: --logging-compress
toml: logging_compressboolShould rotated log files be compressed using gzipfalse
flag: --logging-filename
toml: logging_filenamestringFile to log requests to, empty for stdout"" (stdout)
flag: --logging-local-time
toml: logging_local_timeboolUse local time in log files and backup filenames instead of UTCtrue (local time)
flag: --logging-max-age
toml: logging_max_ageintMaximum number of days to retain old log files7
flag: --logging-max-backups
toml: logging_max_backupsintMaximum number of old log files to retain; 0 to disable0
flag: --logging-max-size
toml: logging_max_sizeintMaximum size in megabytes of the log file before rotation100
flag: --request-id-header
toml: request_id_headerstringRequest header to use as the request ID in loggingX-Request-Id
flag: --request-logging-format
toml: request_logging_formatstringTemplate for request log linessee Logging Configuration
flag: --request-logging
toml: request_loggingboolLog requeststrue
flag: --silence-ping-logging
toml: silence_ping_loggingbooldisable logging of requests to ping & ready endpointsfalse
flag: --standard-logging-format
toml: standard_logging_formatstringTemplate for standard log linessee Logging Configuration
flag: --standard-logging
toml: standard_loggingboolLog standard runtime informationtrue

Page Template Options

Flag / Config FieldTypeDescriptionDefault
flag: --banner
toml: bannerstringcustom (html) banner string. Use "-" to disable default banner.
flag: --custom-sign-in-logo
toml: custom_sign_in_logostringpath or a URL to an custom image for the sign_in page logo. Use "-" to disable default logo.
flag: --custom-templates-dir
toml: custom_templates_dirstringpath to custom html templates
flag: --display-htpasswd-form
toml: display_htpasswd_formbooldisplay username / password login form if an htpasswd file is providedtrue
flag: --footer
toml: footerstringcustom (html) footer string. Use "-" to disable default footer. (Can be used to obfuscate the version)
flag: --show-debug-on-error
toml: show_debug_on_errorboolshow detailed error information on error pages (WARNING: this may contain sensitive information - do not use in production)false

Probe Options

Flag / Config FieldTypeDescriptionDefault
flag: --ping-path
toml: ping_pathstringthe ping endpoint that can be used for basic health checks"/ping"
flag: --ping-user-agent
toml: ping_user_agentstringa User-Agent that can be used for basic health checks"" (don't check user agent)
flag: --ready-path
toml: ready_pathstringthe ready endpoint that can be used for deep health checks"/ready"
flag: --gcp-healthchecks
toml: gcp_healthchecksboolEnable GCP/GKE healthcheck endpoints (deprecated)false

Proxy Options

Flag / Config FieldTypeDescriptionDefault
flag: --allow-query-semicolons
toml: allow_query_semicolonsboolallow the use of semicolons in query args (required for some legacy applications)false
flag: --api-route
toml: api_routesstring | listRequests to these paths must already be authenticated with a cookie, or a JWT if --skip-jwt-bearer-tokens is set. No redirect to login will be done. Return 401 if not. Format: path_regex
flag: --authenticated-emails-file
toml: authenticated_emails_filestringauthenticate against emails via file (one per line)
flag: --bearer-token-login-fallback
toml: bearer_token_login_fallbackboolif --skip-jwt-bearer-tokens is set, if a request includes an invalid JWT (expired, malformed, missing required audiences, etc), fall back to normal login redirect as if the token were not sent at all. If false, respond 403true
flag: --email-domain
toml: email_domainsstring | listauthenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email
flag: --encode-state
toml: encode_stateboolencode the state parameter as UrlEncodedBase64false
flag: --extra-jwt-issuers
toml: extra_jwt_issuersstringif --skip-jwt-bearer-tokens is set, a list of extra JWT issuer=audience (see a token's iss, aud fields) pairs (where the issuer URL has a .well-known/openid-configuration or a .well-known/jwks.json)
flag: --force-https
toml: force_httpsboolenforce https redirectfalse
flag: --force-json-errors
toml: force_json_errorsboolforce JSON errors instead of HTTP error pages or redirectsfalse
flag: --htpasswd-file
toml: htpasswd_filestringadditionally authenticate against a htpasswd file. Entries must be created with htpasswd -B for bcrypt encryption
flag: --htpasswd-user-group
toml: htpasswd_user_groupsstring | listthe groups to be set on sessions for htpasswd users
flag: --proxy-prefix
toml: proxy_prefixstringthe url root path that this proxy should be nested under (e.g. /<oauth2>/sign_in)"/oauth2"
flag: --real-client-ip-header
toml: real_client_ip_headerstringHeader used to determine the real IP of the client, requires --reverse-proxy to be set (one of: X-Forwarded-For, X-Real-IP, X-ProxyUser-IP, X-Envoy-External-Address, or CF-Connecting-IP)X-Real-IP
flag: --redirect-url
toml: redirect_urlstringthe OAuth Redirect URL, e.g. "https://internalapp.yourcompany.com/oauth2/callback"
flag: --relative-redirect-url
toml: relative_redirect_urlboolallow relative OAuth Redirect URL.`false
flag: --reverse-proxy
toml: reverse_proxyboolare we running behind a reverse proxy, controls whether headers like X-Real-IP are accepted and allows X-Forwarded-{Proto,Host,Uri} headers to be used on redirect selectionfalse
flag: --signature-key
toml: signature_keystringGAP-Signature request signature key (algorithm:secretkey)
flag: --skip-auth-preflight
toml: skip_auth_preflightboolwill skip authentication for OPTIONS requestsfalse
flag: --skip-auth-regex
toml: skip_auth_regexstring | list(DEPRECATED for --skip-auth-route) bypass authentication for requests paths that match (may be given multiple times)
flag: --skip-auth-route
toml: skip_auth_routesstring | listbypass authentication for requests that match the method & path. Format: method=path_regex OR method!=path_regex. For all methods: path_regex OR !=path_regex
flag: --skip-jwt-bearer-tokens
toml: skip_jwt_bearer_tokensboolwill skip requests that have verified JWT bearer tokens (the token must have aud that matches this client id or one of the extras from extra-jwt-issuers)false
flag: --skip-provider-button
toml: skip_provider_buttonboolwill skip sign-in-page to directly reach the next step: oauth/startfalse
flag: --ssl-insecure-skip-verify
toml: ssl_insecure_skip_verifyboolskip validation of certificates presented when using HTTPS providersfalse
flag: --trusted-ip
toml: trusted_ipsstring | listlist of IPs or CIDR ranges to allow to bypass authentication (may be given multiple times). When combined with --reverse-proxy and optionally --real-client-ip-header this will evaluate the trust of the IP stored in an HTTP header by a reverse proxy rather than the layer-3/4 remote address. WARNING: trusting IPs has inherent security flaws, especially when obtaining the IP address from an HTTP header (reverse-proxy mode). Use this option only if you understand the risks and how to manage them.
flag: --whitelist-domain
toml: whitelist_domainsstring | listallowed domains for redirection after authentication. Prefix domain with a . or a *. to allow subdomains (e.g. .example.com, *.example.com2

Server Options

Flag / Config FieldTypeDescriptionDefault
flag: --http-address
toml: http_addressstring[http://]<addr>:<port> or unix://<path> or fd:<int> (case insensitive) to listen on for HTTP clients. Square brackets are required for ipv6 address, e.g. http://[::1]:4180"127.0.0.1:4180"
flag: --https-address
toml: https_addressstring[https://]<addr>:<port> to listen on for HTTPS clients. Square brackets are required for ipv6 address, e.g. https://[::1]:443":443"
flag: --metrics-address
toml: metrics_addressstringthe address prometheus metrics will be scraped from""
flag: --metrics-secure-address
toml: metrics_secure_addressstringthe address prometheus metrics will be scraped from if using HTTPS""
flag: --metrics-tls-cert-file
toml: metrics_tls_cert_filestringpath to certificate file for secure metrics server""
flag: --metrics-tls-key-file
toml: metrics_tls_key_filestringpath to private key file for secure metrics server""
flag: --tls-cert-file
toml: tls_cert_filestringpath to certificate file
flag: --tls-key-file
toml: tls_key_filestringpath to private key file
flag: --tls-cipher-suite
toml: tls_cipher_suitesstring | listRestricts TLS cipher suites used by server to those listed (e.g. TLS_RSA_WITH_RC4_128_SHA) (may be given multiple times). If not specified, the default Go safe cipher list is used. List of valid cipher suites can be found in the crypto/tls documentation.
flag: --tls-min-version
toml: tls_min_versionstringminimum TLS version that is acceptable, either "TLS1.2" or "TLS1.3""TLS1.2"

Session Options

Flag / Config FieldTypeDescriptionDefault
flag: --session-cookie-minimal
toml: session_cookie_minimalboolstrip OAuth tokens from cookie session stores if they aren't needed (cookie session store only)false
flag: --session-store-type
toml: session_store_typestringSession data storage backend; redis or cookiecookie
flag: --redis-cluster-connection-urls
toml: redis_cluster_connection_urlsstring | listList of Redis cluster connection URLs (e.g. redis://HOST[:PORT]). Used in conjunction with --redis-use-cluster
flag: --redis-connection-url
toml: redis_connection_urlstringURL of redis server for redis session storage (e.g. redis://HOST[:PORT])
flag: --redis-ca-path
toml: redis_ca_pathstringPath to a CA certificates file that should be used when connecting to redis. If not specified, the system cert pool is used instead.
flag: --redis-insecure-skip-tls-verify
toml: redis_insecure_skip_tls_verifyboolskip TLS verification when connecting to Redisfalse
flag: --redis-password
toml: redis_passwordstringRedis password. Applicable for all Redis configurations. Will override any password set in --redis-connection-url
flag: --redis-sentinel-password
toml: redis_sentinel_passwordstringRedis sentinel password. Used only for sentinel connection; any redis node passwords need to use --redis-password
flag: --redis-sentinel-master-name
toml: redis_sentinel_master_namestringRedis sentinel master name. Used in conjunction with --redis-use-sentinel
flag: --redis-sentinel-connection-urls
toml: redis_sentinel_connection_urlsstring | listList of Redis sentinel connection URLs (e.g. redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel
flag: --redis-use-cluster
toml: redis_use_clusterboolConnect to redis cluster. Must set --redis-cluster-connection-urls to use this featurefalse
flag: --redis-use-sentinel
toml: redis_use_sentinelboolConnect to redis via sentinels. Must set --redis-sentinel-master-name and --redis-sentinel-connection-urls to use this featurefalse
flag: --redis-connection-idle-timeout
toml: redis_connection_idle_timeoutintRedis connection idle timeout seconds. If Redis timeout option is set to non-zero, the --redis-connection-idle-timeout must be less than Redis timeout option. Example: if either redis.conf includes timeout 15 or using CONFIG SET timeout 15 the --redis-connection-idle-timeout must be at least --redis-connection-idle-timeout=140

Upstream Options

Flag / Config FieldTypeDescriptionDefault
flag: --flush-interval
toml: flush_intervaldurationperiod between flushing response buffers when streaming responses"1s"
flag: --pass-host-header
toml: pass_host_headerboolpass the request Host Header to upstreamtrue
flag: --proxy-websockets
toml: proxy_websocketsboolenables WebSocket proxyingtrue
flag: --ssl-upstream-insecure-skip-verify
toml: ssl_upstream_insecure_skip_verifyboolskip validation of certificates presented when using HTTPS upstreamsfalse
flag: --disable-keep-alives
toml: disable_keep_alivesbooldisable HTTP keep-alive connections to the upstream serverfalse
flag: --upstream-timeout
toml: upstream_timeoutdurationmaximum amount of time the server will wait for a response from the upstream30s
flag: --upstream
toml: upstreamsstring | listthe http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path

Upstreams Configuration

oauth2-proxy supports having multiple upstreams, and has the option to pass requests on to HTTP(S) servers, unix socket or serve static files from the file system.

To configure HTTP and HTTPS upstreams, provide such a URL in --upstream=URL. The scheme+host portion and the path portion are extracted to configure proxying behavior. When processing incoming requests, the path portion becomes a lookup key for selecting the destination server of the proxied request.

  • Upstream URLs without a trailing slash, like in --upstream=http://service2.internal/foo, will match an incoming request exactly to /foo in https://this.o2p.example.com/foo, and forward the request on to service2.internal, but not match a request to https://this.o2p.example.com/foo/more nor ....com/food.
  • Upstream URLs with a trailing slash, like in --upstream=http://service1.internal/foo/, will match any incoming request to any incoming requests's path starting with /foo/, like /foo/ and /foo/more and /foo/lots/more?etc.

If multiple --upstream URLs' paths match an incoming request, the one with the longest matching path (the most specific match) takes priority over shorter (less specific) ones.

Unix socket upstreams are configured as unix:///path/to/unix.sock.

Static file paths are configured as a file:// URL. file:///var/www/static/ will serve the files from that directory at http://[oauth2-proxy url]/var/www/static/, which may not be what you want. You can provide the path to where the files should be available by adding a fragment to the configured URL. The value of the fragment will then be used to specify which path the files are available at, e.g. file:///var/www/static/#/static/ will make /var/www/static/ available at http://[oauth2-proxy url]/static/.

Multiple upstreams can either be configured by supplying a comma separated list to the --upstream parameter, supplying the parameter multiple times or providing a list in the config file. When multiple upstreams are used routing to them will be based on the path they are set up with.

Environment variables

Every command line argument can be specified as an environment variable by prefixing it with OAUTH2_PROXY_, capitalising it, and replacing hyphens (-) with underscores (_). If the argument can be specified multiple times, the environment variable should be plural (trailing S).

This is particularly useful for storing secrets outside a configuration file or the command line.

For example, the --cookie-secret flag becomes OAUTH2_PROXY_COOKIE_SECRET. If a flag has the type string | list like the --email-domain flag it is available as an environment variable in plural form e.g. OAUTH2_PROXY_EMAIL_DOMAINS

Values for type string | list usually have a plural environment variable name and need to be seperated by , e.g. OAUTH2_PROXY_SKIP_AUTH_ROUTES="GET=^/api/status,POST=^/api/saved_objects/_import"

Please check the type for each config option first.

Logging Configuration

By default, OAuth2 Proxy logs all output to stdout. Logging can be configured to output to a rotating log file using the --logging-filename command.

If logging to a file you can also configure the maximum file size (--logging-max-size), age (--logging-max-age), max backup logs (--logging-max-backups), and if backup logs should be compressed (--logging-compress).

There are three different types of logging: standard, authentication, and HTTP requests. These can each be enabled or disabled with --standard-logging, --auth-logging, and --request-logging.

Each type of logging has its own configurable format and variables. By default, these formats are similar to the Apache Combined Log.

Logging of requests to the /ping endpoint (or using --ping-user-agent) and the /ready endpoint can be disabled with --silence-ping-logging reducing log volume.

Auth Log Format

Authentication logs are logs which are guaranteed to contain a username or email address of a user attempting to authenticate. These logs are output by default in the below format:

<REMOTE_ADDRESS> - <REQUEST ID> - <[email protected]> [2015/03/19 17:20:19] [<STATUS>] <MESSAGE>

The status block will contain one of the below strings:

  • AuthSuccess If a user has authenticated successfully by any method
  • AuthFailure If the user failed to authenticate explicitly
  • AuthError If there was an unexpected error during authentication

If you require a different format than that, you can configure it with the --auth-logging-format flag. The default format is configured as follows:

{{.Client}} - {{.RequestID}} - {{.Username}} [{{.Timestamp}}] [{{.Status}}] {{.Message}}

Available variables for auth logging:

VariableExampleDescription
Client74.125.224.72The client/remote IP address. Will use the X-Real-IP header it if exists & reverse-proxy is set to true.
Hostdomain.comThe value of the Host header.
MessageAuthenticated via OAuth2The details of the auth attempt.
ProtocolHTTP/1.0The request protocol.
RequestID00010203-0405-4607-8809-0a0b0c0d0e0fThe request ID pulled from the --request-id-header. Random UUID if empty
RequestMethodGETThe request method.
Timestamp2015/03/19 17:20:19The date and time of the logging event.
UserAgent-The full user agent as reported by the requesting client.
Username[email protected]The email or username of the auth request.
StatusAuthSuccessThe status of the auth request. See above for details.

Request Log Format

HTTP request logs will output by default in the below format:

<REMOTE_ADDRESS> - <REQUEST ID> - <[email protected]> [2015/03/19 17:20:19] <HOST_HEADER> GET <UPSTREAM_HOST> "/path/" HTTP/1.1 "<USER_AGENT>" <RESPONSE_CODE> <RESPONSE_BYTES> <REQUEST_DURATION>

If you require a different format than that, you can configure it with the --request-logging-format flag. The default format is configured as follows:

{{.Client}} - {{.RequestID}} - {{.Username}} [{{.Timestamp}}] {{.Host}} {{.RequestMethod}} {{.Upstream}} {{.RequestURI}} {{.Protocol}} {{.UserAgent}} {{.StatusCode}} {{.ResponseSize}} {{.RequestDuration}}

Available variables for request logging:

VariableExampleDescription
Client74.125.224.72The client/remote IP address. Will use the X-Real-IP header it if exists & reverse-proxy is set to true.
Hostdomain.comThe value of the Host header.
ProtocolHTTP/1.0The request protocol.
RequestDuration0.001The time in seconds that a request took to process.
RequestID00010203-0405-4607-8809-0a0b0c0d0e0fThe request ID pulled from the --request-id-header. Random UUID if empty
RequestMethodGETThe request method.
RequestURI"/oauth2/auth"The URI path of the request.
ResponseSize12The size in bytes of the response.
StatusCode200The HTTP status code of the response.
Timestamp2015/03/19 17:20:19The date and time of the logging event.
Upstream-The upstream data of the HTTP request.
UserAgent-The full user agent as reported by the requesting client.
Username[email protected]The email or username of the auth request.

Standard Log Format

All other logging that is not covered by the above two types of logging will be output in this standard logging format. This includes configuration information at startup and errors that occur outside of a session. The default format is below:

[2015/03/19 17:20:19] [main.go:40] <MESSAGE>

If you require a different format than that, you can configure it with the --standard-logging-format flag. The default format is configured as follows:

[{{.Timestamp}}] [{{.File}}] {{.Message}}

Available variables for standard logging:

VariableExampleDescription
Timestamp2015/03/19 17:20:19The date and time of the logging event.
Filemain.go:40The file and line number of the logging statement.
MessageHTTP: listening on 127.0.0.1:4180The details of the log statement.

Footnotes

  1. The following providers support --cookie-refresh: ADFS, Azure, GitLab, Google, Keycloak and all other Identity Providers which support the full OIDC specification

  2. When using the whitelist-domain option, any domain prefixed with a . or a *. will allow any subdomain of the specified domain as a valid redirect URL. By default, only empty ports are allowed. This translates to allowing the default port of the URL's protocol (80 for HTTP, 443 for HTTPS, etc.) since browsers omit them. To allow only a specific port, add it to the whitelisted domain: example.com:8080. To allow any port, use *: example.com:*.