Secrets, Permissions and Supply-Chain Security
Take one task-board application from local tests to a real delivery pipeline: continuous integration fundamentals, push and pull-request quality gates, lint, type-check, unit, component and end-to-end gates, dependency caching, matrix builds, artifacts and checksums, secrets and supply-chain security, release promotion, staging and production, rollback and observability.
What you will be able to do
#- Handle secrets without leaking them into logs or artifacts.
- Apply least-privilege token permissions.
- Explain why pull_request_target with untrusted checkout is dangerous.
Overview
#Secrets are inputs with special handling
A secret is a value the pipeline needs but must not print or commit. The platform masks known secret values in logs, but masking is a safety net, not a licence to echo secrets. Never write a secret into a file that is uploaded as an artifact, and never pass it on a command line where it can appear in process listings.
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
Least privilege for the token
The automatic workflow token has default permissions that may be broader than needed. Set permissions at the workflow or job level and grant only what the job uses. A job that only reads source needs contents: read. A job that requests a cloud identity needs id-token: write and nothing more.
Pin actions to a commit
A third-party action referenced by a tag can change under you if the tag moves. Pin actions to a full commit SHA so the code that runs is the code you reviewed. This is supply-chain hygiene: the pipeline executes whatever the action contains.
pull_request_target is dangerous
A workflow triggered by pull_request_target runs in the context of the base repository, which means it can access secrets. If it then checks out and runs the pull request's code, it executes untrusted code with access to those secrets. Do not combine pull_request_target with checkout of untrusted code.
Script injection
Interpolating untrusted input such as a pull request title directly into a shell command allows command injection. Pass untrusted values through an environment variable and quote them, or avoid the shell entirely.
Sandbox boundary
The browser sandbox has no access to repository secrets and cannot request a cloud identity. Security exercises here are authored configuration and reasoning, not executed credential flows.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
A workflow uses pull_request_target, checks out the pull request code and runs it. Why is that dangerous?
Exercise 2Implement
Set least-privilege permissions on this job so it can only read repository contents, and pin the checkout action to a full commit SHA.
starter.yamljobs: verify: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4Reveal the reference answer
reference.yamljobs: verify: runs-on: ubuntu-latest permissions: contents: read steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683Authored expected output: The job declares permissions contents: read and the checkout action is pinned to a commit SHA.
Least privilege limits what a compromised step can do. Pinning to a SHA means the action code cannot change without a review.
Exercise 3Debug
This step leaks a secret into the logs. Fix it so the token is not printed.
starter.yaml- run: echo "token is ${{ secrets.API_TOKEN }}"Reveal the reference answer
reference.yaml- run: ./verify-token.sh env: API_TOKEN: ${{ secrets.API_TOKEN }}Authored expected output: The secret is passed through an environment variable and never echoed.
Echoing a secret prints it, and masking is not guaranteed for transformed values. Passing it as an environment variable keeps it out of the command text.
Exercise 4Interview
How do you let a CI job deploy to a cloud provider without storing long-lived keys?
Reveal the reference answer
reference.textUse short-lived identity federation. The job requests an OIDC token from the CI provider, the cloud provider trusts that issuer and exchanges the token for temporary credentials scoped to the job. No long-lived key is stored, and the credential expires when the job ends.Authored expected output: A correct answer describes OIDC or workload identity federation with short-lived credentials.
Federation replaces stored secrets with short-lived, scoped credentials, which removes a class of leak.
Common misconceptions
#- Masking makes it safe to echo secrets.
- A third-party action referenced by a tag is immutable.
- pull_request_target is always safe because it runs on the base repository.
Follow-up practice
#- cicd-12-release-promotion
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.