|
| 1 | +--- |
| 2 | +title: Import certificates from Azure Key Vault to Azure Container Apps |
| 3 | +description: Learn to managing secure certificates in Azure Container Apps. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 05/09/2024 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Import certificates from Azure Key Vault to Azure Container Apps (preview) |
| 13 | + |
| 14 | +You can set up Azure Key Vault to manage your container app's certificates to handle updates, renewals, and monitoring. Without Key Vault, you're left managing your certificate manually, which means you can't manage certificates in a central location and can't take advantage of lifecycle automation or notifications. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- [Azure Key Vault](/azure/key-vault/general/manage-with-cli2): Create a Key Vault resource. |
| 19 | + |
| 20 | +- [Azure CLI](/cli/azure/install-azure-cli): You need the Azure CLI updated with the Azure Container Apps extension version `0.3.49` or higher. Use the `az extension add` command to install the latest version. |
| 21 | + |
| 22 | + ```azurecli |
| 23 | + az extension add --name containerapp --upgrade --allow-preview` |
| 24 | + ``` |
| 25 | +
|
| 26 | +- [Managed identity](./managed-identity.md): Enable managed identity on your Container Apps environment. |
| 27 | +
|
| 28 | +## Secret configuration |
| 29 | +
|
| 30 | +An [Azure Key Vault](/azure/key-vault/general/manage-with-cli2) instance is required to store your certificate. Make the following updates to your Key Vault instance: |
| 31 | +
|
| 32 | +1. Open the [Azure portal](https://portal.azure.com). |
| 33 | +
|
| 34 | +1. Go to your Azure Container Apps environment. |
| 35 | +
|
| 36 | +1. From *Settings*, select Access control (IAM). |
| 37 | +
|
| 38 | +1. From the *Roles* tab, and set yourself as a *Key Vault Administrator*. |
| 39 | +
|
| 40 | +1. Go to your certificate's details and copy the value for *Secret Identifier* and paste it into a text editor for use in an upcoming step. |
| 41 | +
|
| 42 | + > [!NOTE] |
| 43 | + > To retrieve a specific version of the certificate, include the version suffix with the secret identifier. To get the latest version, remove the version suffix from the identifier. |
| 44 | +
|
| 45 | +## Enable and configure Key Vault Certificate |
| 46 | +
|
| 47 | +1. Open the Azure portal and go to your Key Vault. |
| 48 | +
|
| 49 | +1. In the *Objects* section, select **Certificates**. |
| 50 | +
|
| 51 | +1. Select the certificate you want to use. |
| 52 | +
|
| 53 | +1. In the *Access control (IAM)* section, select **Add role assignment**. |
| 54 | +
|
| 55 | +1. Add the roles: **Key Vault Certificates Officer** and **Key Vault Secrets Officer**. |
| 56 | +
|
| 57 | +1. Go to your certificate's details and copy the value for **Secret Identifier**. |
| 58 | +
|
| 59 | +1. Paste the identifier into a text editor for use in an upcoming step. |
| 60 | +
|
| 61 | +## Assign roles for environment-level managed identity |
| 62 | +
|
| 63 | +1. Open the [Azure portal](https://portal.azure.com) and find your instance of your Azure Container Apps environment where you want to import a certificate. |
| 64 | +
|
| 65 | +1. From *Settings*, select **Identity**. |
| 66 | +
|
| 67 | +1. On the *System assigned* tab, find the *Status* switch and select **On**. |
| 68 | +
|
| 69 | +1. Select **Save**, and when the *Enable system assigned managed identity* window appears, select **Yes**. |
| 70 | +
|
| 71 | +1. Under the *Permissions* label, select **Azure role assignments** to open the role assignments window. |
| 72 | +
|
| 73 | +1. Select **Add role assignment** and enter the following values: |
| 74 | +
|
| 75 | + | Property | Value | |
| 76 | + |--|--| |
| 77 | + | Scope | Select **Key Vault**. | |
| 78 | + | Subscription | Select your Azure subscription. | |
| 79 | + | Resource | Select your vault. | |
| 80 | + | Role | Select *Key Vault Secrets User**. | |
| 81 | +
|
| 82 | +1. Select **Save**. |
| 83 | +
|
| 84 | +For more detail on RBAC vs. legacy access policies, see [Azure role-based access control (Azure RBAC) vs. access policies](/azure/key-vault/general/rbac-access-policy). |
| 85 | +
|
| 86 | +## Import a certificate |
| 87 | +
|
| 88 | +Once you authorize your container app to read the vault, you can use the `az containerapp env certificate upload` command to import your vault to your Container Apps environment. |
| 89 | +
|
| 90 | +Before you run the following command, replace the placeholder tokens surrounded by `<>` brackets with your own values. |
| 91 | +
|
| 92 | +```azurecli |
| 93 | +az containerapp env certificate upload \ |
| 94 | + --resource-group <RESOURCE_GROUP> \ |
| 95 | + --name <CONTAINER_APP_NAME> \ |
| 96 | + --akv-url <KEY_VAULT_URL> \ |
| 97 | + --certificate-identity <CERTIFICATE_IDENTITY> |
| 98 | +``` |
| 99 | + |
| 100 | +For more information regarding the command parameters, see the following table. |
| 101 | + |
| 102 | +| Parameter | Description | |
| 103 | +|---|---| |
| 104 | +| `--resource-group` | Your resource group name. | |
| 105 | +| `--name` | Your container app name. | |
| 106 | +| `--akv-url` | The URL for your secret identifier. This URL is the value you set aside in a previous step. | |
| 107 | +| `--certificate-identity` | The ID for your managed identity. This value can either be `system`, or the ID for your user-assigned managed identity. | |
| 108 | + |
| 109 | +## Troubleshooting |
| 110 | + |
| 111 | +If you encounter an error message as you import your certificate, verify your actions using the following steps: |
| 112 | + |
| 113 | +- Ensure that permissions are correctly configured for both your certificate and environment-level managed identity. |
| 114 | + |
| 115 | + - You should assign both *Key Vault Secrets Officer* and *Key Vault Certificates Officer* roles. |
| 116 | + |
| 117 | +- Make sure that you're using the correct URL for accessing your certificate. You should be using the *Secret Identifier* URL. |
| 118 | + |
| 119 | +## Related |
| 120 | + |
| 121 | +> [!div class="nextstepaction"] |
| 122 | +> [Manage secrets](manage-secrets.md) |
0 commit comments