Azure static credentials
With static credentials, Stategraph Orchestration reaches Azure with a dedicated service principal and its client secret. It gets a first plan running quickly.
Consider OIDC
Static credentials are long-lived secrets in your repository settings. For production, OIDC authenticates with short-lived tokens and nothing to rotate.
Setup has two steps:
- Create the service principal with the Azure CLI.
- Store its values as GitHub secrets with the GitHub CLI, or as GitLab CI/CD variables in the GitLab UI.
The runner gets the values as environment variables, and the AzureRM provider reads them there. Keep hooks and workflow steps from printing them. See Variables.
Prerequisites
- The Azure CLI
- The GitHub CLI, if you store the credentials on GitHub
Create a service principal
- Log in to the Azure CLI:
az login
- List your subscriptions. The
idfield is your subscription ID:
az account list
Output:
[
{
"cloudName": "AzureCloud",
"id": "00000000-0000-0000-0000-000000000000",
"isDefault": true,
"name": "PAYG Subscription",
"state": "Enabled",
"tenantId": "00000000-0000-0000-0000-000000000000",
"user": {
"name": "user@example.com",
"type": "user"
}
}
]
- Export the subscription ID and select it:
export SUBSCRIPTION_ID="<subscription-id>"
az account set --subscription "$SUBSCRIPTION_ID"
- Create the service principal with a role on the subscription:
az ad sp create-for-rbac --role="Contributor" \
--scopes="/subscriptions/$SUBSCRIPTION_ID"
Contributor is an Azure built-in role. It grants full access to manage resources, but it cannot assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries. Use the role that fits your organization.
Output:
{
"appId": "00000000-0000-0000-0000-000000000000",
"displayName": "azure-cli-2017-06-05-10-41-15",
"name": "http://azure-cli-2017-06-05-10-41-15",
"password": "0000-0000-0000-0000-000000000000",
"tenant": "00000000-0000-0000-0000-000000000000"
}
The AzureRM provider uses other names for these values. Record the mapping for the next section:
appIdmaps toARM_CLIENT_IDpasswordmaps toARM_CLIENT_SECRETtenantmaps toARM_TENANT_ID
Store the credentials
Store the four values for your VCS. Then Orchestration can run stategraph plan and stategraph apply against your Azure resources.
GitHub
- Export your
organization/reponame:
export REPO="<OWNER/REPO>"
- Create the subscription ID secret:
gh secret --repo "$REPO" set ARM_SUBSCRIPTION_ID --body "$SUBSCRIPTION_ID"
- Create the client ID secret, and paste the
appIdvalue when the CLI asks for it:
gh secret --repo "$REPO" set ARM_CLIENT_ID
- Create the client secret, and paste the
passwordvalue:
gh secret --repo "$REPO" set ARM_CLIENT_SECRET
- Create the tenant ID secret, and paste the
tenantvalue:
gh secret --repo "$REPO" set ARM_TENANT_ID
GitLab
- Open your GitLab project and go to Settings, then CI/CD, then Variables.
- Click Add variable, enter the Key
ARM_SUBSCRIPTION_ID, and paste your subscription ID as the Value. Leave Protect variable cleared, then click Add variable. - Do the same for
ARM_CLIENT_IDwith theappIdvalue, and forARM_TENANT_IDwith thetenantvalue. - Do the same for
ARM_CLIENT_SECRETwith thepasswordvalue, and mark this variable as masked.
GitLab passes protected variables only to pipelines on protected branches. Orchestration runs plans on the merge request's source branch, so those runs do not get a protected variable. To share the credentials across projects, add the variables to the GitLab group.
Next Steps
- Configuration: customize workflows in
.stategraph/config.yml - Azure OIDC: migrate to keyless authentication
- Cloud credentials: credential patterns across providers