azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

MSI login using Docker stack

Open theMichaelB opened this issue 9 years ago • 4 comments

I am trying to get cli to log in via MSI on docker stack. The problem is that docker stack doesn't appear to allow access to 127.0.0.1 (it doesn't support host networking)

To get around this, I have obtained the token and written it to file, with the hope of being able to use it to log into az login, in the same way that can be done for Powershell.

Is there a way to use the token from MSI to log in to cli?

This is using the azuresdk/azure-cli-python image.

theMichaelB avatar Nov 09 '17 18:11 theMichaelB

@theMichaelB I'm unsure if MSI is supported on Docker stack machines - it may only be directly supported on Azure VM. However, we have documentation on using the CLI to perform MSI login:

https://docs.microsoft.com/en-us/azure/active-directory/msi-qs-configure-cli-windows-vm?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json&view=azure-cli-latest

https://docs.microsoft.com/en-us/azure/active-directory/msi-how-to-get-access-token-using-msi?toc=%2fcli%2fazure%2ftoc.json&bc=%2fcli%2fazure%2fbreadcrumb%2ftoc.json&view=azure-cli-latest

sptramer avatar Nov 10 '17 00:11 sptramer

using the command line sudo docker run --net=host -it azuresdk/azure-cli-python it works as expected as this maps the container to localhost - however when running under Docker stack, it is not possible - or at least I've not yet found out how - to map through to localhost

Obviously, it is possible to pass the token into the container (via the filesystem) but CLI would need to support logging in with just a token to make it work. (a function that PS has)

theMichaelB avatar Nov 10 '17 03:11 theMichaelB

Propagating the token cache by mounting the ~/.azure/ directory into your docker container should mean that the CLI instance has access to those tokens and is authenticated. However, you'd have to keep a daemon running on your host machine to keep hitting the MSI endpoint to keep the token cache up-to-date. To me this all feels very hacky.

I'd recommend just using Service Principals to authenticate your agents in Docker containers independently and not relying on parlaying the host's MSI tokens through. I'm going to close this issue out, but feel free to keep this conversation going if you really believe this is an important scenario. I'll be happy to re-open if there's lots of interest.

marstr avatar Feb 20 '19 00:02 marstr

Hi @marst,

I think it would be usefull to be able to authenticate using MSI with docker.

Currently we have built an azure function that connects to AML to get some metadata from our models to postprocess some predictions done by an AML scoring pipeline.

When using MSI in the azure function (invoked via an HTTP call with ADF) everything works as we have configured the managed identity properly. And when we run the python code locally in our azure ml VM this also works as we get the workspace config from.

However when testing the docker file that we mount in azure function locally in the azure ml vm we get the following error:

azureml._vendor.azure_cli_core.azclierror.AzureResponseError: AzureResponseError:
        Message: Failed to connect to MSI. Please make sure MSI is configured correctly.
Get Token request returned http error: 400, reason: Bad Request
        InnerException None
        ErrorResponse 
{
    "error": {
        "message": "Failed to connect to MSI. Please make sure MSI is configured correctly.\nGet Token request returned http error: 400, reason: Bad Request"
    }
}
The terminal process "/bin/bash '-c', 'docker run --rm -it  postprocessor:latest'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Suggestions are welcome!

edgBR avatar Apr 22 '22 07:04 edgBR