Azure secrets engine
The Azure secrets engine dynamically generates Azure service principals along with role and group assignments. Vault roles can be mapped to one or more Azure roles, and optionally group assignments, providing a simple, flexible way to manage the permissions granted to generated service principals.
Each service principal is associated with a Vault lease. When the lease expires (either during normal revocation or through early revocation), the service principal is automatically deleted.
If an existing service principal is specified as part of the role configuration, a new password will be dynamically generated instead of a new service principal. The password will be deleted when the lease is revoked.
Most secrets engines must be configured in advance before they can perform their functions. These steps are usually completed by an operator or configuration management tool.
Enable the Azure secrets engine:
$ vault secrets enable azure Success! Enabled the azure secrets engine at: azure/
By default, the secrets engine will mount at the name of the engine. To enable the secrets engine at a different path, use the
Configure the secrets engine with account credentials:
$ vault write azure/config \ subscription_id=$AZURE_SUBSCRIPTION_ID \ tenant_id=$AZURE_TENANT_ID \ client_id=$AZURE_CLIENT_ID \ client_secret=$AZURE_CLIENT_SECRET Success! Data written to: azure/config
If you are running Vault inside an Azure VM with MSI enabled,
client_secretmay be omitted. For more information on authentication, see the authentication section below.
Configure a role. A role may be set up with either an existing service principal, or a set of Azure roles that will be assigned to a dynamically created service principal.
To configure a role called "my-role" with an existing service principal:
$ vault write azure/roles/my-role \
Alternatively, to configure the role to create a new service principal with Azure roles:
$ vault write azure/roles/my-role ttl=1h azure_roles=-<<EOF
Roles may also have their own TTL configuration that is separate from the mount's TTL. For more information on roles see the roles section below.
After the secrets engine is configured and a user/machine has a Vault token with the proper permissions, it can generate credentials. The usage pattern is the same whether an existing or dynamic service principal is used.
To generate a credential using the "my-role" role:
$ vault read azure/creds/my-role
This endpoint generates a renewable set of credentials. The application can login
client_secret and will have access provided by configured service
principal or the Azure roles set in the "my-role" configuration.
If the mount is configured with credentials directly, the credential's key may be rotated to a Vault-generated value that is not accessible by the operator. This will ensure that only Vault is able to access the "root" user that Vault uses to manipulate dynamic & static credentials.
vault write -f azure/rotate-root
For more details on this operation, please see the Root Credential Rotation API docs.
Vault roles let you configure either an existing service principal or a set of Azure roles, along with
role-specific TTL parameters. If an existing service principal is not provided, the configured Azure
roles will be assigned to a newly created service principal. The Vault role may optionally specify
max_ttl values. When the lease is created, the more restrictive of the
mount or role TTL value will be used.
If an existing service principal is to be used, the Application Object ID must be set on the Vault role.
This ID can be found by inspecting the desired Application with the
az CLI tool, or via the Azure Portal. Note
that the Application Object ID must be provided, not the Application ID.
If dynamic service principals are used, Azure roles must be configured on the Vault role.
Azure roles are provided as a JSON list, with each element describing an Azure role and scope to be assigned.
Azure roles may be specified using the
role_name parameter ("Owner"), or
role_id is the definitive ID that's used during Vault operation;
role_name is a convenience during
role management operations. All roles must exist when the configuration is written or the operation will fail. The role lookup priority is:
role_idis provided, it is validated and the corresponding
- If only
role_nameis provided, a case-insensitive search-by-name is made, succeeding only if exactly one matching role is found. The
role_idfield will updated with the matching role ID.
scope must be provided for every role assignment.
If dynamic service principals are used, a list of Azure groups may be configured on the Vault role.
When the service principal is created, it will be assigned to these groups. Similar to the format used
for specifying Azure roles, Azure groups may be referenced by either their
Group specification by name must yield a single matching group.
Example of role configuration:
$ vault write azure/roles/my-role \
$ cat az_roles.json
"role_name": "This won't matter as it will be overwritten",
$ cat az_groups.json
"group_name": "This won't matter as it will be overwritten",
If dynamic service principals are used, the option to permanently delete the applications and service principals created by Vault may be configured on the Vault role. When this option is enabled and a lease is expired or revoked, the application and service principal associated with the lease will be permanently deleted from the Azure Active Directory. As a result, these objects will not count toward the quota of total resources in an Azure tenant. When this option is not enabled and a lease is expired or revoked, the application and service principal associated with the lease will be deleted, but not permanently. These objects will be available to restore for 30 days from deletion.
Example of role configuration:
$ vault write azure/roles/my-role permanently_delete=true ttl=1h azure_roles=-<<EOF
The Azure secrets backend must have sufficient permissions to read Azure role information and manage service principals. The authentication parameters can be set in the backend configuration or as environment variables. Environment variables will take precedence. The individual parameters are described in the configuration section of the API docs.
If the client ID or secret are not present and Vault is running on an Azure VM, Vault will attempt to use Managed Service Identity (MSI) to access Azure. Note that when MSI is used, tenant and subscription IDs must still be explicitly provided in the configuration or environment variables.
The following MS Graph API permissions must be assigned to the service principal provided to Vault for managing Azure. The permissions differ depending on if you're using dynamic or existing service principals.
Note: If you plan to use the rotate root
credentials API, you'll need to change
The following Azure role assignments must be granted in order for the secrets engine to manage role assignments for service principles it creates.
|User Access Administrator
|Service Principal ID given in configuration
Dynamic service principals are preferred if the desired Azure resources can be provided via the RBAC system and Azure roles defined in the Vault role. This form of credential is completely decoupled from any other clients, is not subject to permission changes after issuance, and offers the best audit granularity.
Access to some Azure services cannot be provided with the RBAC system, however. In these cases, an existing service principal can be set up with the necessary access, and Vault can create new passwords for this service principal. Any changes to the service principal permissions affect all clients. Furthermore, Azure does not provide any logging with regard to which credential was used for an operation.
An important limitation when using an existing service principal is that Azure limits the number of passwords for a single Application. This limit is based on Application object size and isn't firmly specified, but in practice hundreds of passwords can be issued per Application. An error will be returned if the object size is reached. This limit can be managed by reducing the role TTL, or by creating another Vault role against a different Azure service principal configured with the same permissions.
If a referenced Azure role doesn't exist, a credential will not be generated. Service principals will only be generated if all role assignments are successful. This is important to note if you're using custom Azure role definitions that might be deleted at some point.
Azure roles are assigned only once, when the service principal is created. If the Vault role changes the list of Azure roles, these changes will not be reflected in any existing service principal, even after token renewal.
The time required to issue a credential is roughly proportional to the number of Azure roles that must be assigned. This operation make take some time (10s of seconds are common, and over a minute has been seen).
Service principal credential timeouts are not used. Vault will revoke access by deleting the service principal.
The Application Name for dynamic service principals will be prefixed with
vault-. Similarly the
keyIdof any passwords added to an existing service principal will begin with
ffffff. These may be used to search for Vault-created credentials using the
aztool or Portal.
The Azure secret engine plugin supports debug logging which includes additional information about requests and responses from the Azure API.
To enable the Azure debug logs, set the
AZURE_GO_SDK_LOG_LEVEL environment variable to
DEBUG on your Vault
The Azure secrets engine is written as an external Vault plugin and thus exists outside the main Vault repository. It is automatically bundled with Vault releases, but the code is managed separately.
Please report issues, add feature requests, and submit contributions to the vault-plugin-secrets-azure repo on GitHub.
Refer to the Azure Secrets Engine tutorial to learn how to use the Azure secrets engine to dynamically generate Azure credentials.
The Azure secrets engine has a full HTTP API. Please see the Azure secrets engine API docs for more details.