Join our Newsletter — 33% off our NHI Course
Home› Guides› Azure Bicep and ARM Template Security Guide: Secure…
Guide Cloud Security

Azure Bicep and ARM Template Security Guide: Secure Parameters, Deployment Identities and Linting

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 19 November 2026 12 min read
On this page

Bicep and ARM templates decide which secrets pass through Azure Resource Manager, which identity deploys your infrastructure and what that identity is allowed to change, so template security is identity security. This guide covers secure parameters and outputs, Key Vault references, the deployment identity used by pipelines, the Bicep linter rules that catch secret leaks, what-if previews and deployment stack deny settings.

It is written for platform engineers, cloud security teams and DevOps engineers who deploy Azure infrastructure from Bicep files or ARM JSON templates. Bicep compiles to ARM JSON, so the Resource Manager behaviour described here applies to both. For Azure tenant and subscription hardening more broadly, see the Microsoft Azure Security Guide, and for vendor-neutral principles see the Infrastructure as Code Security Guide.

This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Avoid secrets entirely where you can: Microsoft recommends managed identities so resources authenticate without credentials.
  • Mark every secret parameter with @secure(), and never return secrets through outputs, because outputs are logged to deployment history and visible to anyone with access to the deployment.
  • Pull secrets at deploy time with getSecret() or az.getSecret() in .bicepparam files, rather than storing them in parameter files or pipeline YAML.
  • Deploy from pipelines with OpenID Connect federated credentials and an identity scoped to the target resource group, not a subscription-wide service principal with a client secret.
  • Raise the security linter rules, such as secure-secrets-in-parameters and outputs-should-not-contain-secrets, to error in bicepconfig.json so they fail the build.
  • Use what-if before deployment and deployment stack deny settings to stop out-of-band changes to managed resources.

Where identities and secrets appear in Bicep and ARM

A Bicep deployment touches non-human identities at several points:

  • The deployment identity. The user, service principal or managed identity that submits the deployment to Azure Resource Manager. Its role assignments define the blast radius of any pipeline compromise.
  • Secrets passed as parameters. Administrator passwords, connection strings and third-party API keys supplied at deploy time.
  • Secrets created or read by the template. Keys retrieved with listKeys(), Key Vault secrets created as child resources, or values returned as outputs.
  • Identities the template creates. Managed identities and role assignments declared as resources, which give workloads their own access.

Each of these can leak or over-grant. MITRE ATT&CK tracks credentials found in files and repositories as T1552.001 Credentials In Files, and abuse of stolen cloud identities as T1078.004 Cloud Accounts. Template repositories and deployment history are common places for both to start.

Avoiding secrets with managed identities

Microsoft's guidance on managing secrets in Bicep starts with avoiding them: use managed identities so resources authenticate to each other without credentials, and use service-managed certificates for HTTPS so you do not handle certificates or private keys. Every secret you remove from a template is one less value to protect in parameter files, pipeline variables and deployment history.

In practice, NHI Mgmt Group recommends a simple review question for every new template: for each secret parameter, is there a managed identity path instead? Common examples are an App Service reading from Storage or Key Vault, or a Function App connecting to a database that supports Microsoft Entra authentication. Where the answer is yes, declare the managed identity and the role assignment in the template and drop the parameter. The AKS Workload Identity Guide covers the equivalent pattern for Kubernetes workloads.

Secure parameters, outputs and deployment history

When a secret is unavoidable, the @secure() decorator tells Azure Resource Manager not to log the value or display it in the Azure portal, Azure CLI or Azure PowerShell:

@secure()
param adminPassword string

Microsoft is explicit about outputs: do not use Bicep outputs for secure data. Outputs are logged to the deployment history, and anyone with access to the deployment can view the values of a deployment's outputs. This is one of the most common real-world leaks, because a module that returns a connection string or key to its parent seems harmless during development.

Patterns that keep secrets out of history:

  • Look secrets up where they are used. Reference the resource with the existing keyword and call listKeys() inside the consuming template, instead of passing keys between modules as parameters or outputs.
  • Pass Key Vault references to modules. Reference a vault with existing (and scope if it lives in another resource group) and pass keyVault.getSecret('name') as the module parameter. The secret value is resolved by Resource Manager rather than written into the template.
  • Return names and resource IDs, not values. If a downstream system needs a secret, output the Key Vault secret name and let it read the value with its own identity.

