Background
Not long after the resource groups were split, Dee from the platform team spotted another problem.
The service connection behind relay's release pipeline still ran on a deployment identity holding Contributor on the entire subscription. When people found out, the reaction was mild surprise — the humans had been split into teams, but deployments still traveled the old shared road.
All three teams used the same Azure DevOps project. It had been the only one since the early days; teams kept arriving, and the project was never split.
While tracing one pipeline, Dee casually opened a variable group's Key Vault link: relay's production vault sat there in the pick list. The secret values stayed hidden — but the link itself went through. Nobody had ever reported it. The risk was real all the same.
He went through the whole project. Repos: visible and editable. Pipelines: visible and editable. Variable groups and project settings: same. In ADO, the shared account was a Contributor, while personal accounts had only ordinary build permissions — so to get anything done, everyone detoured back to the shared account. You could see other teams' things, and change them too — "convenient," after all.
Once the picture was complete, Dee set two goals: split pipeline permissions per team, and switch DevOps work to personal accounts.
Splitting the project itself was ruled out first — dozens of pipelines ran inside it, dragging many repos along; too risky to move in the short term. New teams could get new projects.
So the split would happen inside the project walls.
Comparison: one connection for dev, one for prod, three teams sharing both
The old project had exactly two service connections: one for the dev subscription, one for prod — both backed by that same subscription-level Contributor deployment identity. All three teams' pipelines pointed at these two. When linking a Key Vault, every team's vault in the subscription lay in the pick list; deployments were the same — the connection could land in any RG in the subscription.
# The whole project had just these two connections; relay, pulse, and harbor deploy pipelines all pointed at them
resource "azuredevops_serviceendpoint_azurerm" "shared_prd" {
project_id = data.azuredevops_project.apps.id
service_endpoint_name = "sc-shared-prd"
credentials {
serviceprincipalid = var.shared_deploy_client_id # the subscription-level Contributor deployment identity
}
azurerm_spn_tenantid = var.tenant_id
azurerm_subscription_id = var.prod_subscription_id # the entire prod subscription
azurerm_subscription_name = "SUB-EG-APP-PRD"
}
# Same again for the dev subscription: sc-shared-dev
Approach
Dee had two ends to close. The Azure end: the service connections pipelines use — for deploying and for linking Key Vault — could no longer land on the whole subscription. The DevOps end: a project is wide by default; other teams' pipelines and variable groups open up unless each is individually restricted. Relay's production KV being selectable from a variable group, back in the Background, was exactly this line left open.
The method is allow-only: members are maintained only in the Entra team SGRPs; each team gets a group in the project with nothing but door-opening GENERIC_READ — teams are not nested into Contributors. Who may change what comes from individual Allow entries later. A person in two team SGRPs carries both team groups, and the two sides' Allow entries simply stack — so no Deny is needed to fence teams off each other.
On the DevOps side, a team_ado sheet registers which service connections, pipeline folders, Git repos, Library variable groups, and deployment environments each team may use; member rosters don't go into tfvars.
team_ado = {
relay = {
service_connection_names = ["sc-relay-dev", "sc-relay-prd", "sc-relay-acr"]
pipeline_path = "\\relay"
git_repositories = { relay-app = {} }
library = {
variable_groups = { vg_relay_prd_kv = 101, vg_shared_templates = 102 }
environments = { relay-uat = 49, relay-prod = 53 }
}
}
}
The Library grant sheet can carry numeric ids alongside. The DevOps API can't batch-list a project's variable groups or environments by name prefix, so maintain a small name → id table yourself: when something new is created, look up its id and add a row — workable, and it speeds Terraform up. The shared ACR isolates repositories by team path prefix, but credentials must not be shared: issue each team its own scope token, and create a team-specific Docker Registry service connection in ADO (username/password bound to the token, scoped to that team's relay/* push/pull). Register this ACR SC in team_ado.service_connection_names alongside the team's ARM connections. For the old subscription-level ARM connections and the legacy whole-registry ACR SC, just note their names — delete them after pipelines have switched over.
Team groups mirror the SGRPs
Membership changes happen only in the Entra SGRPs. In DevOps, each team gets one project group; hook the Entra group in via a group entitlement (what gets nested is the entitlement, not individual UPNs), and grant GENERIC_READ — otherwise opening the project returns 401.
data "azuread_group" "relay_sgrp" { display_name = "SGRP-RELAY" }
resource "azuredevops_group_entitlement" "team" {
origin = "aad"
origin_id = data.azuread_group.relay_sgrp.object_id
account_license_type = "express"
}
resource "azuredevops_group_membership" "team_entra" {
group = azuredevops_group.team_project.descriptor
members = [azuredevops_group_entitlement.team.descriptor]
}
resource "azuredevops_project_permissions" "team_project_view" {
principal = azuredevops_group.team_project.id
permissions = { GENERIC_READ = "Allow" }
}
Deployment reaches only the team's own RGs
One service connection per environment, backed by the team's own workload identity; Contributor and the roles needed to read Key Vault are granted on the team's dev/prod RGs only — never on the whole subscription. Only then does the vault pick list line up with this edge when a variable group links a KV.
resource "azuredevops_serviceendpoint_azurerm" "relay_prd" {
service_endpoint_name = "sc-relay-prd"
service_endpoint_authentication_scheme = "WorkloadIdentityFederation"
# …
}
resource "azurerm_role_assignment" "relay_prd_contributor" {
scope = data.azurerm_resource_group.relay_prd.id
role_definition_name = "Contributor" # tighten further as needed
principal_id = azuread_service_principal.relay_deploy.object_id
}
Per-team allow lists inside DevOps
Four areas lock down together: service connections can only be Used under the team's registered names; the Library first loses project-level visibility, then reopens only to the variable groups and environments listed in the sheet; pipelines can be edited and queued only inside the team's folder, like \relay; code repositories are registered by repo name in team_ado.git_repositories, with Contribute for the team's own group — and Deny against other teams' ADO groups where isolation requires it.
resource "azuredevops_library_permissions" "relay_library_deny" {
principal = azuredevops_group.team_project["relay"].id
permissions = { View = "Deny", Use = "Deny", ViewSecrets = "Deny" }
}
resource "azuredevops_securityrole_assignment" "relay_vg_kv" {
scope = "distributedtask.variablegroup"
resource_id = format("%s$%s", data.azuredevops_project.apps.id, 101)
role_name = "Administrator"
}
resource "azuredevops_serviceendpoint_permissions" "relay_sc" {
serviceendpoint_id = azuredevops_serviceendpoint_azurerm.relay_prd.id
permissions = { Use = "allow", ViewEndpoint = "allow" }
}
resource "azuredevops_build_folder_permissions" "relay_folder" {
path = "\\relay"
permissions = { EditBuildDefinition = "Allow", QueueBuilds = "Allow" }
}
resource "azuredevops_git_permissions" "relay_app" {
repository_id = data.azuredevops_git_repository.relay_app.id
principal = azuredevops_group.team_project["relay"].id
permissions = {
GenericRead = "Allow"
GenericContribute = "Allow"
Administer = "Deny"
}
}
New teams simply get a new project; everything above serves only the legacy shared project.
Example
Directory: permissions/shared-project-team-access/. Reading order: comparison → after the switch → ADO allow lists (the file list lives in that directory's README.md).
| Stage | Files |
|---|---|
| Comparison (the "Comparison" section above) |
legacy_shared_service_connections.tf + legacy_subscription_service_connections in tfvars (sc-shared-dev / sc-shared-prd) |
| Azure team-level deployment |
service_connections.tf, azure_deploy_rbac.tf, acr_scope_tokens.tf
|
| ADO allow-only |
project.tf, service_connection_access.tf, library_access.tf, pipeline_access.tf, repo_access.tf
|
| Config sheet | Three teams' team_ado in case.auto.tfvars
|
Open the files following the table; when needed, run terraform init and terraform plan to see the dependency wiring.
Quiz
Wouldn't one Azure DevOps project per team be much simpler? Think through how the two options differ.
Takeaway
People belong to teams, resources belong to teams, deployments belong to teams — even "who gets to see what" belongs to teams. On Azure, team service connections point at the team's own Resource Groups, and deployments touch only what lives in the team's RG. In DevOps, allow-only lists watch the repos, variable groups, pipelines, and Library. Only at this point is the shared deployment identity truly the spare key in the project — not the one everyone reaches for by default.
Top comments (0)