Overview
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).
Generating a Cookie Secret
To generate a strong cookie secret use one of the below commands:
- Python
- Bash
- OpenSSL
- PowerShell
- Terraform
python -c 'import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())'
dd if=/dev/urandom bs=32 count=1 2>/dev/null | base64 | tr -d -- '\n' | tr -- '+/' '-_' ; echo
openssl rand -base64 32 | tr -- '+/' '-_'
# 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("/","_")
# 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 = "-_"
}
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
| Flag | Description |
|---|---|
--config | path to config file |
--version | print version string |
General Provider Options
Provider specific options can be found on their respective subpages.
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --acr-valuestoml: acr_values | string | optional, see docs | "" |
flag: --allowed-grouptoml: allowed_groups | string | list | Restrict 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-prompttoml: approval_prompt | string | OAuth approval_prompt | "force" |
flag: --backend-logout-urltoml: backend_logout_url | string | URL 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-idtoml: client_id | string | the OAuth Client ID, e.g. "123456.apps.googleusercontent.com" | |
flag: --client-secret-filetoml: client_secret_file | string | the file with OAuth Client Secret | |
flag: --client-secrettoml: client_secret | string | the OAuth Client Secret | |
flag: --code-challenge-methodtoml: code_challenge_method | string | use PKCE code challenges with the specified method. Either 'plain' or 'S256' (recommended) | |
flag: --insecure-oidc-allow-unverified-emailtoml: insecure_oidc_allow_unverified_email | bool | don't fail if an email address in an id_token is not verified | false |
flag: --insecure-oidc-skip-issuer-verificationtoml: insecure_oidc_skip_issuer_verification | bool | allow the OIDC issuer URL to differ from the expected (currently required for Azure multi-tenant compatibility) | false |
flag: --insecure-oidc-skip-noncetoml: insecure_oidc_skip_nonce | bool | skip verifying the OIDC ID Token's nonce claim | true |
flag: --jwt-key-filetoml: jwt_key_file | string | path 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-keytoml: jwt_key | string | private 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-urltoml: login_url | string | Authentication endpoint | |
flag: --oidc-audience-claimtoml: oidc_audience_claims | string | which OIDC claim contains the audience | "aud" |
flag: --oidc-email-claimtoml: oidc_email_claim | string | which OIDC claim contains the user's email | "email" |
flag: --oidc-extra-audiencetoml: oidc_extra_audiences | string | list | additional audiences which are allowed to pass verification | "[]" |
flag: --oidc-groups-claimtoml: oidc_groups_claim | string | which OIDC claim contains the user groups | "groups" |
flag: --oidc-issuer-urltoml: oidc_issuer_url | string | the OpenID Connect issuer URL, e.g. "https://accounts.google.com" | |
flag: --oidc-jwks-urltoml: oidc_jwks_url | string | OIDC JWKS URI for token verification; required if OIDC discovery is disabled | |
flag: --profile-urltoml: profile_url | string | Profile access endpoint | |
flag: --prompttoml: prompt | string | OIDC prompt; if present, approval-prompt is ignored | "" |
flag: --provider-ca-filetoml: provider_ca_files | string | list | Paths 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-nametoml: provider_display_name | string | Override the provider's name with the given string; used for the sign-in page | (depends on provider) |
flag: --providertoml: provider | string | OAuth provider | |
flag: --pubjwk-urltoml: pubjwk_url | string | JWK pubkey access endpoint: required by login.gov | |
flag: --redeem-urltoml: redeem_url | string | Token redemption endpoint | |
flag: --scopetoml: scope | string | OAuth 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-urltoml: skip_claims_from_profile_url | bool | skip request to Profile URL for resolving claims not present in id_token | false |
flag: --skip-oidc-discoverytoml: skip_oidc_discovery | bool | bypass OIDC endpoint discovery. --login-url, --redeem-url and --oidc-jwks-url must be configured in this case | false |
flag: --use-system-trust-storetoml: use_system_trust_store | bool | Determines 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-urltoml: validate_url | string | Access token validation endpoint |
Cookie Options
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --cookie-csrf-expiretoml: cookie_csrf_expire | duration | expire timeframe for CSRF cookie | 15m |
flag: --cookie-csrf-per-requesttoml: cookie_csrf_per_request | bool | Enable having different CSRF cookies per request, making it possible to have parallel requests. | false |
flag: --cookie-domaintoml: cookie_domains | string | list | Optional 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-expiretoml: cookie_expire | duration | expire timeframe for cookie. If set to 0, cookie becomes a session-cookie which will expire when the browser is closed. | 168h0m0s |
flag: --cookie-httponlytoml: cookie_httponly | bool | set HttpOnly cookie flag | true |
flag: --cookie-nametoml: cookie_name | string | the 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-pathtoml: cookie_path | string | an optional cookie path to force cookies to (e.g. /poc/) | "/" |
flag: --cookie-refreshtoml: cookie_refresh | duration | refresh the cookie after this duration; 0 to disable; not supported by all providers 1 | |
flag: --cookie-samesitetoml: cookie_samesite | string | set SameSite cookie attribute ("lax", "strict", "none", or ""). | "" |
flag: --cookie-secrettoml: cookie_secret | string | the seed string for secure cookies (optionally base64 encoded) | |
flag: --cookie-securetoml: cookie_secure | bool | set secure (HTTPS only) cookie flag | true |
Header Options
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --basic-auth-passwordtoml: basic_auth_password | string | the password to set when passing the HTTP Basic Auth header | |
flag: --set-xauthrequesttoml: set_xauthrequest | bool | set 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-headertoml: set_authorization_header | bool | set Authorization Bearer response header (useful in Nginx auth_request mode) | false |
flag: --set-basic-authtoml: set_basic_auth | bool | set HTTP Basic Auth information in response (useful in Nginx auth_request mode) | false |
flag: --skip-auth-strip-headerstoml: skip_auth_strip_headers | bool | strips X-Forwarded-* style authentication headers & Authorization header if they would be set by oauth2-proxy | true |
flag: --pass-access-tokentoml: pass_access_token | bool | pass 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 response | false |
flag: --pass-authorization-headertoml: pass_authorization_header | bool | pass OIDC IDToken to upstream via Authorization Bearer header | false |
flag: --pass-basic-authtoml: pass_basic_auth | bool | pass HTTP Basic Auth, X-Forwarded-User, X-Forwarded-Email and X-Forwarded-Preferred-Username information to upstream | true |
flag: --prefer-email-to-usertoml: prefer_email_to_user | bool | Prefer 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-headers | false |
flag: --pass-user-headerstoml: pass_user_headers | bool | pass X-Forwarded-User, X-Forwarded-Groups, X-Forwarded-Email and X-Forwarded-Preferred-Username information to upstream | true |
Logging Options
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --auth-logging-formattoml: auth_logging_format | string | Template for authentication log lines | see Logging Configuration |
flag: --auth-loggingtoml: auth_logging | bool | Log authentication attempts | true |
flag: --errors-to-info-logtoml: errors_to_info_log | bool | redirects error-level logging to default log channel instead of stderr | false |
flag: --exclude-logging-pathtoml: exclude_logging_paths | string | comma separated list of paths to exclude from logging, e.g. "/ping,/path2" | "" (no paths excluded) |
flag: --logging-compresstoml: logging_compress | bool | Should rotated log files be compressed using gzip | false |
flag: --logging-filenametoml: logging_filename | string | File to log requests to, empty for stdout | "" (stdout) |
flag: --logging-local-timetoml: logging_local_time | bool | Use local time in log files and backup filenames instead of UTC | true (local time) |
flag: --logging-max-agetoml: logging_max_age | int | Maximum number of days to retain old log files | 7 |
flag: --logging-max-backupstoml: logging_max_backups | int | Maximum number of old log files to retain; 0 to disable | 0 |
flag: --logging-max-sizetoml: logging_max_size | int | Maximum size in megabytes of the log file before rotation | 100 |
flag: --request-id-headertoml: request_id_header | string | Request header to use as the request ID in logging | X-Request-Id |
flag: --request-logging-formattoml: request_logging_format | string | Template for request log lines | see Logging Configuration |
flag: --request-loggingtoml: request_logging | bool | Log requests | true |
flag: --silence-ping-loggingtoml: silence_ping_logging | bool | disable logging of requests to ping & ready endpoints | false |
flag: --standard-logging-formattoml: standard_logging_format | string | Template for standard log lines | see Logging Configuration |
flag: --standard-loggingtoml: standard_logging | bool | Log standard runtime information | true |
Page Template Options
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --bannertoml: banner | string | custom (html) banner string. Use "-" to disable default banner. | |
flag: --custom-sign-in-logotoml: custom_sign_in_logo | string | path or a URL to an custom image for the sign_in page logo. Use "-" to disable default logo. | |
flag: --custom-templates-dirtoml: custom_templates_dir | string | path to custom html templates | |
flag: --display-htpasswd-formtoml: display_htpasswd_form | bool | display username / password login form if an htpasswd file is provided | true |
flag: --footertoml: footer | string | custom (html) footer string. Use "-" to disable default footer. (Can be used to obfuscate the version) | |
flag: --show-debug-on-errortoml: show_debug_on_error | bool | show detailed error information on error pages (WARNING: this may contain sensitive information - do not use in production) | false |
Probe Options
| Flag / Config Field | Type | Description | Default |
|---|---|---|---|
flag: --ping-pathtoml: ping_path | string | the ping endpoint that can be used for basic health checks | "/ping" |
flag: --ping-user-agenttoml: ping_user_agent | string | a User-Agent that can be used for basic health checks | "" (don't check user agent) |
flag: --ready-pathtoml: ready_path | string | the ready endpoint that can be used for deep health checks | "/ready" |
flag: --gcp-healthcheckstoml: gcp_healthchecks | bool | Enable GCP/GKE healthcheck endpoints (deprecated) | false |