diff --git a/pom.xml b/pom.xml index 6672afb..06b012b 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ com.uid2 uid2-attestation-api - 1.1.0 + 1.5.0-676519b018 com.google.code.gson @@ -44,6 +44,31 @@ 2.10 compile + + com.google.guava + guava + 32.1.2-jre + + + com.azure + azure-security-keyvault-secrets + 4.7.0 + + + com.azure + azure-identity + 1.10.1 + + + ch.qos.logback + logback-core + 1.3.5 + + + ch.qos.logback + logback-classic + 1.3.5 + junit junit diff --git a/src/main/java/com/uid2/attestation/azure/AzureVaultOperatorKeyRetriever.java b/src/main/java/com/uid2/attestation/azure/AzureVaultOperatorKeyRetriever.java new file mode 100644 index 0000000..08225d5 --- /dev/null +++ b/src/main/java/com/uid2/attestation/azure/AzureVaultOperatorKeyRetriever.java @@ -0,0 +1,43 @@ +package com.uid2.attestation.azure; + +import com.azure.identity.ManagedIdentityCredentialBuilder; +import com.azure.security.keyvault.secrets.SecretClientBuilder; +import com.google.common.base.Strings; +import com.uid2.enclave.IOperatorKeyRetriever; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AzureVaultOperatorKeyRetriever implements IOperatorKeyRetriever { + private static final Logger LOGGER = LoggerFactory.getLogger(AzureVaultOperatorKeyRetriever.class); + + private final String vaultName; + private final String secretName; + + public AzureVaultOperatorKeyRetriever(String vaultName, String secretName) { + if (Strings.isNullOrEmpty(vaultName)) { + throw new IllegalArgumentException("vaultName is null or empty"); + } + if (Strings.isNullOrEmpty(secretName)) { + throw new IllegalArgumentException("secretName is null or empty"); + } + this.vaultName = vaultName; + this.secretName = secretName; + } + + // ManagedIdentityCredential is used here. + @Override + public String retrieve() { + String vaultUrl = "https://" + this.vaultName + ".vault.azure.net"; + LOGGER.info(String.format("Load OperatorKey secret (%s) from %s", this.secretName, vaultUrl)); + // Use default ExponentialBackoff retry policy + var secretClient = new SecretClientBuilder() + .vaultUrl(vaultUrl) + .credential(new ManagedIdentityCredentialBuilder().build()) + .buildClient(); + + var retrievedSecret = secretClient.getSecret(secretName); + + LOGGER.info("OperatorKey secret is loaded."); + return retrievedSecret.getValue(); + } +}