Courseiva
Design and implement build and release pipelineshardMultiple ChoiceObjective-mapped

How GitHub Actions Automatically Masks Secrets Referenced in Workflows

Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets stored in GitHub are not exposed in build logs. A developer accidentally printed a secret to the console in a workflow step. How can you prevent this from happening in the future?

Quick Answer

Enabling secret scanning and push protection closes the gap that let a developer's console print slip through: push protection actively blocks commits containing recognizable secret patterns before they ever reach the remote, while secret scanning catches anything that gets through another way. GitHub Actions already masks known repository secrets in logs, but only push protection stops a raw print from being committed in the first place.

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

Enable 'Secret scanning' and 'Push protection' for the repository.

Enabling Secret scanning and Push protection for the repository helps prevent secrets from being exposed in build logs. Secret scanning can detect secrets when they are pushed or used in workflows, and Push protection blocks pushes containing secrets. Additionally, GitHub Actions automatically masks any string that matches a repository secret or organization secret if it appears in logs, but the developer accidentally printed it. Enabling these features provides proactive detection and prevention. Option B is incorrect because adding the secret to the exclusion list would allow it to be exposed. Option C is incorrect because echoing with `::set-output` still prints the value to logs. Option D is incorrect because the `actions/secrets` action does not exist; secrets are accessed via the `secrets` context.

Answer analysis

Option-by-option breakdown

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

  • Enable 'Secret scanning' and 'Push protection' for the repository.

    Why this is correct

    These features detect and block secrets in code and logs.

  • Add the secret to the 'Secret scanning' exclusion list.

    Why it's wrong here

    Excluding it would allow it to be exposed.

  • Instruct developers to avoid using 'echo' and use '::set-output' instead.

    Why it's wrong here

    Secrets can still be leaked through other commands.

  • Use the 'actions/secrets' action to mask secrets automatically.

    Why it's wrong here

    No such action exists; secrets are automatically masked when used correctly.

About these practice questions

Courseiva writes every AZ-400 question from scratch — 823 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

8 more ways 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. Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets stored in GitHub are not exposed in build logs. A developer accidentally printed a secret to the console in a workflow step. What built-in feature of GitHub Actions automatically prevents this?

hard
  • A.Audit log monitoring
  • B.Secret scanning alerts
  • C.Required reviewers on workflows
  • D.Automatic log redaction

Why D: GitHub Actions includes a built-in feature that automatically redacts secrets from workflow run logs. When a secret is printed to the console, GitHub detects the secret value and replaces it with '***' in the log output, preventing accidental exposure. This redaction happens at the log rendering layer, not in the workflow execution, so the secret is never visible to users viewing the logs.

Variation 2. Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets stored in GitHub Actions are not exposed in logs. A developer accidentally logs a secret using 'echo ${{ secrets.API_KEY }}' in a workflow step. What is the default behavior?

hard
  • A.The secret value is replaced with an empty string in the log
  • B.The workflow run fails with an error about secret exposure
  • C.The secret is redacted before the step runs, and the step fails if it tries to use the secret
  • D.The secret value is masked with asterisks in the log output

Why D: GitHub Actions automatically masks secrets in workflow logs. When a secret is used in a step (e.g., via `${{ secrets.API_KEY }}`), GitHub replaces any occurrence of the secret's value in the log output with `***`. This redaction happens at runtime, so even if a developer accidentally echoes the secret, the log will show asterisks instead of the actual value.

Variation 3. Your organization uses GitHub Actions for CI/CD. A workflow that deploys to production uses a secret stored in GitHub Actions secrets. The secret is exposed in the logs due to a debug step. What is the most effective way to prevent future exposure?

hard
  • A.Remove the debug step from the workflow.
  • B.Use the ::add-mask:: command in the workflow to mask the secret in logs.
  • C.Delete the compromised secret and create a new one.
  • D.Enable secret scanning and push protection for the repository.

