Authentication overview
Azure DevOps provides a centralized platform for software development, offering services like Azure Boards, Azure Repos, Azure Pipelines, Azure Test Plans, and Azure Artifacts as detailed in the official documentation. To interact with these services, whether through the web portal, command-line interface (CLI), REST APIs, or integrated development environments (IDEs), users and applications must authenticate. The authentication process verifies identity and determines authorization based on assigned permissions.
The choice of authentication method in Azure DevOps depends on the use case. For interactive user access to the web portal, credentials typically managed by Azure Active Directory (AAD) are used. For programmatic access, such as automating tasks in CI/CD pipelines or custom tools, Personal Access Tokens (PATs) and OAuth are common. SSH is specifically for Git operations with Azure Repos. Each method offers different levels of control over scope, lifetime, and security, allowing administrators to implement a least-privilege approach.
Understanding the available authentication mechanisms is critical for maintaining a secure and efficient development environment, particularly within enterprise settings where compliance standards like ISO 27001 and GDPR are often required for Azure DevOps deployments.
Supported authentication methods
Azure DevOps supports several authentication methods to accommodate a variety of access scenarios. Each method is designed for specific types of interactions, from direct user logins to automated API calls.
- Azure Active Directory (AAD): This is the default and recommended method for user authentication to Azure DevOps organizations. When an Azure DevOps organization is connected to AAD, users authenticate using their AAD credentials. This enables features like Multi-Factor Authentication (MFA), Conditional Access policies, and centralized identity management as described in Microsoft's guide to connecting organizations to AAD.
- Personal Access Tokens (PATs): PATs are alphanumeric strings that serve as an alternative password for programmatic access to Azure DevOps. They are commonly used for CI/CD pipelines, automation scripts, and third-party tools. PATs can be scoped to specific organizations, activities (e.g., code, build, work items), and given a defined expiration period, offering fine-grained control over access according to the Azure DevOps documentation on PATs.
- OAuth 2.0: Azure DevOps implements the OAuth 2.0 authorization framework, allowing third-party applications to integrate with Azure DevOps on behalf of a user without requiring the application to store the user's credentials. This is suitable for web applications or services that need to access Azure DevOps resources with explicit user consent as defined by the IETF RFC 6749 for OAuth 2.0.
- SSH Authentication: Secure Shell (SSH) provides a secure way to connect to Azure Repos Git repositories without entering credentials every time. This method uses a public/private key pair. The public key is uploaded to Azure DevOps, and the private key remains on the client machine. This is particularly useful for command-line Git operations as explained in the Azure Repos SSH key usage guide.
- Azure DevOps CLI: The Azure DevOps Command Line Interface (CLI) supports authentication via web browser interactive login using AAD credentials, or by providing PATs. The CLI can also leverage Azure's managed identity features when run within Azure services as detailed in the Azure DevOps CLI authentication documentation.
Authentication Method Comparison
| Method | When to Use | Security Level |
|---|---|---|
| Azure Active Directory (AAD) | Interactive user access to web portal, desktop applications, enterprise environments | High (supports MFA, Conditional Access) |
| Personal Access Tokens (PATs) | Automation scripts, CI/CD pipelines, API calls, command-line tools | Medium-High (scoped, time-limited, revocable) |
| OAuth 2.0 | Third-party applications, web services needing delegated access | High (user consent, token refresh, no credential sharing) |
| SSH Authentication | Git operations from command line, automated Git tasks | High (key-based, no password exposure) |
| Azure DevOps CLI | Command-line administration, scripting (interactive or PAT-based) | Depends on underlying method (AAD or PAT) |
Getting your credentials
The process for obtaining credentials varies depending on the chosen authentication method:
Personal Access Tokens (PATs)
- Sign in to Azure DevOps: Access your Azure DevOps organization through a web browser.
- Navigate to User Settings: Click on your profile picture in the top right corner and select 'User settings' or 'Security'.
- Select Personal Access Tokens: In the left navigation, choose 'Personal access tokens'.
- Create a New Token: Click 'New Token'.
- Configure Token Details: Provide a descriptive name, select the organization, set an expiration date (up to one year, but shorter is recommended), and define the scopes (permissions) the token will have. Grant only the minimum necessary permissions.
- Generate and Copy Token: Click 'Create'. The generated PAT will be displayed once. Copy it immediately, as it cannot be retrieved again after you close the window. Treat it like a password.
OAuth 2.0
- Register Your Application: To use OAuth, you must first register your application with Azure DevOps. Navigate to your Azure DevOps organization settings, go to 'Security' -> 'OAuth configurations'.
- Create New OAuth Application: Provide a name, homepage URL, and authorized callback URLs. These URLs are where Azure DevOps will redirect the user after they grant permission.
- Obtain Client ID and Client Secret: After registration, Azure DevOps will provide a Client ID and Client Secret. These are used by your application to initiate the OAuth flow.
- Implement OAuth Flow: Your application will redirect the user to an Azure DevOps authorization URL, where the user grants consent. Azure DevOps then redirects back to your callback URL with an authorization code. Your application exchanges this code for an access token and a refresh token following the steps outlined in the Azure DevOps OAuth guide.
SSH Keys
- Generate SSH Key Pair: On your client machine, use a tool like
ssh-keygen(on Linux/macOS) or PuTTYgen (on Windows) to generate a public and private key pair. For example:ssh-keygen -t rsa -b 4096 -C "[email protected]". - Copy Public Key: Copy the content of your public key file (typically
~/.ssh/id_rsa.pub). - Add Public Key to Azure DevOps: Sign in to Azure DevOps, go to 'User settings' -> 'SSH public keys'. Click 'New Key', paste your public key, and provide a description.
- Configure SSH Client: Ensure your SSH client is configured to use your private key when connecting to Azure Repos.
Authenticated request example
This example demonstrates how to make an authenticated REST API request to Azure DevOps using a Personal Access Token (PAT). This approach is suitable for scripts and automated tasks.
Using a Personal Access Token (PAT) with cURL
To make a request, you'll need the following:
- Your Azure DevOps organization name (e.g.,
https://dev.azure.com/your-organization). - A valid PAT with appropriate scopes (e.g., 'Work Items > Read' to query work items).
The PAT needs to be Base64 encoded. The username for Basic authentication with a PAT is typically an empty string.
# Replace with your actual PAT
PAT="YOUR_PERSONAL_ACCESS_TOKEN"
# Encode the PAT in Base64 (empty string for username followed by PAT)
# For Windows PowerShell, use '[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$PAT"))'
# For Linux/macOS, use 'echo -n ":$PAT" | base64'
ENCODED_PAT=$(echo -n ":$PAT" | base64)
# Replace with your organization and project
ORGANIZATION="your-organization-name"
PROJECT="your-project-name"
# Example: Get a list of work items from a project
curl -X GET \
"https://dev.azure.com/$ORGANIZATION/$PROJECT/_apis/wit/workitems?api-version=7.1" \
-H "Accept: application/json" \
-H "Authorization: Basic $ENCODED_PAT"
This cURL command fetches a list of work items from the specified project using the provided PAT for Basic authentication. The api-version parameter is crucial for Azure DevOps REST API calls to ensure compatibility as detailed in the Azure DevOps REST API reference.
Security best practices
Implementing robust security practices for authentication in Azure DevOps is essential to protect your code, build artifacts, and intellectual property. Adhering to these guidelines helps mitigate risks:
- Leverage Azure Active Directory (AAD): For user authentication, always connect your Azure DevOps organization to Azure Active Directory. This enables centralized identity management, single sign-on (SSO), and critical security features.
- Enable Multi-Factor Authentication (MFA): For all users accessing Azure DevOps via AAD, enforce MFA. This adds an extra layer of security by requiring a second form of verification during login, significantly reducing the risk of unauthorized access due to compromised passwords.
- Implement Conditional Access Policies: Use AAD Conditional Access to define policies that restrict access based on factors like user location, device compliance, or application. For example, you can block access from untrusted networks or require managed devices.
- Minimize PAT Scopes and Lifetimes: When creating Personal Access Tokens, grant only the absolute minimum required permissions (scopes). Set the shortest possible expiration period for PATs. For automated agents or CI/CD pipelines, consider using PATs that expire frequently and are rotated automatically.
- Store PATs Securely: Never hardcode PATs directly into scripts or source code. Store them in secure credential managers, environment variables, Azure Key Vault, or other secure secrets management solutions. For Azure Pipelines, use secret variables or variable groups linked to Azure Key Vault as recommended for Azure Key Vault integration.
- Regularly Audit and Rotate Credentials: Periodically review active PATs and SSH keys. Revoke any unused or expired credentials. Establish a schedule for rotating critical credentials, such as PATs used by service accounts.
- Use SSH Keys for Git Operations: For command-line Git interactions, prefer SSH authentication over PATs, as it removes the need to transmit credentials over the network with each command. Ensure private SSH keys are protected with strong passphrases.
- Monitor Audit Logs: Regularly review Azure DevOps audit logs for unusual authentication attempts, unauthorized access, or changes to security settings. This can help detect and respond to security incidents promptly.
- Principle of Least Privilege: Grant users and service accounts only the permissions necessary to perform their tasks. Avoid assigning broad administrative roles unless absolutely essential. Regularly review and adjust permissions as roles and responsibilities change.
- Educate Users: Train your team members on secure authentication practices, including the dangers of sharing credentials, recognizing phishing attempts, and the importance of strong, unique passwords and MFA.
- Consider Managed Identities for Azure Resources: When Azure DevOps services interact with other Azure resources (e.g., Azure Key Vault, Azure Storage), use Managed Identities for Azure Resources instead of hardcoded credentials or PATs. This provides an automatically managed identity that authenticates with AAD.