This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new a99c10d4b40b CAMEL-26832: Support verified SPIFFE identity across HTTP
transports (#29820)
a99c10d4b40b is described below
commit a99c10d4b40bc9bd588a36f7d1e0298763279dd9
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Nov 16 14:31:58 2026 +0100
CAMEL-26832: Support verified SPIFFE identity across HTTP transports
(#29820)
SPIFFE route authorization currently depends on a transport-specific Netty
context. Add a transport-neutral TLS peer certificate provider on the Exchange
and populate it from authenticated transport state in servlet/Jetty, Netty
HTTP, Undertow and Vert.x platform HTTP consumers.
A present provider is authoritative: unverified peers fail closed even when
a legacy session header is present. The legacy Netty context fallback remains
available when no provider is supplied. Forwarded certificate/identity headers
do not establish verified TLS state. Includes the migration note, transport
support documentation and regression coverage for verified/unverified peers
plus the existing real-TLS Netty tests.
_Codex on behalf of oscerd_
Co-authored-by: Codex <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
.../camel/catalog/docs/spiffe-component.adoc | 62 +++++++--
.../org/apache/camel/http/common/HttpMessage.java | 11 ++
.../camel/http/common/HttpMessageTlsPeerTest.java | 89 ++++++++++++
.../http/handlers/HttpServerChannelHandler.java | 8 ++
...NettyHttpSSLServerHostnameVerificationTest.java | 14 ++
.../component/netty/http/NettyHttpSSLTest.java | 8 ++
.../netty/http/handlers/NettyHttpTlsPeerTest.java | 88 ++++++++++++
.../http/vertx/VertxPlatformHttpSupport.java | 6 +
.../platform/http/vertx/VertxTlsPeerTest.java | 73 ++++++++++
.../src/main/docs/spiffe-component.adoc | 62 +++++++--
.../camel/component/spiffe/SpiffePeerIdentity.java | 22 ++-
.../component/spiffe/SpiffeSecurityPolicyTest.java | 79 +++++++++++
.../camel/component/undertow/UndertowConsumer.java | 9 ++
.../component/undertow/UndertowTlsPeerTest.java | 82 +++++++++++
.../camel/spi/TlsPeerCertificateProvider.java | 46 +++++++
.../camel/support/TlsPeerCertificateSupport.java | 90 ++++++++++++
.../support/TlsPeerCertificateSupportTest.java | 153 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 ++
18 files changed, 889 insertions(+), 21 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
index c5e571cc5a82..d14b43034d9a 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
@@ -390,14 +390,41 @@ A few things about the server side decide whether, and
for which peers, this pol
accept (or use `acceptAnySpiffeId` and let each policy narrow it), otherwise
the handshake turns a peer away
before its route could have authorized it.
-Only camel-netty and camel-netty-http put the `SSLSession` on the message
today, as the `CamelNettySSLSession`
-header. Behind platform-http, jetty, undertow or servlet there is no session
on the exchange, so the policy has no
-verified peer certificate to read and denies everything.
+The consumer must expose the peer authenticated by its own TLS connection.
Supported sources are:
+
+[cols="1,3"]
+|===
+| Consumer | Authenticated peer source
+
+| `netty-http`
+| The channel's `SslHandler` session.
+
+| `servlet`, `jetty`
+| The secure servlet request's container-authenticated
`jakarta.servlet.request.X509Certificate` attribute.
+
+| `undertow`
+| The real TLS session supplied by the connection's `SSLSessionInfo`.
Forwarded SSL information without a TLS session is rejected.
+
+| `platform-http` with the Vert.x engine
+| The server request's actual `sslSession()`.
+
+| `netty`
+| The existing `CamelNettySSLSession` message header remains supported.
+
+| Other engines and TLS-terminating reverse proxies
+| No automatic peer authentication support. The proxy's connection identity
does not prove the original client's identity.
+|===
+
+These adapters publish a `org.apache.camel.spi.TlsPeerCertificateProvider` in
the `CamelTlsPeerCertificates`
+exchange property. This typed contract is for trusted consumers integrating
actual authenticated server TLS state. It
+is never populated from HTTP identity or certificate headers. A TLS connection
without a client certificate is
+recorded as an unverified peer, which fails closed; a plain connection leaves
the property absent, and the policy then
+falls back to the session header. Custom consumers must uphold the same
provenance contract.
====
-The peer SPIFFE ID is taken from the *verified* TLS peer certificate the
consumer put on the exchange - the
-`CamelNettySSLSession` header for camel-netty-http - and never from a message
header a sender could set (see the
-Security notes below). A peer that is not on the `acceptedSpiffeIds`
allow-list, or that presents no verified SVID at
+The peer SPIFFE ID is taken from the *verified* TLS peer certificate the
consumer put on the exchange through the
+typed TLS peer property (or the legacy Netty session header). Sender-supplied
identity and certificate headers are
+never used (see the Security notes below). A peer that is not on the
`acceptedSpiffeIds` allow-list, or that presents no verified SVID at
all, is denied with a `CamelAuthorizationException`, so the route stops and
the regular `onException` machinery applies.
Set exactly one of:
@@ -454,8 +481,25 @@ YAML::
====
For a TLS consumer that exposes the `SSLSession` under a different header
name, set `sslSessionHeader` accordingly. The
-identity is always read from the verified `SSLSession`, never from a
certificate object placed on a message header -
-nothing would prove the TLS layer had verified such a certificate.
+legacy session header is used only when the typed TLS peer property is absent.
A present but unverified or invalid
+typed property fails closed; a different session header cannot override it.
Certificate objects and identity strings
+in message headers are never a substitute for authenticated TLS state.
+
+For OpenFGA composition, bind the user expression to the same verified
exchange property. The OpenFGA model must
+define the corresponding `workload` type and tuples for those SPIFFE IDs:
+
+[source,java]
+----
+openFgaPolicy.setUser("workload:${exchangeProperty.CamelSpiffePeerId}");
+from("platform-http:/documents") // Vert.x engine with mutual TLS configured
on its server
+ .policy(spiffePolicy)
+ .policy(openFgaPolicy)
+ .to("direct:documents");
+----
+
+`X-Forwarded-Client-Cert`, `X-SPIFFE-ID`, and similar proxy headers are not
accepted. Terminate mutually
+authenticated TLS at the Camel consumer to authorize its direct peer.
Authenticate an original client through an
+independent validated credential when TLS terminates at a reverse proxy; the
proxy's own SVID identifies the proxy.
include::spring-boot:partial$starter.adoc[]
@@ -478,7 +522,7 @@ include::spring-boot:partial$starter.adoc[]
`acceptAnySpiffeId` accepts any SVID that chains to the trust bundle, which
authenticates the trust domain but not
the peer.
* *The authorization decision is made on the certificate, not a header.*
`SpiffeSecurityPolicy` reads the peer SPIFFE
- ID from the verified TLS peer certificate (the `CamelNettySSLSession` header
for camel-netty-http), so a sender
+ ID from the verified TLS peer certificate in trusted consumer state (with
the legacy Netty session fallback), so a sender
cannot assert an identity by setting a header - and it requires mutual TLS,
failing closed when the peer presented
no verified certificate. The verified id it publishes is the
`CamelSpiffePeerId` exchange *property*, never a header,
so it likewise cannot be injected by an inbound message.
diff --git
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
index 3871a36118ae..ea84ec977051 100644
---
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
+++
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpMessage.java
@@ -17,6 +17,7 @@
package org.apache.camel.http.common;
import java.io.IOException;
+import java.security.cert.X509Certificate;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -24,6 +25,7 @@ import jakarta.servlet.http.HttpServletResponse;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.support.DefaultMessage;
+import org.apache.camel.support.TlsPeerCertificateSupport;
import org.apache.camel.util.ObjectHelper;
public class HttpMessage extends DefaultMessage {
@@ -59,6 +61,15 @@ public class HttpMessage extends DefaultMessage {
this.request = request;
this.response = response;
+ // Servlet containers expose the chain authenticated for this request
as an attribute, not an HTTP header.
+ if (request.isSecure()) {
+ Object certificates =
request.getAttribute("jakarta.servlet.request.X509Certificate");
+
TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange,
+ certificates instanceof X509Certificate[] chain ? chain :
null);
+ } else {
+ TlsPeerCertificateSupport.clear(exchange);
+ }
+
// Check the setting of exchange
Boolean flag = exchange.getProperty(Exchange.SKIP_WWW_FORM_URLENCODED,
Boolean.class);
if (flag != null && flag) {
diff --git
a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpMessageTlsPeerTest.java
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpMessageTlsPeerTest.java
new file mode 100644
index 000000000000..a4ea800948b9
--- /dev/null
+++
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpMessageTlsPeerTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.http.common;
+
+import java.security.cert.X509Certificate;
+
+import jakarta.servlet.http.HttpServletRequest;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class HttpMessageTlsPeerTest {
+
+ private void initialize(Exchange exchange, HttpServletRequest request) {
+ var endpoint = mock(HttpCommonEndpoint.class);
+ when(endpoint.getHttpBinding()).thenReturn(mock(HttpBinding.class));
+ new HttpMessage(exchange, endpoint, request, null);
+ }
+
+ @Test
+ void publishesTheSecureContainerAttributeAndOverwritesStateOnReuse()
throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var certificate = mock(X509Certificate.class);
+ var request = mock(HttpServletRequest.class);
+ when(request.isSecure()).thenReturn(true);
+
when(request.getAttribute("jakarta.servlet.request.X509Certificate"))
+ .thenReturn(new X509Certificate[] { certificate });
+ initialize(exchange, request);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertArrayEquals(new X509Certificate[] { certificate },
provider.getPeerCertificates());
+ // reused for a plain request: the TLS state of the earlier
request must not survive
+ initialize(exchange, mock(HttpServletRequest.class));
+
assertNull(exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY));
+ }
+ }
+
+ @Test
+ void refusesCertificateHeadersAndAttributesOnAnInsecureRequest() throws
Exception {
+ try (var context = new DefaultCamelContext()) {
+ var certificate = mock(X509Certificate.class);
+ for (boolean secure : new boolean[] { false, true }) {
+ var exchange = new DefaultExchange(context);
+ var request = mock(HttpServletRequest.class);
+ when(request.isSecure()).thenReturn(secure);
+
when(request.getHeader("X-Forwarded-Client-Cert")).thenReturn("spiffe://example.org/frontend");
+ if (!secure) {
+
when(request.getAttribute("jakarta.servlet.request.X509Certificate"))
+ .thenReturn(new X509Certificate[] { certificate });
+ }
+ initialize(exchange, request);
+ var provider
+ =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ if (secure) {
+ // TLS without a client certificate: present and
unverified, so a forwarded header cannot stand in
+ assertThrows(SSLPeerUnverifiedException.class,
provider::getPeerCertificates);
+ } else {
+ // a plain connection: absent, and the certificate
attribute is not trusted either
+ assertNull(provider);
+ }
+ }
+ }
+ }
+}
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
index 7a004ff7f020..a5fb044cbd84 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
@@ -38,6 +38,7 @@ import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpUtil;
+import io.netty.handler.ssl.SslHandler;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.LoggingLevel;
@@ -58,6 +59,7 @@ import
org.apache.camel.http.base.OAuthHttpSecuritySupport.Validation;
import org.apache.camel.spi.CamelLogger;
import org.apache.camel.support.ExceptionHelper;
import org.apache.camel.support.ObjectHelper;
+import org.apache.camel.support.TlsPeerCertificateSupport;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -507,9 +509,15 @@ public class HttpServerChannelHandler extends
ServerChannelHandler {
return response;
}
+ static void populateTlsPeer(Exchange exchange, ChannelHandlerContext
context) {
+ var ssl = context.pipeline().get(SslHandler.class);
+ TlsPeerCertificateSupport.populateFromSession(exchange, ssl != null ?
ssl.engine().getSession() : null);
+ }
+
@Override
protected Exchange createExchange(ChannelHandlerContext ctx, Object
message) throws Exception {
Exchange exchange = this.consumer.createExchange(false);
+ populateTlsPeer(exchange, ctx);
// create a new IN message as we cannot reuse with netty
Message in;
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLServerHostnameVerificationTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLServerHostnameVerificationTest.java
index df5a234629ed..0b369e3ee2ad 100644
---
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLServerHostnameVerificationTest.java
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLServerHostnameVerificationTest.java
@@ -17,10 +17,13 @@
package org.apache.camel.component.netty.http;
import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty.NettyConstants;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
import org.apache.camel.support.jsse.KeyManagersParameters;
import org.apache.camel.support.jsse.KeyStoreParameters;
import org.apache.camel.support.jsse.SSLContextParameters;
@@ -28,7 +31,9 @@ import org.apache.camel.support.jsse.TrustManagersParameters;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -76,6 +81,15 @@ public class NettyHttpSSLServerHostnameVerificationTest
extends BaseNettyTestSup
public void configure() {
from("netty-http:https://localhost:{{port}}/hello?sslContextParameters=#clientCertParameters"
+ "&needClientAuth=true&hostnameVerification=true")
+ .process(exchange -> {
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
+ TlsPeerCertificateProvider.class);
+ assertNotNull(provider);
+ var peer = provider.getPeerCertificates();
+ assertTrue(peer.length > 0);
+ var session =
exchange.getMessage().getHeader(NettyConstants.NETTY_SSL_SESSION,
SSLSession.class);
+ assertArrayEquals(session.getPeerCertificates(),
peer);
+ })
.transform().constant("Bye World");
}
};
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
index f4dd0cf2593d..5ed7d50b6796 100644
---
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
@@ -20,16 +20,20 @@ import java.net.URL;
import java.util.Map;
import java.util.Properties;
+import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.netty.NettyConstants;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledIfSystemProperty(named = "java.vendor", matches = ".*ibm.*")
public class NettyHttpSSLTest extends BaseNettyTestSupport {
@@ -83,6 +87,10 @@ public class NettyHttpSSLTest extends BaseNettyTestSupport {
from("netty-http:https://localhost:{{port}}?ssl=true&passphrase=changeit&keyStoreResource=jsse/localhost.p12&trustStoreResource=jsse/localhost.p12")
.to("mock:input")
.process(exchange -> {
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
+ TlsPeerCertificateProvider.class);
+ assertNotNull(provider);
+ assertThrows(SSLPeerUnverifiedException.class,
provider::getPeerCertificates);
SSLSession session =
exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
if (session != null) {
exchange.getMessage().setBody("Bye World");
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/handlers/NettyHttpTlsPeerTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/handlers/NettyHttpTlsPeerTest.java
new file mode 100644
index 000000000000..a85868071bbb
--- /dev/null
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/handlers/NettyHttpTlsPeerTest.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.netty.http.handlers;
+
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPipeline;
+import io.netty.handler.ssl.SslHandler;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class NettyHttpTlsPeerTest {
+
+ @Test
+ void obtainsPeerFromChannelPipelineAndRejectsForgedHeaderWithoutTls()
throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var certificate = mock(X509Certificate.class);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenReturn(new Certificate[] {
certificate });
+ var engine = mock(SSLEngine.class);
+ when(engine.getSession()).thenReturn(session);
+ var handler = mock(SslHandler.class);
+ when(handler.engine()).thenReturn(engine);
+ var pipeline = mock(ChannelPipeline.class);
+ when(pipeline.get(SslHandler.class)).thenReturn(handler);
+ var channel = mock(ChannelHandlerContext.class);
+ when(channel.pipeline()).thenReturn(pipeline);
+ HttpServerChannelHandler.populateTlsPeer(exchange, channel);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertArrayEquals(new X509Certificate[] { certificate },
provider.getPeerCertificates());
+
+ when(pipeline.get(SslHandler.class)).thenReturn(null);
+ exchange.getMessage().setHeader("CamelNettySSLSession", session);
+ HttpServerChannelHandler.populateTlsPeer(exchange, channel);
+
assertNull(exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY),
+ "a plain connection leaves the property absent");
+ }
+ }
+
+ @Test
+ void missingClientAuthenticationIsNotIdentity() throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenThrow(new
SSLPeerUnverifiedException("No client certificate"));
+ var engine = mock(SSLEngine.class);
+ when(engine.getSession()).thenReturn(session);
+ var handler = mock(SslHandler.class);
+ when(handler.engine()).thenReturn(engine);
+ var pipeline = mock(ChannelPipeline.class);
+ when(pipeline.get(SslHandler.class)).thenReturn(handler);
+ var channel = mock(ChannelHandlerContext.class);
+ when(channel.pipeline()).thenReturn(pipeline);
+ HttpServerChannelHandler.populateTlsPeer(exchange, channel);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertThrows(SSLPeerUnverifiedException.class,
provider::getPeerCertificates);
+ }
+ }
+}
diff --git
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
index 0490adf90f6f..1046c166fef0 100644
---
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
+++
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
@@ -46,6 +46,7 @@ import org.apache.camel.support.ExceptionHelper;
import org.apache.camel.support.ExchangeHelper;
import org.apache.camel.support.MessageHelper;
import org.apache.camel.support.ObjectHelper;
+import org.apache.camel.support.TlsPeerCertificateSupport;
import org.apache.camel.support.http.HttpUtil;
import org.apache.camel.util.IOHelper;
import org.slf4j.Logger;
@@ -327,6 +328,10 @@ public final class VertxPlatformHttpSupport {
})));
}
+ static void populateTlsPeer(Exchange exchange, HttpServerRequest request) {
+ TlsPeerCertificateSupport.populateFromSession(exchange,
request.sslSession());
+ }
+
static void populateCamelHeaders(
RoutingContext ctx,
Map<String, Object> headersMap,
@@ -334,6 +339,7 @@ public final class VertxPlatformHttpSupport {
HeaderFilterStrategy headerFilterStrategy) {
final HttpServerRequest request = ctx.request();
+ populateTlsPeer(exchange, request);
headersMap.put(Exchange.HTTP_PATH, ctx.normalizedPath());
if (headerFilterStrategy != null) {
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxTlsPeerTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxTlsPeerTest.java
new file mode 100644
index 000000000000..6f617af0b873
--- /dev/null
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxTlsPeerTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.platform.http.vertx;
+
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import io.vertx.core.http.HttpServerRequest;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class VertxTlsPeerTest {
+
+ @Test
+ void usesActualRequestSessionRatherThanInboundHeaders() throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var certificate = mock(X509Certificate.class);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenReturn(new Certificate[] {
certificate });
+ var request = mock(HttpServerRequest.class);
+ when(request.sslSession()).thenReturn(session);
+ VertxPlatformHttpSupport.populateTlsPeer(exchange, request);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertArrayEquals(new X509Certificate[] { certificate },
provider.getPeerCertificates());
+
+ when(request.sslSession()).thenReturn(null);
+
when(request.getHeader("X-Forwarded-Client-Cert")).thenReturn("spiffe://example.org/frontend");
+ VertxPlatformHttpSupport.populateTlsPeer(exchange, request);
+
assertNull(exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY),
+ "a plain connection leaves the property absent");
+ }
+ }
+
+ @Test
+ void missingClientAuthenticationIsNotIdentity() throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenThrow(new
SSLPeerUnverifiedException("No client certificate"));
+ var request = mock(HttpServerRequest.class);
+ when(request.sslSession()).thenReturn(session);
+ VertxPlatformHttpSupport.populateTlsPeer(exchange, request);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertThrows(SSLPeerUnverifiedException.class,
provider::getPeerCertificates);
+ }
+ }
+}
diff --git a/components/camel-spiffe/src/main/docs/spiffe-component.adoc
b/components/camel-spiffe/src/main/docs/spiffe-component.adoc
index c5e571cc5a82..d14b43034d9a 100644
--- a/components/camel-spiffe/src/main/docs/spiffe-component.adoc
+++ b/components/camel-spiffe/src/main/docs/spiffe-component.adoc
@@ -390,14 +390,41 @@ A few things about the server side decide whether, and
for which peers, this pol
accept (or use `acceptAnySpiffeId` and let each policy narrow it), otherwise
the handshake turns a peer away
before its route could have authorized it.
-Only camel-netty and camel-netty-http put the `SSLSession` on the message
today, as the `CamelNettySSLSession`
-header. Behind platform-http, jetty, undertow or servlet there is no session
on the exchange, so the policy has no
-verified peer certificate to read and denies everything.
+The consumer must expose the peer authenticated by its own TLS connection.
Supported sources are:
+
+[cols="1,3"]
+|===
+| Consumer | Authenticated peer source
+
+| `netty-http`
+| The channel's `SslHandler` session.
+
+| `servlet`, `jetty`
+| The secure servlet request's container-authenticated
`jakarta.servlet.request.X509Certificate` attribute.
+
+| `undertow`
+| The real TLS session supplied by the connection's `SSLSessionInfo`.
Forwarded SSL information without a TLS session is rejected.
+
+| `platform-http` with the Vert.x engine
+| The server request's actual `sslSession()`.
+
+| `netty`
+| The existing `CamelNettySSLSession` message header remains supported.
+
+| Other engines and TLS-terminating reverse proxies
+| No automatic peer authentication support. The proxy's connection identity
does not prove the original client's identity.
+|===
+
+These adapters publish a `org.apache.camel.spi.TlsPeerCertificateProvider` in
the `CamelTlsPeerCertificates`
+exchange property. This typed contract is for trusted consumers integrating
actual authenticated server TLS state. It
+is never populated from HTTP identity or certificate headers. A TLS connection
without a client certificate is
+recorded as an unverified peer, which fails closed; a plain connection leaves
the property absent, and the policy then
+falls back to the session header. Custom consumers must uphold the same
provenance contract.
====
-The peer SPIFFE ID is taken from the *verified* TLS peer certificate the
consumer put on the exchange - the
-`CamelNettySSLSession` header for camel-netty-http - and never from a message
header a sender could set (see the
-Security notes below). A peer that is not on the `acceptedSpiffeIds`
allow-list, or that presents no verified SVID at
+The peer SPIFFE ID is taken from the *verified* TLS peer certificate the
consumer put on the exchange through the
+typed TLS peer property (or the legacy Netty session header). Sender-supplied
identity and certificate headers are
+never used (see the Security notes below). A peer that is not on the
`acceptedSpiffeIds` allow-list, or that presents no verified SVID at
all, is denied with a `CamelAuthorizationException`, so the route stops and
the regular `onException` machinery applies.
Set exactly one of:
@@ -454,8 +481,25 @@ YAML::
====
For a TLS consumer that exposes the `SSLSession` under a different header
name, set `sslSessionHeader` accordingly. The
-identity is always read from the verified `SSLSession`, never from a
certificate object placed on a message header -
-nothing would prove the TLS layer had verified such a certificate.
+legacy session header is used only when the typed TLS peer property is absent.
A present but unverified or invalid
+typed property fails closed; a different session header cannot override it.
Certificate objects and identity strings
+in message headers are never a substitute for authenticated TLS state.
+
+For OpenFGA composition, bind the user expression to the same verified
exchange property. The OpenFGA model must
+define the corresponding `workload` type and tuples for those SPIFFE IDs:
+
+[source,java]
+----
+openFgaPolicy.setUser("workload:${exchangeProperty.CamelSpiffePeerId}");
+from("platform-http:/documents") // Vert.x engine with mutual TLS configured
on its server
+ .policy(spiffePolicy)
+ .policy(openFgaPolicy)
+ .to("direct:documents");
+----
+
+`X-Forwarded-Client-Cert`, `X-SPIFFE-ID`, and similar proxy headers are not
accepted. Terminate mutually
+authenticated TLS at the Camel consumer to authorize its direct peer.
Authenticate an original client through an
+independent validated credential when TLS terminates at a reverse proxy; the
proxy's own SVID identifies the proxy.
include::spring-boot:partial$starter.adoc[]
@@ -478,7 +522,7 @@ include::spring-boot:partial$starter.adoc[]
`acceptAnySpiffeId` accepts any SVID that chains to the trust bundle, which
authenticates the trust domain but not
the peer.
* *The authorization decision is made on the certificate, not a header.*
`SpiffeSecurityPolicy` reads the peer SPIFFE
- ID from the verified TLS peer certificate (the `CamelNettySSLSession` header
for camel-netty-http), so a sender
+ ID from the verified TLS peer certificate in trusted consumer state (with
the legacy Netty session fallback), so a sender
cannot assert an identity by setting a header - and it requires mutual TLS,
failing closed when the peer presented
no verified certificate. The verified id it publishes is the
`CamelSpiffePeerId` exchange *property*, never a header,
so it likewise cannot be injected by an inbound message.
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffePeerIdentity.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffePeerIdentity.java
index 6c21b949fdb7..690ee61ba2aa 100644
---
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffePeerIdentity.java
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffePeerIdentity.java
@@ -28,13 +28,15 @@ import javax.net.ssl.SSLSession;
import io.spiffe.spiffeid.SpiffeId;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
/**
* Extracts the peer SPIFFE ID from the <em>verified</em> TLS peer certificate
carried on an exchange.
* <p>
* The identity is taken from the certificate the TLS layer authenticated,
never from a message header a sender could
- * set (see CAMEL-24730 for why that distinction matters in this component).
The source is the {@link SSLSession} a TLS
- * consumer places on the message - camel-netty-http stores it under {@code
CamelNettySSLSession}:
+ * set (see CAMEL-24730 for why that distinction matters in this component).
The preferred source is the
+ * transport-neutral {@link TlsPeerCertificateProvider} exchange property,
populated from server TLS state. For
+ * compatibility, an {@link SSLSession} a consumer places on the message is
accepted when the property is absent:
* {@link SSLSession#getPeerCertificates()} returns only the peer certificates
the handshake verified, and throws when
* the peer presented none. A certificate object read from a message header is
deliberately not trusted, because nothing
* proves the TLS layer verified it.
@@ -54,7 +56,21 @@ final class SpiffePeerIdentity {
* certificate or the certificate is not a valid SPIFFE X509-SVID.
*/
static SpiffeId fromExchange(Exchange exchange, String sslSessionHeader) {
- X509Certificate peer = peerCertificate(exchange.getMessage(),
sslSessionHeader);
+ Object state =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY);
+ X509Certificate peer;
+ if (state != null) {
+ if (!(state instanceof TlsPeerCertificateProvider provider)) {
+ return null;
+ }
+ try {
+ peer = leafOf(provider.getPeerCertificates());
+ } catch (SSLPeerUnverifiedException e) {
+ return null;
+ }
+ } else {
+ // Preserve the legacy Netty session contract for consumers that
have not adopted the property.
+ peer = peerCertificate(exchange.getMessage(), sslSessionHeader);
+ }
return peer != null ? fromCertificate(peer) : null;
}
diff --git
a/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeSecurityPolicyTest.java
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeSecurityPolicyTest.java
index d45a7ed177d2..c00bf25a53f7 100644
---
a/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeSecurityPolicyTest.java
+++
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeSecurityPolicyTest.java
@@ -29,6 +29,8 @@ import org.apache.camel.CamelAuthorizationException;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.apache.camel.support.TlsPeerCertificateSupport;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
@@ -82,6 +84,83 @@ class SpiffeSecurityPolicyTest extends CamelTestSupport {
});
}
+ @Test
+ void authorizesTransportNeutralVerifiedPeerWithoutSessionHeader() throws
Exception {
+ var certificate = certWithUriSans(FRONTEND);
+ Exchange result = template.request("direct:start", exchange -> {
+
TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange, new
Certificate[] { certificate });
+ });
+ assertThat(result.getException()).isNull();
+
assertThat(result.getProperty(SpiffeConstants.PEER_SPIFFE_ID)).isEqualTo(FRONTEND);
+ }
+
+ @Test
+ void transportStateTakesPrecedenceOverMismatchedLegacySession() throws
Exception {
+ var certificate = certWithUriSans(BACKEND);
+ var legacy = sessionPresenting(certWithUriSans(FRONTEND));
+ Exchange result = template.request("direct:start", exchange -> {
+
TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange, new
Certificate[] { certificate });
+
exchange.getMessage().setHeader(SpiffeSecurityPolicy.DEFAULT_SSL_SESSION_HEADER,
legacy);
+ });
+
assertThat(result.getException()).isInstanceOf(CamelAuthorizationException.class);
+
assertThat(result.getProperty(SpiffeConstants.PEER_SPIFFE_ID)).isNull();
+ }
+
+ @Test
+ void unverifiedTransportStateCannotFallBackToLegacySession() throws
Exception {
+ var legacy = sessionPresenting(certWithUriSans(FRONTEND));
+ Exchange result = template.request("direct:start", exchange -> {
+ // a TLS connection without a client certificate: the consumer
recorded an unverified peer
+
TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange, null);
+
exchange.getMessage().setHeader(SpiffeSecurityPolicy.DEFAULT_SSL_SESSION_HEADER,
legacy);
+ });
+
assertThat(result.getException()).isInstanceOf(CamelAuthorizationException.class);
+ }
+
+ @Test
+ void plainConnectionLeavesNoTransportStateAndTheLegacySessionStillCounts()
throws Exception {
+ var legacy = sessionPresenting(certWithUriSans(FRONTEND));
+ Exchange result = template.request("direct:start", exchange -> {
+ // a consumer that has not adopted the property, or a plain
connection, leaves it absent
+ TlsPeerCertificateSupport.populateFromSession(exchange, null);
+
exchange.getMessage().setHeader(SpiffeSecurityPolicy.DEFAULT_SSL_SESSION_HEADER,
legacy);
+ });
+
assertThat(result.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY)).isNull();
+ assertThat(result.getException()).isNull();
+
assertThat(result.getProperty(SpiffeConstants.PEER_SPIFFE_ID)).isEqualTo(FRONTEND);
+ }
+
+ @Test
+ void typedStateStillRejectsInvalidSvid() throws Exception {
+ var certificate = certWithUriSans(FRONTEND,
"https://example.org/other");
+ Exchange result = template.request("direct:start", exchange -> {
+
TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange, new
Certificate[] { certificate });
+ });
+
assertThat(result.getException()).isInstanceOf(CamelAuthorizationException.class);
+ }
+
+ @Test
+ void malformedTypedStateCannotFallBackToLegacySession() throws Exception {
+ var legacy = sessionPresenting(certWithUriSans(FRONTEND));
+ Exchange result = template.request("direct:start", exchange -> {
+ exchange.setProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
FRONTEND);
+
exchange.getMessage().setHeader(SpiffeSecurityPolicy.DEFAULT_SSL_SESSION_HEADER,
legacy);
+ });
+
assertThat(result.getException()).isInstanceOf(CamelAuthorizationException.class);
+ }
+
+ @Test
+ void forgedTypedProviderHeaderIsNotAnExchangeProperty() throws Exception {
+ var certificate = certWithUriSans(FRONTEND);
+ Exchange result = template.request("direct:start", exchange -> {
+
exchange.getMessage().setHeader(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
+ (TlsPeerCertificateProvider) () -> new X509Certificate[] {
certificate });
+ exchange.getMessage().setHeader("X-Forwarded-Client-Cert",
FRONTEND);
+ });
+
assertThat(result.getException()).isInstanceOf(CamelAuthorizationException.class);
+
assertThat(result.getProperty(SpiffeConstants.PEER_SPIFFE_ID)).isNull();
+ }
+
@Test
void authorizesAListedPeerAndExposesTheIdAsAnExchangeProperty() throws
Exception {
MockEndpoint authorized = getMockEndpoint("mock:authorized");
diff --git
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index 25c72927685b..834fa859593a 100644
---
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -60,6 +60,7 @@ import org.apache.camel.spi.OAuthTokenValidationResult;
import org.apache.camel.support.CamelContextHelper;
import org.apache.camel.support.DefaultConsumer;
import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.support.TlsPeerCertificateSupport;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -401,9 +402,17 @@ public class UndertowConsumer extends DefaultConsumer
implements HttpHandler, Su
return nextHandler;
}
+ static void populateTlsPeer(Exchange exchange, HttpServerExchange request)
{
+ // SSL-header forwarding handlers can install synthetic
SSLSessionInfo. Only the connection's actual TLS
+ // session is evidence of a handshake; a forwarded certificate without
a session must not become identity.
+ var info = request.getConnection().getSslSessionInfo();
+ TlsPeerCertificateSupport.populateFromSession(exchange, info != null ?
info.getSSLSession() : null);
+ }
+
private Exchange createExchange(HttpServerExchange httpExchange) throws
Exception {
Exchange exchange = createExchange(false);
exchange.setPattern(ExchangePattern.InOut);
+ populateTlsPeer(exchange, httpExchange);
Message in =
getEndpoint().getUndertowHttpBinding().toCamelMessage(httpExchange, exchange);
OAuthTokenValidationResult oauthTokenValidationResult
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTlsPeerTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTlsPeerTest.java
new file mode 100644
index 000000000000..e9d953587a10
--- /dev/null
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTlsPeerTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.undertow;
+
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import io.undertow.server.HttpServerExchange;
+import io.undertow.server.SSLSessionInfo;
+import io.undertow.server.ServerConnection;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class UndertowTlsPeerTest {
+
+ @Test
+ void
usesAuthenticatedConnectionSessionAndRejectsForwardedCertificateInfo() throws
Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var certificate = mock(X509Certificate.class);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenReturn(new Certificate[] {
certificate });
+ var info = mock(SSLSessionInfo.class);
+ when(info.getSSLSession()).thenReturn(session);
+ var connection = mock(ServerConnection.class);
+ when(connection.getSslSessionInfo()).thenReturn(info);
+ var request = new HttpServerExchange(connection);
+ UndertowConsumer.populateTlsPeer(exchange, request);
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertArrayEquals(new X509Certificate[] { certificate },
provider.getPeerCertificates());
+
+ // Undertow's SSLHeaderHandler may expose forwarded certificates
without a real TLS session.
+ when(info.getSSLSession()).thenReturn(null);
+ when(info.getPeerCertificates()).thenReturn(new Certificate[] {
certificate });
+ exchange.getMessage().setHeader("X-Forwarded-Client-Cert",
"spiffe://example.org/frontend");
+ UndertowConsumer.populateTlsPeer(exchange, request);
+
assertNull(exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY),
+ "a plain connection leaves the property absent");
+ }
+ }
+
+ @Test
+ void missingClientAuthenticationIsNotIdentity() throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ var exchange = new DefaultExchange(context);
+ var session = mock(SSLSession.class);
+ when(session.getPeerCertificates()).thenThrow(new
SSLPeerUnverifiedException("No client certificate"));
+ var info = mock(SSLSessionInfo.class);
+ when(info.getSSLSession()).thenReturn(session);
+ var connection = mock(ServerConnection.class);
+ when(connection.getSslSessionInfo()).thenReturn(info);
+ UndertowConsumer.populateTlsPeer(exchange, new
HttpServerExchange(connection));
+ var provider =
exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
TlsPeerCertificateProvider.class);
+ assertThrows(SSLPeerUnverifiedException.class,
provider::getPeerCertificates);
+ }
+ }
+}
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/TlsPeerCertificateProvider.java
b/core/camel-api/src/main/java/org/apache/camel/spi/TlsPeerCertificateProvider.java
new file mode 100644
index 000000000000..5008e376f2df
--- /dev/null
+++
b/core/camel-api/src/main/java/org/apache/camel/spi/TlsPeerCertificateProvider.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+
+/**
+ * Supplies the peer certificate chain authenticated by an inbound transport's
TLS handshake. Consumers place this typed
+ * value in an exchange property, never in message headers. Implementations
must derive certificates from the actual
+ * server connection or container TLS state, not from inbound
identity/certificate headers. Route authors and container
+ * authentication configuration remain trusted.
+ * <p>
+ * The property is present only on an exchange that arrived over TLS: it
carries the authenticated chain, or throws for
+ * a TLS connection without an authenticated client. A plain connection leaves
it absent.
+ *
+ * @since 4.24
+ */
+@FunctionalInterface
+public interface TlsPeerCertificateProvider {
+
+ /** The name of the exchange property that carries the provider. */
+ String EXCHANGE_PROPERTY = "CamelTlsPeerCertificates";
+
+ /**
+ * Returns the authenticated X509 chain, leaf first.
+ *
+ * @throws SSLPeerUnverifiedException when the connection has no
authenticated X509 peer
+ */
+ X509Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException;
+}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/TlsPeerCertificateSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/TlsPeerCertificateSupport.java
new file mode 100644
index 000000000000..d3d666f61c57
--- /dev/null
+++
b/core/camel-support/src/main/java/org/apache/camel/support/TlsPeerCertificateSupport.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+
+/**
+ * Helpers for consumer adapters publishing authenticated TLS state as a
transport-neutral exchange property.
+ *
+ * @since 4.24
+ */
+public final class TlsPeerCertificateSupport {
+
+ private static final X509Certificate[] NO_CERTIFICATES = new
X509Certificate[0];
+ private static final TlsPeerCertificateProvider UNVERIFIED_PEER = () -> {
+ throw new SSLPeerUnverifiedException("The inbound connection has no
authenticated X509 peer");
+ };
+
+ private TlsPeerCertificateSupport() {
+ }
+
+ /**
+ * Snapshots the actual server TLS session. A TLS session without an
authenticated client records an unverified
+ * peer, which overwrites any prior exchange state; no session, that is a
plain connection, leaves the property
+ * absent and removes a stale one.
+ */
+ public static void populateFromSession(Exchange exchange, SSLSession
session) {
+ if (session == null) {
+ clear(exchange);
+ return;
+ }
+ Certificate[] chain = null;
+ try {
+ chain = session.getPeerCertificates();
+ } catch (SSLPeerUnverifiedException e) {
+ // Server-only TLS and connections without client authentication
have no authenticated peer identity.
+ }
+ populateFromVerifiedCertificates(exchange, chain);
+ }
+
+ /** Removes the property, for an exchange that arrived over a plain
connection; a pooled exchange may carry one. */
+ public static void clear(Exchange exchange) {
+ exchange.removeProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY);
+ }
+
+ /**
+ * Snapshots a chain already authenticated by the server container.
Callers must never obtain this chain from an
+ * inbound certificate header or a proxy's forwarded identity. An absent
chain records an unverified peer.
+ */
+ public static void populateFromVerifiedCertificates(Exchange exchange,
Certificate[] chain) {
+ X509Certificate[] certificates = x509Chain(chain);
+ TlsPeerCertificateProvider provider = certificates.length == 0 ?
UNVERIFIED_PEER : () -> certificates.clone();
+ exchange.setProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY,
provider);
+ }
+
+ private static X509Certificate[] x509Chain(Certificate[] chain) {
+ if (chain == null || chain.length == 0) {
+ return NO_CERTIFICATES;
+ }
+ X509Certificate[] certificates = new X509Certificate[chain.length];
+ for (int i = 0; i < chain.length; i++) {
+ if (!(chain[i] instanceof X509Certificate certificate)) {
+ return NO_CERTIFICATES;
+ }
+ certificates[i] = certificate;
+ }
+ return certificates;
+ }
+}
diff --git
a/core/camel-support/src/test/java/org/apache/camel/support/TlsPeerCertificateSupportTest.java
b/core/camel-support/src/test/java/org/apache/camel/support/TlsPeerCertificateSupportTest.java
new file mode 100644
index 000000000000..781ac6a901dc
--- /dev/null
+++
b/core/camel-support/src/test/java/org/apache/camel/support/TlsPeerCertificateSupportTest.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.Proxy;
+import java.nio.charset.StandardCharsets;
+import java.security.PublicKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.TlsPeerCertificateProvider;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class TlsPeerCertificateSupportTest {
+ // Certificate validity is immaterial: these tests exercise transport
snapshots, not certificate verification.
+ private static final String CERTIFICATE = """
+ -----BEGIN CERTIFICATE-----
+ MIIBiTCCAS+gAwIBAgIUPconUFLaFpyI9v3cnRRgkW5RuA4wCgYIKoZIzj0EAwIw
+ GjEYMBYGA1UEAwwPY2FtZWwtdW5pdC10ZXN0MB4XDTI2MTExMTEzMTE0MloXDTI3
+ MTExMTEzMTE0MlowGjEYMBYGA1UEAwwPY2FtZWwtdW5pdC10ZXN0MFkwEwYHKoZI
+ zj0CAQYIKoZIzj0DAQcDQgAE09OFOJCozTqJcYA93cEs/qaqlkPNbmxS/Lv8sldB
+ RVT7SxsXpJJVMzXeaxdevH5h5ML2bOyJdxCbKC6oCiQe7qNTMFEwHQYDVR0OBBYE
+ FJLqeVCObGKDlpPZKeXaMGkLJRggMB8GA1UdIwQYMBaAFJLqeVCObGKDlpPZKeXa
+ MGkLJRggMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIhALAsOTMV
+ V6ypVb7yivMjhVU9QxMsRa3MI28P3KRYqvpFAiAxDSl2inwNtqPE7fgG/5AsqO7d
+ DR07AV8Iz8j07ZtrfQ==
+ -----END CERTIFICATE-----
+ """;
+
+ private final Map<String, Object> properties = new HashMap<>();
+ private final Exchange exchange = (Exchange)
Proxy.newProxyInstance(Exchange.class.getClassLoader(),
+ new Class<?>[] { Exchange.class }, (proxy, method, args) -> {
+ if (method.getName().equals("setProperty")) {
+ properties.put((String) args[0], args[1]);
+ return null;
+ }
+ if (method.getName().equals("removeProperty") && args.length
== 1) {
+ return properties.remove((String) args[0]);
+ }
+ if (method.getName().equals("getProperty") && args.length ==
1) {
+ return properties.get((String) args[0]);
+ }
+ throw new UnsupportedOperationException(method.getName());
+ });
+
+ private TlsPeerCertificateProvider captured() {
+ return (TlsPeerCertificateProvider)
properties.get(TlsPeerCertificateProvider.EXCHANGE_PROPERTY);
+ }
+
+ private static X509Certificate certificate() throws Exception {
+ return (X509Certificate) CertificateFactory.getInstance("X.509")
+ .generateCertificate(new
ByteArrayInputStream(CERTIFICATE.getBytes(StandardCharsets.US_ASCII)));
+ }
+
+ private static SSLSession session(Certificate[] chain) {
+ return (SSLSession)
Proxy.newProxyInstance(SSLSession.class.getClassLoader(), new Class<?>[] {
SSLSession.class },
+ (proxy, method, args) -> {
+ if (method.getName().equals("getPeerCertificates")) {
+ if (chain == null) {
+ throw new SSLPeerUnverifiedException("No client
certificate");
+ }
+ return chain;
+ }
+ throw new UnsupportedOperationException(method.getName());
+ });
+ }
+
+ @Test
+ void snapshotsInputAndReturnedArrays() throws Exception {
+ X509Certificate certificate = certificate();
+ Certificate[] chain = { certificate };
+ TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange,
chain);
+ chain[0] = null;
+ TlsPeerCertificateProvider provider = captured();
+ provider.getPeerCertificates()[0] = null;
+
assertThat(provider.getPeerCertificates()).containsExactly(certificate);
+ }
+
+ @Test
+ void obtainsOnlyVerifiedSessionCertificates() throws Exception {
+ X509Certificate certificate = certificate();
+ TlsPeerCertificateSupport.populateFromSession(exchange, session(new
Certificate[] { certificate }));
+
assertThat(captured().getPeerCertificates()).containsExactly(certificate);
+ }
+
+ @Test
+ void unverifiedSessionCreatesAuthoritativeAbsence() throws Exception {
+ TlsPeerCertificateSupport.populateFromSession(exchange, session(null));
+ assertThatThrownBy(() ->
captured().getPeerCertificates()).isInstanceOf(SSLPeerUnverifiedException.class);
+ }
+
+ @Test
+ void plainConnectionLeavesThePropertyAbsentAndRemovesAStaleOne() throws
Exception {
+ TlsPeerCertificateSupport.populateFromSession(exchange, session(new
Certificate[] { certificate() }));
+ TlsPeerCertificateSupport.populateFromSession(exchange, null);
+
assertThat(exchange.getProperty(TlsPeerCertificateProvider.EXCHANGE_PROPERTY)).isNull();
+ }
+
+ @Test
+ void rejectsNonX509Chains() {
+ Certificate certificate = new Certificate("unit-test") {
+ @Override
+ public byte[] getEncoded() {
+ return new byte[] { 1 };
+ }
+
+ @Override
+ public void verify(PublicKey key) {
+ }
+
+ @Override
+ public void verify(PublicKey key, String provider) {
+ }
+
+ @Override
+ public String toString() {
+ return "Unit test non-X509 certificate";
+ }
+
+ @Override
+ public PublicKey getPublicKey() {
+ return null;
+ }
+ };
+ TlsPeerCertificateSupport.populateFromVerifiedCertificates(exchange,
new Certificate[] { certificate });
+ assertThatThrownBy(() ->
captured().getPeerCertificates()).isInstanceOf(SSLPeerUnverifiedException.class);
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 58f5e7609422..37027c372c50 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -9172,6 +9172,14 @@ not pass a language on; a language header alone turns
OCR on, unless the endpoin
The language itself is passed to docling untouched, in both forms: it is
docling's own identifier (language codes such
as `en,de`, BCP-47 tags such as `iso:zh-Hant`, or `script/Latin`), and docling
validates it.
+=== camel-spiffe - SpiffeSecurityPolicy reads the TLS peer from servlet,
Undertow and Vert.x consumers
+
+`SpiffeSecurityPolicy` now recognizes authenticated TLS peer certificates
supplied by servlet/Jetty, Undertow,
+Netty HTTP and Vert.x platform HTTP consumers through a typed exchange
property. When that property is present,
+it takes precedence over `sslSessionHeader`; an unverified peer fails closed
even if a legacy session header is
+present. Consumers without the property retain the existing session-header
behavior. Mutual TLS must still be
+configured at the consuming server; forwarded certificate and identity headers
do not establish a verified peer.
+
=== camel-influxdb2 - the retentionPolicy option and the
camelInfluxDB.RetentionPolicy header are deprecated
Neither has ever had any effect. A retention policy is an InfluxDB 1.x
concept: its write API takes one per write, and