GH-200 domain - 15% of the exam

Secure and optimize automation

Secure and optimize automation is 15% of the GH-200 exam. These are the objectives it covers, each with practice questions, with every answer explained.

The domain in numbers

40
Practice questions
5
Objectives
25
Medium
15
Hard

Where people go wrong

  • Treating a tag, branch or badge as an immutable pin

    The wrong answers reach for a reference that feels stable: a major version tag, a patch tag, a release branch, a signed annotated tag, or a tag on an action with a verified creator badge. Each of these can move. A maintainer can re-point a tag, delete and recreate it against different code, or push to a branch tip. A verified creator badge confirms only the publisher's identity. Only a full commit SHA names one immutable commit, so the exact reviewed code runs every time.

    See it in a sample question
  • Expecting quoting or token scoping to stop expression injection

    The wrong answers try to contain an untrusted title or branch name after it is already in the script, with single quotes or with set -e and a trap. The ${{ }} expression is substituted into the script text before the shell parses it, so crafted characters can close a quote and run commands. Binding the value to a step-level env variable delivers it as data, and actions/github-script reads it from context.payload as a JavaScript string. A narrower GITHUB_TOKEN only limits the damage.

    See it in a sample question
  • Assuming unlisted token scopes keep their default

    The wrong answers treat a permissions block as an addition to the repository default. Declaring any permission sets every unlisted scope to none, so a block listing contents: read and checks: write leaves nothing else writable. A top-level block applies to every job, while a job-level block covers only that job, and permissions: {} grants the token no access at all. A job block can also raise a scope above a read-only default.

    See it in a sample question
  • Reaching for a stored secret or write scope instead of id-token: write

    For cloud authentication and attestations, the wrong answers add a stored credential or a repository write scope: a role ARN kept as a secret, an organisation secret, a personal access token, contents: write, or packages: write. OIDC federation removes the long-lived secret. The job needs id-token: write to request a signed token from GitHub, which the credentials action exchanges for temporary cloud credentials. Build provenance also needs attestations: write to record the signed statement.

    See it in a sample question
  • Substituting branch protection or workflow logic for environment rules

    The wrong answers use a control that sits somewhere else. Branch protection governs merges to a branch, CODEOWNERS requests reviews, an if check is workflow logic an author can edit, and concurrency only queues or cancels runs. None of these pauses a deployment. Rules on the environment itself do that: required reviewers hold the run for approval, a wait timer holds it for a fixed delay, and a deployment branches rule limits which branches may deploy.

    See it in a sample question

Objectives in this domain

What to study

The official documents this domain's practice questions cite most.

Sample questions from this domain

Free sampleSecure and optimize automationmedium

During a supply-chain hardening review, an engineer must classify which uses reference for a third-party action is genuinely immutable, meaning the referenced code cannot be changed afterwards by the action's maintainer. Which of the following references meets that immutability requirement?

# candidate references
uses: vendor/scan-action@v2
uses: vendor/scan-action@v2.4.0
uses: vendor/scan-action@release-2024
uses: vendor/scan-action@9f3a2c1d4e5b6a7c8d9e0f1a2b3c4d5e6f7a8b9c
  • AThe major version reference vendor/scan-action@v2, because a major version tag is protected from being moved once downstream consumers depend on it widely.
  • BThe patch version reference vendor/scan-action@v2.4.0, because a fully qualified release tag is frozen to its published assets and is rejected if the maintainer tries to move it.
  • CThe full commit SHA reference vendor/scan-action@9f3a2c1d4e5b6a7c8d9e0f1a2b3c4d5e6f7a8b9c, because a commit SHA addresses one fixed commit that cannot later be reassigned to different code. Correct
  • DThe named branch reference vendor/scan-action@release-2024, because a dedicated release branch is locked after publication so its tip commit stays fixed for that release year.
Only a full commit SHA is immutable; tags and branches remain movable references the maintainer can change. GitHub references for actions fall into mutable and immutable categories. Tags, whether major like v2 or fully qualified like v2.4.0, can be deleted and recreated against different commits, and branches resolve to a moving tip, so all three can be changed by the maintainer afterwards. A full commit SHA is content-addressed to one specific commit and cannot be reassigned, which is why it is the only reference that satisfies the immutability requirement.

Why A is wrong: Tempting because major version tags are the documented convenience, but v2 is a mutable tag the maintainer can re-point to any commit at will, so it is not immutable regardless of how many consumers depend on it.

