|
| 1 | +--- |
| 2 | +title: What is secret injection in online endpoints (preview)? |
| 3 | +titleSuffix: Azure Machine Learning |
| 4 | +description: Learn about secret injection as it applies to online endpoints in Azure Machine Learning. |
| 5 | +services: machine-learning |
| 6 | +ms.service: machine-learning |
| 7 | +ms.subservice: inferencing |
| 8 | +ms.topic: concept-article |
| 9 | +author: dem108 |
| 10 | +ms.author: sehan |
| 11 | +ms.reviewer: mopeakande |
| 12 | +reviewer: msakande |
| 13 | +ms.custom: ignite-2023 |
| 14 | +ms.date: 01/10/2024 |
| 15 | + |
| 16 | +#CustomerIntent: As an ML Pro, I want to retrieve and inject secrets into the deployment environment easily so that deployments I create can consume the secrets in a secured manner. |
| 17 | +--- |
| 18 | + |
| 19 | +# Secret injection in online endpoints (preview) |
| 20 | + |
| 21 | +[!INCLUDE [dev v2](includes/machine-learning-dev-v2.md)] |
| 22 | + |
| 23 | +Secret injection in the context of an online endpoint is a process of retrieving secrets (such as API keys) from secret stores, and injecting them into your user container that runs inside an online deployment. Secrets are eventually accessed securely via environment variables, which are used by the inference server that runs your scoring script or by the inferencing stack that you bring with a BYOC (bring your own container) deployment approach. |
| 24 | + |
| 25 | +[!INCLUDE [machine-learning-preview-generic-disclaimer](includes/machine-learning-preview-generic-disclaimer.md)] |
| 26 | + |
| 27 | +## Problem statement |
| 28 | + |
| 29 | +When you create an online deployment, you might want to use secrets from within the deployment to access external services. Some of these external services include Microsoft Azure OpenAI service, Azure AI Services, and Azure AI Content Safety. |
| 30 | + |
| 31 | +To use the secrets, you have to find a way to securely pass them to your user container that runs inside the deployment. We don't recommend that you include secrets as part of the deployment definition, since this practice would expose the secrets in the deployment definition. |
| 32 | + |
| 33 | +A better approach is to store the secrets in secret stores and then retrieve them securely from within the deployment. However, this approach poses its own challenge: how the deployment should authenticate itself to the secret stores to retrieve secrets. Because the online deployment runs your user container using the _endpoint identity_, which is a [managed identity](/entra/identity/managed-identities-azure-resources/overview), you can use [Azure RBAC](../role-based-access-control/overview.md) to control the endpoint identity's permissions and allow the endpoint to retrieve secrets from the secret stores. |
| 34 | +Using this approach requires you to do the following tasks: |
| 35 | + |
| 36 | +- Assign the right roles to the endpoint identity so that it can read secrets from the secret stores. |
| 37 | +- Implement the scoring logic for the deployment so that it uses the endpoint's managed identity to retrieve the secrets from the secret stores. |
| 38 | + |
| 39 | +While this approach of using a managed identity is a secure way to retrieve and inject secrets, [secret injection via the secret injection feature](#secret-injection-via-the-secret-injection-feature) further simplifies the process of retrieving secrets for [workspace connections](prompt-flow/concept-connections.md) and [key vaults](../key-vault/general/overview.md). |
| 40 | + |
| 41 | + |
| 42 | +## Managed identity associated with the endpoint |
| 43 | + |
| 44 | + |
| 45 | +An online deployment runs your user container with the managed identity associated with the endpoint. This managed identity, called the _endpoint identity_, is a [Microsoft Entra ID](/entra/fundamentals/whatis) that supports [Azure RBAC](../role-based-access-control/overview.md). Therefore, you can assign Azure roles to the identity to control permissions that are required to perform operations. The endpoint identity can be either a system-assigned identity (SAI) or a user-assigned identity (UAI). You can decide which of these kinds of identities to use when you create the endpoint. |
| 46 | + |
| 47 | +- For a _system-assigned identity_, the identity is created automatically when you create the endpoint, and roles with fundamental permissions (such as the Azure Container Registry pull permission and the storage blob data reader) are automatically assigned. |
| 48 | +- For a _user-assigned identity_, you need to create the identity first, and then associate it with the endpoint when you create the endpoint. You're also responsible for assigning proper roles to the UAI as needed. |
| 49 | + |
| 50 | +For more information on using managed identities of an endpoint, see [How to access resources from endpoints with managed identities](how-to-access-resources-from-endpoints-managed-identities.md), and the example for [using managed identities to interact with external services](https://github.com/Azure/azureml-examples/tree/main/cli/endpoints/online/managed/managed-identities). |
| 51 | + |
| 52 | + |
| 53 | +## Role assignment to the endpoint identity |
| 54 | + |
| 55 | +The following roles are required by the secret stores: |
| 56 | + |
| 57 | +- For __secrets stored in workspace connections under your workspace__: `Workspace Connections` provides a [List Secrets API (preview)](/rest/api/azureml/2023-08-01-preview/workspace-connections/list-secrets) that requires the identity that calls the API to have `Azure Machine Learning Workspace Connection Secrets Reader` role (or equivalent) assigned to the identity. |
| 58 | +- For __secrets stored in an external Microsoft Azure Key Vault__: Key Vault provides a [Get Secret Versions API](/rest/api/keyvault/secrets/get-secret-versions/get-secret-versions) that requires the identity that calls the API to have `Key Vault Secrets User` role (or equivalent) assigned to the identity. |
| 59 | + |
| 60 | + |
| 61 | +## Implementation of secret injection |
| 62 | + |
| 63 | +Once secrets (such as API keys) are retrieved from secret stores, there are two ways to inject them into a user container that runs inside the online deployment: |
| 64 | + |
| 65 | +- Inject secrets yourself, using managed identities. |
| 66 | +- Inject secrets, using the secret injection feature. |
| 67 | + |
| 68 | +Both of these approaches involve two steps: |
| 69 | + |
| 70 | +1. First, retrieve secrets from the secret stores, using the endpoint identity. |
| 71 | +1. Second, inject the secrets into your user container. |
| 72 | + |
| 73 | +### Secret injection via the use of managed identities |
| 74 | + |
| 75 | +In your deployment definition, you need to use the endpoint identity to call the APIs from secret stores. You can implement this logic either in your scoring script or in shell scripts that you run in your BYOC container. To implement secret injection via the use of managed identities, see the [example for using managed identities to interact with external services](https://github.com/Azure/azureml-examples/tree/main/cli/endpoints/online/managed/managed-identities). |
| 76 | + |
| 77 | +### Secret injection via the secret injection feature |
| 78 | + |
| 79 | +To use the secret injection feature, in your deployment definition, map the secrets (that you want to refer to) from workspace connections or the Key Vault onto the environment variables. This approach doesn't require you to write any code in your scoring script or in shell scripts that you run in your BYOC container. To map the secrets from workspace connections or the Key Vault onto the environment variables, the following conditions must be met: |
| 80 | + |
| 81 | +- During endpoint creation, if an online endpoint was defined to enforce access to default secret stores (workspace connections under the current workspace), your user identity that creates the deployment under the endpoint should have the permissions to read secrets from workspace connections. |
| 82 | +- The endpoint identity that the deployment uses should have permissions to read secrets from either workspace connections or the Key Vault, as referenced in the deployment definition. |
| 83 | + |
| 84 | +> [!NOTE] |
| 85 | +> - If the endpoint was successfully created with an SAI and the flag set to enforce access to default secret stores, then the endpoint would automatically have the permission for workspace connections. |
| 86 | +> - In the case where the endpoint used a UAI, or the flag to enforce access to default secret stores wasn't set, then the endpoint identity might not have the permission for workspace connections. In such a situation, you need to manually assign the role for the workspace connections to the endpoint identity. |
| 87 | +> - The endpoint identity won't automatically receive permission for the external Key Vault. If you're using the Key Vault as a secret store, you'll need to manually assign the role for the Key Vault to the endpoint identity. |
| 88 | +
|
| 89 | +For more information on using secret injection, see [Deploy machine learning models to online endpoints with secret injection (preview)](how-to-deploy-online-endpoint-with-secret-injection.md). |
| 90 | + |
| 91 | + |
| 92 | +## Related content |
| 93 | + |
| 94 | +- [Deploy machine learning models to online endpoints with secret injection (preview)](how-to-deploy-online-endpoint-with-secret-injection.md) |
| 95 | +- [Authentication for managed online endpoints](concept-endpoints-online-auth.md) |
| 96 | +- [Online endpoints](concept-endpoints-online.md) |
0 commit comments