Task 01: Bootstrap
DOCUMENT CATEGORY: Runbook Step
SCOPE: CI/CD service principal bootstrap
PURPOSE: Create an Entra ID app registration and service principal for CI/CD pipeline authentication MASTER REFERENCE: Azure Pipelines Agent Documentation
Status: Active
Objective
Create an Entra ID app registration and service principal in the target tenant so CI/CD pipelines can authenticate to Azure and manage resources.
Prerequisites
- Azure CLI installed and authenticated (
az login) - Signed in to the target tenant (verify with
az account show) - Application Administrator or Global Administrator role in Entra ID
- Owner or User Access Administrator on each target subscription
- Target subscription ID(s) available
Values from infrastructure.yml
The script reads the devops section (platform, URL, organization, project, authentication), azure, key_vaults[] and landing_zone of infrastructure.yml (schema 5). Each key, with its type, default and example, is in the variables reference.
Procedure
Step 1: Create the App Registration and Service Principal
# Set variables
APP_NAME="azurelocal-cicd"
SUBSCRIPTION_IDS=("subscription-id-1" "subscription-id-2")
# Create app registration with a 2-year secret
az ad app create --display-name "$APP_NAME"
APP_ID=$(az ad app list --display-name "$APP_NAME" --query "[0].appId" -o tsv)
# Create service principal
az ad sp create --id "$APP_ID"
# Create client secret (2-year expiry)
SECRET=$(az ad app credential reset --id "$APP_ID" --years 2 --query "password" -o tsv)
# Get tenant ID
TENANT_ID=$(az account show --query "tenantId" -o tsv)
echo "ARM_CLIENT_ID: $APP_ID"
echo "ARM_CLIENT_SECRET: $SECRET"
echo "ARM_TENANT_ID: $TENANT_ID"
Important: Save the
ARM_CLIENT_SECRETimmediately — it cannot be retrieved again.
Step 2: Assign RBAC Roles
Assign roles on each target subscription:
for SUB_ID in "${SUBSCRIPTION_IDS[@]}"; do
# Contributor — manage resources
az role assignment create \
--assignee "$APP_ID" \
--role "Contributor" \
--scope "/subscriptions/$SUB_ID"
# User Access Administrator — manage RBAC assignments
az role assignment create \
--assignee "$APP_ID" \
--role "User Access Administrator" \
--scope "/subscriptions/$SUB_ID"
done
Step 3: Register Providers and Features
for SUB_ID in "${SUBSCRIPTION_IDS[@]}"; do
az account set --subscription "$SUB_ID"
# Register the Compute provider
az provider register --namespace "Microsoft.Compute"
# Enable EncryptionAtHost feature
az feature register \
--namespace "Microsoft.Compute" \
--name "EncryptionAtHost"
done
Step 4: Add API Permissions
# Add Microsoft Graph — RoleManagement.ReadWrite.Directory (Application)
GRAPH_APP_ID="00000003-0000-0000-c000-000000000000"
ROLE_MGMT_ID="9e3f62cf-ca93-4989-b6ce-bf83c28f9fe8"
az ad app permission add \
--id "$APP_ID" \
--api "$GRAPH_APP_ID" \
--api-permissions "$ROLE_MGMT_ID=Role"
Step 5: Grant Admin Consent
Grant admin consent via the Azure Portal or CLI:
- Portal
- Azure CLI
- Navigate to Entra ID → App registrations → azurelocal-cicd
- Select API permissions
- Click Grant admin consent for <tenant>
az ad app permission admin-consent --id "$APP_ID"
Verification
- App registration
azurelocal-cicdexists in Entra ID - Service principal created
-
ContributorandUser Access Administratorroles assigned on all target subscriptions -
Microsoft.Computeprovider registered -
EncryptionAtHostfeature enabled - Admin consent granted for API permissions
- Credentials saved securely (will be stored in CI/CD platform in Task 05)
- GitHub
- GitLab
- Azure DevOps
When to use: Use if running GitHub Actions pipeline.
See the procedure steps above for GitHub-specific configuration.
When to use: Use if running GitLab CI/CD pipeline.
See procedure steps for GitLab-specific configuration.
When to use: Use if running Azure DevOps Pipelines.
See procedure steps for Azure DevOps-specific configuration.
The toolkit script for this task is PowerShell 7. It reads infrastructure.yml through the mandatory -InfrastructureFile parameter and never prompts. It ends with exit code 0, 1 or 2. Run it with -WhatIf first: the script reads what exists and lists what it would do.
- Orchestrated Script
- Azure CLI
PowerShell
Script
| Script | What it does |
|---|---|
scripts/deploy/01-cicd-infra/phase-01-cicd-setup/task-01-bootstrap/powershell/New-CicdBootstrap.ps1 | Task 01. Creates the CI/CD service principal and its Azure access. Supports -WhatIf. |
Requires: PowerShell 7.
Run
./New-CicdBootstrap.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
Azure CLI
When to use: Run the task from a host that has the Azure CLI and not the Az PowerShell modules. The script is PowerShell 7 that calls
az; it readsinfrastructure.ymland carries no values of its own.
Script
| Script | What it does |
|---|---|
scripts/deploy/01-cicd-infra/phase-01-cicd-setup/task-01-bootstrap/azurecli/New-CicdBootstrap.azcli.ps1 | Task 01, Azure CLI variant. Creates the CI/CD service principal and its Azure access with az commands. Supports -WhatIf. |
Requires: PowerShell 7 and the Azure CLI, signed in with az login --tenant <azure.tenant_id>.
It does the Azure side of the PowerShell script and makes the same objects: the app registration and service principal (azure.automation_identity.name), the federated credentials of the platform (or, with devops.authentication.method client_secret, a client secret kept only in Key Vault), the role assignments on each subscription, and the Microsoft.Compute and EncryptionAtHost registrations. It creates nothing on GitHub, GitLab or Azure DevOps (tasks 02 to 05 do) and does not sign in. It is idempotent, and -Platform overrides devops.platform.
Limits: with the client secret method the check that the secret is in Key Vault goes through the toolkit's secret resolver, which needs the Az.KeyVault module; every other Azure call is an az command. The secret goes to Key Vault from a temporary file that is removed at once, never on a command line, and is never printed. A client secret is not rotated: delete the Key Vault secret to have a new one issued.
Run
./New-CicdBootstrap.azcli.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
./New-CicdBootstrap.azcli.ps1 -InfrastructureFile ./infrastructure.yml
Alternatives
The procedures in this task use the methods shown in the tabs above. The toolkit is PowerShell 7 only and has no Bash scripts. A few tasks that act on Azure also have an Azure CLI script written in PowerShell. The script status page of the toolkit lists which task has which script.
Navigation
| Previous | Up | Next |
|---|---|---|
| --- | Phase 01: CI/CD Setup | Task 02: Create source control project -> |
Troubleshooting
App already exists:
An app registration with the name "azurelocal-cicd" already exists.
→ Delete the existing app registration first: az ad app delete --id <APP_ID>
Insufficient permissions:
Insufficient privileges to complete the operation.
→ Ensure you have Application Administrator role in Entra ID and Owner on the target subscription(s)
Feature registration pending:
Feature "EncryptionAtHost" is in "Registering" state.
→ Wait a few minutes, then check status: az feature show --namespace Microsoft.Compute --name EncryptionAtHost
References
- Register an application with Microsoft Entra ID
- Assign Azure roles using Azure CLI
- Azure CLI — az ad app
Next Steps
Version Control
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2025-03-25 | Azure Local Cloud | Initial release |