-
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.
add logic to handle azure operator key load
- Loading branch information
Showing
2 changed files
with
58 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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
package com.uid2.attestation.azure; | ||
|
||
import com.azure.identity.ManagedIdentityCredentialBuilder; | ||
import com.azure.security.keyvault.secrets.SecretClientBuilder; | ||
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) { | ||
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(); | ||
} | ||
} |