Treat read access to deployment history as sensitive. Even with good template hygiene, older deployments may already contain outputs that exposed secrets; review them and rotate any value found.

Key Vault references in templates and .bicepparam files

Azure Key Vault is the documented home for secrets used in deployments:

  • To let deployments read vault secrets, the vault (Microsoft.KeyVault/vaults) must have enabledForTemplateDeployment: true. Set this only on vaults intended for deployment-time secrets, not on every vault.
  • Secrets can be created as child resources of type Microsoft.KeyVault/vaults/secrets using parent:. Avoid hardcoding the value in a template in source control; Microsoft notes third-party secrets often need to be added to the vault manually before deployments reference them.
  • In .bicepparam files, az.getSecret() takes the subscription ID, resource group name, vault name and secret name, with an optional version. If the version is omitted the latest is used.

NHI Mgmt Group recommends pinning secret versions for production deployments where reproducibility matters, and using latest only where rotation should flow automatically into the next deployment. Either way, the identity running the deployment needs permission to read the referenced secrets, which is another reason to keep deployment identities narrowly scoped and to separate deployment vaults from application vaults.

Microsoft also says: do not store secrets in the code repository, including parameter files or pipeline YAML. Use GitHub Actions encrypted secrets and secret scanning, or Azure Pipelines secret variables, for anything that must live in the pipeline.

Deployment identities for pipelines

The pipeline identity is the most privileged non-human identity in most infrastructure-as-code setups. Microsoft's guidance for deploying Bicep with GitHub Actions uses OpenID Connect rather than a stored client secret:

  • Configure an application or user-assigned managed identity and create a federated identity credential for your GitHub repository. The credential must match the branch or environment that runs the workflow.
  • Grant the workflow id-token: write so it can request the OIDC token, and contents: read to check out code.
  • Sign in with azure/login using AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_SUBSCRIPTION_ID, then deploy with azure/bicep-deploy.
  • Scope role assignments to the target resource group, not the whole subscription.

Microsoft notes that Contributor cannot manage deny settings, so stacks with deny settings other than none also need the Azure Deployment Stack Owner role. Grant that role only to the pipeline that owns protected stacks.

Recommended practices from NHI Mgmt Group:

  • One deployment identity per environment, with federated credentials bound to protected branches or GitHub environments with required reviewers for production.
  • No role assignment write permission (Owner or User Access Administrator) unless the template must create role assignments; where it must, constrain it with role assignment conditions or a separate, tightly reviewed pipeline.
  • Remove any legacy client secrets on the application once federation works, and alert on new credentials being added.

The GitHub Actions OIDC Federation Hardening Guide covers subject claim design in more depth.

Linting templates with the Bicep linter

The Bicep linter ships with security-relevant rules, all at warning by default. The rule names describe what each one guards:

RuleWhat it guards
secure-secrets-in-parametersParameters that look like secrets but lack @secure()
secure-parameter-defaultSecure parameters with hardcoded default values
outputs-should-not-contain-secretsSecrets returned through outputs
protect-commandtoexecute-secretsSecrets in extension command properties
secure-parameters-in-nested-deploySecure parameters in nested deployments
secure-parameters-in-parameters-fileSecure values written into parameter files
use-secure-value-for-secure-inputsSecure resource properties fed with non-secure values
adminusername-should-not-be-literalLiteral administrator user names
no-hardcoded-env-urlsHardcoded cloud environment URLs

Warnings alone do not fail pipelines. Set each security rule's level to error under analyzers.core.rules in bicepconfig.json so violations fail the build, and run bicep lint (or bicep build) as a required pipeline step. Commit bicepconfig.json at the repository root so local editors and CI apply the same rules, and require security team review for any change that lowers a rule level.

Linting complements, rather than replaces, secret scanning of the repository and policy checks against deployed resources.

Previewing changes with what-if

What-if previews how a deployment would change resources without making changes, at resource group, subscription, management group and tenant scope (az deployment group what-if and its sub, mg and tenant equivalents). --confirm-with-what-if previews then prompts before deploying, and --no-pretty-print returns JSON for pipelines to inspect.

