The problem: whoever can ship can also weaken the controls
- The built-in Project Administrator role bundles two different powers: the rights to deliver (repos, pipelines, environments) and the rights to manage permissions and policies. Anyone who can ship can also weaken the controls around shipping.
- Projects were configured by hand in the Azure DevOps UI, so governance varied: some projects had no branch protection, others had different reviewer counts, and service connections were created ad hoc.
- Access provisioning was broken. The design was that adding someone to an Entra ID group would grant them a licence and project membership automatically. In practice, only a small fraction of the required group rules existed, covering a handful of projects, so most access still needed a manual administrator step. Orphaned entitlements were taking up licence slots without granting anyone access.
The approach: identity upstream, policy in code, nothing configurable by hand
Entra ID groups (source of truth)
→ Group rules (licence + project role assigned automatically)
→ Project module (Terraform: one definition for every project)
→ Limited Project Administrator (delivery rights, no permission management)
→ Branch policies (changeable only through code)
What I built
1. One Terraform module for the whole project lifecycle
A module covering the full project configuration surface: project creation, Entra ID group wiring and membership, branch policies, service connections, artifact feeds, environments, pipeline authorizations, project-scoped teams and wikis. Every project built from it gets the same governance, with per-project settings exposed as variables.
Group membership is authoritative. Membership runs in overwrite mode, so access granted outside Terraform is automatically reverted on the next apply.
Illustrative: an Entra ID group materialized in Azure DevOps, with code as the only source of membership.
# Bring the Entra ID group into Azure DevOps.
resource "azuredevops_group" "contributors_aad" {
origin_id = azuread_group.project_contributors.object_id
}
# Code is authoritative: members added by hand are removed on the next apply.
resource "azuredevops_group_membership" "contributors" {
group = azuredevops_group.project_contributors.descriptor
members = [azuredevops_group.contributors_aad.descriptor]
mode = "overwrite"
}
2. The Limited Project Administrator role
A custom role that replaced the built-in Project Administrator: full delivery autonomy without permission-management rights. Its permissions are provisioned automatically across area paths, pipeline folders, repositories, iteration paths, environments, variable groups and artifacts. The IAM team is a code owner for the role's definition, so changing what it can do needs their review. That's separation of duties applied to the control itself.
3. Branch policies as blocking, code-only controls
On the default branch, as blocking policies: - at least two reviewers - the submitter can't vote on their own change - the last person to push can't approve - all votes reset on a new push - all comments must be resolved
Branch policies are configurable only through Terraform, which closes the UI paths a delivery team could use to weaken them.
Illustrative: the reviewer policy, applied to the default branch of every repository in a project.
resource "azuredevops_branch_policy_min_reviewers" "default_branch" {
project_id = azuredevops_project.this.id
enabled = true
blocking = true
settings {
reviewer_count = 2
submitter_can_vote = false
last_pusher_cannot_approve = true
on_push_reset_all_votes = true
allow_completion_with_rejects_or_waits = false
scope {
match_type = "DefaultBranch"
}
}
}
resource "azuredevops_branch_policy_comment_resolution" "default_branch" {
project_id = azuredevops_project.this.id
enabled = true
blocking = true
settings {
scope {
match_type = "DefaultBranch"
}
}
}
4. Fixing access provisioning across 60+ projects
A PowerShell tool against the Azure DevOps group entitlement API, with three modes: - Dry run: inventory the current state, compute the difference, write the planned actions to a CSV. No changes. - Apply: create the missing group rules in controlled batches, slice by slice. - Validate: audit the result against the full expected rule set.
It created every required group rule across 60+ projects and cleaned up the orphaned entitlements. Now adding someone to an Entra ID group grants their licence and project membership on the next sync, with no manual step.
5. Service connections without stored secrets where possible
The module supports both workload identity federation (OIDC, no secret) and secret-based service principals. Where a secret is still needed, it's managed outside Terraform: the configuration ignores changes to it, so it never lands in state.
6. A governance guidebook
I wrote the Azure DevOps governance guidebook: the permission model, who holds each permission, the reason behind each decision, and the owner of each setting.
Things to watch
- Always dry-run bulk access changes. Creating access rules in bulk against a live organization can grant or remove access for many people at once. Inventory first, review the diff, then apply in small batches.
- Naming drift breaks automation. Groups that don't follow the naming convention are silently skipped by name-based tooling. Report mismatches and fix them at the source.
- Overwrite mode is powerful. It reverts every manual grant, including emergency ones. Make sure the team knows the code is the only way in.
- Don't let Terraform fight the platform. Some resources (repositories and pipelines that teams create themselves) conflict with Azure DevOps's own management. Manage the governance layer and leave the team-owned resources alone.
What it solves
- Delivery teams keep full autonomy without being able to weaken the controls on their own work.
- Every project has the same branch protection, set in code and impossible to change in the UI.
- Access follows Entra ID automatically: joiners get access without a ticket, and access granted outside code doesn't survive.
- Licence slots are no longer wasted on orphaned entitlements.
What it doesn't solve
- Organization-level administrators. Project-level controls don't restrict people who administer the whole organization. Keep that group small and reviewed.
- Pipeline content. Branch policies control who can merge, not what a pipeline does once it runs. Pipeline permissions, environment approvals and checks are separate layers.
- Group sprawl in Entra ID. Automation makes access follow groups faithfully, including groups nobody reviews. Group membership still needs access reviews.
Checklist
- [ ] Every project built from one module, with per-project settings as variables
- [ ] Built-in Project Administrator replaced with a delivery-only custom role
- [ ] Branch policies blocking on the default branch and changeable only through code
- [ ] Group membership authoritative from code (overwrite mode)
- [ ] Entra ID group rules for every project and role, created dry-run first
- [ ] Orphaned entitlements cleaned up
- [ ] Workload identity federation for service connections wherever possible
- [ ] A written guidebook: who holds what, why, and who owns each setting
Further reading
- Azure DevOps permissions and security groups: https://learn.microsoft.com/azure/devops/organizations/security/about-permissions
- Azure DevOps group rules / group entitlements (Microsoft Learn)
- Terraform
azuredevopsprovider:azuredevops_branch_policy_min_reviewers,azuredevops_group_membership,azuredevops_serviceendpoint_azurerm(Terraform Registry)