1. What is a Service Connection?
A Service Connection in Azure DevOps is a secure configuration that allows Azure Pipelines to connect to external services such as Microsoft Azure, Docker Hub, GitHub, or Kubernetes.
In simple terms, a Service Connection acts as a secure bridge between Azure DevOps and external resources.
For example, suppose you have:
-
An ASP.NET Core Web API application.
-
Source code stored in Azure Repos.
-
An Azure Pipeline to build and deploy the application.
-
An Azure App Service to host the application.
Azure DevOps needs permission to deploy your application to Azure App Service.
Instead of entering Azure credentials directly into the pipeline YAML, you configure a Service Connection.
Simple definition for interviews:
A Service Connection is a secure, reusable connection in Azure DevOps that stores or references authentication information and allows pipelines to access external services for deployment and other operations.
2. Why do we need a Service Connection?
Consider the following scenario.
You have developed an ASP.NET Core Web API application and want to deploy it automatically to Azure App Service.
Without a Service Connection, Azure Pipelines cannot automatically assume that it has permission to access your Azure subscription.
It needs an authenticated identity with appropriate authorization.
Without a Service Connection
Developer
|
v
Azure Repos
|
v
Azure Pipeline
|
| Build ASP.NET Core Application
|
v
Build Artifact
|
v
Azure App Service
|
X Authentication / Authorization Required
With a Service Connection
Developer
|
v
Azure Repos
|
v
Azure Pipeline
|
| Build Application
|
v
Build Artifact
|
v
Azure Service Connection
|
| Authenticate with Microsoft Entra ID
| Obtain Azure access token
| Use assigned permissions
|
v
Azure App Service
|
v
Application Deployed Successfully
The Service Connection provides the authentication configuration required by the deployment task. Deployment succeeds only if the identity has sufficient permissions and the target resource is accessible.
3. How does a Service Connection work?
Let's understand the internal working step by step.
Suppose your application is deployed to an Azure App Service named jntech-api-prod.
Step 1 – Developer pushes code
The developer commits and pushes ASP.NET Core application code to Azure Repos.
Step 2 – Pipeline starts
Azure Pipelines detects the code change and triggers the CI pipeline.
Step 3 – Application is built
The pipeline performs the following operations:
dotnet restore
dotnet build --configuration Release
dotnet test --configuration Release
dotnet publish --configuration Release --output ./publish
Step 4 – Deployment task requests the Service Connection
The deployment task references a configured Azure Resource Manager Service Connection.
Step 5 – Azure DevOps authenticates
With the recommended workload identity federation approach, Azure DevOps obtains a federated token, which Microsoft Entra ID validates and exchanges for an Azure access token.
Step 6 – Azure checks authorization
Azure checks whether the associated identity has permission to perform the requested operation on the Azure resource.
Step 7 – Application is deployed
If authentication and authorization succeed, the deployment task publishes the application to Azure App Service.
Complete flow
Developer
|
v
Azure Repos
|
v
CI Pipeline
|
| Restore
| Build
| Test
| Publish
|
v
Build Artifact
|
v
CD Pipeline
|
v
Service Connection
|
v
Microsoft Entra ID
|
| Validate Identity
| Issue Access Token
|
v
Azure Resource Manager
|
| Check RBAC Permissions
|
v
Azure App Service
|
v
Deploy ASP.NET Core Web API
Important: A Service Connection does not automatically grant access to every Azure resource. The identity behind it must have the required permissions.
4. Types of Service Connections
Azure DevOps supports several types of Service Connections.
|
Service Connection |
Purpose |
|---|---|
|
Azure Resource Manager |
Deploy applications and manage Azure resources |
|
Docker Registry |
Push and pull container images |
|
GitHub |
Access GitHub repositories and related resources |
|
Kubernetes |
Deploy applications to Kubernetes clusters |
|
SSH |
Connect to remote servers |
|
Generic |
Authenticate to supported external services using configured credentials |
For ASP.NET Core applications deployed to Azure, Azure Resource Manager is one of the most important Service Connection types.
Azure Resource Manager authentication methods
|
Authentication method |
Description |
|---|---|
|
Workload Identity Federation |
Uses federated identity credentials without storing a client secret |
|
Service Principal with Secret |
Uses an application identity and client secret |
|
Service Principal with Certificate |
Uses an application identity and certificate |
|
Managed Identity |
Uses an Azure managed identity in supported agent configurations |
Recommended: Use Workload Identity Federation whenever supported. It avoids long-lived client secrets and reduces credential-management risks.
5. How to create a Service Connection in Azure DevOps
Let's create a Service Connection to deploy an ASP.NET Core Web API to Azure App Service.
Step 1 – Open Azure DevOps
Navigate to:
Azure DevOps
|
v
Organization
|
v
Project
|
v
Project Settings
|
v
Service Connections
|
v
New Service Connection
Step 2 – Select connection type
Choose:
Azure Resource Manager
Click Next.
Step 3 – Choose authentication
Select:
Workload Identity Federation (automatic)
This is generally the preferred option when the Azure DevOps organization, Azure tenant, and your permissions support automatic configuration.
Step 4 – Select Azure resources
Provide the required details.
|
Field |
Example |
|---|---|
|
Subscription |
MyAzureSubscription |
|
Resource Group |
rg-jntech-prod |
|
Service Connection Name |
sc-azure-production |
|
Description |
Azure Production Deployment |
Depending on the creation flow, you may select the subscription or resource group scope.
Step 5 – Configure pipeline access
You may see an option similar to:
Grant access permission to all pipelines
For production, avoid enabling this unnecessarily. Prefer explicitly authorizing only the pipelines that need the connection.
Step 6 – Save and verify
Click Save.
The Service Connection is now available for authorized pipelines.
If automatic configuration is unavailable, manual workload identity federation configuration may be required.
6. How to use a Service Connection in a YAML Pipeline
Suppose you created a Service Connection named:
sc-azure-production
Your ASP.NET Core Web API must be deployed to:
jntech-api-prod
Example: Azure App Service deployment
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: 'sdk'
version: '8.0.x'
- script: |
dotnet restore
dotnet publish --configuration Release --output $(Build.ArtifactStagingDirectory)/publish
displayName: 'Build and Publish ASP.NET Core'
- task: AzureWebApp@1
displayName: 'Deploy to Azure App Service'
inputs:
azureSubscription: 'sc-azure-production'
appType: 'webApp'
appName: 'jntech-api-prod'
package: '$(Build.ArtifactStagingDirectory)/publish'
Important properties
|
Property |
Purpose |
|---|---|
|
|
Name of the Azure Resource Manager Service Connection |
|
|
Type of Azure App Service |
|
|
Target App Service name |
|
|
Application files to deploy |
The most important line is:
azureSubscription: 'sc-azure-production'
This tells Azure Pipelines which Service Connection to use when authenticating to Azure.
The YAML example demonstrates a basic build-and-deploy pipeline. In production, it is preferable to separate CI and CD stages and deploy a previously published artifact.
7. How are Service Connections used for Dev, SIT, UAT, and Production?
In enterprise applications, different environments often use different Azure resources.
For example:
|
Environment |
Service Connection |
App Service |
|---|---|---|
|
Development |
sc-azure-dev |
jntech-api-dev |
|
SIT |
sc-azure-sit |
jntech-api-sit |
|
UAT |
sc-azure-uat |
jntech-api-uat |
|
Production |
sc-azure-prod |
jntech-api-prod |
Deployment flow
CI Pipeline
|
v
Build Artifact
|
v
DEV Service Connection
|
v
Azure Dev App
|
v
SIT Service Connection
|
v
Azure SIT App
|
v
UAT Service Connection
|
v
Azure UAT App
|
v
Production Approval
|
v
PROD Service Connection
|
v
Azure Production App
Each environment can use its own identity and Azure RBAC permissions.
For example, the Dev connection may have access only to development resources, while the Production connection may have access only to production resources.
This follows the principle of least privilege.
Separate Service Connections are especially useful when environments belong to different subscriptions, resource groups, or security boundaries.
8. Service Connection vs Variable Group vs Azure Key Vault
These three concepts are important in Azure DevOps interviews.
|
Feature |
Service Connection |
Variable Group |
Azure Key Vault |
|---|---|---|---|
|
Main purpose |
Authenticate to external services |
Share pipeline configuration values |
Securely store and manage secrets |
|
Stores configuration values |
Connection configuration |
Yes |
Secrets |
|
Stores secrets |
Sometimes, depending on authentication method |
Yes, as protected secret variables |
Yes |
|
Used for Azure deployment |
Yes |
Not directly |
Not directly |
|
Supports multiple pipelines |
Yes |
Yes |
Yes, through authorized integration |
|
Typical example |
Azure deployment identity |
Environment name, API URL |
Database password, API key |
Real-world example
Suppose you deploy an ASP.NET Core Web API to Azure App Service.
You might use:
-
Service Connection: Authenticate the pipeline to Azure.
-
Variable Group: Store non-sensitive configuration such as environment name and API URL.
-
Azure Key Vault: Store database passwords, API keys, and other secrets.
These services complement each other rather than replace each other.
9. Security and permissions
A Service Connection has two important security aspects.
A. Pipeline authorization
Controls which Azure Pipelines can use the Service Connection.
For example:
Pipeline A ---- Allowed ----> Service Connection
Pipeline B ---- Denied -----> Service Connection
You configure this through the Service Connection's pipeline permissions.
B. Azure RBAC permissions
Controls what the authenticated identity can do in Azure.
Examples:
|
Azure Role |
Typical capability |
|---|---|
|
Reader |
View Azure resources |
|
Contributor |
Manage resources within the assigned scope |
|
Website Contributor |
Manage websites within the assigned scope |
|
Owner |
Manage resources and assign access |
The required role depends on the deployment task and operation.
For production deployments, grant the minimum permissions required. Avoid using Owner or subscription-wide Contributor unless there is a justified operational need.
Common security practices
-
Prefer Workload Identity Federation over client secrets.
-
Restrict Service Connection usage to authorized pipelines.
-
Use separate identities for production and non-production where practical.
-
Apply least-privilege Azure RBAC permissions.
-
Configure approval and checks for sensitive deployment resources.
-
Never expose credentials or access tokens in pipeline logs.
10. Common Service Connection errors
|
Error |
Possible reason |
Solution |
|---|---|---|
|
Service Connection not found |
Incorrect name or missing connection |
Verify name and project |
|
Pipeline not authorized |
Pipeline lacks permission to use connection |
Authorize the pipeline |
|
Authorization failed |
Identity lacks required Azure RBAC role |
Assign appropriate permissions |
|
Authentication failed |
Expired secret or incorrect federation configuration |
Check authentication settings |
|
Subscription not visible |
Insufficient subscription access |
Verify identity and Azure permissions |
|
Resource not found |
Wrong subscription, resource group, or name |
Verify deployment target |
One important troubleshooting distinction is:
Authentication failure: Azure cannot establish who the pipeline is.
Authorization failure: Azure recognizes the identity, but that identity does not have permission to perform the requested action.
11. Important interview questions and answers
Q1. What is a Service Connection in Azure DevOps?
A Service Connection is a secure configuration that allows Azure Pipelines to authenticate to external services such as Azure, GitHub, Docker, and Kubernetes.
Q2. Why is a Service Connection required?
It allows a pipeline to securely access external resources without hardcoding authentication credentials directly into the pipeline YAML.
Q3. Is a Service Connection mandatory for every Azure Pipeline?
No. A pipeline that only restores, builds, and tests an ASP.NET Core application generally does not require an Azure Service Connection. It is needed when a task must authenticate to an external service and uses a Service Connection for that authentication.
Q4. Can multiple pipelines use the same Service Connection?
Yes. Multiple authorized pipelines can share a Service Connection. However, production connections should have tightly controlled access.
Q5. What is the difference between a Service Connection and a Service Principal?
A Service Principal is an identity in Microsoft Entra ID used by applications and automation.
A Service Connection is an Azure DevOps configuration that enables pipelines to authenticate to external services. An Azure Resource Manager Service Connection may use a Service Principal as its identity.
Q6. What happens if a Service Connection is deleted?
Pipelines that reference the deleted Service Connection will generally fail when they attempt to use it.
Q7. What is Workload Identity Federation?
Workload Identity Federation allows Azure Pipelines to authenticate to Azure using trusted federated tokens instead of storing long-lived client secrets.
Q8. Can a Service Connection access multiple Azure resources?
Yes, provided the identity has the required Azure RBAC permissions at the appropriate scope. Access is not automatically unlimited.
Q9. Can we use different Service Connections for Dev, SIT, UAT, and Production?
Yes. This is a common enterprise approach to isolate deployment permissions and improve environment security.
Q10. Where do you configure Service Connections?
Azure DevOps
↓
Project Settings
↓
Service Connections
↓
New Service Connection
12. Real-time interview scenario
Interviewer: You have an ASP.NET Core Web API application in Azure Repos. How do you securely deploy it to Azure App Service using Azure Pipelines?
Answer:
First, I create an Azure Resource Manager Service Connection in Azure DevOps using Workload Identity Federation.
I configure the connection to access the required Azure subscription or resource group and assign the necessary RBAC permissions to its identity.
Next, I authorize the deployment pipeline to use that Service Connection.
In the YAML pipeline, I use the AzureWebApp@1 task and specify the Service Connection name through the azureSubscription input.
During deployment, Azure DevOps authenticates using the configured identity, Azure validates the permissions, and the pipeline deploys the published ASP.NET Core application to Azure App Service.
For production, I use a separate Service Connection with restricted permissions and configure deployment approvals.
Key points to remember
-
Service Connection = Secure authentication configuration between Azure Pipelines and external services.
-
Service Principal = An identity that an Azure Service Connection can use.
-
Workload Identity Federation = Recommended secretless authentication approach.
-
Pipeline permissions = Which pipelines may use the connection.
-
Azure RBAC = What the connection's identity may do in Azure.
-
Production security = Restricted permissions, authorized pipelines, and deployment approvals.
The most important concept for interviews is that a Service Connection handles authentication configuration, while Azure RBAC determines the identity's permissions on Azure resources.