Vault

Vault Azure Secrets Engine: Ephemeral Service Principals in Practice

2026-04-19
NicheeLab Editorial Team

Handing out long-lived client secrets to workloads that need Azure permissions is risky. With the Vault Azure secrets engine, you can mint short-lived Service Principals on demand and let them expire automatically when the TTL elapses or the lease is revoked.

This article walks through least-privilege permission design, setup, issuance and revocation, and the operational pitfalls — all end to end. It also calls out the points that come up on the Associate and Ops certifications.

What the Azure Secrets Engine Does, and When to Choose It

The Vault Azure secrets engine registers an application in Azure AD with a matching Service Principal, assigns the configured Azure RBAC at the target scope, and then returns the client ID and client secret. Every issued credential carries a lease, and it is automatically invalidated when the TTL elapses or the lease is explicitly revoked.

The main operational benefits are minimizing exposure through short-lived credentials, automatic RBAC grant and revoke, and traceability via Vault audit logs. Unlike Key Vault, which is a storage-oriented service, this engine is purpose-built for issuance and lifecycle management.

  • Key paths: azure/config, azure/roles/<name>, azure/creds/<name>
  • Define role_name and scope in a role to automate RBAC assignment
  • Leases and TTLs drive automatic expiry; vault lease revoke handles immediate revocation
  • Audit: every issuance is recorded by Vault audit devices
AspectVault Azure Secrets EngineAzure Key VaultManual Service Principal Management
Credential lifetimeShort-lived with a TTL; supports automatic expiry and revocationLong-term storage by default; rotation is implemented separatelyTends to be long-lived, with the risk of missed revocations
RBAC assignment automationRole definition automatically assigns RBAC at the scopeNot in scope; primarily for storing secretsGranted manually each time via portal or CLI
Expiry and revocationLease revocation immediately invalidates the credential and removes permissionsSecrets are disabled or deleted manuallyManual deletion of app/SP and role assignments
AuditabilityIssuance and revocation are recorded in Vault audit logsKey Vault audits focus on storage operationsHard to guarantee; tends to be scattered
Exam angleIssued by reading azure/creds/<role>Storage use case, not issuanceOften featured on exams as a discouraged pattern

Prerequisites and Least-Privilege Permissions

Because Vault performs app registration, Service Principal creation, and role assignments on the Azure side, the configuration credential it uses needs both directory and RBAC permissions. You also need a network environment where Vault can reach Microsoft Graph and Azure Resource Manager.

In practice, the key is to minimize the creation and assignment permissions and tightly scope them. Exams also frequently ask which permission is required for which operation.

  • App/Service Principal creation: directory-side permissions such as Application Administrator
  • Role assignment: Owner or User Access Administrator at the assignment scope
  • Required endpoint reachability: login.microsoftonline.com, Microsoft Graph, and the management API
  • Vault side: control paths through an appropriate auth method (AppRole, OIDC/JWT, etc.) and policy

Setup: Enabling the Engine and Writing the Config

Start by enabling the secrets engine and saving the tenant_id along with the client_id/client_secret used for configuration. Specifying the environment (such as AzurePublicCloud) lets Vault pick the right endpoints. Then tune the TTL policy.

Role definition and issuance are covered in the next section. Here we show the fastest path to a working setup via CLI/HTTP API, along with an example Terraform definition for operational automation.

  • Enable: vault secrets enable azure
  • Configure: vault write azure/config tenant_id, client_id, client_secret, environment
  • TTL settings: tune default TTL and max TTL via azure/config/lease

Initial setup and smoke test using CLI/HTTP and Terraform

#!/usr/bin/env bash
set -euo pipefail

# 1) 有効化と Azure クレデンシャル設定
vault secrets enable azure || true
vault write azure/config \
  tenant_id="$AZURE_TENANT_ID" \
  client_id="$AZURE_CLIENT_ID" \
  client_secret="$AZURE_CLIENT_SECRET" \
  environment="AzurePublicCloud"

# (任意)デフォルトのリース設定
vault write azure/config/lease ttl=1h max_ttl=24h

# 2) ロール定義(resource group 範囲に Contributor を付与する例)
cat > role-dev.json <<'JSON'
{
  "azure_roles": [
    {
      "role_name": "Contributor",
      "scope": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/app-rg"
    }
  ],
  "ttl": "1h",
  "max_ttl": "24h"
}
JSON

curl \
  --silent \
  --header "X-Vault-Token: $VAULT_TOKEN" \
  --request POST \
  --data @role-dev.json \
  "$VAULT_ADDR/v1/azure/roles/dev" | jq '.'

# 3) 認証情報の発行(出力に client_id, client_secret, tenant_id, lease_id など)
vault read -format=json azure/creds/dev | jq '.'

# 4) 取り消し(即時失効)
# vault lease revoke <lease_id>

# ------------------------------
# Terraform 例(抜粋)
# ------------------------------
# provider "vault" {}
# resource "vault_azure_secret_backend" "az" {
#   path          = "azure"
#   tenant_id     = var.tenant_id
#   client_id     = var.client_id
#   client_secret = var.client_secret
#   environment   = "AzurePublicCloud"
# }
# resource "vault_azure_secret_backend_role" "dev" {
#   backend  = vault_azure_secret_backend.az.path
#   role     = "dev"
#   ttl      = "1h"
#   max_ttl  = "24h"
#   azure_roles = [{
#     role_name = "Contributor"
#     scope     = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/app-rg"
#   }]
# }

