Authorization on batch endpoints

Batch endpoints support Azure Active Directory authentication, or aad_token. That means that in order to invoke a batch endpoint, the user must present a valid Azure Active Directory authentication token to the batch endpoint URI. Authorization is enforced at the endpoint level. The following article explains how to correctly interact with batch endpoints and the security requirements for it.

Prerequisites

  • This example assumes that you have a model correctly deployed as a batch endpoint. Particularly, we are using the heart condition classifier created in the tutorial Using MLflow models in batch deployments.

How authorization works

To invoke a batch endpoint, the user must present a valid Azure Active Directory token representing a security principal. This principal can be a user principal or a service principal. In any case, once an endpoint is invoked, a batch deployment job is created under the identity associated with the token. The identity needs the following permissions in order to successfully create a job:

  • Read batch endpoints/deployments.
  • Create jobs in batch inference endpoints/deployment.
  • Create experiments/runs.
  • Read and write from/to data stores.
  • Lists datastore secrets.

You can either use one of the built-in security roles or create a new one. In any case, the identity used to invoke the endpoints requires to be granted the permissions explicitly. See Steps to assign an Azure role for instructions to assign them.

Important

The identity used for invoking a batch endpoint may not be used to read the underlying data depending on how the data store is configured. Please see Security considerations when reading data for more details.

How to run jobs using different types of credentials

The following examples show different ways to start batch deployment jobs using different types of credentials:

Important

When working on a private link-enabled workspaces, batch endpoints can't be invoked from the UI in Azure ML studio. Please use the Azure ML CLI v2 instead for job creation.

Running jobs using user's credentials

In this case, we want to execute a batch endpoint using the identity of the user currently logged in. Follow these steps:

Note

When working on Azure ML studio, batch endpoints/deployments are always executed using the identity of the current user logged in.

  1. Use the Azure CLI to log in using either interactive or device code authentication:

    az login
    
  2. Once authenticated, use the following command to run a batch deployment job:

    az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/heart-disease-uci
    

Running jobs using a service principal

In this case, we want to execute a batch endpoint using a service principal already created in Azure Active Directory. To complete the authentication, you will have to create a secret to perform the authentication. Follow these steps:

  1. Create a secret to use for authentication as explained at Option 2: Create a new application secret.

  2. To authenticate using a service principal, use the following command. For more details see Sign in with Azure CLI.

    az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>
    
  3. Once authenticated, use the following command to run a batch deployment job:

    az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/heart-disease-uci/
    

Running jobs using a managed identity

You can use managed identities to invoke batch endpoint and deployments. Please notice that this manage identity doesn't belong to the batch endpoint, but it is the identity used to execute the endpoint and hence create a batch job. Both user assigned and system assigned identities can be use in this scenario.

On resources configured for managed identities for Azure resources, you can sign in using the managed identity. Signing in with the resource's identity is done through the --identity flag. For more details see Sign in with Azure CLI.

az login --identity

Once authenticated, use the following command to run a batch deployment job:

az ml batch-endpoint invoke --name $ENDPOINT_NAME --input https://azuremlexampledata.blob.core.windows.net/data/heart-disease-uci

Next steps