Security and Permissions
1 - Security model
2 - Security groups
2.1 Default groups (Project)
| Group | Description |
|---|---|
| Project Administrators | Full project admin |
| Build Administrators | Pipeline management |
| Contributors | Commit, PR, work items |
| Readers | Read-only |
| Project Valid Users | Basic access |
2.2 Organization groups
| Group | Description |
|---|---|
| Project Collection Administrators | Super admin |
| Project Collection Build Administrators | Org build admin |
| Project Collection Valid Users | Organization access |
2.3 Create a custom group
# Via CLI
az devops security group create \
--name "DevOps Engineers" \
--description "DevOps team members" \
--project MonProjet
3 - Permissions
3.1 Permission levels
| Level | Description |
|---|---|
| Allow | Permission granted |
| Deny | Permission denied (takes priority) |
| Not set | Inherits from the parent |
3.2 Repos permissions
| Permission | Description |
|---|---|
| Read | Read the code |
| Contribute | Push to allowed branches |
| Create branch | Create branches |
| Force push | Force push (not recommended) |
| Manage permissions | Manage permissions |
| Bypass policies | Bypass branch policies |
3.3 Pipelines permissions
| Permission | Description |
|---|---|
| View | View pipelines |
| Edit build pipeline | Edit builds |
| Queue builds | Start builds |
| Delete builds | Delete builds |
| Stop builds | Stop builds |
| Manage build resources | Manage agents |
4 - Service Connections
4.1 Connection types
| Type | Usage |
|---|---|
| Azure Resource Manager | Deploy to Azure |
| Docker Registry | Push/pull images |
| Kubernetes | Deploy to K8s |
| GitHub | Access GitHub repos |
| SSH | SSH connection |
| Generic | Custom service |
4.2 Create an Azure Service Connection
# Via CLI
az devops service-endpoint azurerm create \
--name "Azure-Production" \
--azure-rm-subscription-id "subscription-id" \
--azure-rm-subscription-name "My Subscription" \
--azure-rm-tenant-id "tenant-id" \
--azure-rm-service-principal-id "sp-id" \
--azure-rm-service-principal-key "sp-key"
4.3 Secure the Service Connections
- Pipeline permissions: Limit to certain pipelines
- Approvals: Require approval before use
- Branch control: Limit to protected branches
5 - Variable Groups and Secrets
5.1 Create a Variable Group
# Via CLI
az pipelines variable-group create \
--name "Production-Secrets" \
--variables API_URL=https://api.prod.com \
--authorize true
5.2 Secret variables
# Ajouter une variable secrète
az pipelines variable-group variable create \
--group-id 123 \
--name "API_KEY" \
--value "secret-value" \
--secret true
5.3 Azure Key Vault Integration
variables:
- group: 'my-variable-group'
- group: 'keyvault-secrets' # Linked to Key Vault
# Dans le pipeline YAML
steps:
- task: AzureKeyVault@2
inputs:
azureSubscription: 'Azure-Connection'
KeyVaultName: 'my-keyvault'
SecretsFilter: '*'
RunAsPreJob: true
6 - Organization policies
6.1 Available policies
| Policy | Description |
|---|---|
| Third-party app access | Control OAuth apps |
| SSH authentication | Enable/disable SSH |
| Alternate credentials | Enable Git credentials |
| External guest access | Invite external users |
6.2 Audit Logs
Azure DevOps records all actions:
# Voir les logs d'audit
az devops audit query \
--organization https://dev.azure.com/MonOrg \
--start-time 2024-01-01T00:00:00Z \
--end-time 2024-01-31T23:59:59Z
Audited events:
- Permission changes
- Resource creation/deletion
- Pipeline changes
- Access to secrets
7 - Security best practices
7.1 Checklist
- Use groups rather than individual permissions
- Apply the principle of least privilege
- Protect the main branches
- Secure the Service Connections
- Store secrets in Key Vault
- Enable audit logging
- Review permissions regularly
- Use Service Principals with rotation
7.2 Recommended Branch Policies
# Pour la branche main
Policies:
- Require pull request: true
- Minimum reviewers: 2
- Linked work items: true
- Comment resolution: true
- Build validation: required
- Limit merge types: Squash only
7.3 Pipeline Security
# Limiter les permissions du pipeline
jobs:
- job: Build
pool:
vmImage: 'ubuntu-latest'
# Ne pas autoriser les scripts à accéder aux secrets
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
8 - Compliance and governance
8.1 Recommended Project Settings
- Disable classic pipelines
- Require YAML for all pipelines
- Limit parallel jobs
- Configure retention policies
8.2 Environment protection
# Environment avec approvals
- stage: DeployProd
jobs:
- deployment: Deploy
environment: 'Production' # Requiert approbation
strategy:
runOnce:
deploy:
steps:
- script: echo Deploying
Summary
In this chapter, we learned:
- The Azure DevOps security model
- Groups and permissions
- Service Connections and how to secure them
- Variable Groups and secrets
- Organization policies
- Security best practices
Next step
In the next chapter, we will look at the overall Best practices.
→ Next chapter: Best practices