Why B is wrong: Tempting because a patch tag looks final, but GitHub does not prevent a maintainer from deleting and recreating v2.4.0 against different code, so a release tag is still a mutable reference.

Why C is correct: A 40-character commit SHA is a content-addressed identifier for a single commit, so the maintainer cannot reassign it to other code, making it the only genuinely immutable reference among the candidates.

Why D is wrong: Tempting because a release branch sounds stable, but a branch reference resolves to the current tip and advances on every push, so it is among the least stable references rather than immutable.

Free sampleSecure and optimize automationhard

A workflow runs on pull_request_target so it can comment on pull requests from forks, and a run step echoes the fork branch name while the repository default grants the GITHUB_TOKEN write access to all scopes. A reviewer wants both to close the injection hole in the run step and to shrink the blast radius if any step is still compromised, making the smallest set of changes. Which two changes together meet both goals? Select TWO.

on:
  pull_request_target:
jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      - run: echo "PR from ${{ github.head_ref }}"
  • ABind github.head_ref to a step-level env variable and reference it in the run step as "$HEAD_REF", so the branch name reaches the shell as environment data instead of being substituted into the script text. Correct
  • BWrap the expression in single quotes as echo 'PR from ${{ github.head_ref }}', because single quotes stop the shell from interpreting any of the metacharacters that the fork branch name might contain.
  • CAdd a job-level permissions block listing only pull-requests: write, so every other scope of the GITHUB_TOKEN drops to none and an injected step can no longer push code or read packages. Correct
  • DSwitch the trigger from pull_request_target back to pull_request, because that event sanitises attacker-supplied fields such as the head branch before the job starts and removes the need to change the run step.
Combine an intermediate environment variable with a least-privilege permissions block to both close run-step injection and limit token blast radius. Two independent defences apply here. Passing github.head_ref through a step env variable keeps the untrusted value out of the script text, so the shell expands it as data and cannot execute embedded characters. A permissions block that names only the scope the job needs sets every other GITHUB_TOKEN scope to none, so even a still-compromised step can do far less damage. Single quoting fails because substitution happens before the shell parses the line, and changing the event does not sanitise anything, so neither distractor addresses the mechanism.

Why A is correct: Assigning the untrusted ref to an env variable means the runner never inlines it into the script, so the shell expands it as a quoted string value and crafted characters cannot break out into commands.

Why B is wrong: Tempting because single quotes do disable shell expansion, but the expression is substituted before the shell parses the line, so the ref can simply close the quote and inject commands regardless.

Why C is correct: A permissions block replaces the broad default with an explicit allow list, so naming only pull-requests: write leaves all other scopes at none and limits what a compromised step can do with the token.

Why D is wrong: Tempting because pull_request is lower privilege, but GitHub never sanitises event fields under either trigger, so the injection remains and changing the event alone does not protect the run step.

Free sampleSecure and optimize automationhard

A security lead is hardening how the automatic GITHUB_TOKEN is granted across an organisation's workflows, aiming for least privilege without breaking jobs that genuinely need a scope. Which two statements about controlling GITHUB_TOKEN permissions are accurate? Select TWO.

permissions:
  contents: read
  packages: write
  • ASetting the organisation or repository default token permissions to read-only gives every workflow a restrictive baseline that a job can still raise per scope with its own permissions block. Correct
  • BA job-level permissions block can only ever reduce scopes below the repository default and is silently ignored whenever it tries to grant a scope the default set to read-only.
  • CDeclaring permissions: {} for a job grants the token no access to any scope, which suits a job that needs neither repository writes nor any read scope at all. Correct
  • DOnce any workflow declares a permissions block, GitHub keeps every unlisted scope at the repository default rather than lowering the unlisted scopes to none for that workflow.
Understand that a read-only default is the safe baseline a job can raise per scope, and permissions: {} grants the token no access at all. Least privilege for GITHUB_TOKEN starts with a read-only organisation or repository default, which a job can selectively raise by declaring its own permissions block for the scopes it truly needs. An empty permissions: {} map sets every scope to none for that job, the tightest possible grant. A job block does not merely reduce scopes, it defines them and can grant a write scope above a read-only default, and once any permission is declared GitHub lowers every unlisted scope to none rather than preserving the default.

Why A is correct: A read-only default is the recommended safe baseline, and an individual job may still declare a permissions block to add the specific write scopes it needs without loosening the default for others.

Why B is wrong: Tempting because least privilege implies reduction, but a job block defines the token's scopes outright and can grant a write scope even when the default is read-only, so it is not ignored.

