Search code examples
azureazure-machine-learning-serviceazure-container-instances

How to enable authentication for an ACI webservice in Azure Machine Learning service?


I am able to deploy a Azure Machine learning prediction service in my workspace ws using the syntax

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

and then

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

as described in the documentation.
However, this exposes a service publicly and this is not really optimal.

What's the easiest way to shield the ACI service? I understand that passing an auth_enabled=True parameter may do the job, but then how can I instruct a client (say, using curl or Postman) to use the service afterwards?


Solution

  • See here for an example (in C#). When you enable auth, you will need to send the API key in the "Authorization" header in the HTTP request:

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

    See here how to retrieve the key.