For identity reviews, the useful pattern is to fail or hold a pipeline when what-if shows Create, Modify or Delete on sensitive types such as role assignments, managed identities, federated identity credentials and Key Vault access settings, and to route those changes to a human approver. Know the limits: what-if does not expand templateLink nested deployments (including template spec references), stops expanding at 500 nested templates, 800 resource groups or five minutes, and does not evaluate secure parameter values or functions such as listKeys(). It needs the same permissions as a deployment, so it should run under the same scoped identity.

Protecting deployed resources with deployment stacks

Deployment stacks manage a set of resources as a unit and can apply deny settings so the resources cannot be changed outside the pipeline:

  • Deny settings modes: None, DenyDelete and DenyWriteAndDelete. They apply to control plane operations only, not data plane operations such as secrets or blob containers, and only to explicitly defined resources.
  • Apply to child scopes extends the deny to child resources, including ones the stack does not manage.
  • Excluded principals accept Entra object IDs for users, groups, service principals and managed identities, with a limit of five. Microsoft notes specifying more does not return an error, so check the count, and recommends managing exclusions through groups.
  • Excluded actions exempt up to 200 management operations.
  • Action on unmanage is detachAll by default; deleteResources and deleteAll delete resources, and deleteAll on resource groups deletes everything inside them.

The roles matter: Azure Deployment Stack Contributor can manage stacks but cannot create or delete deny assignments, while Azure Deployment Stack Owner can. Microsoft recommends placing stacks at a parent scope, because the deny assignment is created where the stack exists. NHI Mgmt Group recommends excluding only the pipeline's deployment identity (through a group) from deny settings, so that the pipeline is the single path for changes and break-glass access is handled through your privileged access process.

Governing template repositories and deployment identities over time

Controls drift unless someone owns them. NHI Mgmt Group recommends treating the template repository and its deployment identities as one governed system:

  • Name an owner for every deployment identity. Record which repository, branch or environment each federated credential trusts, and who approves changes to it.
  • Review role assignments quarterly. Compare each deployment identity's assignments with the resource groups its templates actually target, and remove the rest.
  • Protect the configuration files. Use code owners rules so that changes to bicepconfig.json, pipeline definitions and parameter files need security review.
  • Retire cleanly. When an application is decommissioned, delete its federated credentials, deployment identities, deployment vault secrets and stacks together, so no orphaned identity keeps rights to recreate resources.
  • Record evidence. Keep lint results and what-if output with each production deployment, which gives auditors a change record mapped to NIST SP 800-218 secure development practices.

Common failure patterns

  • Secrets in outputs. A module returns a key or connection string, which then sits in deployment history.
  • Plain-text parameter files. Passwords committed in .bicepparam or JSON parameter files instead of az.getSecret() references.
  • Linter left at warning. Security rules flag issues that never block a merge.
  • Subscription-wide Owner for the pipeline. A compromised workflow can grant itself or others any role.
  • Client secrets that never expire. Legacy service principal secrets stored in pipeline variables after OIDC was introduced.
  • Every vault enabled for template deployment. Deployment identities gain a path to application secrets they never need.
  • Deny settings with broad exclusions. Too many excluded principals, or a silently ignored sixth one, undermine the protection.

Practitioner checklist

  • Replace secret parameters with managed identities wherever the target service supports Entra authentication.
  • Mark every remaining secret parameter @secure() and remove secret values from outputs.
  • Reference secrets with getSecret() or az.getSecret(), and enable enabledForTemplateDeployment only on dedicated deployment vaults.
  • Set Bicep security linter rules to error in a committed bicepconfig.json and run bicep lint in CI.
  • Deploy with OIDC federated credentials bound to protected branches or environments, one identity per environment.
  • Scope deployment identity roles to resource groups and avoid role assignment write permissions where possible.
  • Gate deployments on what-if output for role assignments, identities and Key Vault changes.
  • Use deployment stacks with deny settings for critical resources, excluding only a group containing the pipeline identity.
  • Review deployment history for previously exposed outputs and rotate any secrets found.

Standards and references

Related NHI Mgmt Group resources: Microsoft Azure Security Guide · Infrastructure as Code Security Guide · GitHub Actions OIDC Federation Hardening Guide · AKS Workload Identity Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

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.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 19 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.