From b93b4176ad95d261741399bf16cae2aa2cf69a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slobodan=20Adamovi=C4=87?= Date: Tue, 29 Oct 2024 16:45:52 +0100 Subject: [PATCH] [8.15] Fix lingering license warning header in IP filter (#115510) (#115840) * Fix lingering license warning header in IP filter (#115510) Fixes another place where we do not stash thread context that causes the license warning header to persist in the thread context across Netty worker threads. Resolves #114865 Relates to #107573 --- docs/changelog/115510.yaml | 6 ++++++ .../org/elasticsearch/license/LicensingTests.java | 2 ++ .../netty4/IpFilterRemoteAddressFilter.java | 10 ++++++++-- .../netty4/SecurityNetty4ServerTransport.java | 2 +- .../netty4/IpFilterRemoteAddressFilterTests.java | 12 +++++++++--- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 docs/changelog/115510.yaml diff --git a/docs/changelog/115510.yaml b/docs/changelog/115510.yaml new file mode 100644 index 0000000000000..1e71270e18f97 --- /dev/null +++ b/docs/changelog/115510.yaml @@ -0,0 +1,6 @@ +pr: 115510 +summary: Fix lingering license warning header in IP filter +area: License +type: bug +issues: + - 114865 diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/license/LicensingTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/license/LicensingTests.java index 27b85888864c9..0785c92446c2a 100644 --- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/license/LicensingTests.java +++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/license/LicensingTests.java @@ -41,6 +41,7 @@ import org.elasticsearch.xpack.security.LocalStateSecurity; import org.hamcrest.Matchers; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import java.nio.file.Files; @@ -241,6 +242,7 @@ public void testNoWarningHeaderWhenAuthenticationFailed() throws Exception { Header[] headers = null; try { getRestClient().performRequest(request); + Assert.fail("expected response exception"); } catch (ResponseException e) { headers = e.getResponse().getHeaders(); List afterWarningHeaders = getWarningHeaders(headers); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilter.java index 9a3c9c847d131..55a3dbcdfde95 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/IpFilterRemoteAddressFilter.java @@ -10,6 +10,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.ipfilter.AbstractRemoteAddressFilter; +import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.xpack.security.transport.filter.IPFilter; import java.net.InetSocketAddress; @@ -19,16 +20,21 @@ class IpFilterRemoteAddressFilter extends AbstractRemoteAddressFilter