Service principal secret expired — authentication failures
az login --service-principal fails with AADSTS7000222 or invalid client secret
Focused incident mode — strips away everything but this runbook.
Symptoms
- az login --service-principal fails with AADSTS7000222 or invalid client secret
- CD/CD pipelines fail authentication after working previously
- Azure service outages reported from automation scripts with no code change
Set a reminder (or automated alert) at 30 days before SP secret expiry. Store the secret in Key Vault and rotate via a scheduled runbook to avoid manual misses.
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
Service principal details
az ad sp show --id <APP-ID> --query "{appId:appId,displayName:displayName}" -o jsonClient secret expiration
az ad sp credential list --id <APP-ID> --query "[].{keyId:keyId,endDate:endDate}" -o table
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- az ad sp credential list shows endDate in the past
- az login --service-principal returns AADSTS7000222
Confirm before fixing
az ad sp credential list --id <APP-ID> --query "[?endDate < now()]" -o tableFind expired credentials
Fix
az ad sp credential reset --id <APP-ID> --years 2Reset the service principal credential with a new expiry
Expected: A new password is output — store it in the key vault
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
az ad sp credential list --id <APP-ID> --query "[].{keyId:keyId,endDate:endDate}" -o tableCheck credential expirations
az ad sp credential reset --id <APP-ID> --years 2Reset and generate a new secret
az keyvault secret set --vault-name <KV-NAME> --name <SP-SECRET-NAME> --value <NEW-CLIENT-SECRET>Store the new secret in Key Vault
az login --service-principal --username <APP-ID> --password <NEW-CLIENT-SECRET> --tenant <TENANT-ID>Verify the new secret authenticates
Expected: The user or service principal is signed in.
Prevention
- Store service principal secrets in Key Vault and reference them in pipelines.
- Rotate client secrets on a 12-month schedule with an automated runbook.
- Set up Azure Monitor alerts on AADSTS7000222 login failures.
- Use workload identity federation to eliminate service principal secret rotation.
Related runbooks
Same stack, same failure family — worth a skim.
Application throws ClientAuthenticationError: ManagedIdentityCredential authentication failed
az keyvault secret show returns Forbidden: insufficient permissions
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.