This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-27068-main-insecure-options
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c3331b70eb2d21283687918857e772d91e4af7e1
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 16 16:28:19 2026 +0100

    CAMEL-27068: camel-main - the security policy reports the camel-main 
options flagged insecure:dev from the metadata
    
    UpdateSensitizeHelper now generates the camel-main options with a security
    category into SECURITY_KEYS of SecurityUtils, matched by their whole key,
    instead of the hand-kept map that held only camel.chaos.rules and
    camel.chaos.scenario. This adds camel.management.mcpEnabled,
    camel.management.openapiUiEnabled and the two
    jwtAllowMissingIssuerAndAudience options of camel.server and
    camel.management, which the security policy did not report.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../apache/camel/main/MainSecurityPolicyTest.java  | 29 +++++++++
 .../java/org/apache/camel/util/SecurityUtils.java  | 48 ++++++++++-----
 .../org/apache/camel/util/SecurityUtilsTest.java   | 22 +++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    | 13 ++++
 .../maven/packaging/UpdateSensitizeHelper.java     | 71 ++++++++++++++++++++--
 5 files changed, 164 insertions(+), 19 deletions(-)

diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
index e4cd649e32c4..56e990cd9364 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
@@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -569,6 +570,34 @@ public class MainSecurityPolicyTest {
         });
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "camel.management.mcpEnabled", "camel.management.openapiUiEnabled",
+            "camel.server.jwtAllowMissingIssuerAndAudience", 
"camel.management.jwtAllowMissingIssuerAndAudience" })
+    public void testInsecureDevMainOptionFailsWithProdProfile(String key) {
+        // the camel-main options flagged insecure:dev in the metadata are 
reported by the security policy
+        Main main = new Main();
+        main.addInitialProperty("camel.main.profile", "prod");
+        main.addInitialProperty(key, "true");
+
+        RuntimeCamelException ex = assertThrows(RuntimeCamelException.class, 
main::start);
+        assertTrue(ex.getMessage().contains("[insecure:dev]"), 
ex.getMessage());
+        assertTrue(ex.getMessage().contains(key), ex.getMessage());
+    }
+
+    @Test
+    public void testInsecureDevMainOptionDisabledWithProdProfile() {
+        Main main = new Main();
+        main.addInitialProperty("camel.main.profile", "prod");
+        main.addInitialProperty("camel.management.mcpEnabled", "false");
+        
main.addInitialProperty("camel.server.jwtAllowMissingIssuerAndAudience", 
"false");
+
+        assertDoesNotThrow(() -> {
+            main.start();
+            main.stop();
+        });
+    }
+
     @Test
     public void testComponentOptionWithTheNameOfASecretVaultOption() {
         // serviceAccountKey and tenantId are secret as camel.vault options, 
but not as component options
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/SecurityUtils.java 
b/core/camel-util/src/main/java/org/apache/camel/util/SecurityUtils.java
index e0f2d0bb1fa9..ffd1a1dc60fb 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/SecurityUtils.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/SecurityUtils.java
@@ -354,13 +354,30 @@ public final class SecurityUtils {
         SECURITY_OPTION_OWNERS = Collections.unmodifiableMap(owners);
     }
 
-    // options that are matched by their whole configuration key rather than 
by their name, because options of other
-    // components have the same name (such as the rules option of the 
schematron endpoint), and that are insecure with
-    // any value that is not empty: the key in lower case without dashes, and 
the security category
-    private static final Map<String, String> SECURITY_KEYS = Map.of(
-            // the rules of camel-chaos to add at startup (CAMEL-26330), and a 
scenario file of rules (CAMEL-26722)
-            "camel.chaos.rules", INSECURE_DEV,
-            "camel.chaos.scenario", INSECURE_DEV);
+    // the camel-main options with a security category (such as 
camel.management.mcpEnabled), matched by their whole
+    // configuration key in lower case without dashes, as options of 
components can have the same name (such as the
+    // rules option of the schematron endpoint for camel.chaos.rules)
+    private static final Map<String, SecurityOption> SECURITY_KEYS;
+
+    static {
+        Map<String, SecurityOption> keys = new HashMap<>();
+        // Generated by camel build tools - do NOT edit this map!
+        // SECURITY-KEYS: START
+        keys.put("camel.chaos.rules", new SecurityOption(INSECURE_DEV, null));
+        keys.put("camel.chaos.scenario", new SecurityOption(INSECURE_DEV, 
null));
+        keys.put("camel.main.devconsoleenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.devconsoleenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.downloadenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.jwtallowmissingissuerandaudience", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.mcpenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.openapiuienabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.sendenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.management.uploadenabled", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.server.jwtallowmissingissuerandaudience", new 
SecurityOption(INSECURE_DEV, "true"));
+        keys.put("camel.ssl.trustallcertificates", new 
SecurityOption(INSECURE_SSL, "true"));
+        // SECURITY-KEYS: END
+        SECURITY_KEYS = Collections.unmodifiableMap(keys);
+    }
 
     private SecurityUtils() {
     }
@@ -375,19 +392,20 @@ public final class SecurityUtils {
     /**
      * Get security information for a configuration property.
      * <p>
-     * A key that identifies a component, data format or language (such as 
{@code camel.component.netty.ssl}) only
-     * matches a security option that this component, data format or language 
declares. Any other key (such as a
-     * camel-main option, or an option name without a prefix) matches by the 
option name, except that a configuration
-     * key never matches an option that only languages declare (such as {@code 
camel.beans.foo.nested} for the
-     * {@code nested} option of the simple language).
+     * A camel-main option with a security category (such as {@code 
camel.management.mcpEnabled}) matches by its whole
+     * key. A key that identifies a component, data format or language (such 
as {@code camel.component.netty.ssl}) only
+     * matches a security option that this component, data format or language 
declares. Any other key (such as an option
+     * name without a prefix) matches by the option name, except that a 
configuration key never matches an option that
+     * only languages declare (such as {@code camel.beans.foo.nested} for the 
{@code nested} option of the simple
+     * language).
      *
      * @param  text the configuration property key (e.g., 
"camel.component.aws2-s3.trustAllCertificates")
      * @return      the security option info, or null if the property has no 
security category
      */
     public static SecurityOption getSecurityOption(String text) {
-        String category = 
SECURITY_KEYS.get(text.toLowerCase(Locale.ENGLISH).replace("-", ""));
-        if (category != null) {
-            return new SecurityOption(category, null);
+        SecurityOption key = 
SECURITY_KEYS.get(text.toLowerCase(Locale.ENGLISH).replace("-", ""));
+        if (key != null) {
+            return key;
         }
         String name = normalizeOptionName(text);
         SecurityOption answer = SECURITY_OPTIONS.get(name);
diff --git 
a/core/camel-util/src/test/java/org/apache/camel/util/SecurityUtilsTest.java 
b/core/camel-util/src/test/java/org/apache/camel/util/SecurityUtilsTest.java
index 60e94f63b989..cbe43a2d7e79 100644
--- a/core/camel-util/src/test/java/org/apache/camel/util/SecurityUtilsTest.java
+++ b/core/camel-util/src/test/java/org/apache/camel/util/SecurityUtilsTest.java
@@ -288,6 +288,28 @@ class SecurityUtilsTest {
         
assertNotNull(SecurityUtils.getSecurityOption("camel.main.devConsoleEnabled"));
     }
 
+    @Test
+    void testCamelMainOptionsMatchByWholeKey() {
+        // the camel-main options flagged insecure:dev, generated from the 
camel-main metadata
+        for (String key : List.of("camel.management.mcpEnabled", 
"camel.management.openapiUiEnabled",
+                "camel.server.jwtAllowMissingIssuerAndAudience", 
"camel.management.jwtAllowMissingIssuerAndAudience",
+                "camel.management.devConsoleEnabled", 
"camel.main.devConsoleEnabled")) {
+            SecurityUtils.SecurityOption option = 
SecurityUtils.getSecurityOption(key);
+            assertNotNull(option, key);
+            assertEquals(SecurityUtils.INSECURE_DEV, option.category(), key);
+            assertTrue(SecurityUtils.isInsecureValue(key, "true"), key);
+            assertFalse(SecurityUtils.isInsecureValue(key, "false"), key);
+        }
+        // dash case
+        
assertTrue(SecurityUtils.isInsecureValue("camel.management.mcp-enabled", 
"true"));
+        // an option of a component with the same name is not the camel-main 
option
+        
assertNull(SecurityUtils.getSecurityOption("camel.component.foo.mcpEnabled"));
+        
assertNull(SecurityUtils.getSecurityOption("camel.component.foo.jwtAllowMissingIssuerAndAudience"));
+        // a camel-main option that is not boolean is insecure with any value 
that is not empty
+        assertTrue(SecurityUtils.isInsecureValue("camel.chaos.rules", 
"delay:route1:1000"));
+        assertFalse(SecurityUtils.isInsecureValue("camel.chaos.rules", ""));
+    }
+
     @Test
     void testLanguageOptionMatchesOnlyItsOwnLanguage() {
         // nested is declared only by the simple and file languages
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 db27e67ca87c..8bdf1fd3887f 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
@@ -61,6 +61,19 @@ 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 - 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
+when they are set to `true`: a warning by default, and the startup fails with 
`camel.main.profile=prod`.
+
+* `camel.management.mcpEnabled`
+* `camel.management.openapiUiEnabled`
+* `camel.server.jwtAllowMissingIssuerAndAudience`
+* `camel.management.jwtAllowMissingIssuerAndAudience`
+
+To keep one of them enabled in production, set 
`camel.security.insecureDevPolicy=allow`, or add the key to
+`camel.security.allowedProperties`.
+
 === camel-observability-services - promoted to Stable
 
 The `camel-observability-services` component has been promoted from _Preview_ 
to _Stable_ support level.
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
index 3a35ab58d73f..fd5f07788fc6 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
@@ -66,6 +66,8 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
     private static final String SECURITY_END_TOKEN = "// SECURITY-OPTIONS: 
END";
     private static final String OWNERS_START_TOKEN = "// 
SECURITY-OPTION-OWNERS: START";
     private static final String OWNERS_END_TOKEN = "// SECURITY-OPTION-OWNERS: 
END";
+    private static final String SECURITY_KEYS_START_TOKEN = "// SECURITY-KEYS: 
START";
+    private static final String SECURITY_KEYS_END_TOKEN = "// SECURITY-KEYS: 
END";
 
     private static final String SECRET = "secret";
     private static final String INSECURE_DEV = "insecure:dev";
@@ -99,10 +101,11 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
     // their whole key, as a component can have an option with the same name 
that is not secret (such as tenantId)
     private static final String MAIN_METADATA = 
"camel-main-configuration-metadata.json";
 
-    // extra security options from camel-main properties that are not in 
component JSON files
+    // extra security options that are not in component JSON files, matched by 
their option name
     // each entry: option name (lowercase, no dashes), security category, 
insecure value
-    // (an option that must be matched by its whole key, such as 
camel.chaos.rules, is in SECURITY_KEYS of SecurityUtils,
-    // which is written by hand and not generated)
+    // (the camel-main options with a security category are generated into 
SECURITY_KEYS of SecurityUtils, matched by
+    // their whole key; the camel-main options below are also matched by name, 
for the security scan of the Camel MCP
+    // server, which reads the option names from 
SecurityUtils.getSecurityOptions())
     private static final String[][] EXTRA_SECURITY_OPTIONS = {
             { "devconsoleenabled", INSECURE_DEV, "true" },
             { "uploadenabled", INSECURE_DEV, "true" },
@@ -146,6 +149,9 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         // key -> [category, insecureValue]
         Map<String, String[]> securityOptions = new TreeMap<>();
         // key -> the components, data formats and languages that declare the 
option (such as component:netty)
+        // the whole key of the camel-main options with a security category 
(such as camel.management.mcpenabled)
+        // -> [category, insecureValue]
+        Map<String, String[]> securityKeys = new TreeMap<>();
         Map<String, Set<String>> securityOptionOwners = new TreeMap<>();
 
         for (Path file : jsonFiles) {
@@ -175,7 +181,10 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
                 if (isMain) {
                     // the option names are whole keys (such as 
camel.server.jwtKeystorePassword)
                     MainModel mm = JsonMapper.generateMainModel(obj);
-                    mm.getOptions().forEach(o -> collectSecretOption(o, 
wholeKeys));
+                    mm.getOptions().forEach(o -> {
+                        collectSecretOption(o, wholeKeys);
+                        collectSecurityKey(o, securityKeys);
+                    });
                 } else if (isBean) {
                     PojoBeanModel pm = JsonMapper.generatePojoBeanModel(obj);
                     pm.getOptions().forEach(o -> collectSecretOption(o, 
secrets));
@@ -256,6 +265,7 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
             try {
                 boolean updated = updateSecurityUtils(camelDir, 
securityOptions);
                 updated |= updateSecurityOptionOwners(camelDir, 
securityOptionOwners);
+                updated |= updateSecurityKeys(camelDir, securityKeys);
                 if (updated) {
                     getLog().info("Updated 
camel-util/src/main/java/org/apache/camel/util/SecurityUtils.java file");
                 } else {
@@ -399,6 +409,59 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         }
     }
 
+    private static void collectSecurityKey(BaseOptionModel o, Map<String, 
String[]> securityKeys) {
+        String security = o.getSecurity();
+        if (!Strings.isNullOrEmpty(security) && !SECRET.equals(security)) {
+            String key = o.getName().toLowerCase(Locale.ENGLISH).replace("-", 
"");
+            String insecureValue = o.getInsecureValue();
+            if (Strings.isNullOrEmpty(insecureValue)) {
+                // boolean options are insecure when true, and other options 
with any value that is not empty
+                insecureValue = "boolean".equals(o.getType()) ? "true" : null;
+            }
+            securityKeys.put(key, new String[] { security, insecureValue });
+        }
+    }
+
+    private boolean updateSecurityKeys(File camelDir, Map<String, String[]> 
securityKeys) throws Exception {
+        File java = new File(camelDir, 
"src/main/java/org/apache/camel/util/SecurityUtils.java");
+        String text = PackageHelper.loadText(java);
+        String spaces8 = "        ";
+
+        StringJoiner sb = new StringJoiner("\n");
+        for (Map.Entry<String, String[]> entry : securityKeys.entrySet()) {
+            String category = entry.getValue()[0];
+            String insecureValue = entry.getValue()[1];
+            String categoryRef = CATEGORY_CONSTANTS.get(category);
+            String categoryExpr = categoryRef != null ? categoryRef : "\"" + 
category + "\"";
+            String valueExpr;
+            if (insecureValue == null) {
+                valueExpr = "null";
+            } else {
+                String valueRef = VALUE_CONSTANTS.get(insecureValue);
+                valueExpr = valueRef != null ? valueRef : "\"" + insecureValue 
+ "\"";
+            }
+            sb.add(spaces8 + "keys.put(\"" + entry.getKey() + "\", new 
SecurityOption(" + categoryExpr + ", " + valueExpr
+                   + "));");
+        }
+        String changed = sb.toString().trim();
+
+        String existing = Strings.between(text, SECURITY_KEYS_START_TOKEN, 
SECURITY_KEYS_END_TOKEN);
+        if (existing != null) {
+            existing = existing.trim();
+            if (existing.equals(changed)) {
+                return false;
+            }
+            String before = Strings.before(text, SECURITY_KEYS_START_TOKEN);
+            String after = Strings.after(text, SECURITY_KEYS_END_TOKEN);
+            String block = changed.isEmpty() ? "" : spaces8 + changed + "\n";
+            text = before + SECURITY_KEYS_START_TOKEN + "\n" + block + spaces8 
+ SECURITY_KEYS_END_TOKEN + after;
+            PackageHelper.writeText(java, text);
+            return true;
+        }
+
+        return false;
+    }
+
     private boolean updateSecurityUtils(File camelDir, Map<String, String[]> 
securityOptions) throws Exception {
         File java = new File(camelDir, 
"src/main/java/org/apache/camel/util/SecurityUtils.java");
         String text = PackageHelper.loadText(java);

Reply via email to