Courseiva

Three Best Practices for Managing Secrets in Azure Pipelines

Which TWO actions should you take to ensure that your Azure DevOps pipeline securely manages secrets?

⚠ Common exam trap

AZ-400 often tests the temptation to 'debug' by printing secrets or storing them in YAML — candidates must recognize that only Key Vault variable groups and UI-defined secret variables are secure.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Use Azure Key Vault variable groups

Option A is correct because linking an Azure Key Vault to a variable group lets the pipeline fetch secrets at runtime from Key Vault, so the secret values are never stored in the pipeline definition and access is governed by Key Vault access policies or RBAC. Option D is correct because secret variables defined in the pipeline UI or in variable groups are encrypted at rest by Azure DevOps, masked in logs, and not exposed in the YAML source, which is the supported way to hold secrets the pipeline needs directly. Option B is wrong because enabling scripts to access the system token and printing secrets to logs deliberately exposes credentials, defeating masking and enabling token theft. Option C is wrong because secrets committed in the YAML pipeline file are stored in source control in plain text and visible to anyone with repo access. Option E is wrong because storing secrets as plain text in the repository exposes them to all readers of the repo and to its history, with no encryption or masking.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Use Azure Key Vault variable groups

    Why this is correct

    Azure Key Vault variable groups securely store secrets in Azure Key Vault and link them to pipelines via variable group metadata, enabling pipelines to fetch secrets at runtime without writing them into YAML or repository files; access is governed by Azure RBAC and Key Vault access policies.

  • ✗

    Enable 'Allow scripts to access the system token' and print secrets in logs for debugging

    Why it's wrong here

    Enabling 'Allow scripts to access the system token' and printing secrets in logs is insecure because it exposes credentials, tokens, or other sensitive values in pipeline logs, which are often retained for audit or debugging and may be accessible to unauthorized users; this violates secret-management best practices.

  • ✗

    Store secrets directly in the YAML pipeline file

    Why it's wrong here

    Storing secrets directly in the YAML pipeline file is a critical security flaw because YAML files live in your version control repository (e.g., Azure Repos, GitHub) and are visible to anyone with read access to that repo, including contractors, external collaborators, or through forks and mirrors. Unlike Azure Key Vault or secret variables, once a secret is committed to YAML, it becomes part of the repository history and cannot be fully purged without rewriting history, leaving an indefinite exposure window. Furthermore, secrets in YAML are injected as plain text into build logs if any task echoes variables or fails with verbose output, defeating Azure DevOps' secret-masking protections that only apply to variables explicitly marked as secret.

  • ✓

    Use secret variables set in the pipeline UI or variable groups

    Why this is correct

    Secret variables set in the pipeline UI or variable groups are masked in logs by Azure DevOps, preventing accidental exposure; they are stored encrypted and injected only into pipeline tasks that explicitly reference them, but they do not provide the centralized management and rotation features of Key Vault.

  • ✗

    Store secrets as plain text in the repository

    Why it's wrong here

    Storing secrets as plain text in the repository is highly insecure because any user or service with read access to the repository (including forks, mirrors, or external contractors) can see them, and secrets in version control persist in history even after deletion, creating a long-term security leak.

Quick reference

Access Control Model Comparison

ModelAcronymWho Controls Access?Best For
Discretionary Access ControlDACResource ownerSmall teams, file shares
Mandatory Access ControlMACSystem / security labelsClassified govt / military
Role-Based Access ControlRBACAdministrator (via roles)Enterprise environments
Attribute-Based Access ControlABACPolicy engine (user + resource attributes)Fine-grained, dynamic policies
Rule-Based Access ControlRuBACSystem rules / ACLsFirewall rules, network ACLs

About these practice questions

One of 696 original AZ-400 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on AZ-400

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which TWO strategies can you use to manage secrets in Azure Pipelines securely?

easy
  • ✓ A.Use a variable group linked to Azure Key Vault.
  • B.Store secrets directly in the YAML pipeline file.
  • ✓ C.Use the 'secret' variable type in the pipeline UI.
  • D.Use environment variables in the build agent.
  • E.Print the secret in a script to verify it is correct.

Why A: Options A and C are correct. Variable groups can be linked to Azure Key Vault to fetch secrets, and you can mark variables as secret in the pipeline UI to prevent them from being displayed in logs. Option B is wrong because storing secrets in YAML files exposes them in source control. Option D is wrong because using environment variables on the build agent is not inherently secure; they can be accessed by other processes and may be logged. Option E is wrong because printing secrets in scripts exposes them in the pipeline logs, which is a security risk.

You might also like

Similar AZ-400 questions

Written and reviewed by Johnson Ajibi, MSc IT Security

Security Systems Architect · founder of Courseiva

Last reviewed September 2026 · checked against the official Microsoft exam blueprint

This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.