1
<#import "/templates/guide.adoc" as tmpl>
2
<#import "/templates/kc.adoc" as kc>
3
<#import "/templates/links.adoc" as links>
6
title="Configuring outgoing HTTP requests"
7
summary="How to configure the client used for outgoing HTTP requests."
10
{project_name} often needs to make requests to the applications and services that it secures. {project_name} manages these outgoing connections using an HTTP client. This {section} shows how to configure the client, connection pool, proxy environment settings, timeouts, and more.
12
== Client Configuration Command
13
The HTTP client that {project_name} uses for outgoing communication is highly configurable. To configure the {project_name} outgoing HTTP client, enter this command:
15
<@kc.start parameters="--spi-connections-http-client-default-<configurationoption>=<value>"/>
17
The following are the command options:
19
*establish-connection-timeout-millis*::
20
Maximum time in milliseconds until establishing a connection times out. Default: Not set.
22
*socket-timeout-millis*::
23
Maximum time of inactivity between two data packets until a socket connection times out, in milliseconds. Default: 5000ms
25
*connection-pool-size*::
26
Size of the connection pool for outgoing connections. Default: 128.
28
*max-pooled-per-route*::
29
How many connections can be pooled per host. Default: 64.
31
*connection-ttl-millis*::
32
Maximum connection time to live in milliseconds. Default: Not set.
34
*max-connection-idle-time-millis*::
35
Maximum time an idle connection stays in the connection pool, in milliseconds. Idle connections will be removed from the pool by a background cleaner thread. Set this option to -1 to disable this check. Default: 900000.
38
Enable or disable caching of cookies. Default: true.
41
File path to a Java keystore file. This keystore contains client certificates for two-way SSL.
43
*client-keystore-password*::
44
Password for the client keystore. REQUIRED, when `client-keystore` is set.
46
*client-key-password*::
47
Password for the private key of the client. REQUIRED, when client-keystore is set.
50
Specify proxy configurations for outgoing HTTP requests. For more details, see <<Proxy mappings for outgoing HTTP requests>>.
52
*disable-trust-manager*::
53
If an outgoing request requires HTTPS and this configuration option is set to true, you do not have to specify a truststore. This setting should be used only during development and *never in production* because it will disable verification of SSL certificates. Default: false.
55
== Proxy mappings for outgoing HTTP requests
56
To configure outgoing requests to use a proxy, you can use the following standard proxy environment variables to configure the proxy mappings: `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`.
58
* The `HTTP_PROXY` and `HTTPS_PROXY` variables represent the proxy server that is used for outgoing HTTP requests. {project_name} does not differentiate between the two variables. If you define both variables, `HTTPS_PROXY` takes precedence regardless of the actual scheme that the proxy server uses.
60
* The `NO_PROXY` variable defines a comma separated list of hostnames that should not use the proxy. For each hostname that you specify, all its subdomains are also excluded from using proxy.
62
The environment variables can be lowercase or uppercase. Lowercase takes precedence. For example, if you define both `HTTP_PROXY` and `http_proxy`, `http_proxy` is used.
64
.Example of proxy mappings and environment variables
67
HTTPS_PROXY=https://www-proxy.acme.com:8080
68
NO_PROXY=google.com,login.facebook.com
70
In this example, the following results occur:
72
* All outgoing requests use the proxy `https://www-proxy.acme.com:8080` except for requests to google.com or any subdomain of google.com, such as auth.google.com.
73
* login.facebook.com and all its subdomains do not use the defined proxy, but groups.facebook.com uses the proxy because it is not a subdomain of login.facebook.com.
75
== Proxy mappings using regular expressions
77
An alternative to using environment variables for proxy mappings is to configure a comma-delimited list of proxy-mappings for outgoing requests sent by {project_name}. A proxy-mapping consists of a regex-based hostname pattern and a proxy-uri, using the format `hostname-pattern;proxy-uri`.
79
For example, consider the following regex:
83
.*\.(google|googleapis)\.com
86
You apply a regex-based hostname pattern by entering this command:
88
<@kc.start parameters="--spi-connections-http-client-default-proxy-mappings=\"\'*\\\\\\.(google|googleapis)\\\\\\.com;http://www-proxy.acme.com:8080\'\""/>
90
To determine the proxy for the outgoing HTTP request, the following occurs:
92
* The target hostname is matched against all configured hostname patterns.
93
* The proxy-uri of the first matching pattern is used.
94
* If no configured pattern matches the hostname, no proxy is used.
96
When your proxy server requires authentication, include the credentials of the proxy user in the format `username:password@`. For example:
100
.*\.(google|googleapis)\.com;http://proxyuser:password@www-proxy.acme.com:8080
103
.Example of regular expressions for proxy-mapping:
106
# All requests to Google APIs use http://www-proxy.acme.com:8080 as proxy
107
.*\.(google|googleapis)\.com;http://www-proxy.acme.com:8080
109
# All requests to internal systems use no proxy
110
.*\.acme\.com;NO_PROXY
112
# All other requests use http://fallback:8080 as proxy
113
.*;http://fallback:8080
116
In this example, the following occurs:
118
* The special value NO_PROXY for the proxy-uri is used, which means that no proxy is used for hosts matching the associated hostname pattern.
119
* A catch-all pattern ends the proxy-mappings, providing a default proxy for all outgoing requests.
121
== Configuring trusted certificates for TLS connections
123
See <@links.server id="keycloak-truststore"/> for how
124
to configure a {project_name} Truststore so that {project_name} is able to perform outgoing requests using TLS.