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 cb46185aab94 CAMEL-26562: camel-opa, camel-openfga - let the security
policies use the global SSL context (#29145)
cb46185aab94 is described below
commit cb46185aab94ba28b38176383862df1410bc22d5
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Nov 4 10:33:55 2026 +0100
CAMEL-26562: camel-opa, camel-openfga - let the security policies use the
global SSL context (#29145)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/catalog/docs/opa-component.adoc | 2 +
.../camel/catalog/docs/openfga-component.adoc | 4 +-
.../camel-opa/src/main/docs/opa-component.adoc | 2 +
.../component/opa/security/OpaSecurityPolicy.java | 31 +++--
.../security/OpaSecurityPolicyGlobalSslTest.java | 122 ++++++++++++++++++++
.../src/main/docs/openfga-component.adoc | 4 +-
.../openfga/security/OpenFgaSecurityPolicy.java | 31 +++--
.../OpenFgaSecurityPolicyGlobalSslTest.java | 126 +++++++++++++++++++++
8 files changed, 304 insertions(+), 18 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
index 72e74bf9dbe4..f87d0b185987 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
@@ -525,6 +525,8 @@ YAML::
====
Set `useGlobalSslContextParameters=true` on the component to pick up the
context-wide configuration instead.
+`OpaSecurityPolicy` is a bean rather than an endpoint of the component, so the
component's option does not reach it:
+set `useGlobalSslContextParameters`, or `sslContextParameters`, on the policy
itself.
That is what lets a workload present a client certificate to an OPA server
requiring mutual TLS — a SPIFFE
X.509-SVID, for example, so the application authenticates to the policy
decision point as itself rather than
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfga-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfga-component.adoc
index 517718a756ad..087fc299d502 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfga-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/openfga-component.adoc
@@ -434,8 +434,8 @@ For a server started with `--authn-method preshared`, set
`apiToken`. For one be
TLS. A SPIFFE X.509-SVID obtained through `camel-spiffe` works here, which
closes the
loop: the workload authenticates to the authorization decision point as itself.
-NOTE: `useGlobalSslContextParameters` on the component has no effect on
`OpenFgaSecurityPolicy`. The policy is a
-standalone bean and is not bound to a component instance, so set
`sslContextParameters` on it explicitly.
+NOTE: `useGlobalSslContextParameters` on the component does not reach
`OpenFgaSecurityPolicy`, which is a bean rather
+than an endpoint of the component. Set `useGlobalSslContextParameters`, or
`sslContextParameters`, on the policy itself.
=== Timeouts
diff --git a/components/camel-opa/src/main/docs/opa-component.adoc
b/components/camel-opa/src/main/docs/opa-component.adoc
index 72e74bf9dbe4..f87d0b185987 100644
--- a/components/camel-opa/src/main/docs/opa-component.adoc
+++ b/components/camel-opa/src/main/docs/opa-component.adoc
@@ -525,6 +525,8 @@ YAML::
====
Set `useGlobalSslContextParameters=true` on the component to pick up the
context-wide configuration instead.
+`OpaSecurityPolicy` is a bean rather than an endpoint of the component, so the
component's option does not reach it:
+set `useGlobalSslContextParameters`, or `sslContextParameters`, on the policy
itself.
That is what lets a workload present a client certificate to an OPA server
requiring mutual TLS — a SPIFFE
X.509-SVID, for example, so the application authenticates to the policy
decision point as itself rather than
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
index ca5071016951..e60e1406e198 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
@@ -81,6 +81,7 @@ public class OpaSecurityPolicy implements AuthorizationPolicy
{
private long connectionTimeout = 10000;
private long requestTimeout = 30000;
private SSLContextParameters sslContextParameters;
+ private boolean useGlobalSslContextParameters;
private volatile OpaPolicyEvaluator evaluator;
private volatile OpaSecurityPolicyHealthCheck healthCheck;
@@ -399,11 +400,16 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
* wrapping - which is the only place one is available.
*/
private SSLContext createSslContext(CamelContext camelContext) {
- if (sslContextParameters == null) {
+ // the same precedence as the endpoint: an explicit configuration wins
over the context-wide one
+ SSLContextParameters parameters = sslContextParameters;
+ if (parameters == null && useGlobalSslContextParameters) {
+ parameters = camelContext.getSSLContextParameters();
+ }
+ if (parameters == null) {
return null;
}
try {
- return sslContextParameters.createSSLContext(camelContext);
+ return parameters.createSSLContext(camelContext);
} catch (GeneralSecurityException | IOException e) {
// beforeWrap cannot throw checked exceptions, and a policy whose
TLS configuration is broken must not
// start a route that would then talk to OPA over the JVM default
trust material instead
@@ -442,16 +448,27 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
/**
* TLS configuration for the connection to the OPA server. Needed to trust
a server whose certificate comes from a
- * private CA, and to present a client certificate to a server requiring
mutual TLS.
- * <p/>
- * Note: {@code useGlobalSslContextParameters} on the {@link
org.apache.camel.component.opa.OpaComponent} has no
- * effect here. {@code OpaSecurityPolicy} is a standalone bean and is not
bound to any component instance, so the
- * global SSL context cannot be resolved automatically. Set this field
explicitly when TLS is required.
+ * private CA, and to present a client certificate to a server requiring
mutual TLS. Takes precedence over
+ * {@code useGlobalSslContextParameters}.
*/
public void setSslContextParameters(SSLContextParameters
sslContextParameters) {
this.sslContextParameters = sslContextParameters;
}
+ public boolean isUseGlobalSslContextParameters() {
+ return useGlobalSslContextParameters;
+ }
+
+ /**
+ * Whether to use the global SSL context parameters, the context-wide
{@link SSLContextParameters} that camel-main
+ * builds from {@code camel.ssl.*}, when {@code sslContextParameters} is
not set. This is the policy's own option:
+ * {@code useGlobalSslContextParameters} on the {@link
org.apache.camel.component.opa.OpaComponent} does not reach a
+ * policy, which is a standalone bean rather than an endpoint of that
component. Not used in {@code wasm} mode.
+ */
+ public void setUseGlobalSslContextParameters(boolean
useGlobalSslContextParameters) {
+ this.useGlobalSslContextParameters = useGlobalSslContextParameters;
+ }
+
public boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}
diff --git
a/components/camel-opa/src/test/java/org/apache/camel/component/opa/security/OpaSecurityPolicyGlobalSslTest.java
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/security/OpaSecurityPolicyGlobalSslTest.java
new file mode 100644
index 000000000000..d251637a48b5
--- /dev/null
+++
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/security/OpaSecurityPolicyGlobalSslTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.opa.security;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * The policy is a bean, not an endpoint of the {@code opa} component, so the
component's
+ * {@code useGlobalSslContextParameters} cannot reach it: the policy has the
option itself, with the endpoint's
+ * precedence.
+ */
+class OpaSecurityPolicyGlobalSslTest extends CamelTestSupport {
+
+ private final RecordingSslContextParameters global = new
RecordingSslContextParameters();
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").to("mock:result");
+ }
+ };
+ }
+
+ private OpaSecurityPolicy policy() {
+ OpaSecurityPolicy policy = new OpaSecurityPolicy();
+ policy.setPolicyPath("authz/allow");
+ policy.setServerUrl("https://opa.example.org:8181");
+ policy.setHealthCheckEnabled(false);
+ return policy;
+ }
+
+ @Test
+ void usesTheGlobalSslContextParametersWhenAskedTo() {
+ context.setSSLContextParameters(global);
+ OpaSecurityPolicy policy = policy();
+ policy.setUseGlobalSslContextParameters(true);
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(global.built).hasValue(1);
+ }
+
+ @Test
+ void ignoresTheGlobalSslContextParametersByDefault() {
+ context.setSSLContextParameters(global);
+ OpaSecurityPolicy policy = policy();
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(policy.isUseGlobalSslContextParameters()).isFalse();
+ assertThat(global.built).hasValue(0);
+ }
+
+ @Test
+ void prefersItsOwnSslContextParametersOverTheGlobalOnes() {
+ context.setSSLContextParameters(global);
+ RecordingSslContextParameters own = new
RecordingSslContextParameters();
+ OpaSecurityPolicy policy = policy();
+ policy.setSslContextParameters(own);
+ policy.setUseGlobalSslContextParameters(true);
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(own.built).hasValue(1);
+ assertThat(global.built).hasValue(0);
+ }
+
+ @Test
+ void buildsNoSslContextWhenThereAreNoGlobalSslContextParameters() {
+ OpaSecurityPolicy policy = policy();
+ policy.setUseGlobalSslContextParameters(true);
+
+ // there is nothing to use, so the policy falls back to the JVM
default, as it does without the option
+ assertThat(context.getSSLContextParameters()).isNull();
+ assertThatCode(() -> policy.beforeWrap(context.getRoutes().get(0),
null)).doesNotThrowAnyException();
+ }
+
+ private static final class RecordingSslContextParameters extends
SSLContextParameters {
+
+ private final AtomicInteger built = new AtomicInteger();
+
+ @Override
+ public SSLContext createSSLContext(CamelContext camelContext) throws
GeneralSecurityException, IOException {
+ built.incrementAndGet();
+ try {
+ return SSLContext.getDefault();
+ } catch (NoSuchAlgorithmException e) {
+ throw new GeneralSecurityException(e);
+ }
+ }
+ }
+}
diff --git a/components/camel-openfga/src/main/docs/openfga-component.adoc
b/components/camel-openfga/src/main/docs/openfga-component.adoc
index 517718a756ad..087fc299d502 100644
--- a/components/camel-openfga/src/main/docs/openfga-component.adoc
+++ b/components/camel-openfga/src/main/docs/openfga-component.adoc
@@ -434,8 +434,8 @@ For a server started with `--authn-method preshared`, set
`apiToken`. For one be
TLS. A SPIFFE X.509-SVID obtained through `camel-spiffe` works here, which
closes the
loop: the workload authenticates to the authorization decision point as itself.
-NOTE: `useGlobalSslContextParameters` on the component has no effect on
`OpenFgaSecurityPolicy`. The policy is a
-standalone bean and is not bound to a component instance, so set
`sslContextParameters` on it explicitly.
+NOTE: `useGlobalSslContextParameters` on the component does not reach
`OpenFgaSecurityPolicy`, which is a bean rather
+than an endpoint of the component. Set `useGlobalSslContextParameters`, or
`sslContextParameters`, on the policy itself.
=== Timeouts
diff --git
a/components/camel-openfga/src/main/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicy.java
b/components/camel-openfga/src/main/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicy.java
index f8338738ae75..e2d0a5f102b6 100644
---
a/components/camel-openfga/src/main/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicy.java
+++
b/components/camel-openfga/src/main/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicy.java
@@ -68,6 +68,7 @@ public class OpenFgaSecurityPolicy implements
AuthorizationPolicy {
private final OpenFgaConfiguration configuration = new
OpenFgaConfiguration();
private boolean healthCheckEnabled = true;
+ private boolean useGlobalSslContextParameters;
private volatile OpenFgaAuthorizer authorizer;
private volatile OpenFgaSecurityPolicyHealthCheck healthCheck;
@@ -191,11 +192,16 @@ public class OpenFgaSecurityPolicy implements
AuthorizationPolicy {
* wrapping - which is the only place one is available.
*/
private SSLContext createSslContext(CamelContext context) {
- if (configuration.getSslContextParameters() == null) {
+ // the same precedence as the endpoint: an explicit configuration wins
over the context-wide one
+ SSLContextParameters parameters =
configuration.getSslContextParameters();
+ if (parameters == null && useGlobalSslContextParameters) {
+ parameters = context.getSSLContextParameters();
+ }
+ if (parameters == null) {
return null;
}
try {
- return
configuration.getSslContextParameters().createSSLContext(context);
+ return parameters.createSSLContext(context);
} catch (GeneralSecurityException | IOException e) {
// as above: a policy whose TLS configuration is broken must not
start a route that would then talk to
// OpenFGA over the JVM default trust material instead
@@ -444,16 +450,27 @@ public class OpenFgaSecurityPolicy implements
AuthorizationPolicy {
/**
* TLS configuration for the connection to OpenFGA. Needed to trust a
server whose certificate comes from a private
- * CA, and to present a client certificate to a server requiring mutual
TLS.
- * <p/>
- * Note: {@code useGlobalSslContextParameters} on the {@code
OpenFgaComponent} has no effect here. This policy is a
- * standalone bean and is not bound to any component instance, so the
global SSL context cannot be resolved
- * automatically. Set this field explicitly when TLS is required.
+ * CA, and to present a client certificate to a server requiring mutual
TLS. Takes precedence over
+ * {@code useGlobalSslContextParameters}.
*/
public void setSslContextParameters(SSLContextParameters
sslContextParameters) {
configuration.setSslContextParameters(sslContextParameters);
}
+ public boolean isUseGlobalSslContextParameters() {
+ return useGlobalSslContextParameters;
+ }
+
+ /**
+ * Whether to use the global SSL context parameters, the context-wide
{@link SSLContextParameters} that camel-main
+ * builds from {@code camel.ssl.*}, when {@code sslContextParameters} is
not set. This is the policy's own option:
+ * {@code useGlobalSslContextParameters} on the {@code OpenFgaComponent}
does not reach a policy, which is a
+ * standalone bean rather than an endpoint of that component.
+ */
+ public void setUseGlobalSslContextParameters(boolean
useGlobalSslContextParameters) {
+ this.useGlobalSslContextParameters = useGlobalSslContextParameters;
+ }
+
public boolean isHealthCheckEnabled() {
return healthCheckEnabled;
}
diff --git
a/components/camel-openfga/src/test/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicyGlobalSslTest.java
b/components/camel-openfga/src/test/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicyGlobalSslTest.java
new file mode 100644
index 000000000000..3ca9276912f3
--- /dev/null
+++
b/components/camel-openfga/src/test/java/org/apache/camel/component/openfga/security/OpenFgaSecurityPolicyGlobalSslTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.openfga.security;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * The policy is a bean, not an endpoint of the {@code openfga} component, so
the component's
+ * {@code useGlobalSslContextParameters} cannot reach it: the policy has the
option itself, with the endpoint's
+ * precedence.
+ */
+class OpenFgaSecurityPolicyGlobalSslTest extends CamelTestSupport {
+
+ private final RecordingSslContextParameters global = new
RecordingSslContextParameters();
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").to("mock:result");
+ }
+ };
+ }
+
+ private OpenFgaSecurityPolicy policy() {
+ OpenFgaSecurityPolicy policy = new OpenFgaSecurityPolicy();
+ policy.setApiUrl("https://openfga.example.org:8443");
+ policy.setStoreId("01HSTORE");
+ policy.setAuthorizationModelId("01HMODEL");
+ policy.setRelation("reader");
+ policy.setUser("user:anne");
+ policy.setObject("document:budget");
+ policy.setHealthCheckEnabled(false);
+ return policy;
+ }
+
+ @Test
+ void usesTheGlobalSslContextParametersWhenAskedTo() {
+ context.setSSLContextParameters(global);
+ OpenFgaSecurityPolicy policy = policy();
+ policy.setUseGlobalSslContextParameters(true);
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(global.built).hasValue(1);
+ }
+
+ @Test
+ void ignoresTheGlobalSslContextParametersByDefault() {
+ context.setSSLContextParameters(global);
+ OpenFgaSecurityPolicy policy = policy();
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(policy.isUseGlobalSslContextParameters()).isFalse();
+ assertThat(global.built).hasValue(0);
+ }
+
+ @Test
+ void prefersItsOwnSslContextParametersOverTheGlobalOnes() {
+ context.setSSLContextParameters(global);
+ RecordingSslContextParameters own = new
RecordingSslContextParameters();
+ OpenFgaSecurityPolicy policy = policy();
+ policy.setSslContextParameters(own);
+ policy.setUseGlobalSslContextParameters(true);
+
+ policy.beforeWrap(context.getRoutes().get(0), null);
+
+ assertThat(own.built).hasValue(1);
+ assertThat(global.built).hasValue(0);
+ }
+
+ @Test
+ void buildsNoSslContextWhenThereAreNoGlobalSslContextParameters() {
+ OpenFgaSecurityPolicy policy = policy();
+ policy.setUseGlobalSslContextParameters(true);
+
+ // there is nothing to use, so the policy falls back to the JVM
default, as it does without the option
+ assertThat(context.getSSLContextParameters()).isNull();
+ assertThatCode(() -> policy.beforeWrap(context.getRoutes().get(0),
null)).doesNotThrowAnyException();
+ }
+
+ private static final class RecordingSslContextParameters extends
SSLContextParameters {
+
+ private final AtomicInteger built = new AtomicInteger();
+
+ @Override
+ public SSLContext createSSLContext(CamelContext camelContext) throws
GeneralSecurityException, IOException {
+ built.incrementAndGet();
+ try {
+ return SSLContext.getDefault();
+ } catch (NoSuchAlgorithmException e) {
+ throw new GeneralSecurityException(e);
+ }
+ }
+ }
+}