
Authentication Decides What Azurehound Sees
Azurehound can only collect what its identity is allowed to read. The way you authenticate therefore shapes everything: which objects appear in your graph, whether collection succeeds against MFA-protected accounts, how easily you can schedule repeat runs and how much risk the credential itself introduces.
Azurehound supports five main approaches: username and password, refresh token, JWT access token, service principal with a client secret, and service principal with a certificate. This guide explains each one, when to use it and how to handle it safely.
A Quick Overview
| Method | Flags | Works with MFA | Best for |
|---|---|---|---|
| Username and password | -u, -p | No | Lab tenants, legacy test accounts |
| Refresh token | -r | Yes | Interactive assessments |
| JWT access token | -j | Yes | Short, targeted collections |
| Service principal secret | -a, -s | Not applicable | Automation, quick setup |
| Service principal certificate | -a, --cert, --key | Not applicable | Long-term, scheduled collection |
All methods are combined with --tenant to specify the target tenant.
Method 1: Username and Password
azurehound list -u "auditor@contoso.com" -p "<password>" --tenant "contoso.onmicrosoft.com" -o output.json
This is the simplest method and the most limited. It uses a non-interactive sign-in flow, so it fails whenever the account requires multi-factor authentication or is blocked by Conditional Access policies. Since MFA should protect virtually every real account, password authentication is mostly useful in lab environments.
Security notes: passwords typed on the command line may be stored in shell history and visible in process listings. If you must use this method, read the password from a prompt or environment variable and clear it afterwards.
Method 2: Refresh Token
azurehound list -r "<refresh-token>" --tenant "contoso.onmicrosoft.com" -o output.json
A refresh token is issued after a successful interactive sign-in, including MFA. Azurehound exchanges it for access tokens for Microsoft Graph and Azure Resource Manager as needed. That makes it the most practical choice for assessments using a real, MFA-protected account.
Refresh tokens can be obtained in several ways, such as the device-code flow or authentication tooling used during authorised testing. Whatever the source, the token represents a signed-in session.
Security notes:
- Treat refresh tokens like passwords. They can be long-lived and grant access to multiple resources.
- Store them in environment variables or secret stores, never in scripts or documentation.
- Revoke sessions for the account after the engagement if your process requires it.
Method 3: JWT Access Token
azurehound list -j "<access-token>" --tenant "contoso.onmicrosoft.com" -o output.json
An access token (a JSON Web Token) is issued for a specific resource, such as Microsoft Graph, and typically lasts around an hour. You might obtain one from the Azure CLI:
az account get-access-token --resource https://graph.microsoft.com
Because an access token is scoped to a single resource, a Graph token will not authorise Azure Resource Manager calls, and vice versa. That makes the JWT method best suited to targeted collections, for example azurehound list az-ad with a Graph token. For a full collection in one run, a refresh token or service principal is more convenient.
Security notes: access tokens expire quickly, which limits exposure, but they are still bearer credentials. Do not paste them into chat tools or tickets.
Method 4: Service Principal With a Client Secret
azurehound list -a "<application-id>" -s "<client-secret>" --tenant "contoso.onmicrosoft.com" -o output.json
A service principal is an application identity in Entra ID. Collecting as a service principal has clear advantages:
- Permissions are explicit and documented.
- No human sign-in or MFA prompt is involved.
- Activity is easy to attribute in sign-in and audit logs.
- It suits scheduled, repeatable collections.
To set it up, register an application, create a client secret, and grant read-oriented permissions. Commonly used settings are the Microsoft Graph application permissions Directory.Read.All and RoleManagement.Read.All, granted with admin consent, plus the Azure RBAC Reader role at subscription or root management-group scope. Our permissions guide covers this in detail.
Security notes: client secrets are passwords for applications. Give them short expiry periods, store them in a vault, and rotate them regularly.
Method 5: Service Principal With a Certificate
azurehound list -a "<application-id>" --cert "./azurehound.pem" --key "./azurehound.key" --keypass "<key-passphrase>" \
--tenant "contoso.onmicrosoft.com" -o output.json
Certificate authentication uses the same service principal but proves identity with a private key instead of a shared secret. Microsoft recommends certificates over secrets for application credentials, and the reasoning is sound:
- The private key never leaves the collection host.
- Certificates can be stored in hardware-backed or protected key stores.
- Expiry and rotation are handled through standard certificate processes.
For any long-running Azurehound programme, certificate-based service principal authentication is the strongest choice.
Choosing the Right Method
- Penetration test with a supplied user account: refresh token.
- Quick directory-only check with existing CLI login: JWT for Microsoft Graph.
- Monthly internal collection: service principal with certificate.
- Proof of concept in a lab: username and password, or a client secret.
- BloodHound Enterprise deployment: service principal, configured through
azurehound configure.
Conditional Access Considerations
Conditional Access policies can block Azurehound even when credentials are valid. Policies might require compliant devices, specific locations or particular client applications. If collection fails with an AADSTS error mentioning policy, review the sign-in logs for the identity. For service principals, workload identity policies may apply. Agree any exclusions formally with your identity team rather than weakening policies ad hoc.
Logging and Attribution
Every Azurehound collection produces sign-in events and API activity in Entra ID logs. This is desirable: defenders should be able to see who collected what and when. Using a dedicated, clearly named identity, such as an application called AzureHound-Audit, makes collections easy to recognise and distinguish from genuine attacker activity.
Cleaning Up After Collection
When an engagement ends:
- Remove secrets and certificates you created for temporary service principals.
- Delete or disable the application if it is no longer needed.
- Revoke user sessions associated with refresh tokens if policy requires it.
- Clear environment variables and shell history on collection machines.
Protecting Tokens on the Collection Host
Whatever authentication method you choose, the collection host becomes temporarily sensitive. A few habits greatly reduce the risk of leaking credentials.
Avoid typing secrets directly into commands. Shell history files and process listings can expose them. Instead, read values into environment variables from a prompt or secret store, then reference the variables in the Azurehound command. On Linux and macOS, read -s prompts without echoing input; in PowerShell, Read-Host -AsSecureString serves the same purpose.
Limit lifetime. Clear variables immediately after the collection finishes, and close the terminal session. For service principals, prefer short certificate lifetimes and rotate them on a schedule.
Restrict log verbosity. Higher verbosity levels are helpful for troubleshooting, but review logs before sharing them, and never attach logs to tickets without checking for sensitive values.
Separate duties. In larger organisations, the person who creates and holds the service principal certificate does not need to be the analyst who interprets the graph. Automation can run the collection with the credential while analysts work only with the output.
Recognising when a method is wrong for the job
If collections repeatedly fail because tokens expire mid-run, switch from a JWT to a refresh token or service principal. If Conditional Access keeps blocking a user account, a properly governed service principal is usually the cleaner answer than requesting a policy exception. Choosing the right method up front saves time and avoids weakening controls.
Key Takeaways
- Password authentication fails on MFA-protected accounts and suits only lab scenarios.
- Refresh tokens are the most practical option for interactive assessments with real accounts.
- JWT access tokens are scoped to one resource, so they suit targeted collections.
- Service principals with certificates are the strongest choice for repeatable collection.
- Keep credentials out of command history and clean up temporary identities afterwards.
FAQs
Directory.Read.All and RoleManagement.Read.All with admin consent, plus the Reader role at the scope you want to collect.Conclusion
Azurehound's flexibility in authentication is one of its strengths. Refresh tokens make interactive assessments practical despite MFA, JWTs allow quick targeted runs, and service principals with certificates provide a secure foundation for repeatable collection. Choose the method that fits your scenario, protect every credential as carefully as the data it unlocks, and clean up thoroughly when the work is done.


