Skip to content

Commit 5a19daa

Browse files
authored
Spring Boot Azure Key Vault JCA certificates samples - Update the .yml and README files for local certificates. (#46)
1 parent 8b3e27a commit 5a19daa

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

keyvault/azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-client-side/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ This sample should work together with [azure-spring-boot-sample-keyvault-certifi
2121
- Start azure-spring-boot-sample-keyvault-certificates-server-side's SampleApplication.
2222

2323
### Run sample with service principal
24-
1. Set environment variables created in `azure-spring-boot-sample-keyvault-certificates-server-side` application by running command:
24+
1. Option 1 - If you created the resources via the script, you need set environment variables created in `azure-spring-boot-sample-keyvault-certificates-server-side` application by running command:
2525
```
2626
source script/setup.sh
2727
```
28-
#### Using TLS with service principal
28+
2. Option 2 - If you created the resource via the Azure Portal, you need configure the application.yml manually, please replace the placeholders with the resources you created.
29+
#### Using TLS with service principal created via App registration.
2930
1. Start azure-spring-boot-sample-keyvault-certificates-client-side's SampleApplication by running command:
3031
```
3132
mvn spring-boot:run
@@ -37,7 +38,7 @@ This sample should work together with [azure-spring-boot-sample-keyvault-certifi
3738
Response from "https://localhost:8443/": Hello World
3839
```
3940
40-
#### Using mTLS with service principal
41+
#### Using mTLS with service principal created via App registration.
4142
1. In the sample `ApplicationConfiguration.class`, change the `self-signed` to your certificate alias.
4243
<!-- embedme ../azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-client-side/src/main/java/com/azure/spring/security/keyvault/certificates/sample/client/side/SampleApplicationConfiguration.java#L70-L75 -->
4344
```java
@@ -134,6 +135,19 @@ This sample should work together with [azure-spring-boot-sample-keyvault-certifi
134135
```
135136
1. Follow the above step of [Using mTLS with service principal](#using-mtls-with-service-principal).
136137
138+
139+
### (Optional) Use the KeyVaultKeyStore with local certificates as the trust resources.
140+
- For example, there are some well known CAs. You can put them into a folder, then configure in the application.yml the azure:cert-path:well-known=\<yourFolderPath>. The certificates in this folder will be loaded by KeyVaultKeystore. If you don't configure such a property, the default well-known path will be `/etc/certs/well-known/`.
141+
- Besides the well-known path, you can also put your customized certificates into another folder specified by azure:cert-path:custom=\<yourCustomPath>, by default, the custom path is `/etc/certs/custom/`.
142+
- You can also put certificates under the class path, build a folder named `keyvault` and configure it under the class path, then all the certificates in this folder will be loaded by key vault keystore.
143+
144+
To configure the local certificates, please uncomment and configure the optional local certificates path.
145+
```yaml
146+
azure:
147+
#cert-path:
148+
#well-known: # Optional local certificates path. Your local path that holds the well-known certificates.
149+
#custom: # Optional local certificates path. Your local path that holds your customized certificates.
150+
```
137151
## Examples
138152
## Troubleshooting
139153
## Next steps

keyvault/azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-client-side/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ azure:
66
client-secret: ${SERVICE_PRINCIPAL_SECRET} # The Client Secret that will be used for accessing your Azure Key Vault (needed if you are not using managed identity).
77
# managed-identity: # client-id of the user-assigned managed identity to use.
88
# If the above 4 properties are empty, then system-assigned managed identity will be used.
9+
#cert-path:
10+
#well-known: # Optional local certificates path. Your local path that holds the well-known certificates.
11+
#custom: # Optional local certificates path. Your local path that holds your customized certificates.
912
server:
1013
port: 8080

keyvault/azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-server-side/README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ This sample can work together with [azure-spring-boot-sample-keyvault-certificat
2424
- This sample will create and store a certificate in your Azure Key Vault.
2525
- This sample will create a service principal to read certificates/keys/secrets from your Azure Key Vault.
2626

27-
### Run Sample with service principal
27+
### Create resources: Service Principal and Key Vault.
28+
#### Option 1 - via the script
2829
1. Run command `az login` to login to the Azure CLI.
2930
1. Open `scripts/export_environment_variables.sh` and enter the following information:
3031
```
@@ -50,7 +51,18 @@ This sample can work together with [azure-spring-boot-sample-keyvault-certificat
5051
```
5152
source script/setup.sh
5253
```
53-
#### Using TLS with service principal
54+
55+
#### Option 2 - via Azure Portal
56+
You can also create resources manually via Azure Portal. Please follow:
57+
1. Obtain a Service Principal. There are two ways to obtain a service principal:
58+
- Recommended: enable a managed identity for the application. For more information, see [the Managed identity overview][the_managed_identity_overview].
59+
- If you cannot use managed identity, you can register your application with AAD, see [register app with AAD][register_app_with_AAD]. The registration also creates a second application object that identifies your app.
60+
2. Create the key vault and certificates. Please refer to [create key vault and certificates][create_key_vault_and_certificates]
61+
3. Make the key vault accessible to your service principal. Please refer to [assign key vault access policy][assign_key_vault_access_policy]
62+
4. You need manually configure the application.yml, replace the placeholders with the resources you created in the Azure Portal.
63+
64+
If you used the script to create the resources, or you created the resources via Azure Portal and created the Service Principal in App Registration way.
65+
### Run sample Using TLS.
5466
1. Run command `mvn spring-boot:run`
5567
1. Access https://localhost:8443/
5668

@@ -59,23 +71,26 @@ Then you will get
5971
Hello World
6072
```
6173

62-
#### Using mTLS with service principal
74+
### Run sample Using mTLS
6375

6476
1. Add properties in application.yml on the base of current configuration:
6577
```yaml
6678
server:
6779
ssl:
6880
client-auth: need # Used for mTLS
6981
trust-store-type: AzureKeyVault # Used for mTLS
82+
7083
```
71-
2. Run command `mvn spring-boot:run`
72-
1. mTLS for mutual authentication. So your client needs have a trusted CA certificate.([azure-spring-boot-sample-keyvault-certificates-client-side]is a trusted client sample.)
84+
1. Run command `mvn spring-boot:run`
85+
1. mTLS for mutual authentication. So your client needs to have a trusted CA certificate.([azure-spring-boot-sample-keyvault-certificates-client-side]is a trusted client sample.)
7386
1. Your client access https://localhost:8443/
7487

7588
Then the client or server will get
7689
```text
7790
Hello World
7891
```
92+
93+
If you created resources via Azure Portal and created the Service Principal in Managed Identity way.
7994
### Run Sample with managed identity
8095
If you are using managed identity instead of service principal, use below properties in your `application.yml`:
8196

@@ -86,7 +101,7 @@ azure:
86101
# managed-identity: # client-id of the user-assigned managed identity to use. If empty, then system-assigned managed identity will be used.
87102
server:
88103
ssl:
89-
key-alias: self-signed
104+
key-alias: ${CERTIFICATE_NAME}
90105
key-store-type: AzureKeyVault
91106
```
92107
Make sure the managed identity can access target Key Vault.
@@ -113,6 +128,19 @@ Make sure the managed identity can access target Key Vault.
113128
114129
1. Follow the above step of [Using TLS with service principal](#using-tls-with-service-principal) or [Using mTLS with service principal](#using-mtls-with-service-principal).
115130
131+
132+
### (Optional) Use the KeyVaultKeyStore with local certificates as the trust resources. This is only useful when server needs to trust its party, for example when the server opens mTLS mode.
133+
- For example, there are some well known CAs. You can put them into a folder, then configure in the application.yml the azure:cert-path:well-known=\<yourFolderPath>. The certificates in this folder will be loaded by KeyVaultKeystore. If you don't configure such a property, the default well-known path will be `/etc/certs/well-known/`.
134+
- Besides the well-known path, you can also put your customized certificates into another folder specified by azure:cert-path:custom=\<yourCustomPath>, by default, the custom path is `/etc/certs/custom/`.
135+
- You can also put certificates under the class path, build a folder named `keyvault` and configure it under the class path, then all the certificates in this folder will be loaded by key vault keystore.
136+
137+
To configure the local certificates, please uncomment and configure the optional local certificates path.
138+
```yaml
139+
azure:
140+
#cert-path:
141+
#well-known: # Optional local certificates path. Your local path that holds the well-known certificates.
142+
#custom: # Optional local certificates path. Your local path that holds your customized certificates.
143+
```
116144
## Examples
117145
## Troubleshooting
118146
## Next steps
@@ -124,3 +152,7 @@ Make sure the managed identity can access target Key Vault.
124152
[azure_spring_boot_starter_key_vault_certificates]: https://github.com/Azure/azure-sdk-for-java/blob/azure-spring-boot_3.6.0/sdk/spring/azure-spring-boot-starter-keyvault-certificates/README.md
125153
[steps_to_store_certificate]: https://github.com/Azure/azure-sdk-for-java/blob/azure-spring-boot_3.6.0/sdk/spring/azure-spring-boot-starter-keyvault-certificates/README.md#creating-an-azure-key-vault
126154
[azure-spring-boot-sample-keyvault-certificates-client-side]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/main/keyvault/azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-client-side
155+
[the_managed_identity_overview]: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
156+
[register_app_with_AAD]: https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app
157+
[create_key_vault_and_certificates]: https://docs.microsoft.com/en-us/azure/key-vault/certificates/quick-create-portal
158+
[assign_key_vault_access_policy]: https://docs.microsoft.com/en-us/azure/key-vault/general/assign-access-policy?tabs=azure-portal

keyvault/azure-spring-boot-starter-keyvault-certificates/keyvault-certificates-server-side/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ azure:
66
client-secret: ${SERVICE_PRINCIPAL_SECRET} # The Client Secret that will be used for accessing your Azure Key Vault (needed if you are not using managed identity).
77
# managed-identity: # The user-assigned managed identity client-id to use.
88
# If the above 4 properties are empty, then system-assigned managed identity will be used.
9+
#cert-path:
10+
#well-known: # Optional local certificates path. Your local path that holds the well-known certificates.
11+
#custom: # Optional local certificates path. Your local path that holds your customized certificates.
912
server:
1013
port: 8443
1114
ssl:

0 commit comments

Comments
 (0)