Prevent credential exposure in Azure VM custom data by treating custom data as non-secret bootstrap input only. Do not place passwords, tokens or keys in it, because the data can be retrievable by people or processes with VM access. Use managed identity or a secret store for credentials instead, and review templates and automation so secrets are not injected during provisioning.
Why custom data should never carry credentials
Azure VM custom data is best treated as one-time bootstrap input, not as a secret delivery channel. Anything placed there should be safe to disclose to administrators, automation, or other processes that can inspect the VM. That means passwords, API keys, OAuth tokens, certificates, and similar material belong in a secret store or identity-backed access flow, not in provisioning payloads.
The practical rule is simple: if the value would be damaging to expose after deployment, do not encode it in custom data. Use custom data for non-sensitive configuration hints, initialization parameters, or bootstrap references. For secret handling patterns, NHIMG’s Secrets Management Guide is the right starting point, because it frames the move away from embedded secrets toward secretless workload design.
In Azure, this is especially important because provisioning often crosses hands between platform teams, CI/CD systems, and imaging workflows. The safest design is to separate configuration from credential material so that the VM can retrieve what it needs at runtime with managed identity or a controlled secret retrieval path. That separation reduces the chance that a template, image, or deployment log becomes a long-lived credential source.
How exposure happens in practice
Custom data is vulnerable mainly through visibility, reuse, and lifecycle mistakes. A secret added during deployment can persist in templates, automation variables, image builds, or troubleshooting outputs long after the original operator has forgotten it. If the VM, deployment tooling, or a reader with access to the provisioning records can retrieve the custom data, the secret is effectively exposed.
The risk grows when custom data is copied across environments or reused as a convenient place to pass setup information to many machines. That pattern creates secret sprawl, makes rotation harder, and can turn a temporary bootstrap exception into a permanent access path. NHIMG’s Guide to the Secret Sprawl Challenge is useful here because it connects credential exposure to the broader operational failure mode of secrets accumulating in places that were never meant to be secret stores.
Teams also underestimate how often provisioning artifacts are retained. ARM templates, Terraform variables, pipeline logs, custom script extensions, and VM initialization tooling can all become secondary disclosure channels if a secret is embedded upstream. The fix is not just “do not hardcode secrets”, it is “make sure the entire provisioning chain never needs them in cleartext.”
Safer patterns for provisioning and recovery
The cleanest pattern is to let the VM authenticate to a secret store or service using its own managed identity, then fetch only the credentials it needs at runtime. That keeps the secret out of the deployment payload and lets you control access centrally, audit retrieval, and rotate values without changing every template. If custom data must include a reference, use it only to point the VM at a secret location or bootstrap endpoint, not to carry the secret itself.
Azure RBAC matters because the identity that can retrieve secrets should be narrowly scoped. A VM, its managed identity, and the automation that deploys it should each have different permissions aligned to their job. NHIMG’s Azure RBAC and Service Principals Guide helps with that access design, especially where service principals, managed identities, and scope boundaries determine whether a secret retrieval path stays constrained.
Where rotation is involved, use short-lived or centrally managed credentials instead of embedding long-lived ones in setup data. If a secret ever reaches custom data, treat it as a provisioning defect and rotate it as though it were exposed, because in practice it may already be recoverable by anyone with sufficient VM or deployment access. NHIMG’s Guide to NHI Rotation Challenges is relevant to the lifecycle problem: the harder rotation becomes, the more likely teams are to keep secrets in unsafe places.
Risk and Threat Considerations
Credential exposure in custom data creates both a confidentiality problem and a downstream access problem. If an attacker, contractor, or overly broad operator can read the bootstrap content, they may inherit whatever access the embedded secret grants. The failure is not just disclosure, it is that the disclosed material may be immediately usable for authentication, privilege escalation, or lateral movement.
Failure mechanism: Secrets are passed through a deployment channel that is designed for initialization, then retained or copied into logs, templates, or VM-accessible metadata where they can be recovered later.
Impact: exposed credentials can enable unauthorized login, access to cloud resources, unauthorized secret retrieval, or persistence through a reused bootstrap artifact.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 addresses the attack surface, NIST SP 800-53 Rev 5 sets the technical controls, and ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Custom data can expose credentials before or during VM provisioning. |
| NHI-07 — Long-Lived Secrets | Embedding credentials in provisioning data encourages durable secrets and slow rotation. | |
| NHI-05 — Overprivileged NHI | VM identities and retrieval paths need narrow scope to limit blast radius. | |
| Recommendation — Keep secrets out of custom data and move them to managed secret retrieval. Replace embedded credentials with short-lived or centrally rotated secrets. Scope VM secret-read permissions to the minimum required resources. | ||
| NIST SP 800-53 Rev 5 | IA-9 — Identification and Authentication (Non-Organizational Users) | VMs and service workloads authenticate to cloud resources with machine credentials. |
| IA-5 — Authenticator Management | Credential lifecycle and protection are central when provisioning secrets are exposed. | |
| Recommendation — Use machine authentication instead of embedding reusable secrets in deployment data. Protect, rotate, and revoke credentials through managed lifecycle controls. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access control | Access to bootstrap data must be constrained so secrets are not broadly readable. |
| Recommendation — Restrict who and what can read provisioning inputs and metadata. | ||
Practitioner Guidance
What to verify: Check whether any provisioning path, including templates, pipeline variables, custom script extensions, or image baking, can emit passwords, tokens, keys, or connection strings into custom data. If it can, treat that path as a secret-handling defect, not a minor configuration issue.
Decision rule: If the VM needs to authenticate to something after boot, prefer managed identity plus runtime secret retrieval. If the value is only needed to start the VM, ask whether it can be replaced with a non-secret reference, a bootstrap token with very short lifetime, or a controlled post-provisioning handoff.
Common mistake: Teams often secure the destination secret store but forget the provisioning source. That leaves the secret exposed before the VM ever reaches the store, which defeats the point of centralised secret management.
Practitioner takeaway: The right design is to make custom data disposable and non-sensitive; if a value must survive beyond bootstrap, it belongs in managed secret handling, not in provisioning input.
Related resources from NHI Mgmt Group
- How can organizations secure their MCP server credentials?
- Why do ephemeral credentials still leave risk in machine access models?
- When should organizations transition from static to dynamic credentials?
- How should security teams prevent sensitive data from being exposed when employees use Gemini at work?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 20, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org