如何在 Azure 机器学习服务中为 ACI Web 服务启用身份验证?



我能够使用以下语法在工作区ws部署 Azure 机器学习预测服务

aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, 
memory_gb=8, 
tags={"method" : "some method"}, 
description='Predict something')

然后

service = Webservice.deploy_from_image(deployment_config = aciconfig,
image = image,
name = service_name,
workspace = ws)

如文档中所述。
但是,这会公开服务,这并不是真正的最佳选择。

屏蔽 ACI 服务的最简单方法是什么?我知道传递auth_enabled=True参数可能会完成这项工作,但是我如何指示客户端(例如,使用curl或Postman)之后使用该服务?

有关示例,请参阅此处(在 C# 中)。启用身份验证后,您需要在 HTTP 请求的"授权"标头中发送 API 密钥:

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authKey);

请参阅此处如何检索密钥。

首先,使用(Python)语法检索主键和辅助键,例如

service.get_keys()

如果您使用的是curl,语法可能如下所示:

curl -H "Content-Type:application/json" -H "Authorization: Bearer <authKey>" -X POST -d '{"data": [some data]}' http://<url>:<port>/<method>

其中<authKey>是上面检索到的密钥之一。

最新更新