-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from IABTechLab/ysh-UID2-2123-load-azure-secret…
…-from-vault load azure secret key from vault
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/uid2/attestation/azure/AzureVaultOperatorKeyRetriever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |