Skip to content

Commit 9e8d8f4

Browse files
authored
Merge pull request #85354 from Blackmist/fixes02
beefing up authentication section
2 parents b554255 + f499919 commit 9e8d8f4

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

articles/machine-learning/service/how-to-deploy-azure-kubernetes-service.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,57 @@ az ml model deploy -ct myaks -m mymodel:1 -n myservice -ic inferenceconfig.json
207207

208208
For more information, see the [az ml model deploy](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/model?view=azure-cli-latest#ext-azure-cli-ml-az-ml-model-deploy) reference.
209209

210-
## Using VS Code
210+
### Using VS Code
211211

212212
For information on using VS Code, see [deploy to AKS via the VS Code extension](how-to-vscode-tools.md#deploy-and-manage-models).
213213

214214
> [!IMPORTANT]
215215
> Deploying through VS Code requires the AKS cluster to be created or attached to your workspace in advance.
216216
217+
## Web service authentication
218+
219+
When deploying to Azure Kubernetes Service, __key-based__ authentication is enabled by default. You can also enable __token__ authentication. Token authentication requires clients to use an Azure Active Directory account to request an authentication token, which is used to make requests to the deployed service.
220+
221+
To __disable__ authentication, set the `auth_enabled=False` parameter when creating the deployment configuration. The following example disables authentication using the SDK:
222+
223+
```python
224+
deployment_config = AksWebservice.deploy_configuration(cpu_cores=1, memory_gb=1, auth_enabled=False)
225+
```
226+
227+
For information on authenticating from a client application, see the [Consume an Azure Machine Learning model deployed as a web service](how-to-consume-web-service.md).
228+
229+
### Authentication with keys
230+
231+
If key authentication is enabled, you can use the `get_keys` method to retrieve a primary and secondary authentication key:
232+
233+
```python
234+
primary, secondary = service.get_keys()
235+
print(primary)
236+
```
237+
238+
> [!IMPORTANT]
239+
> If you need to regenerate a key, use [`service.regen_key`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.webservice(class)?view=azure-ml-py)
240+
241+
### Authentication with tokens
242+
243+
To enable token authentication, set the `token_auth_enabled=True` parameter when you are creating or updating a deployment. The following example enables token authentication using the SDK:
244+
245+
```python
246+
deployment_config = AksWebservice.deploy_configuration(cpu_cores=1, memory_gb=1, token_auth_enabled=True)
247+
```
248+
249+
If token authentication is enabled, you can use the `get_token` method to retrieve a JWT token and that token's expiration time:
250+
251+
```python
252+
token, refresh_by = service.get_token()
253+
print(token)
254+
```
255+
256+
> [!IMPORTANT]
257+
> You will need to request a new token after the token's `refresh_by` time.
258+
>
259+
> Microsoft strongly recommends that you create your Azure Machine Learning workspace in the same region as your Azure Kubernetes Service cluster. To authenticate with a token, the web service will make a call to the region in which your Azure Machine Learning workspace is created. If your workspace's region is unavailable, then you will not be able to fetch a token for your web service even, if your cluster is in a different region than your workspace. This effectively results in Azure AD Authentication being unavailable until your workspace's region is available again. In addition, the greater the distance between your cluster's region and your workspace's region, the longer it will take to fetch a token.
260+
217261
## Update the web service
218262

219263
[!INCLUDE [aml-update-web-service](../../../includes/machine-learning-update-web-service.md)]

0 commit comments

Comments
 (0)