Why C is correct: An empty permissions map sets every scope to none, so the token can do nothing, which is the tightest posture for a job that performs no privileged repository operations.

Why D is wrong: Tempting because preserving defaults sounds safe, but declaring any permission sets all unlisted scopes to none, so the unlisted scopes are dropped rather than kept at the default.

Free sampleSecure and optimize automationhard

A team currently authenticates a deployment workflow to Azure by storing a service principal client secret as a repository secret, but the secret must be rotated manually every ninety days and has twice expired unnoticed. They want to remove the stored cloud credential entirely while keeping the deployment automated and avoiding any secret value appearing in logs. Which approach best meets these goals with the least ongoing maintenance?

  • AReplace the repository secret with an organisation secret holding the same client secret, because organisation secrets are rotated automatically by GitHub and are masked in logs, removing the manual rotation burden.
  • BConfigure OIDC federation so the workflow requests a short-lived token with id-token: write and exchanges it for temporary Azure credentials, removing the stored client secret and its rotation entirely. Correct
  • CMove the client secret into an environment secret protected by required reviewers, because environment protection rotates the credential on each deployment and prevents the secret from being printed to the run log.
  • DSwitch authentication to a fine-grained personal access token stored as a secret, because a personal access token can be given a long expiry and narrow scopes, reducing how often the credential needs rotating.
Adopt OIDC token federation to eliminate stored long-lived cloud credentials and their rotation rather than relocating or re-scoping a stored secret. OIDC federation has the workflow request a short-lived signed token from GitHub and exchange it for temporary cloud credentials at run time, so there is no long-lived client secret to store, rotate, or accidentally print. Relocating the secret to an organisation or environment scope, or swapping it for a personal access token, all keep a stored long-lived credential that must still be rotated, and a personal access token does not even authenticate to Azure.

Why A is wrong: Tempting because organisation secrets reduce duplication, but GitHub does not rotate their values for you and the long-lived client secret still exists, so the manual rotation and expiry problem remains unsolved.

Why B is correct: OIDC federation lets the workflow mint a short-lived signed token and trade it for temporary cloud credentials, so no long-lived client secret is stored or rotated and no secret value is exposed in the logs.

Why C is wrong: Tempting because environment protection adds approval gates and masking, but it does not rotate the stored client secret, so the long-lived credential and its manual rotation requirement still persist.

Why D is wrong: Tempting because fine-grained tokens narrow scope, but a personal access token is a GitHub credential, does not authenticate to Azure, and remains a stored long-lived secret needing rotation.

Free sampleSecure and optimize automationmedium

An organisation keeps an environment named production that holds deployment secrets. Security requires that only workflow runs originating from the main branch may deploy to this environment, while runs from feature branches must be refused even if their workflow references the environment. Which environment configuration enforces this restriction?

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
  • AConfigure a deployment branches rule on the production environment set to selected branches, listing main so only runs from that branch can deploy. Correct
  • BAdd the main branch to a repository CODEOWNERS file, because ownership of that branch limits which branches are permitted to deploy to the production environment.
  • CConfigure a branch protection rule on main that requires status checks, because protecting the branch stops feature branches from deploying to the production environment.
  • DAdd an if condition to the deploy job that checks the ref equals main, because the job is then skipped whenever the run starts from any other branch.
Restrict which branches can deploy to an environment by setting a deployment branches rule to selected branches. An environment can carry a deployment branches and tags rule that names exactly which refs may deploy to it. Setting it to selected branches and listing only main means GitHub refuses any run from another branch that targets the environment, enforced by the platform rather than by workflow steps. CODEOWNERS only assigns reviewers, branch protection governs activity on the branch itself, and an if condition is editable workflow logic rather than an enforced environment control.

Why A is correct: A deployment branches rule on the environment restricts which branches may deploy, so listing only main blocks any run from another branch from reaching the protected environment.

Why B is wrong: Tempting because CODEOWNERS controls review assignment, but it only requests reviews on changed paths and has no effect on which branch may deploy to a protected environment.

Why C is wrong: Tempting because branch protection secures main, but it governs merges and pushes to that branch and does not decide which branches are allowed to deploy to an environment.

Why D is wrong: Tempting because an if check can skip a job, but it is workflow logic that an author can edit or omit and is not an enforced environment rule on which branch may deploy.

Other domains in this exam

See also the GH-200 cert hub, the study guide, and the cheat sheet.

Examworthy is not affiliated with or endorsed by GitHub. Original, blueprint-aligned practice material only.