-
Notifications
You must be signed in to change notification settings - Fork 7
Integrating with Key Vault
To protect the application settings in the Static Web App, we recommend you integrate with Key Vault. This Wiki page describes the process of creating a Key Vault, configuring managed identity for the Static Web App to access the Key Vault, creating secrets, and referencing them in the Static Web App (SWA) configuration.
When creating a Key Vault instance, it's recommended to create it in the same region as the SWA.
When configuring the access policy, select Azure role-based access control.
Assign, at a minimum, the Key Vault Secrets Officer role to the user who will add the secrets to the Key Vault.
Note: You can also use a user assigned managed identity for the SWA, but that is beyond the scope of this guide.
- In the Azure Portal, navigate to the Static Web App.
- Select Identity from the left menu. You will see the status of the System Assigned managed identity.
- Change the Status to On.
- Select Save and Yes.
- Once the system assigned managed identity is created, the new identity's Object (principal) ID will be shown.
While still in the system assigned managed identity page of the SWA:
- Select Azure role assignments.
- Select + Add role assignment.
- From the Scope dropdown, select Key Vault.
- Select the subscription and the Key Vault resource you created above.
- From the Role dropdown, select Key Vault Secrets User.
- Select Save.
-
In the Static Web App, navigate to Configuration.
-
The following configuration values would be considered secrets; however, you can choose to add any of the configuration values to the Key Vault.
- AZURE_CLIENT_SECRET
- FILESYSTEMS_API_KEY
- CONFIGURATION_API_KEY
When deploying multiple instances of Storage-as-a-service that will share configuration values, using Key Vault to centralize them can be very effective.
-
In the Azure Portal, navigate to the Key Vault configured for the SWA.
-
In the left menu, select Secrets.
-
For each secret value to be added:
-
Select + Generate/Import.
-
Complete the Create a secret dialog:
- Upload options: Manual
- Name: The name does not need to match the configuration value exactly, but for ease of reference, you should use at least reference the configuration setting's name, e.g.,
Saas-Azure-Client-Secret
. - Value: Enter the matching value of the SWA configuration setting.
- Content type: You may choose to enter a description of the secret.
- Do not set an activation or expiration date.
-
Select Create.
-
Select the newly created secret, select the current version, and copy the secret identifier. This secret identifier will need to be used later.
-
-
Return to the Static Web App configuration screen.
-
For each application setting that has a secret in Key Vault:
- Edit the value.
- Change the value to this pattern:
@Microsoft.KeyVault(SecretUri=<YOUR-KEY-VAULT-SECRET-URI>)
. Change<YOUR-KEY-VAULT-SECRET-URI>
to the secret identifier you captured when creating the secret. - Select OK.
-
Select Save to persist the application settings.
-
Test the application to ensure that the values are being retrieved correctly from Key Vault.
https://docs.microsoft.com/en-us/azure/static-web-apps/key-vault-secrets