# Azure (Microsoft Entra app client secrets) API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/azure
Last checked: 2026-10-25

An Azure service principal signs in with a client secret created in the Microsoft Entra admin center under Entra ID → App registrations → your app → Certificates & secrets → Client secrets → New client secret. The secret value is shown only once and a client secret lasts at most 24 months. Microsoft recommends certificates or federated credentials instead of secrets in production.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Client secret | — | Yes | The Azure roles assigned to the app's service principal | Maximum 24 months; Microsoft recommends under 12 months |
| Certificate credential | — | Yes | The Azure roles assigned to the app's service principal | Set by the certificate's expiry date |

## How to create a Azure (Microsoft Entra app client secrets) key

1. Sign in to the Microsoft Entra admin center.
2. Browse to **Entra ID** → **App registrations** and select your application.
3. Select **Certificates & secrets** → **Client secrets** → **New client secret**.
4. Add a description and choose an expiration (or custom lifetime, up to 24 months), then select **Add**.
5. Copy the secret **Value** immediately; it is not shown again.

## Limiting what the key can do

A client secret has no scopes of its own; it authenticates the app, and access is set by the Azure roles assigned to the service principal (for example on a subscription, resource group or single resource) and by API permissions granted to the app. Assign the narrowest built-in role at the narrowest scope.

## How to rotate a Azure (Microsoft Entra app client secrets) key

1. In the app registration, add a new client secret under **Certificates & secrets** (multiple secrets can exist at once).
2. Update your application or pipeline with the new secret value.
3. Delete the old secret once nothing uses it.

## How to revoke a Azure (Microsoft Entra app client secrets) key

1. In the Entra admin center open the app registration and select **Certificates & secrets**.
2. Delete the client secret you want to revoke.

## If the key leaked

1. Add a replacement secret and update the application.
2. Delete the exposed client secret from the app registration.
3. Review the service principal's role assignments and sign-in activity, and consider replacing the secret with a certificate or federated credential.

## Gotchas

- The secret Value is shown only once; the Secret ID is not a credential.
- Secrets expire (24 months at most), so apps break silently on the expiry date unless you track it.
- Microsoft says client secrets should not be used in production; prefer certificates, federated credentials or managed identities.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `cli_login`: Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `store_secret`: Saves a value the agent already holds as a new vault item.
- `capture_secret`: Planned, not built yet: will read a newly created key straight from the page or command output into the vault.

## FAQ

### Where do I find my Azure client secret?

You can't view it again after creation. In Entra ID → App registrations → your app → Certificates & secrets, only the Secret ID and expiry are listed, so create a new secret if the value is lost.

### How long does an Azure client secret last?

At most 24 months, and Microsoft recommends setting under 12 months.

### How do I log in to Azure CLI with a service principal?

Run `az login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_ID`.

### What does AADSTS7000215 mean?

It means the client secret supplied is invalid, often because the secret ID was used instead of the secret value.

### Can an AI agent use my Azure (Microsoft Entra app client secrets) key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `list_credentials`, `run_with`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://learn.microsoft.com/en-us/entra/identity-platform/how-to-add-credentials
- https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal
- https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli-service-principal
- https://learn.microsoft.com/en-us/entra/identity-platform/reference-error-codes
- https://learn.microsoft.com/en-us/azure/developer/azure-mcp-server/overview
