-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Azure Key Vault Extension #218
Merged
Merged
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8740472
Initialize file structure for keyvault extension.
galiacheng c38313e
use quarkus cli application for testing.
galiacheng 99cf94e
add internal extension for azure identity
galiacheng 5e2aca5
add dynamic-proxy.
galiacheng ee81987
add reflectiveHierarchyClass
galiacheng ccf8b97
complete integration test.
galiacheng cb93ba0
remove unused dependency.
galiacheng 552ebed
rename test sample.
galiacheng 4e6a06e
procude SecretAsyncClient.
galiacheng 1ebbdbf
add ut.
galiacheng ea03ef6
complete integration test
galiacheng 8dd8879
create doc for key vault extension.
galiacheng ea7b823
add ci for key vault extension.
galiacheng c2f3b72
code clean up
galiacheng 50cb09a
clean up import
galiacheng 1c5b5d0
update integration test.
galiacheng 53b12c7
update top README.
galiacheng 6ada004
Update README of integration-test for keyvault
galiacheng e993ce7
add KeyVaultSecretResourceIT.
galiacheng 010b51b
fix com.microsoft.aad.msal4j.AbstractClientApplicationBase$Builder no…
galiacheng bf46fce
update azure-identity denpendency versions.
galiacheng 6d2f6dc
clean up.
galiacheng 690a3d7
build.yaml: specify -DskipTests before az login, as the key vault ext…
galiacheng 9f0c28f
add script to delete keyvault resource.
galiacheng 626f496
use reactive programing in integration test.
galiacheng b68c60b
remove unused import.
galiacheng 1b0f9b4
apply Jianguo's comment.
galiacheng 5b3010c
apply Zhihao's comments.
galiacheng a04324d
use -Dskip.azure.test=true to skip tests that require real azure serv…
galiacheng 0db5e3b
use io.quarkus.logging.Log.
galiacheng b0cfd37
remove unused dependency.
galiacheng af62cb7
as we disscussed, move otherkeyvault API test to the next PR.
galiacheng d895ebe
fix build failure
galiacheng 06eb3f8
sort imports used in Key Vault Extension.
galiacheng 5fce42c
apply Ed's comments.
galiacheng a605c5b
add identitifier to track key vault secret clients.
galiacheng 24cdcdb
format AzureQuarkusIdentifier.
galiacheng 52a3125
format KeyVaultSecretClientProducer.java
galiacheng 37c8dc9
add comment for azure-identity native resources.
galiacheng 02eff46
fix length of application id cannot be greater than 24
galiacheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
Binary file added
BIN
+44.3 KB
docs/modules/ROOT/assets/images/quarkus-azure-keyvault-deleted-secret-portal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.3 KB
docs/modules/ROOT/assets/images/quarkus-azure-keyvault-secret-portal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* xref:quarkus-azure-app-configuration.adoc[Quarkus Azure App Configuration Extension] | ||
* xref:quarkus-azure-keyvault.adoc[Quarkus Azure Key Vault Extension] | ||
* xref:quarkus-azure-storage-blob.adoc[Quarkus Azure Blob Storage Extension] |
29 changes: 29 additions & 0 deletions
29
docs/modules/ROOT/pages/includes/quarkus-azure-keyvault.adoc
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,29 @@ | ||
|
||
:summaryTableId: quarkus-azure-keyvault | ||
[.configuration-legend] | ||
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime | ||
[.configuration-reference.searchable, cols="80,.^10,.^10"] | ||
|=== | ||
|
||
h|[[quarkus-azure-keyvault_configuration]]link:#quarkus-azure-keyvault_configuration[Configuration property] | ||
|
||
h|Type | ||
h|Default | ||
|
||
a| [[quarkus-azure-keyvault_quarkus.quarkus.azure.keyvault.secret.endpoint]]`link:#quarkus-azure-keyvualt_quarkus.azure.keyvault.secret.endpoint[quarkus.azure.keyvault.secret.endpoint]` | ||
|
||
|
||
[.description] | ||
-- | ||
The endpoint of Azure Key Vault. | ||
|
||
ifdef::add-copy-button-to-env-var[] | ||
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT+++[] | ||
endif::add-copy-button-to-env-var[] | ||
ifndef::add-copy-button-to-env-var[] | ||
Environment variable: `+++QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT+++` | ||
endif::add-copy-button-to-env-var[] | ||
--|string | ||
|required icon:exclamation-circle[title=Configuration property is required] | ||
|
||
|=== |
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
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,167 @@ | ||
= Quarkus Azure Key Vault Extension | ||
|
||
include::./includes/attributes.adoc[] | ||
|
||
include::./includes/support.adoc[] | ||
|
||
https://azure.microsoft.com/en-us/products/key-vault[Azure Key Vault] is a cloud service for securely storing and accessing secrets. A secret is anything that you want to tightly control access to, such as API keys, passwords, certificates, or cryptographic keys. | ||
This extension allows you to create and retrieve secret from Azure Key Vault by injecting the following object inside your Quarkus application. | ||
|
||
* `com.azure.security.keyvault.secrets.SecretClient` | ||
* `com.azure.security.keyvault.secrets.SecretAsyncClient` | ||
|
||
The extension produces SecretClient and SecretAsyncClient using https://learn.microsoft.com/java/api/overview/azure/identity-readme#defaultazurecredential[DefaultAzureCredential]. | ||
Developers who want more control or whose scenario isn't served by the default settings should build client using other credential types. | ||
|
||
== Installation | ||
|
||
If you want to use this extension, you need to add the `io.quarkiverse.azureservices:quarkus-azure-services` extension first to your build file. | ||
|
||
For instance, with Maven, add the following dependency to your POM file: | ||
|
||
[source,xml,subs=attributes+] | ||
---- | ||
<dependency> | ||
<groupId>io.quarkiverse.azureservices</groupId> | ||
<artifactId>quarkus-azure-keyvault</artifactId> | ||
<version>{project-version}</version> | ||
</dependency> | ||
---- | ||
|
||
== How to Use It | ||
|
||
Once you have added the extension to your project, follow the next steps, so you can inject `com.azure.security.keyvault.secrets.SecretClient` or `com.azure.security.keyvault.secrets.SecretAsyncClient` object in your application to manage secret. | ||
|
||
=== Setup your Azure Environment | ||
|
||
include::includes/azure-setup-environment.adoc[] | ||
|
||
Create an Azure resource group with the `az group create` command. | ||
A resource group is a logical container into which Azure resources are deployed and managed. | ||
|
||
[source,shell] | ||
---- | ||
az group create \ | ||
--name rg-quarkus-azure-keyvault \ | ||
--location eastus | ||
---- | ||
|
||
Create a general-purpose key vault with the following command: | ||
|
||
[source,shell] | ||
---- | ||
az keyvault create --name kvquarkusazurekv0423 \ | ||
--resource-group rg-quarkus-azure-keyvault \ | ||
--location eastus | ||
---- | ||
|
||
Key Vault provides secure storage of generic secrets, such as passwords and database connection strings. | ||
All secrets in your key vault are stored encrypted. The Azure Key Vault service encrypts your secrets when you add them, and decrypts them automatically when you read them. | ||
|
||
Access Control for secrets managed in Key Vault, is provided at the level of the Key Vault. | ||
The following command uses your Azure AD account to authorize the operation to manage secret. | ||
Even if you are the key vault owner, you need explicit permissions to perform operations against secret. | ||
|
||
Assign all secret permissions(backup, delete, get, list, purge, recover, restore, set) to yourself: | ||
|
||
[source,shell] | ||
---- | ||
az ad signed-in-user show --query id -o tsv \ | ||
| az keyvault set-policy \ | ||
--name kvquarkusazurekv0423 \ | ||
--object-id @- \ | ||
--secret-permissions all | ||
---- | ||
|
||
If you log into the http://portal.azure.com/[Azure portal], you can see the key vault you created. Select **Objects** -> **Secrets**, you will find the Secrets page. | ||
|
||
image::quarkus-azure-keyvault-secret-portal.png[alt=Azure Portal showing Key Vault Secrets] | ||
|
||
=== Configure the Azure Key Vault Secret Client | ||
|
||
As you can see below in the _Configuration Reference_ section, the configuration option `quarkus.azure.keyvault.secret.endpoint` is mandatory. | ||
To get the endpoint, execute the following Azure CLI command: | ||
|
||
[source,shell] | ||
---- | ||
az keyvault show --name kvquarkusazurekv0423 \ | ||
--resource-group rg-quarkus-azure-keyvault \ | ||
--query properties.vaultUri \ | ||
--output tsv | ||
---- | ||
|
||
Then, in the `application.properties` file, add the following property: | ||
|
||
[source,properties] | ||
---- | ||
quarkus.azure.keyvault.secret.endpoint=https://kvquarkusazurekv0423.vault.azure.net/ | ||
---- | ||
|
||
=== Inject the Azure Key Vault Secret Client | ||
|
||
Now that your Azure environment is ready and that you have configured the extension, you can inject the `com.azure.security.keyvault.secrets.SecretClient` object in your application, so you can interact with Azure Key Vault Secret. | ||
|
||
This is a https://quarkus.io/guides/command-mode-reference[Quarkus CLI application]. The application will: | ||
|
||
* Ask for a secret value. | ||
* Create a secret with name `mySecret` and set its value. | ||
* Retrieve and print the secret value. | ||
* Delete the secret. | ||
|
||
You can build and run the application in development mode using command: | ||
|
||
``` | ||
quarkus dev | ||
``` | ||
|
||
[source,java] | ||
---- | ||
@QuarkusMain | ||
public class KeyVaultSecretApplication implements QuarkusApplication { | ||
|
||
@Inject | ||
SecretClient secretClient; | ||
|
||
@Override | ||
public int run(String... args) throws Exception { | ||
|
||
Console con = System.console(); | ||
|
||
String secretName = "mySecret"; | ||
System.out.println("Create secret: " + secretName); | ||
|
||
System.out.println("Please provide the value of your secret > "); | ||
|
||
String secretValue = con.readLine(); | ||
|
||
System.out.println("Creating a secret called '" + secretName + "' with value '" + secretValue + "' ... "); | ||
|
||
secretClient.setSecret(new KeyVaultSecret(secretName, secretValue)); | ||
|
||
System.out.println("Retrieving your secret..."); | ||
|
||
KeyVaultSecret retrievedSecret = secretClient.getSecret(secretName); | ||
|
||
System.out.println("Your secret's value is '" + retrievedSecret.getValue() + "'."); | ||
System.out.println("Deleting your secret ... "); | ||
|
||
SyncPoller<DeletedSecret, Void> deletionPoller = secretClient.beginDeleteSecret(secretName); | ||
deletionPoller.waitForCompletion(); | ||
|
||
System.out.println("done."); | ||
return 0; | ||
} | ||
} | ||
|
||
---- | ||
|
||
After running the application, if you log into the http://portal.azure.com/[Azure portal], you can see the key vault and the secret you created. | ||
As the secret is deleted, you will find the secret from **Objects** -> **Secrets** -> **Manage deleted secrets**. | ||
|
||
image::quarkus-azure-keyvault-deleted-secret-portal.png[alt=Azure Portal showing the deleted secrets] | ||
|
||
You can also inject `com.azure.security.keyvault.secrets.SecretAsyncClient` object to your application. For more usage, see https://learn.microsoft.com/java/api/com.azure.security.keyvault.secrets.secretasyncclient?view=azure-java-stable[com.azure.security.keyvault.secrets.secretasyncclient]. | ||
|
||
== Extension Configuration Reference | ||
|
||
include::includes/quarkus-azure-keyvault.adoc[leveloffset=+1, opts=optional] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention this duplicates code in
integration-tests/README.md
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 5fce42c.