AzureDevOps project Severityhigh builtIn

Description

Allow deployments based on branches linked to the run. Extend pipeline protection by configuring a protected branch check on each of your resources. This will automatically stop your pipeline from running on top of any user branches. Most pipelines need a second set of eyes look over changes (especially to the pipeline itself) before deploying to production. Checks allow you to pause the pipeline run until certain conditions are met. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints

Recommendation

1. Navigate to Project Settings. 
2. Open the Service connections link under Pipelines. 
3. Select a service connection. 
4. Click on 'Approvals and checks' tab. 
5. Add a new 'Branch control' check.

Policy Rule

{
  "target": "ADOProjectCheckConfiguration",
  "if": {
    "allOf": [
      {
        "resource": "ADOProjectCheckConfiguration",
        "property": "Resource.Type",
        "operator": "equals",
        "value": "endpoint"
      },
      {
        "resource": "ADOProjectCheckConfiguration",
        "property": "Resource.Name",
        "operator": "match",
        "value": "$(POLICY_VAR_PROJECT_PROD_SERVICE_CONNECTION_PATTERNS)"
      },
      {
        "resource": "ADOProjectCheckConfiguration",
        "property": "Type.Name",
        "operator": "equals",
        "value": "Task Check"
      },
      {
        "resource": "ADOProjectCheckConfiguration",
        "property": "BranchControl.DefinitionRef.Name",
        "operator": "equals",
        "value": "evaluatebranchProtection"
      },
      {
        "resource": "ADOProjectCheckConfiguration",
        "property": "BranchControl.Inputs.AllowedBranches",
        "operator": "notEquals",
        "value": "*"
      }
    ]
  },
  "then": {
    "effect": "Audit"
  }
}