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 d7cfdd17eb79 CAMEL-28103: camel-pqc - apply the HashiCorp Vault
namespace to all key operations (#31347)
d7cfdd17eb79 is described below
commit d7cfdd17eb795e2aadd7f40f0f3b5f917049ae2d
Author: Andrea Cosentino <[email protected]>
AuthorDate: Fri Dec 4 14:45:51 2026 +0100
CAMEL-28103: camel-pqc - apply the HashiCorp Vault namespace to all key
operations (#31347)
HashicorpVaultKeyLifecycleManager prepended the configured namespace (when
cloud is true) for the read and list operations, but storeKey,
updateKeyMetadata and deleteKey passed only secretsEngine to
vaultTemplate.opsForKeyValue.
Add getEnginePath() (as in HashicorpVaultProducer of camel-hashicorp-vault)
and use it for all operations, so they resolve the same engine path:
namespace/secretsEngine when cloud is true and the namespace is set, else
secretsEngine. Javadoc and upgrade guide updated.
AI-assisted with Antigravity on behalf of oscerd.
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../HashicorpVaultKeyLifecycleManager.java | 39 ++--
...HashicorpVaultNamespacePathConsistencyTest.java | 206 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc | 9 +
3 files changed, 231 insertions(+), 23 deletions(-)
diff --git
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultKeyLifecycleManager.java
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultKeyLifecycleManager.java
index c96058050bea..ea46cd45c6f1 100644
---
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultKeyLifecycleManager.java
+++
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultKeyLifecycleManager.java
@@ -84,7 +84,8 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
* @param secretsEngine KV secrets engine name
* @param keyPrefix Prefix for key paths in Vault
* @param cloud Whether Vault is deployed on HashiCorp Cloud
Platform
- * @param namespace Namespace for HCP Vault (required if cloud is true)
+ * @param namespace Namespace for HCP Vault (required if cloud is
true). Applied as a path prefix only; pass
+ * {@code cloud=false} if the {@code VaultTemplate}
already sends {@code X-Vault-Namespace}.
*/
public HashicorpVaultKeyLifecycleManager(VaultTemplate vaultTemplate,
String secretsEngine, String keyPrefix,
boolean cloud, String namespace) {
@@ -142,7 +143,8 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
* @param secretsEngine KV secrets engine name
* @param keyPrefix Prefix for key paths in Vault
* @param cloud Whether Vault is deployed on HashiCorp Cloud
Platform
- * @param namespace Namespace for HCP Vault (required if cloud is true)
+ * @param namespace Namespace for HCP Vault (required if cloud is
true). Applied as a path prefix only; pass
+ * {@code cloud=false} if the {@code VaultTemplate}
already sends {@code X-Vault-Namespace}.
*/
public HashicorpVaultKeyLifecycleManager(String host, int port, String
scheme, String token, String secretsEngine,
String keyPrefix, boolean cloud,
String namespace) {
@@ -249,7 +251,7 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
String publicKeyBase64 =
Base64.getEncoder().encodeToString(publicKeyBytes);
String metadataJson = KeyMetadataCodec.toJson(metadata);
- VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(secretsEngine,
+ VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(getEnginePath(),
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
// Store private key separately (strict ACL recommended in production)
@@ -380,7 +382,7 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
*/
@Override
public void updateKeyMetadata(String keyId, KeyMetadata metadata) throws
Exception {
- VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(secretsEngine,
+ VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(getEnginePath(),
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
Map<String, Object> metadataData = new HashMap<>();
@@ -394,7 +396,7 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
@Override
public void deleteKey(String keyId) throws Exception {
- VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(secretsEngine,
+ VaultKeyValueOperations keyValue =
vaultTemplate.opsForKeyValue(getEnginePath(),
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
// Delete private key, public key, and metadata separately
@@ -503,34 +505,25 @@ public class HashicorpVaultKeyLifecycleManager implements
KeyLifecycleManager {
return keyPrefix + "/" + keyId;
}
+ private String getEnginePath() {
+ if (cloud && namespace != null && !namespace.isEmpty()) {
+ return namespace + "/" + secretsEngine;
+ }
+ return secretsEngine;
+ }
+
/**
* Build the data path for reading/writing secrets, following HCP Vault
pattern from camel-hashicorp-vault
*/
private String buildDataPath(String secretPath) {
- if (!cloud) {
- return secretsEngine + "/data/" + secretPath;
- } else {
- if (namespace != null && !namespace.isEmpty()) {
- return namespace + "/" + secretsEngine + "/data/" + secretPath;
- } else {
- return secretsEngine + "/data/" + secretPath;
- }
- }
+ return getEnginePath() + "/data/" + secretPath;
}
/**
* Build the metadata path for listing secrets, following HCP Vault
pattern from camel-hashicorp-vault
*/
private String buildMetadataPath(String secretPath) {
- if (!cloud) {
- return secretsEngine + "/metadata/" + secretPath;
- } else {
- if (namespace != null && !namespace.isEmpty()) {
- return namespace + "/" + secretsEngine + "/metadata/" +
secretPath;
- } else {
- return secretsEngine + "/metadata/" + secretPath;
- }
- }
+ return getEnginePath() + "/metadata/" + secretPath;
}
/**
diff --git
a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultNamespacePathConsistencyTest.java
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultNamespacePathConsistencyTest.java
new file mode 100644
index 000000000000..59e908b20156
--- /dev/null
+++
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/lifecycle/HashicorpVaultNamespacePathConsistencyTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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.pqc.lifecycle;
+
+import java.security.KeyPair;
+import java.security.Security;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.vault.core.VaultKeyValueOperations;
+import org.springframework.vault.core.VaultKeyValueOperationsSupport;
+import org.springframework.vault.core.VaultTemplate;
+import org.springframework.vault.support.VaultResponse;
+
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Verifies that {@link HashicorpVaultKeyLifecycleManager} applies the same
Vault namespace and engine path across
+ * write, update, delete, read, and list operations.
+ */
+class HashicorpVaultNamespacePathConsistencyTest {
+
+ private Map<String, Map<String, Object>> store;
+ private VaultTemplate vaultTemplate;
+
+ @BeforeAll
+ static void setupProviders() {
+ if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
+ Security.addProvider(new BouncyCastleProvider());
+ }
+ if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) ==
null) {
+ Security.addProvider(new BouncyCastlePQCProvider());
+ }
+ }
+
+ @BeforeEach
+ void setup() {
+ store = new ConcurrentHashMap<>();
+ vaultTemplate = mockVaultTemplate(store);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static VaultTemplate mockVaultTemplate(Map<String, Map<String,
Object>> store) {
+ VaultTemplate template = mock(VaultTemplate.class);
+
+ when(template.opsForKeyValue(anyString(),
any(VaultKeyValueOperationsSupport.KeyValueBackend.class)))
+ .thenAnswer(inv -> {
+ String enginePath = inv.getArgument(0);
+ VaultKeyValueOperations ops =
mock(VaultKeyValueOperations.class);
+ doAnswer(putInv -> {
+ String path = putInv.getArgument(0);
+ Object body = putInv.getArgument(1);
+ store.put(enginePath + "/data/" + path, Map.of("data",
body));
+ return null;
+ }).when(ops).put(anyString(), any());
+ doAnswer(delInv -> {
+ String path = delInv.getArgument(0);
+ store.remove(enginePath + "/data/" + path);
+ return null;
+ }).when(ops).delete(anyString());
+ return ops;
+ });
+
+ when(template.read(anyString())).thenAnswer(inv -> {
+ String fullPath = inv.getArgument(0);
+ Map<String, Object> entry = store.get(fullPath);
+ if (entry == null) {
+ return null;
+ }
+ VaultResponse response = new VaultResponse();
+ response.setData(entry);
+ return response;
+ });
+
+ when(template.list(anyString())).thenAnswer(inv -> {
+ String metadataPath = inv.getArgument(0);
+ String dataPrefix = metadataPath.replaceFirst("/metadata/",
"/data/") + "/";
+ Set<String> keyIds = new LinkedHashSet<>();
+ for (String key : store.keySet()) {
+ if (key.startsWith(dataPrefix)) {
+ String remainder = key.substring(dataPrefix.length());
+ int slashIdx = remainder.indexOf('/');
+ if (slashIdx > 0) {
+ keyIds.add(remainder.substring(0, slashIdx) + "/");
+ }
+ }
+ }
+ return List.copyOf(keyIds);
+ });
+
+ return template;
+ }
+
+ @Test
+ void writeAndReadResolveSameNamespace() throws Exception {
+ HashicorpVaultKeyLifecycleManager writer
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "admin");
+ KeyPair generated = writer.generateKeyPair("MLDSA", "ns-key");
+
+ verify(vaultTemplate, atLeastOnce())
+ .opsForKeyValue("admin/secret",
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+
assertTrue(store.containsKey("admin/secret/data/pqc/keys/ns-key/private"));
+
assertTrue(store.containsKey("admin/secret/data/pqc/keys/ns-key/public"));
+
assertTrue(store.containsKey("admin/secret/data/pqc/keys/ns-key/metadata"));
+
+ // Separate instance with an empty in-memory cache forces reads from
Vault
+ HashicorpVaultKeyLifecycleManager reader
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "admin");
+ KeyPair loaded = reader.getKey("ns-key");
+ assertNotNull(loaded);
+ assertArrayEquals(generated.getPublic().getEncoded(),
loaded.getPublic().getEncoded());
+ assertArrayEquals(generated.getPrivate().getEncoded(),
loaded.getPrivate().getEncoded());
+
+ KeyMetadata metadata = reader.getKeyMetadata("ns-key");
+ assertNotNull(metadata);
+ assertEquals("ns-key", metadata.getKeyId());
+ assertEquals(1, reader.listKeys().size());
+ }
+
+ @Test
+ void updateMetadataAndDeleteUseSameNamespace() throws Exception {
+ HashicorpVaultKeyLifecycleManager writer
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "admin");
+ writer.generateKeyPair("MLDSA", "lifecycle-key");
+ writer.revokeKey("lifecycle-key", "scheduled rotation");
+
+ HashicorpVaultKeyLifecycleManager reader
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "admin");
+ KeyMetadata revoked = reader.getKeyMetadata("lifecycle-key");
+ assertNotNull(revoked);
+ assertEquals(KeyMetadata.KeyStatus.REVOKED, revoked.getStatus());
+
+ writer.deleteKey("lifecycle-key");
+ HashicorpVaultKeyLifecycleManager afterDelete
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "admin");
+ assertNull(afterDelete.getKeyMetadata("lifecycle-key"));
+ assertTrue(store.isEmpty());
+ }
+
+ @Test
+ void cloudFalseLeavesEnginePathUnchanged() throws Exception {
+ HashicorpVaultKeyLifecycleManager writer
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", false, "admin");
+ KeyPair generated = writer.generateKeyPair("MLDSA", "non-cloud-key");
+
+ verify(vaultTemplate, atLeastOnce())
+ .opsForKeyValue("secret",
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+
assertTrue(store.containsKey("secret/data/pqc/keys/non-cloud-key/private"));
+
+ HashicorpVaultKeyLifecycleManager reader
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", false, "admin");
+ KeyPair loaded = reader.getKey("non-cloud-key");
+ assertNotNull(loaded);
+ assertArrayEquals(generated.getPublic().getEncoded(),
loaded.getPublic().getEncoded());
+ }
+
+ @Test
+ void cloudTrueWithEmptyNamespaceLeavesEnginePathUnchanged() throws
Exception {
+ HashicorpVaultKeyLifecycleManager writer
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "");
+ KeyPair generated = writer.generateKeyPair("MLDSA", "empty-ns-key");
+
+ verify(vaultTemplate, atLeastOnce())
+ .opsForKeyValue("secret",
VaultKeyValueOperationsSupport.KeyValueBackend.versioned());
+
assertTrue(store.containsKey("secret/data/pqc/keys/empty-ns-key/private"));
+
+ HashicorpVaultKeyLifecycleManager reader
+ = new HashicorpVaultKeyLifecycleManager(vaultTemplate,
"secret", "pqc/keys", true, "");
+ KeyPair loaded = reader.getKey("empty-ns-key");
+ assertNotNull(loaded);
+ assertArrayEquals(generated.getPublic().getEncoded(),
loaded.getPublic().getEncoded());
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index b88d5c87df04..a226939620b1 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -169,6 +169,15 @@ Calling key generation without an explicit `parameterSpec`
for algorithms withou
`EC`) now throws an `IllegalArgumentException`. In addition,
`KeyLifecycleManager.rotateKey` now rejects calls where
`oldKeyId` equals `newKeyId`.
+=== camel-pqc - HashicorpVaultKeyLifecycleManager namespace path consistency
+
+When `cloud=true` and `namespace` is configured on
`HashicorpVaultKeyLifecycleManager`, key writes, metadata updates,
+and deletes now use the same `<namespace>/<secretsEngine>` path prefix as
reads and lists. Keys previously written
+with `cloud=true` and a `namespace` were stored under
`<secretsEngine>/data/...` without the namespace prefix, so they
+will no longer be found at `<namespace>/<secretsEngine>/data/...` after
upgrading and must be re-stored or moved to
+the namespaced path. If your `VaultTemplate` already sends the
`X-Vault-Namespace` header, pass `cloud=false` to
+avoid double-prefixing the namespace.
+
=== camel-kafka, camel-kafka-share - sslContextParameters now configures the
complete TLS engine
The Kafka components now create their TLS engines from the complete
`SSLContext` produced by Camel's