Forum Discussion
adan_11
Oct 13, 2023Copper Contributor
How can I use a Azure AD Service Principal to connect an Azure DevOps pipeline to an artifact feed?
I have the following scenario. I currently have a Nuget Artifact feed that I want to pull from in an Azure DevOps pipeline. The feed is in one DevOps organisation and my pipeline is in another DevO...
Robina
Oct 13, 2023Iron Contributor
To use an Azure AD Service Principal to connect an Azure DevOps pipeline to an artifact feed, follow these steps:
Create an Azure AD Service Principal:
- In your Azure portal, go to Azure Active Directory.
- Create a new App Registration and note down the Application ID and Tenant ID.
- Create a Client Secret or use a certificate for authentication.
- Assign Permissions:
- In your Azure DevOps organization, navigate to the artifact feed.
Go to "Settings" > "Permissions" and assign the Service Principal the required read permissions to the feed.
- In your Azure DevOps organization, navigate to the artifact feed.
- Create a Service Connection:
- In your Azure DevOps organization, go to "Project Settings" > "Service connections."
- Create a new service connection, selecting "Azure Resource Manager" as the service connection type.
- Fill in the details using the Application ID, Tenant ID, and Client Secret created in step 1
In Your Pipeline:
- Use the NuGetAuthenticate@0 task with the service connection you created as the nugetServiceConnections. No PAT is required, and it will use the Azure AD Service Principal credentials for authentication. Here's a snippet of how it might look in your pipeline YAML:
jobs:
- job: build
displayName: 'Build'
steps:
- task: NuGetAuthenticate@0
inputs:
nugetServiceConnections: 'your-service-connection-name'
- script: nuget restore ...
With this setup, you eliminate the need for a PAT and ensure secure authentication through the Azure AD Service Principal. Make sure to protect your Service Principal credentials and manage their lifecycle appropriately for security.
- sottesonJul 25, 2024
Microsoft
Robina I was excited to find the steps you recommended to use a service principal for nuget authentication, but when I try to use an Azure Resource Manager service connection, the pipeline fails to run:
The pipeline is not valid. Job TransferNugetPackages: Step NuGetAuthenticate3 input nuGetServiceConnections expects a service connection of type ExternalNuGetFeed but the provided service connection AIFabricAzureConnection is of type azurerm.
Setting up an external nuget feed service connection would require a PAT instead of being able to use the service principal like I can with the Resource Manager one. Any idea if there is a way around this?