Role Design and the Issuance Flow

A role defines which Azure RBAC to grant to the issued Service Principal at which scope, along with TTL and Max TTL. Scopes can be narrowed down to a subscription, a resource group, or even a specific resource. A single role can include multiple role_name/scope pairs, but following the principle of least privilege and splitting roles by environment and use case keeps operations stable.

Issuance is just a read on azure/creds/<role>: Vault registers the app and Service Principal in Azure AD and applies the role assignments at the defined scope. The response contains client_id, client_secret, tenant_id, and lease information, and it expires automatically when the TTL is exceeded. To revoke explicitly, pass the lease_id to the revoke command.

  • Example scopes: /subscriptions/<subId>/resourceGroups/<rg>, or a specific resource ID
  • Keep TTL short and allow renewal aligned with job runtime
  • azure/creds/<role> is a read operation — watch out for confusing it with write on the exam

Service Principal issuance flow through Vault

ClientVaultAuth / ACLAzure Secrets EngineMicrosoft GraphApp registration / SP creationAzure RBAC assignmentclient_id / client_secret returnedClient connects to AzureService Principal issuance flow through Vault

Operations: TTL/Renewal, Revocation, Auditing, and SRE-Side Pitfalls

Manage TTL via per-role configuration or the default lease setting. For long-running jobs, design the client to renew the lease. On failure, revoke immediately to invalidate and then re-issue. Always enable a Vault audit device to ensure traceability of every issuance and revocation.

Common operational pitfalls include overly broad role-assignment scopes, Graph API rate limits, and creation failures due to insufficient permissions. When using this from CI, make the mapping between the Vault auth method (AppRole/OIDC) and the role explicit to prevent misuse.

  • Decide the lease renewal strategy together with job control
  • Minimize scopes and split roles per environment
  • Regularly review and emit metrics based on audit logs
  • Throttle batch executions to deal with rate limits

Troubleshooting and Exam-Prep Highlights

The typical cause of creation or assignment failures is insufficient permissions. App registration and SP creation need directory permissions, while role assignment needs Owner or User Access Administrator at the target scope. When you see an Insufficient privileges message, check permissions and scope first.

On the exam, the key paths of the engine, the relationship between roles and scopes, and the lease concept come up frequently. Remember that azure/creds/<role> is a read operation and that revocation is done via lease revoke.

  • Insufficient privileges: check both directory permissions and scope permissions
  • 429 Too Many Requests: retry with jitter between executions
  • Bad scope format: always use the full resource ID
  • Exam keywords: azure/config, azure/roles/<name>, azure/creds/<name>, TTL/lease, least privilege

Check Yourself with a Question

Associate / Ops

問題 1

Using the Vault Azure secrets engine, you want to issue a short-lived Service Principal with Contributor on a specific resource group for one hour. Which is the most direct procedure?

  1. Configure tenant_id and client info in azure/config, define scope, role_name, and ttl=1h under azure/roles, then read azure/creds/<role> to issue the credential
  2. Read an existing client secret stored in Azure Key Vault, use it for the required period, and then delete it manually
  3. Generate a token via the Vault AppRole secrets engine and use that token directly to authenticate against Azure
  4. Define only role_name under azure/roles and have the client specify ttl on write

正解: A

With the Azure secrets engine, you register Azure-side credentials in azure/config and define role_name, scope, ttl, and so on under azure/roles. Issuance happens via a read on azure/creds/<role>, which returns the credential along with a lease. Key Vault is for storage, and AppRole is for authenticating to Vault, not to Azure. TTL is correctly managed on the role/lease side.

Frequently Asked Questions

What Azure permissions are required to assign roles?

You need Owner or User Access Administrator at the assignment scope (subscription, resource group, or resource). On top of that, app registration and Service Principal creation requires directory-level permissions such as Application Administrator.

How do I limit the scope to a single resource group?

In the azure_roles array under azure/roles, set scope to the full resource ID, for example /subscriptions/<subId>/resourceGroups/<rgName>. Choose the least-privileged role_name that still satisfies the workload.

Can the engine also issue certificate-based credentials?

The Azure secrets engine is built to issue and manage the lifecycle of Service Principals and client secrets. If you need certificate-based credentials, combine it with a separate issuing and storage workflow such as certificate management via Azure Key Vault.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Vault

Vault Core Concepts: Sealed/Unsealed, Auth, Secrets (2026)

Vault fundamentals — sealed/unsealed state, auth methods, se...

Vault

Vault Operations Professional (VOP-003): Complete Guide (2026)

Pass the Vault Operations Professional exam — enterprise pat...

Vault

Vault Path-Based Routing: API URL Structure (2026)

How Vault's path-based routing works — mount points, sub-pat...

Vault

Vault Tokens: Auth Token Mechanics (2026)

Token fundamentals — service vs. batch tokens, accessor, ren...

Vault

Vault Token Types: Service, Batch, Periodic (2026)

Service vs. batch tokens compared — performance, ACL behavio...

Browse all Vault articles (101)
© 2026 NicheeLab All rights reserved.