Skip to content

Commit

Permalink
Add setting for tcp_keepalive for oidc back-channel (#87868)
Browse files Browse the repository at this point in the history
This PR adds a new setting to enable tcp keepalive probes for the
connections used by the oidc back-channel communication. It defaults to
true as tcp keepalive is generally useful for ES.

Relates: #87773
  • Loading branch information
ywangd authored Jul 7, 2022
1 parent 2ad2720 commit 36336fe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/87868.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 87868
summary: Add setting for `tcp_keepalive` for oidc back-channel
area: Security
type: enhancement
issues: []
7 changes: 7 additions & 0 deletions docs/reference/settings/security-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,13 @@ connections allowed per endpoint.
Defaults to `200`.
// end::oidc-http-max-endpoint-connections-tag[]

// tag::oidc-http-tcp-keepalive-tag[]
`http.tcp.keep_alive` {ess-icon}::
(<<static-cluster-setting,Static>>)
Whether to enable TCP keepalives on HTTP connections used for back-channel communication
to the OpenID Connect Provider endpoints. Defaults to `true`.
// end::oidc-http-tcp-keepalive-tag[]

// tag::oidc-http-connection-pool-ttl-tag[]
`http.connection_pool_ttl` {ess-icon}::
(<<static-cluster-setting,Static>>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ private OpenIdConnectRealmSettings() {}
key -> Setting.intSetting(key, 200, Setting.Property.NodeScope)
);

public static final Setting.AffixSetting<Boolean> HTTP_TCP_KEEP_ALIVE = Setting.affixKeySetting(
RealmSettings.realmSettingPrefix(TYPE),
"http.tcp.keep_alive",
key -> Setting.boolSetting(key, true, Setting.Property.NodeScope)
);

public static final Setting.AffixSetting<TimeValue> HTTP_CONNECTION_POOL_TTL = Setting.affixKeySetting(
RealmSettings.realmSettingPrefix(TYPE),
"http.connection_pool_ttl",
Expand Down Expand Up @@ -314,6 +320,7 @@ public static Set<Setting.AffixSetting<?>> getSettings() {
HTTP_SOCKET_TIMEOUT,
HTTP_MAX_CONNECTIONS,
HTTP_MAX_ENDPOINT_CONNECTIONS,
HTTP_TCP_KEEP_ALIVE,
HTTP_CONNECTION_POOL_TTL,
HTTP_PROXY_HOST,
HTTP_PROXY_PORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.nio.conn.NoopIOSessionStrategy;
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
Expand Down Expand Up @@ -125,6 +126,7 @@
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_PROXY_PORT;
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_PROXY_SCHEME;
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_SOCKET_TIMEOUT;
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_TCP_KEEP_ALIVE;

/**
* Handles an OpenID Connect Authentication response as received by the facilitator. In the case of an implicit flow, validates
Expand Down Expand Up @@ -691,7 +693,9 @@ private CloseableHttpAsyncClient createHttpClient() {
try {
SpecialPermission.check();
return AccessController.doPrivileged((PrivilegedExceptionAction<CloseableHttpAsyncClient>) () -> {
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
IOReactorConfig.custom().setSoKeepAlive(realmConfig.getSetting(HTTP_TCP_KEEP_ALIVE)).build()
);
final String sslKey = RealmSettings.realmSslPrefix(realmConfig.identifier());
final SslConfiguration sslConfiguration = sslService.getSSLConfiguration(sslKey);
final SSLContext clientContext = sslService.sslContext(sslConfiguration);
Expand Down

0 comments on commit 36336fe

Please sign in to comment.