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 85e880a3d072 CAMEL-27161: camel-main - the security policy checks the
properties of the beans that route files define (#30332)
85e880a3d072 is described below
commit 85e880a3d072d2215d718252b04c08788423f3a3
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Nov 19 20:33:38 2026 +0100
CAMEL-27161: camel-main - the security policy checks the properties of the
beans that route files define (#30332)
The security policy checked the camel.* configuration properties only, so
the
beans that a YAML or XML route file defines in its beans section were not
checked: with camel.main.profile=prod, camel.beans.opaPolicy.failOpen=true
in
application.properties failed the startup, while failOpen: true on a YAML
bean
started.
Once the routes are loaded, camel-main now checks the properties of the
beans
in Model.getCustomBeans() under the key of a bean configured from
properties,
camel.beans.<name>.<property>, so the option matching and
camel.security.allowedProperties work the same way. The violations are added
to SecurityPolicyResult for the health check.
The check runs after the registry is post-processed, so the Blueprint XML
beans
and the delayed Spring XML beans of camel-kamelet-main are checked too. It
applies to camel-main and the Camel CLI; camel-spring-boot checks the
configuration properties only. The options set in endpoint URIs remain
outside
the security policy.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../org/apache/camel/main/BaseMainSupport.java | 83 +++++++++-
.../camel/main/MainSecurityPolicyBeansTest.java | 173 +++++++++++++++++++++
design/security.adoc | 5 +-
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 21 +++
.../modules/ROOT/pages/security-policy.adoc | 9 ++
.../main/KameletMainSecurityPolicyBeansTest.java | 78 ++++++++++
.../org/apache/camel/main/app/MyTlsClient.java | 30 ++++
.../camel/main/xml/blueprint-security-policy.xml | 33 ++++
.../camel/main/xml/spring-security-policy.xml | 33 ++++
.../dsl/xml/io/XmlMainSecurityPolicyBeansTest.java | 67 ++++++++
.../apache/camel/dsl/xml/io/beans/MyTlsClient.java | 30 ++++
.../camel/dsl/xml/io/security-policy-beans.xml | 33 ++++
.../dsl/yaml/MainSecurityPolicyBeansTest.java | 65 ++++++++
.../camel/dsl/yaml/support/model/MyTlsClient.java | 30 ++++
.../src/test/resources/security/route-beans.yaml | 27 ++++
15 files changed, 708 insertions(+), 9 deletions(-)
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 7ae76d087b13..076d954d5119 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -65,7 +65,9 @@ import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.health.HealthCheckRepository;
import org.apache.camel.impl.engine.DefaultCompileStrategy;
import org.apache.camel.impl.engine.DefaultRoutesLoader;
+import org.apache.camel.model.BeanFactoryDefinition;
import org.apache.camel.model.BeanModelHelper;
+import org.apache.camel.model.Model;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.Resilience4jConfigurationDefinition;
import org.apache.camel.saga.CamelSagaService;
@@ -1156,6 +1158,13 @@ public abstract class BaseMainSupport extends
BaseService {
// available bean definitions
postProcessCamelRegistry(camelContext, mainConfigurationProperties);
+ if (standalone) {
+ // the beans that the routes define (such as the beans section of
a YAML or XML DSL file) are not
+ // configured from camel.* properties, so their properties are
checked once the routes are loaded and
+ // the registry is post-processed (which adds the delayed Spring
XML and Blueprint XML beans)
+ enforceSecurityPoliciesOnBeans(camelContext);
+ }
+
// allow doing custom configuration before camel is started
if (!listeners.isEmpty()) {
step = recorder.beginStep(BaseMainSupport.class, "afterConfigure",
"MainListener");
@@ -3506,28 +3515,86 @@ public abstract class BaseMainSupport extends
BaseService {
}
private void enforceSecurityPolicies(CamelContext camelContext,
OrderedLocationProperties autoConfiguredProperties) {
- SecurityConfigurationProperties securityConfig =
mainConfigurationProperties.securityConfig();
-
// build a properties map for the shared detection utility
Map<String, Object> propsMap = new LinkedHashMap<>();
for (var entry : autoConfiguredProperties.entrySet()) {
propsMap.put(entry.getKey().toString(), entry.getValue());
}
+ List<SecurityViolation> violations =
detectSecurityViolations(camelContext, propsMap);
+
+ // store violations for health check access
+ camelContext.getCamelContextExtension()
+ .addContextPlugin(SecurityPolicyResult.class, new
SecurityPolicyResult(violations));
+
+ applySecurityPolicies(violations);
+ }
+
+ /**
+ * Enforces the security policies on the properties of the beans that the
routes define, such as the beans section
+ * of a YAML or XML DSL file. A property is checked under the key of a
bean configured from properties
+ * (camel.beans.<name>.<property>), so the option matching and
camel.security.allowedProperties work the
+ * same way.
+ */
+ private void enforceSecurityPoliciesOnBeans(CamelContext camelContext) {
+ Model model =
camelContext.getCamelContextExtension().getContextPlugin(Model.class);
+ if (model == null) {
+ return;
+ }
+ Map<String, Object> propsMap = new LinkedHashMap<>();
+ for (BeanFactoryDefinition<?> def : model.getCustomBeans()) {
+ if (def.getName() != null && def.getProperties() != null) {
+ collectBeanProperties(propsMap, "camel.beans." + def.getName()
+ ".", def.getProperties());
+ }
+ }
+ if (propsMap.isEmpty()) {
+ return;
+ }
+
+ List<SecurityViolation> violations =
detectSecurityViolations(camelContext, propsMap);
+ if (!violations.isEmpty()) {
+ // add them to the violations of the configuration properties, for
health check access
+ SecurityPolicyResult result
+ =
camelContext.getCamelContextExtension().getContextPlugin(SecurityPolicyResult.class);
+ List<SecurityViolation> all = new ArrayList<>();
+ if (result != null) {
+ all.addAll(result.getViolations());
+ }
+ all.addAll(violations);
+ camelContext.getCamelContextExtension()
+ .addContextPlugin(SecurityPolicyResult.class, new
SecurityPolicyResult(all));
+ }
+
+ applySecurityPolicies(violations);
+ }
+
+ private static void collectBeanProperties(Map<String, Object> answer,
String prefix, Map<?, ?> properties) {
+ for (Map.Entry<?, ?> entry : properties.entrySet()) {
+ String key = prefix + entry.getKey();
+ if (entry.getValue() instanceof Map<?, ?> nested) {
+ // nested properties are bound as key.nestedKey
+ collectBeanProperties(answer, key + ".", nested);
+ } else {
+ answer.put(key, entry.getValue());
+ }
+ }
+ }
+
+ private List<SecurityViolation> detectSecurityViolations(CamelContext
camelContext, Map<String, Object> properties) {
+ SecurityConfigurationProperties securityConfig =
mainConfigurationProperties.securityConfig();
+
// build the allowed keys set
Set<String> allowedKeys = securityConfig.getAllowedPropertySet();
// detect all violations using the shared utility
- List<SecurityViolation> violations = SecurityUtils.detectViolations(
- propsMap,
+ return SecurityUtils.detectViolations(
+ properties,
(k, v) -> MainHelper.containsSensitive(camelContext, k, v),
securityConfig::resolvePolicy,
allowedKeys);
+ }
- // store violations for health check access
- camelContext.getCamelContextExtension()
- .addContextPlugin(SecurityPolicyResult.class, new
SecurityPolicyResult(violations));
-
+ private static void applySecurityPolicies(List<SecurityViolation>
violations) {
// apply policy: warn or fail (policy is carried in each violation
from detection)
List<String> failures = new ArrayList<>();
for (SecurityViolation v : violations) {
diff --git
a/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyBeansTest.java
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyBeansTest.java
new file mode 100644
index 000000000000..6587e0a3b8e1
--- /dev/null
+++
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyBeansTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.main;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.BeanFactoryDefinition;
+import org.apache.camel.util.SecurityViolation;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+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;
+
+/**
+ * The security policy checks the properties of the beans that the routes
define (such as the beans section of a YAML or
+ * XML DSL file) under the key of a bean configured from properties:
camel.beans.<name>.<property>.
+ */
+class MainSecurityPolicyBeansTest {
+
+ @Test
+ void insecureBeanPropertyFailsStartup() {
+ Main main = new Main();
+ main.addInitialProperty("camel.security.insecureSslPolicy", "fail");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("trustAllCertificates", "true")));
+
+ RuntimeCamelException ex = assertThrows(RuntimeCamelException.class,
main::start);
+ assertTrue(ex.getMessage().contains("[insecure:ssl]"),
ex.getMessage());
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.trustAllCertificates]"),
ex.getMessage());
+ }
+
+ @Test
+ void insecureBeanPropertyFailsStartupWithProdProfile() {
+ Main main = new Main();
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("trustAllCertificates", "true")));
+
+ RuntimeCamelException ex = assertThrows(RuntimeCamelException.class,
main::start);
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.trustAllCertificates]"),
ex.getMessage());
+ }
+
+ @Test
+ void secureBeanPropertyStarts() {
+ Main main = new Main();
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("trustAllCertificates", "false")));
+
+ assertDoesNotThrow(() -> {
+ main.start();
+ main.stop();
+ });
+ }
+
+ @Test
+ void allowedBeanPropertyStarts() {
+ Main main = new Main();
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.addInitialProperty("camel.security.allowedProperties",
"camel.beans.myClient.trustAllCertificates");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("trustAllCertificates", "true")));
+
+ assertDoesNotThrow(() -> {
+ main.start();
+ main.stop();
+ });
+ }
+
+ @Test
+ void plainTextSecretOnBeanFailsStartup() {
+ Main main = new Main();
+ main.addInitialProperty("camel.security.secretPolicy", "fail");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("password", "plaintext-password")));
+
+ RuntimeCamelException ex = assertThrows(RuntimeCamelException.class,
main::start);
+ assertTrue(ex.getMessage().contains("[secret]"), ex.getMessage());
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.password]"),
ex.getMessage());
+ }
+
+ @Test
+ void secretFromPlaceholderOnBeanStarts() {
+ Main main = new Main();
+ main.addInitialProperty("camel.security.secretPolicy", "fail");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("password", "{{vault:my-secret}}")));
+
+ assertDoesNotThrow(() -> {
+ main.start();
+ main.stop();
+ });
+ }
+
+ @Test
+ void nestedBeanPropertyFailsStartup() {
+ Main main = new Main();
+ main.addInitialProperty("camel.security.insecureSslPolicy", "fail");
+ main.configure().addRoutesBuilder(
+ routeWithBean("myClient", Map.of("tls",
Map.of("trustAllCertificates", "true"))));
+
+ RuntimeCamelException ex = assertThrows(RuntimeCamelException.class,
main::start);
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.tls.trustAllCertificates]"),
ex.getMessage());
+ }
+
+ @Test
+ void warnedBeanPropertyIsReportedWithTheConfigurationProperties() {
+ // the default policy is warn
+ Main main = new Main();
+ main.addInitialProperty("camel.ssl.trustAllCertificates", "true");
+ main.configure().addRoutesBuilder(routeWithBean("myClient",
Map.of("trustAllCertificates", "true")));
+ main.start();
+ try {
+ SecurityPolicyResult result =
main.getCamelContext().getCamelContextExtension()
+ .getContextPlugin(SecurityPolicyResult.class);
+ assertNotNull(result);
+ List<String> keys =
result.getViolations().stream().map(SecurityViolation::propertyKey).toList();
+ assertEquals(List.of("camel.ssl.trustAllCertificates",
"camel.beans.myClient.trustAllCertificates"), keys);
+ } finally {
+ main.stop();
+ }
+ }
+
+ private static RouteBuilder routeWithBean(String name, Map<String, Object>
properties) {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ // a bean as the YAML and XML DSL define it, from the beans
section of the route file
+ BeanFactoryDefinition<?> bean = new BeanFactoryDefinition<>();
+ bean.setName(name);
+ bean.setType("#class:" + MyClient.class.getName());
+ bean.setProperties(properties);
+ getBeans().add(bean);
+ }
+ };
+ }
+
+ public static class MyClient {
+
+ private boolean trustAllCertificates;
+ private String password;
+
+ public boolean isTrustAllCertificates() {
+ return trustAllCertificates;
+ }
+
+ public void setTrustAllCertificates(boolean trustAllCertificates) {
+ this.trustAllCertificates = trustAllCertificates;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+ }
+}
diff --git a/design/security.adoc b/design/security.adoc
index f1de140b5596..25b77df07d4f 100644
--- a/design/security.adoc
+++ b/design/security.adoc
@@ -131,7 +131,10 @@ The annotations flow through the existing build pipeline:
generates `SecurityUtils.java` in `camel-util`, containing a static map of
property patterns
to security categories
4. **Runtime detection** — at startup, `SecurityUtils.detectViolations()`
checks all resolved
- properties against the generated map
+ properties against the generated map. Once the routes are loaded,
camel-main also checks the properties of the
+ beans that the route files define (the `beans` section of a YAML or XML DSL
file, and the Spring XML and Blueprint
+ XML beans, kept as `BeanFactoryDefinition` in the model), under the key of
a bean configured from properties:
+ `camel.beans.<name>.<property>`
No new build plugins are needed. The existing `@UriParam` → JSON → code
generation pipeline
handles everything.
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 db7b6036253c..4e306c995163 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
@@ -75,6 +75,27 @@ including a value set through an environment variable: a
warning by default, and
A file location in `camel.vault.gcp.serviceAccountKey`, such as
`file:/etc/gcp/sa.json`, is also reported. It can go
behind a property placeholder too.
+=== camel-main - the security policy checks the beans that route files define
+
+With camel-main and the Camel CLI, the security policy now also checks the
properties of the beans that route files
+define (the `beans` section of a YAML or XML DSL file, and the beans of a
Spring XML or Blueprint XML file), as it
+checks a bean configured from `camel.beans.*` properties. A property is
reported under the key
+`camel.beans.<name>.<property>`, such as `camel.beans.opaPolicy.failOpen`.
+
+A bean in a route file that sets an insecure option or a plain-text secret is
now reported: a warning by default, and
+the startup fails with `camel.main.profile=prod`. Configure a secret with a
property placeholder or a vault reference
+instead, or add the key to `camel.security.allowedProperties` to allow it.
+
+The secrets include the user name: `user` and `username` are secret keys, like
`password`. So a `DataSource` bean in a
+route file with `username: sa` now logs a warning with `camel run`, and fails
the startup with
+`camel.main.profile=prod`, as `camel.beans.myDataSource.username=sa` in
`application.properties` already does. Use a
+property placeholder instead, such as `username: "{{db.username}}"`.
+
+The options are matched by their name, as for `camel.beans.*` properties. So a
bean option named `ssl` or `tls` that is
+set to `false`, such as the `ssl` option of a `DataSource`, is reported as an
insecure SSL setting, as
+`camel.beans.myDataSource.ssl=false` already is. To keep such a connection
without TLS, add the key to
+`camel.security.allowedProperties`.
+
=== camel-main - more options are reported by the insecure:dev security policy
These camel-main options are flagged `insecure:dev`, and the
`camel.security.insecureDevPolicy` check now reports them
diff --git a/docs/user-manual/modules/ROOT/pages/security-policy.adoc
b/docs/user-manual/modules/ROOT/pages/security-policy.adoc
index 0b8de56f4fba..884f82849a95 100644
--- a/docs/user-manual/modules/ROOT/pages/security-policy.adoc
+++ b/docs/user-manual/modules/ROOT/pages/security-policy.adoc
@@ -37,6 +37,15 @@ an option that merely has the same name as an insecure
option of another compone
camel-hivemq) is not flagged. Any other property (such as
`camel.ssl.trustAllCertificates`) is checked by the
option name.
+With camel-main and the Camel CLI, the properties of the beans that route
files define (the `beans` section of a YAML
+or XML DSL file, and the beans of a Spring XML or Blueprint XML file) are
checked once the routes are loaded, under the
+key of a bean configured from properties: `camel.beans.<name>.<property>`,
such as `camel.beans.opaPolicy.failOpen`.
+The same key goes in `camel.security.allowedProperties` to allow one of them.
Camel Spring Boot checks the
+configuration properties only, not the beans of route files.
+
+The security policy does not check the options set in the endpoint URIs of the
routes, so an insecure option there,
+such as `failOpen=true` in `opa:authz/allow?failOpen=true`, is not reported.
+
== Policy levels
Each category can be set to one of three enforcement levels:
diff --git
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainSecurityPolicyBeansTest.java
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainSecurityPolicyBeansTest.java
new file mode 100644
index 000000000000..eda7cffc13bb
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainSecurityPolicyBeansTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.main;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.main.app.MyTlsClient;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The security policy checks the properties of the beans of Spring XML and
Blueprint XML files, including the beans
+ * that are created after the routes are loaded (all the Blueprint XML beans,
and the delayed Spring XML beans).
+ */
+class KameletMainSecurityPolicyBeansTest {
+
+ private static final String BLUEPRINT =
"classpath:org/apache/camel/main/xml/blueprint-security-policy.xml";
+ private static final String SPRING =
"classpath:org/apache/camel/main/xml/spring-security-policy.xml";
+
+ @Test
+ void blueprintBeanFailsStartupWithProdProfile() {
+ assertInsecureBeanFailsStartup(BLUEPRINT);
+ }
+
+ @Test
+ void springXmlBeanFailsStartupWithProdProfile() {
+ assertInsecureBeanFailsStartup(SPRING);
+ }
+
+ @Test
+ void allowedBlueprintBeanStartsWithProdProfile() {
+ KameletMain main = new KameletMain();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.addInitialProperty("camel.security.allowedProperties",
"camel.beans.myClient.trustAllCertificates");
+ main.configure().withRoutesIncludePattern(BLUEPRINT);
+ main.configure().withAutoConfigurationEnabled(true);
+ main.start();
+
+ MyTlsClient client =
main.getCamelContext().getRegistry().lookupByNameAndType("myClient",
MyTlsClient.class);
+ assertNotNull(client);
+ assertTrue(client.isTrustAllCertificates());
+ } finally {
+ main.stop();
+ }
+ }
+
+ private static void assertInsecureBeanFailsStartup(String routes) {
+ KameletMain main = new KameletMain();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.configure().withRoutesIncludePattern(routes);
+ main.configure().withAutoConfigurationEnabled(true);
+
+ RuntimeCamelException ex =
assertThrows(RuntimeCamelException.class, main::start);
+ assertTrue(ex.getMessage().contains("[insecure:ssl]"),
ex.getMessage());
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.trustAllCertificates]"),
ex.getMessage());
+ } finally {
+ main.stop();
+ }
+ }
+}
diff --git
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/app/MyTlsClient.java
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/app/MyTlsClient.java
new file mode 100644
index 000000000000..4fd55df462ed
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/app/MyTlsClient.java
@@ -0,0 +1,30 @@
+/*
+ * 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.main.app;
+
+public class MyTlsClient {
+
+ private boolean trustAllCertificates;
+
+ public boolean isTrustAllCertificates() {
+ return trustAllCertificates;
+ }
+
+ public void setTrustAllCertificates(boolean trustAllCertificates) {
+ this.trustAllCertificates = trustAllCertificates;
+ }
+}
diff --git
a/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/blueprint-security-policy.xml
b/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/blueprint-security-policy.xml
new file mode 100644
index 000000000000..59105864cf99
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/blueprint-security-policy.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="myClient" class="org.apache.camel.main.app.MyTlsClient">
+ <property name="trustAllCertificates" value="true"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+ <route id="security-policy-blueprint">
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+</blueprint>
diff --git
a/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/spring-security-policy.xml
b/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/spring-security-policy.xml
new file mode 100644
index 000000000000..870a7d8075c7
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/test/resources/org/apache/camel/main/xml/spring-security-policy.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<camel>
+
+ <beans xmlns="http://www.springframework.org/schema/beans">
+ <bean id="myClient" class="org.apache.camel.main.app.MyTlsClient">
+ <property name="trustAllCertificates" value="true"/>
+ </bean>
+ </beans>
+
+ <route id="security-policy-spring">
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+
+</camel>
diff --git
a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainSecurityPolicyBeansTest.java
b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainSecurityPolicyBeansTest.java
new file mode 100644
index 000000000000..fa28526df154
--- /dev/null
+++
b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainSecurityPolicyBeansTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.dsl.xml.io;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.dsl.xml.io.beans.MyTlsClient;
+import org.apache.camel.main.Main;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The security policy checks the properties of the beans that an XML route
file defines, as it checks a bean configured
+ * from camel.beans.* properties.
+ */
+class XmlMainSecurityPolicyBeansTest {
+
+ private static final String ROUTES =
"org/apache/camel/dsl/xml/io/security-policy-beans.xml";
+
+ @Test
+ void insecureBeanPropertyFailsStartupWithProdProfile() {
+ Main main = new Main();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.configure().withRoutesIncludePattern(ROUTES);
+
+ RuntimeCamelException ex =
assertThrows(RuntimeCamelException.class, main::start);
+ assertTrue(ex.getMessage().contains("[insecure:ssl]"),
ex.getMessage());
+
assertTrue(ex.getMessage().contains("[camel.beans.myClient.trustAllCertificates]"),
ex.getMessage());
+ } finally {
+ main.stop();
+ }
+ }
+
+ @Test
+ void allowedBeanPropertyStartsWithProdProfile() {
+ Main main = new Main();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.addInitialProperty("camel.security.allowedProperties",
"camel.beans.myClient.trustAllCertificates");
+ main.configure().withRoutesIncludePattern(ROUTES);
+ main.start();
+
+ MyTlsClient client =
main.getCamelContext().getRegistry().lookupByNameAndType("myClient",
MyTlsClient.class);
+ assertNotNull(client);
+ assertTrue(client.isTrustAllCertificates());
+ } finally {
+ main.stop();
+ }
+ }
+}
diff --git
a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/beans/MyTlsClient.java
b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/beans/MyTlsClient.java
new file mode 100644
index 000000000000..b36e01b05760
--- /dev/null
+++
b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/beans/MyTlsClient.java
@@ -0,0 +1,30 @@
+/*
+ * 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.dsl.xml.io.beans;
+
+public class MyTlsClient {
+
+ private boolean trustAllCertificates;
+
+ public boolean isTrustAllCertificates() {
+ return trustAllCertificates;
+ }
+
+ public void setTrustAllCertificates(boolean trustAllCertificates) {
+ this.trustAllCertificates = trustAllCertificates;
+ }
+}
diff --git
a/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/security-policy-beans.xml
b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/security-policy-beans.xml
new file mode 100644
index 000000000000..83410743e0d7
--- /dev/null
+++
b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/security-policy-beans.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<camel xmlns="http://camel.apache.org/schema/xml-io">
+
+ <bean name="myClient" type="org.apache.camel.dsl.xml.io.beans.MyTlsClient">
+ <properties>
+ <property key="trustAllCertificates" value="true"/>
+ </properties>
+ </bean>
+
+ <route id="security-policy-beans">
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+
+</camel>
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/MainSecurityPolicyBeansTest.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/MainSecurityPolicyBeansTest.java
new file mode 100644
index 000000000000..cf3348d6498f
--- /dev/null
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/MainSecurityPolicyBeansTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.dsl.yaml;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.dsl.yaml.support.model.MyTlsClient;
+import org.apache.camel.main.Main;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * The security policy checks the properties of the beans in the beans section
of a YAML route file, as it checks a bean
+ * configured from camel.beans.* properties.
+ */
+class MainSecurityPolicyBeansTest {
+
+ @Test
+ void insecureBeanPropertyFailsStartupWithProdProfile() {
+ Main main = new Main();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+
main.configure().withRoutesIncludePattern("security/route-beans.yaml");
+
+ assertThatThrownBy(main::start)
+ .isInstanceOf(RuntimeCamelException.class)
+ .hasMessageContaining("[insecure:ssl]")
+
.hasMessageContaining("[camel.beans.myClient.trustAllCertificates]");
+ } finally {
+ main.stop();
+ }
+ }
+
+ @Test
+ void allowedBeanPropertyStartsWithProdProfile() {
+ Main main = new Main();
+ try {
+ main.addInitialProperty("camel.main.profile", "prod");
+ main.addInitialProperty("camel.security.allowedProperties",
"camel.beans.myClient.trustAllCertificates");
+
main.configure().withRoutesIncludePattern("security/route-beans.yaml");
+ main.start();
+
+ MyTlsClient client =
main.getCamelContext().getRegistry().lookupByNameAndType("myClient",
MyTlsClient.class);
+ assertThat(client).isNotNull();
+ assertThat(client.isTrustAllCertificates()).isTrue();
+ } finally {
+ main.stop();
+ }
+ }
+}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/support/model/MyTlsClient.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/support/model/MyTlsClient.java
new file mode 100644
index 000000000000..beef762330ee
--- /dev/null
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/support/model/MyTlsClient.java
@@ -0,0 +1,30 @@
+/*
+ * 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.dsl.yaml.support.model;
+
+public class MyTlsClient {
+
+ private boolean trustAllCertificates;
+
+ public boolean isTrustAllCertificates() {
+ return trustAllCertificates;
+ }
+
+ public void setTrustAllCertificates(boolean trustAllCertificates) {
+ this.trustAllCertificates = trustAllCertificates;
+ }
+}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/security/route-beans.yaml
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/security/route-beans.yaml
new file mode 100644
index 000000000000..064a31e80e06
--- /dev/null
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/security/route-beans.yaml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+- beans:
+ - name: myClient
+ type: org.apache.camel.dsl.yaml.support.model.MyTlsClient
+ properties:
+ trustAllCertificates: true
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - to: mock:result