From 371ca4780737b4d10ea24f6ab11d0a9495a7c117 Mon Sep 17 00:00:00 2001 From: Andrea Cosentino Date: Tue, 12 Dec 2023 13:35:41 +0100 Subject: [PATCH] CAMEL-20223 - Camel-Spring-Boot: Camel Azure Key Vault should Support Azure Identity in the component and secrets function (#1041) Signed-off-by: Andrea Cosentino --- .../catalog/components/azure-key-vault.json | 13 +++++++------ .../src/main/docs/spring-boot.json | 7 +++++++ .../vault/AzureVaultAutoConfiguration.java | 1 + .../AzureVaultConfigurationProperties.java | 18 ++++++++++++++++-- .../vault/AzureVaultConfigurationTest.java | 4 +++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/azure-key-vault.json b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/azure-key-vault.json index 6e16812971f..480370934fd 100644 --- a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/azure-key-vault.json +++ b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/azure-key-vault.json @@ -31,11 +31,12 @@ }, "properties": { "vaultName": { "index": 0, "kind": "path", "displayName": "Vault Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Vault Name to be used" }, - "operation": { "index": 1, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation", "enum": [ "createSecret", "getSecret", "deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Operation to be performed" }, - "secretClient": { "index": 2, "kind": "parameter", "displayName": "Secret Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.azure.security.keyvault.secrets.SecretClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Instance of Secret client" }, - "lazyStartProducer": { "index": 3, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }, - "clientId": { "index": 4, "kind": "parameter", "displayName": "Client Id", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Client Id to be used" }, - "clientSecret": { "index": 5, "kind": "parameter", "displayName": "Client Secret", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Client Secret to be used" }, - "tenantId": { "index": 6, "kind": "parameter", "displayName": "Tenant Id", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Tenant Id to be used" } + "credentialType": { "index": 1, "kind": "parameter", "displayName": "Credential Type", "group": "common", "label": "common", "required": false, "type": "object", "javaType": "org.apache.camel.component.azure.key.vault.CredentialType", "enum": [ "CLIENT_SECRET", "AZURE_IDENTITY" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "CLIENT_SECRET", "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Determines the credential strategy to adopt" }, + "operation": { "index": 2, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation", "enum": [ "createSecret", "getSecret", "deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Operation to be performed" }, + "secretClient": { "index": 3, "kind": "parameter", "displayName": "Secret Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.azure.security.keyvault.secrets.SecretClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Instance of Secret client" }, + "lazyStartProducer": { "index": 4, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }, + "clientId": { "index": 5, "kind": "parameter", "displayName": "Client Id", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Client Id to be used" }, + "clientSecret": { "index": 6, "kind": "parameter", "displayName": "Client Secret", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Client Secret to be used" }, + "tenantId": { "index": 7, "kind": "parameter", "displayName": "Tenant Id", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.azure.key.vault.KeyVaultConfiguration", "configurationField": "configuration", "description": "Tenant Id to be used" } } } diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json index 0db136bc244..594f8f9298b 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -1606,6 +1606,13 @@ "description": "Define the secrets to look at", "sourceType": "org.apache.camel.spring.boot.vault.AwsVaultConfigurationProperties" }, + { + "name": "camel.vault.azure.azure-identity-enabled", + "type": "java.lang.Boolean", + "description": "Whether the Azure Identity Authentication should be used or not.", + "sourceType": "org.apache.camel.spring.boot.vault.AzureVaultConfigurationProperties", + "defaultValue": false + }, { "name": "camel.vault.azure.blob-access-key", "type": "java.lang.String", diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultAutoConfiguration.java index 16621be1e6e..3524f565f9a 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultAutoConfiguration.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultAutoConfiguration.java @@ -37,6 +37,7 @@ public AzureVaultConfiguration azureVaultConfiguration(AzureVaultConfigurationPr answer.setClientSecret(config.getClientSecret()); answer.setVaultName(config.getVaultName()); answer.setTenantId(config.getTenantId()); + answer.setAzureIdentityEnabled(config.isAzureIdentityEnabled()); answer.setRefreshEnabled(config.isRefreshEnabled()); answer.setRefreshPeriod(config.getRefreshPeriod()); answer.setSecrets(config.getSecrets()); diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationProperties.java index 492611bec93..329947360fc 100644 --- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationProperties.java +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationProperties.java @@ -41,7 +41,13 @@ public class AzureVaultConfigurationProperties { * The tenant Id */ private String tenantId; - + + + /** + * Whether the Azure Identity Authentication should be used or not. + */ + private boolean azureIdentityEnabled; + /** * Whether to automatically reload Camel upon secrets being updated in Azure. */ @@ -108,7 +114,15 @@ public String getTenantId() { public void setTenantId(String tenantId) { this.tenantId = tenantId; } - + + public boolean isAzureIdentityEnabled() { + return azureIdentityEnabled; + } + + public void setAzureIdentityEnabled(boolean azureIdentityEnabled) { + this.azureIdentityEnabled = azureIdentityEnabled; + } + public boolean isRefreshEnabled() { return refreshEnabled; } diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationTest.java index d42c964aec0..d0746694ddd 100644 --- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationTest.java +++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/AzureVaultConfigurationTest.java @@ -36,7 +36,8 @@ "camel.vault.azure.clientId=myClientId", "camel.vault.azure.clientSecret=myClientSecret", "camel.vault.azure.tenantId=myTenantId", - "camel.vault.azure.eventhubConnectionString=connString"} + "camel.vault.azure.eventhubConnectionString=connString", + "camel.vault.azure.azureIdentityEnabled=true",} ) public class AzureVaultConfigurationTest { @@ -50,5 +51,6 @@ public void testAzureVault() throws Exception { Assertions.assertEquals("myClientId", camelContext.getVaultConfiguration().azure().getClientId()); Assertions.assertEquals("myTenantId", camelContext.getVaultConfiguration().azure().getTenantId()); Assertions.assertEquals("connString", camelContext.getVaultConfiguration().azure().getEventhubConnectionString()); + Assertions.assertEquals(true, camelContext.getVaultConfiguration().azure().isAzureIdentityEnabled()); } }