Why A: Secret scanning and push protection are designed to detect and block secrets in committed code, not in workflow logs. To prevent future exposure from a debug step, the most effective action is to remove the debug step, which addresses the root cause. While masking with ::add-mask:: can hide the secret value, it does not prevent the step from trying to log the secret. Deleting and rotating the secret is necessary for remediation, but does not prevent future log exposure.

Variation 4. Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets stored in GitHub are not exposed in logs. A developer reports that a secret value appeared in the workflow run log. What is the most likely reason?

hard
  • A.The workflow was triggered via repository_dispatch.
  • B.The secret was printed using a script that bypassed automatic masking.
  • C.The secret name was used in the log output.
  • D.The workflow used 'debug' log level.

Why B: GitHub Actions automatically masks secrets in log output, but this masking can be bypassed if the secret is printed via a script that outputs it directly (e.g., using `echo` with a variable that contains the secret value, or printing it in a manipulated form). The most likely reason the secret appeared is that the developer used a script that directly printed the secret value, bypassing the automatic masking. Option A is incorrect because the trigger type (repository_dispatch) does not affect logging. Option C is incorrect because secret names are not masked; only their values are masked. Option D is incorrect because the 'debug' log level does not disable masking; masking applies to all log levels.

Variation 5. Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets are securely passed to workflows without being exposed in logs. What should you use?

easy
  • A.GitHub Secrets
  • B.Environment variables in the workflow YAML
  • C.Hardcode the secrets in the workflow file
  • D.Azure Key Vault with Azure DevOps encrypted variables

Why A: GitHub Secrets (Option A) is the correct choice because GitHub Actions provides a built-in secrets management system that encrypts sensitive values at rest and masks them in all workflow logs. When you reference a secret using ${{ secrets.MY_SECRET }}, GitHub automatically redacts the value from any log output, ensuring it is never exposed during execution.

Variation 6. Your development team uses GitHub Actions for CI/CD. You need to ensure that secrets stored in GitHub repository secrets are not exposed in build logs. What is the best practice?

easy
  • A.Use a custom action to manually mask secrets in the logs.
  • B.Define secrets as environment variables directly in the workflow YAML.
  • C.Store secrets in GitHub repository secrets and reference them in workflows using ${{ secrets.SECRET_NAME }}. GitHub automatically masks secrets in logs.
  • D.After the workflow runs, delete the logs from GitHub.

Why C: GitHub automatically masks secrets referenced via the ${{ secrets.SECRET_NAME }} syntax in workflow logs. When a secret is used in a workflow, GitHub Actions scans the log output and replaces any occurrence of the secret value with '***', preventing exposure. This built-in mechanism is the recommended best practice as it requires no additional configuration and works across all steps and actions.

Variation 7. Your team uses GitHub Actions for CI/CD. You need to ensure that secrets are not exposed in build logs. What should you use?

easy
  • A.Hardcoded values in the workflow YAML
  • B.Environment variables in the workflow
  • C.GitHub Secrets
  • D.Artifact storage

Why C: GitHub Secrets (Option C) is the correct choice because GitHub Actions provides a built-in encrypted secrets store that automatically masks secret values in build logs. When you reference a secret using `${{ secrets.MY_SECRET }}`, GitHub ensures the value is never printed or exposed in workflow output, unlike plaintext or environment variables that can be inadvertently logged.

Variation 8. Your organization uses GitHub Actions for CI/CD. You need to ensure that secrets used in workflows are not exposed in logs. What should you do?

medium
  • A.Encrypt the secret with a password before using it.
  • B.Use the 'echo' command to output the secret and then delete the log.
  • C.Store the secret in GitHub Secrets and reference it as ${{ secrets.SECRET_NAME }}.
  • D.Disable logging on the self-hosted runner.

Why C: GitHub Secrets are encrypted environment variables that are automatically masked in workflow logs. When you reference a secret using the `${{ secrets.SECRET_NAME }}` syntax, GitHub Actions ensures the value is never printed in plain text, even if the workflow attempts to echo it. This is the built-in, secure method for handling sensitive data in CI/CD pipelines.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.