Safeguard
Security Guides•

Where should Azure DevOps pipeline secrets live?

Prefer no secret, then Azure Key Vault, then variable groups, then pipeline secret variables. How each scopes access and what log masking cannot protect.

Safeguard Security Team
4 min read

Prefer no secret at all, using service connections or managed identities. If you need one, Microsoft recommends Azure Key Vault, because Azure role-based access control can limit who reads it. Variable groups and pipeline secret variables work too, with different scoping. Never put a secret as plain text in YAML.

Options compared

WhereWho can see itStrengthWatch out for
No secret (service connection, managed identity)Nobody holds a valueNothing to leakNot available for every target
Azure Key VaultControlled with Azure RBACCentral, auditable, per secret controlPipeline identity needs read access
Variable groupFollows library security rolesShared by several pipelinesGroup permissions decide who can use it
Pipeline secret variableUsers of that pipeline onlySimple, scoped to one pipelineNot shared, easy to forget

Rules from Microsoft's guidance

  • Do not use a logging command to set a secret variable, because anyone with pipeline access can then see it.
  • Do not echo secrets and do not pass them on the command line. Map them into environment variables instead.
  • Do not wrap secrets in JSON, XML, or YAML blobs, or include control characters such as line feeds. Create one secret per value so redaction works.
  • Azure Pipelines tries to scrub secrets from logs, but is not foolproof. Review logs after testing valid and invalid inputs, since error output can leak.
  • Be careful with Azure CLI commands that print sensitive output. Use the None output format.

Limiting secrets to one branch

Microsoft describes a combination. Enforce build validation policies that allow builds only from a certain branch. Use variable group permissions so only authorized pipelines can read the group. Then use a condition so only a push to the designated branch can reference the group, for example by checking that the source branch is refs/heads/main.

This matters because a pull request pipeline that can read a production secret hands that secret to anyone who can open a pull request. See fork builds.

Rotation and review

  1. Periodically list the secrets registered in your pipelines and delete the ones no longer needed.
  2. Check that service connection secrets are handled carefully.
  3. Keep PAT duration short and scopes minimal.
  4. Rotate secrets on a schedule, so a leaked one has a short useful life.
  5. Review pipeline source and tasks to confirm secrets are not sent to unintended hosts.

Templates help

Instead of inline scripts that take secret parameters, keep the script in a template in a separate, secure repository and pass the secret as a parameter from Key Vault, a variable group, or the pipeline UI. This keeps secret handling in one reviewed place.

A quick decision

Ask three questions in order. Can the pipeline authenticate without a secret? If not, can Key Vault hold it? If not, can a variable group with restricted permissions hold it? Only then use a pipeline level variable.

Quick check

Are masked secrets always hidden in logs?

No. Microsoft says scrubbing is attempted but is not foolproof, so avoid echoing secrets and review logs.

Why one secret per value?

Structured data such as JSON can defeat redaction. Separate secrets are redacted more accurately.

Safeguard can scan repositories and dependencies as part of a pipeline, and a free scan is available at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.