---
title: Secrets, Certificates & SecOps Rotation
summary: SecOps runbook for verifying Managed Identities, inspecting TLS certificates, revoking compromised credentials, rotating secrets, and querying audit logs.
owners:
  - platform-engineering-team
badges:
  - content: SecOps
    backgroundColor: amber
    textColor: amber
---

## When to Use & Blast Radius

Use this runbook during scheduled credential rotations, TLS certificate renewals, suspected secret compromise, or security incident investigations. Rotating session secrets or revoking partner keys invalidates active sessions or interrupts downstream calls until affected Container App revisions restart.

<Admonition type="danger" title="Coordinate Session Secret Rotations">

Rotating frontend authentication secrets logs out active users across **Storefront** and
**Commerce** simultaneously. Revoking **Message Broker**, **Vector Database**, or **SMTP Relay**
credentials requires updating CI/CD environment secrets and restarting dependent Container Apps.

</Admonition>

### Credential Rotation and Revocation Flow

<MermaidFileLoader file="mermaids/006-secrets-certificates-and-secops-rotation-diagram-1.mmd" />

## Pre-Flight Check

Verify Azure CLI context, inspect Key Vault certificates, and confirm Managed Identity assignments:

```bash
az account set --subscription "<SUBSCRIPTION_ID>"
az keyvault certificate list --vault-name "<KEY_VAULT_NAME>" \
  --query "[].{Name:name, Enabled:attributes.enabled, Expires:attributes.expires}" -o table
az identity list --resource-group "<RESOURCE_GROUP>" \
  --query "[].{Name:name, PrincipalId:principalId, ClientId:clientId}" -o table
```

## Procedure

<Steps>
<Step title="Verify Entra ID Federated Identity Credentials and Managed Identities">

Confirm **API Gateway**, backend services, and AI agent identities have valid Federated Identity Credentials and no unauthorized role assignments:

```bash
az ad app federated-credential list --id "<ENTRA_APP_OBJECT_ID>" \
  --query "[].{Name:name, Subject:subject, Audiences:audiences}" -o table
az role assignment list --resource-group "<RESOURCE_GROUP>" --assignee "<PRINCIPAL_ID>" \
  --query "[].{Role:roleDefinitionName, Scope:scope}" -o table
```

</Step>

<Step title="Inspect and renew Container Apps custom TLS certificates">

Check expiration dates on custom domain certificates bound to the Container Apps environment and import renewed certificates from Key Vault:

```bash
az containerapp env certificate list --name "<ENV_NAME>" --resource-group "<RESOURCE_GROUP>" \
  --query "[].{Name:name, Subject:properties.subjectName, Expiration:properties.expirationDate}" -o table
```

</Step>

<Step title="Rotate external partner credentials in GitHub Environments and redeploy">

Generate a new API key or connection string in the external provider (**Message Broker**, **Qdrant Cloud**, or **SMTP Relay**), update the GitHub Environment secret, and roll out updated Container Apps:

```bash
gh secret set "<SECRET_NAME>" --env "<ENV>" --body "<NEW_SECRET_VALUE>"
gh workflow run apphost-cd.yml -f environment="<ENV>" -f clear_cache=false
```

</Step>

<Step title="Update Container App secrets directly during emergency revocation">

When immediate rotation cannot wait for a full CI/CD run, update the Container App secret and restart the active revision:

```bash
az containerapp secret set --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" \
  --secrets "<SECRET_KEY>=<NEW_SECRET_VALUE>"
az containerapp revision restart --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --revision "<REVISION_NAME>"
```

</Step>

<Step title="Query Azure Activity and Entra ID audit logs">

Inspect recent control-plane mutations, role assignment changes, and Key Vault secret access:

```bash
az monitor activity-log list --resource-group "<RESOURCE_GROUP>" --offset 24h \
  --query "[?level=='Warning' || level=='Error' || contains(operationName.value,'roleAssignments')].{Time:eventTimestamp, Caller:caller, Operation:operationName.localizedValue, Status:status.value}" \
  -o table
```

</Step>

</Steps>

## Verification

Confirm all rotated Container Apps are `Running` with healthy revisions and zero `401`/`403` authentication errors in Log Analytics:

```bash
WORKSPACE_ID=$(az monitor log-analytics workspace list --resource-group "<RESOURCE_GROUP>" --query "[0].customerId" -o tsv)
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
  --analytics-query "ContainerAppConsoleLogs_CL | where TimeGenerated > ago(15m) | where Log_s has_any ('401','403','Unauthorized','NOAUTH') | summarize AuthErrors=count() by ContainerAppName_s" \
  -o table
```

Expected output:

```text
(0 rows returned)
```

## Rollback / Escape Hatch

If a rotated partner credential breaks connectivity, re-apply the previous active credential (if not yet revoked) via `az containerapp secret set` and restart the affected revision, or re-run the last known-good CI/CD deployment.

<Accordion title="Emergency Credential Revocation Scenarios">

- **Compromised external API key (Message Broker, Qdrant Cloud, SMTP):** Issue a replacement key in the provider portal first, roll out via Step 3 or Step 4, verify zero auth errors, and **then** revoke the compromised key in the provider portal.
- **Compromised Entra ID application secret or Federated Credential:** Delete the compromised credential via `az ad app federated-credential delete --id "<ENTRA_APP_OBJECT_ID>" --federated-credential-id "<CREDENTIAL_ID>"`, recreate it via `aspire deploy --environment "<ENV>"`, and restart affected revisions.
- **Unauthorized RBAC assignment detected in Activity Log:** Remove the assignment immediately with `az role assignment delete --assignee "<PRINCIPAL_ID>" --role "<ROLE_NAME>" --scope "<SCOPE>"`.

</Accordion>
