Skip to content

Commit 36336fe

Browse files
authored
Add setting for tcp_keepalive for oidc back-channel (#87868)
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
1 parent 2ad2720 commit 36336fe

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

docs/changelog/87868.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 87868
2+
summary: Add setting for `tcp_keepalive` for oidc back-channel
3+
area: Security
4+
type: enhancement
5+
issues: []

docs/reference/settings/security-settings.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,13 @@ connections allowed per endpoint.
18581858
Defaults to `200`.
18591859
// end::oidc-http-max-endpoint-connections-tag[]
18601860

1861+
// tag::oidc-http-tcp-keepalive-tag[]
1862+
`http.tcp.keep_alive` {ess-icon}::
1863+
(<<static-cluster-setting,Static>>)
1864+
Whether to enable TCP keepalives on HTTP connections used for back-channel communication
1865+
to the OpenID Connect Provider endpoints. Defaults to `true`.
1866+
// end::oidc-http-tcp-keepalive-tag[]
1867+
18611868
// tag::oidc-http-connection-pool-ttl-tag[]
18621869
`http.connection_pool_ttl` {ess-icon}::
18631870
(<<static-cluster-setting,Static>>)

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/oidc/OpenIdConnectRealmSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ private OpenIdConnectRealmSettings() {}
214214
key -> Setting.intSetting(key, 200, Setting.Property.NodeScope)
215215
);
216216

217+
public static final Setting.AffixSetting<Boolean> HTTP_TCP_KEEP_ALIVE = Setting.affixKeySetting(
218+
RealmSettings.realmSettingPrefix(TYPE),
219+
"http.tcp.keep_alive",
220+
key -> Setting.boolSetting(key, true, Setting.Property.NodeScope)
221+
);
222+
217223
public static final Setting.AffixSetting<TimeValue> HTTP_CONNECTION_POOL_TTL = Setting.affixKeySetting(
218224
RealmSettings.realmSettingPrefix(TYPE),
219225
"http.connection_pool_ttl",
@@ -314,6 +320,7 @@ public static Set<Setting.AffixSetting<?>> getSettings() {
314320
HTTP_SOCKET_TIMEOUT,
315321
HTTP_MAX_CONNECTIONS,
316322
HTTP_MAX_ENDPOINT_CONNECTIONS,
323+
HTTP_TCP_KEEP_ALIVE,
317324
HTTP_CONNECTION_POOL_TTL,
318325
HTTP_PROXY_HOST,
319326
HTTP_PROXY_PORT,

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.apache.http.impl.nio.client.HttpAsyncClients;
6868
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
6969
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
70+
import org.apache.http.impl.nio.reactor.IOReactorConfig;
7071
import org.apache.http.message.BasicNameValuePair;
7172
import org.apache.http.nio.conn.NoopIOSessionStrategy;
7273
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
@@ -125,6 +126,7 @@
125126
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_PROXY_PORT;
126127
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_PROXY_SCHEME;
127128
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_SOCKET_TIMEOUT;
129+
import static org.elasticsearch.xpack.core.security.authc.oidc.OpenIdConnectRealmSettings.HTTP_TCP_KEEP_ALIVE;
128130

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

0 commit comments

Comments
 (0)