aderesh
aderesh

Reputation: 947

Use Azure AD Managed Identity/Service Principal user in ADO to use ADO API

I was following this guide https://learn.microsoft.com/en-us/azure/devops/repos/git/create-pr-status-server-with-azure-functions?view=azure-devops to create a custom branch policy. The gist of the article is: when an ADO PR is created or updated, the following happens:

Azure functions use Personal Access Token to authenticate with ADO to post a custom status. Two things I don't like about this approach:

So, I wonder if there is a way to use Azure Functions Managed Identity/Service Principal directly in ADO: give ADO permissions to the managed identity and use Azure AD token to authenticate user in ADO API.

I know that you can set up your ADO organization to user Azure AD users. This is how my organization is set up currently: enter image description here All "alive" users are shown but I don't see any Managed Identities/Service Principals. It looks like only users are synchronized with ADO.

Upvotes: 1

Views: 1323

Answers (2)

Yochai Lehman
Yochai Lehman

Reputation: 372

Using Managed Identity is possible now

With python, you can do something like this:


from azure.identity import DefaultAzureCredential
from msrest.authentication import BasicAuthentication
from azure.devops.connection import Connection

credentials = DefaultAzureCredential()
ADO_APP_CLIENT_ID = "499b84ac-1321-427f-aa17-267ca6975798/.default"
accessToken = credentials.get_token(ADO_APP_CLIENT_ID)
auth = BasicAuthentication("", accessToken.token)
azure_devops_connection = Connection(base_url="<ado org url>", creds=auth)
... do whatever you want
azure_devops_client = azure_devops_connection.clients.get_git_client()

using DefaultAzureCredential you can connect using managed identity, service principle, az cli and more see docs for available env var configuration.

Upvotes: 1

Allen Wu
Allen Wu

Reputation: 16438

Unfortunately Azure AD Managed Identity/Service Principal user which uses Client credentials flow are not supported to authenticate to ADO.

You can see that there is no related Authenticate method which you want in this list.

See this answer for more details.

Upvotes: 2

Related Questions