GitHub Hour 5: Production-Grade Actions: Reuse, Releases, and Hardening
- Use reusable workflows (
on: workflow_call) to turn build, release, and deploy into organization-level “pipeline templates”, explain how inputs / secrets / outputs flow,secrets: inheritthe boundaries and limits of 10 levels of nesting and 50 distinct reusable workflows ; choose between reusable workflows and composite actions. - Write JavaScript (node24) / Docker / composite three kinds of custom actions. You will learn to use
@actions/corencc to package them, understand how to publish to Marketplace, and understand immutable releases (2025-10 GA) and their impact on the traditional practice of “moving the v1 tag”. - Automate releases: automatically generate release notes,
gh release createupload assets, and publish drafts before publishing; connect with the release-please / semantic-release tools from the Git course. - Push images to GHCR:
packages: write, link packages and repositories, inherit permissions, multi-architecture images, and clean up old versions. - Use artifact attestations to generate SLSA build provenance and SBOM attestations for binaries and images, and use
gh attestation verifyto verify; understand how it relates to Sigstore / cosign, and “reusable workflow build → SLSA Build L3”. - System hardening: least-privilege
permissions, SHA pinning, or workflow dependency lock files, Dependabot, script injection protection,pull_request_targetrisks (checkout v7 protections and the default event policy from 2026-12-02), zizmor / OpenSSF Scorecard audits, and a review of the tj-actions/changed-files incident. - Organization governance: allowed actions list and SHA pinning policy, default
GITHUB_TOKENpermissions, the rule “require workflow to pass” in rulesets, Actions policies (workflow execution protection), organization secrets access scope, and runner groups.
1-hour time allocation table
| # | Time | Module | Core content | Animation / interaction | Lab (myorg-lab organization) |
|---|---|---|---|---|---|
| 0 | Before class | Preparation: organization and shared repository | Free organization myorg-lab, move myapp into the organization, create a platform-workflows shared repository, gh login and permission check | 8-item “production-grade Actions” self-assessment | Two public repositories ready |
| 1 | 00–08 | Reusable workflows and composite actions | workflow_call inputs/secrets/outputs,secrets: inherit, permissions can only be lowered, not raised, 10-level / 50-workflow limits, composite actions, and choosing between them | Core animation: call chain and permission intersection | Extract an organization-shared build-test workflow |
| 2 | 08–15 | Writing custom actions | action.yml, JS action (@actions/core, ncc, node24), Docker action, composite,$/ self-reference, Marketplace, version tags, and immutable releases | Comparison of the three action execution paths | Write a setup-myapp composite action + one JS action |
| 3 | 15–22 | Release automation | Releases and tags, automatically generated release notes,.github/release.yml,gh release create, assets, draft → publish, immutable releases, release attestations | Release pipeline timeline | Push a tag to trigger a Release and upload assets |
| 4 | 22–29 | GitHub Packages and GHCR | GHCR authentication,packages: write, package linking and permission inheritance, visibility, multi-architecture images, cleaning up old versions | Multi-architecture manifest list builder | Push amd64+arm64 images |
| 5 | 29–37 | Artifact attestations and the supply chain | actions/attest (provenance / SBOM), OIDC → Fulcio → Rekor,gh attestation verify, SLSA Build L2/L3, cosign/Notation | Core animation: attestation generation and verification | Generate and verify attestations for an image |
| 6 | 37–46 | Actions security hardening | SHA pinning / lock files / Dependabot, permissions, pull_request_target and workflow_run, script injection, zizmor, Scorecard, tj-actions review | Script injection attack and defense simulator | Scan and fix with zizmor |
| 7 | 46–54 | Organization governance | allowed actions, SHA pinning policy, default GITHUB_TOKEN permissions, ruleset requiring workflows, Actions policies, organization secrets, runner groups | Policy layering calculator | Configure the governance baseline for myorg-lab |
| 8 | 54–60 | Recap, self-check, and cleanup for the first five hours | Connecting the five lessons, common troubleshooting decision tree, cleanup | Interactive troubleshooting tree | Clean up packages, tokens, and test repositories |
| — | After class | Cheat sheet · Integrated lab | Refactor myapp CI/CD into “organization-shared reusable workflows + composite actions + GHCR multi-architecture + attestations + auditing” | Final quiz (12 questions) | Integrated lab |
Knowledge Coverage Matrix
| Target skill | M1 | M2 | M3 | M4 | M5 | M6 | M7 | M8 | Key commands / keywords | Lab |
|---|---|---|---|---|---|---|---|---|---|---|
| Write and call reusable workflows | ✓ | · | · | · | ✓ | · | ✓ | ✓ | workflow_call,secrets: inherit | M1 / integrated |
| Write custom actions | ✓ | ✓ | · | · | · | ✓ | · | · | action.yml,ncc build | M2 |
| Release and asset automation | · | ✓ | ✓ | · | ✓ | · | · | · | gh release create --generate-notes | M3 |
| GHCR push and permissions | · | · | · | ✓ | ✓ | · | ✓ | ✓ | packages: write,docker buildx | M4 |
| Generate and verify build attestations | ✓ | · | ✓ | ✓ | ✓ | · | · | ✓ | actions/attest,gh attestation verify | M5 |
| Dependency pinning and updates | · | ✓ | · | · | · | ✓ | ✓ | · | SHA pinning,gh actions-lock, Dependabot | M6 |
| Identify and fix workflow vulnerabilities | · | · | · | · | · | ✓ | ✓ | ✓ | zizmor, Scorecard | M6 |
| Organization-level Actions governance | ✓ | · | · | ✓ | · | ✓ | ✓ | · | allowed actions, rulesets, Actions policies | M7 |
| Troubleshooting and cleanup | ✓ | · | · | ✓ | ✓ | · | ✓ | ✓ | gh run view --log-failed | M8 |
Topics not covered in this lesson (and where to learn them)
| Topic | Why it is not in this lesson | Where to learn |
|---|---|---|
| Signed commits and tags (GPG/SSH/gitsign), conventional commits, and configuration details for release-please / semantic-release | Already covered in full in the Git course | Git Hour 5(module 4 signing, module 6 conventional commits and automated releases) |
| Workflow syntax, triggers, matrix, caching, artifacts, environments and approvals | Assumed as already mastered in this lesson | GitHub Hour 2 |
| OIDC login to Azure / AWS, federated credentials, and immutable subjects | Belongs to cloud platform topics | Hour 3 (Azure) · Hour 4 (AWS) |
| GHAS: code scanning, secret scanning and push protection, dependency review, security configuration | Belongs to enterprise security topics | Hour 6 |
| ARC self-hosted runners, larger runners, API rate limits, performance tuning | Belongs to advanced operations topics | Hour 7 |
| Writing Dockerfiles, BuildKit caching, image slimming | Belongs to container topics | Docker 8-hour course |
How to use this courseware
Theory · diagrams · animation · commands · labs · production cases · troubleshooting · quizzes · voice · video. Read “Theory” and “Animation” first, then do the “Lab”.
A quiz score of 70% or more, or clicking “Mark this module complete”, counts toward progress. It is saved in this browser (cleared on refresh if local storage is disabled).
The “Voice” page uses the browser Web Speech API (en-US) to read the narration script aloud; without a Chinese voice pack, you can read the narration script directly.
actions/checkout v7.0.1,actions/attest v4.2.2 (attest-build-provenance v4 onward is only its wrapper,attest-sbom which is being deprecated),docker/build-push-action v7.4.0,docker/setup-buildx-action v4.4.1,docker/setup-qemu-action v4.4.0,docker/login-action v4.8.0,docker/metadata-action v6.2.0,@actions/core 3.0.1,@vercel/ncc 0.45.0, zizmor v1.32.0,ossf/scorecard-action v2.5.0, gh 2.104.0, cosign v3.1.4. The SHAs in the examples were looked up git ls-remote on the verification date; re-check them before you use them. GitHub platform features change quickly, so follow the official documentation for UI paths and plan limits.Module 0 · Preparation: organization and shared repository (complete before class)
- CompletedHour 2: the
myapprepository under your personal account (Flask + gunicorn + Redis, includingDockerfile,/healthz,tests/) and.github/workflows/ci.yml. - Local machine:
gh≥ 2.104, Git 2.56, Docker Engine 29 (with buildx), Node.js 24 (for the module 2 JS action), Python 3.12+ oruv(for zizmor in module 6). - Why use public repositories: under GitHub Free / Team plans, artifact attestations can only be used with public repositories (private and internal repositories require GitHub Enterprise Cloud); private repositories in a Free organization also cannot read organization-level secrets/variables. Public repositories let every lab in this course be completed at zero cost.
Step 1: check gh login and token scopes
gh --version gh auth status # This lesson needs workflow (to edit .github/workflows), read:org / admin:org (organization settings), write:packages / delete:packages (GHCR) gh auth refresh -h github.com -s workflow,admin:org,write:packages,delete:packages
gh version 2.104.0 (2026-11-12) github.com ✓ Logged in to github.com account YOUR-USER (keyring) - Active account: true - Git operations protocol: https - Token: gho_************************************ - Token scopes: 'admin:org', 'delete:packages', 'gist', 'read:org', 'repo', 'workflow', 'write:packages'
GITHUB_TOKEN, not fine-grained PATs. To push images locally, the gh token is enough; after the course ends, revoke extra scopes in module 8 .Step 2: create the free organization myorg-lab
Organizations can only be created on the web: top-right avatar → Your organizations → New organization → choose Free, and enter the name myorg-lab (names are globally unique; if it is taken, pick another, for example myorg-lab-yourname; replace it consistently in the rest of the lesson).
export ORG=myorg-lab # replace with your organization name
gh api orgs/$ORG --jq '{login, plan: .plan.name, default_repository_permission}'
{"default_repository_permission":"read","login":"myorg-lab","plan":"free"}
Step 3: move myapp into the organization and create the shared repository
cd ~/src/myapp # Option A (recommended, keeps the personal repository): create a public repository under the organization and push gh repo create $ORG/myapp --public --source=. --remote=org --push # Organization shared repository: holds reusable workflows and composite actions gh repo create $ORG/platform-workflows --public --clone --description "Shared reusable workflows and actions" gh repo list $ORG
✓ Created repository myorg-lab/myapp on github.com ✓ Added remote https://github.com/myorg-lab/myapp.git ✓ Pushed commits to https://github.com/myorg-lab/myapp.git ✓ Created repository myorg-lab/platform-workflows on github.com Showing 2 of 2 repositories in @myorg-lab myorg-lab/platform-workflows Shared reusable workflows and actions public now myorg-lab/myapp public now
.github/workflows/ directory (they cannot be in subdirectories). Keeping them in one repository maintained by the platform team and protected by rulesets lets you apply version tags consistently, and application repositories reference them by tag or SHA. This is exactly the “trusted build definition” that “SLSA Build L3” in module 5 requires.Step 4: confirm the organization Actions settings allow this lesson's labs
gh api orgs/$ORG/actions/permissions gh api orgs/$ORG/actions/permissions/workflow
{"enabled_repositories":"all","allowed_actions":"all","sha_pinning_required":false}
{"default_workflow_permissions":"read","can_approve_pull_request_reviews":false}
New organizations default to GITHUB_TOKEN read-only (read) and do not allow workflows to create or approve PRs. This is a good thing: every workflow in this lesson declares the permissions it needs explicitly at the job level permissions. Field names follow the current response of the REST API: Actions permissions endpoint.
Warm-up: answer from memory (30 seconds)
At the job level permissions If you write contents: read, what are the other permissions?
Any permission not listed is none (metadata always readable). So once you write permissions, list everything you need, for example pushing images requires packages: write, and generating attestations requires id-token: write + attestations: write.
GITHUB_TOKEN Can it still be used after a run finishes?
No. It is issued when the job starts, expires after the job ends (at most 24 hours later), and its permissions only apply to the current repository. This is the fundamental reason it is safer than a PAT, and why module 4 recommends it for pushing to GHCR.
“Production-grade Actions” self-assessment (8 items)
Check the items your myapp currently meets (saved in this browser). Check again after you finish the integrated lab.
Module 1 · Reusable workflows and composite actions
- Write a reusable workflow that uses
inputs,secrets,outputsandworkflow_calland call it from another repository by tag or SHA. - Explain
secrets: inheritthe boundaries (same organization/enterprise, only to direct callees),envdoes not propagate across calls,GITHUB_TOKENand permissions can only be kept or lowered. - Remember the official limits: at most 10 levels of nesting, and a single workflow file can call at most 50 distinct reusable workflows (including the entire nested tree).
- Write a composite action (
runs.using: composite), and choose between the two depending on the scenario.
What: two units of reuse
- Reusable workflow: an ordinary workflow file whose trigger includes
on: workflow_call. The caller uses at the job level Usejobs.<id>.uses: OWNER/REPO/.github/workflows/FILE.yml@REFto call; all jobs in the called file will run in this run of the caller, each taking a runner, and appear in the run graph as an expandable group. - Composite action (composite action): a directory containing
action.yml,runs.using: composite, with several steps. The caller uses at the step level to calluses: OWNER/REPO/PATH@REF, all steps run on the same runner as the caller's current job and logs are collapsed into one step.
Why: why reuse
An organization with dozens or hundreds of repositories, each copy-pasting CI YAML, ends up with version drift (some still use old node16 actions), security fixes that must be made a hundred times, and audits with no clear starting point. Reusable workflows let the platform team maintain “one trusted pipeline definition” while application teams only pass parameters. Composite actions turn repeated step fragments (installing toolchains, logging in, caching) into a versioned building block.
How: how data flows through the call chain
| Channel | Declared by the called side | Passed in by the caller | Key rules (docs.github.com, verified 2026-11) |
|---|---|---|---|
| inputs | on.workflow_call.inputs.<id>: type (boolean / number / string),required,default | with: | in the called workflow, use ${{ inputs.id }} to read; type mismatches error at startup |
| secrets | on.workflow_call.secrets.<id> (can required: true) | secrets: { NAME: ${{ secrets.X }} } or secrets: inherit | inherit only applies to calls within the same organization or enterprise; secrets are passed only to the directly called workflow, so in A→B→C, for C to get A's secret, A must pass it to B, and B must explicitly pass it on to C |
| outputs | on.workflow_call.outputs.<id>.value: ${{ jobs.J.outputs.K }} | ${{ needs.CALLER_JOB.outputs.id }} | step output → job output → workflow output: all three mapping layers are required; for matrix calls, the value taken is from the last run that completed successfully and actually set a value |
| env | — | — | Caller workflow level env does not pass to the called workflow, and vice versa; share values at the organization/repository level vars or inputs |
| GITHUB_TOKEN permissions | of the called job permissions | of the calling job permissions | can only stay the same or be reduced, and cannot be raised; if the calling job does not write permissions, the called workflow gets GITHUB_TOKEN the default permissions |
| github context | — | — | is always the caller's event context; github.workflow is the caller's name (concurrency group name collisions!) |
Keywords the calling job can use
A job that calls a reusable workflow can only write: name,uses,with,secrets (including inherit),strategy,needs,if,concurrency,permissions,cache-mode. Cannot write runs-on,steps,environment,env,timeout-minutes—these are all declared by the called job itself. When an environment secret is needed, on the called side's job, write environment, and the caller must still pass (or inherit) that secret.
Official limits (verified 2026-11)
- Maximum chain of 10 levels of workflows (top-level caller + 9 nested levels). Earlier docs and blogs said 4 levels and 20 workflows; those are outdated.
- A single workflow file can call at most 50 distinct reusable workflows,including the entire nested tree (caller → w1 → w2 counts as 2).
- No redirects: after the called repository is renamed or transferred, old references fail outright.
- Access rules: callers in public repositories can only call reusable workflows in public repositories; callers in private repositories can call public or authorized private repositories (set in the called repository's Settings → Actions → General → Access).
- Runners and billing: GitHub-hosted runners are always allocated and billed according to the caller context; called workflows in the same organization can use self-hosted runners that the caller can access.
- Re-runs: when the reference is not a SHA, “re-run all jobs” re-resolves the reference; “re-run failed jobs” uses the same SHA as the first run.
Composite action key points
- Each
runstep must writeshell:; inside a step you canuses:use other actions (including other composite actions). - No separate
secretschannel: secrets must be passed in viainputsinputs (the caller writeswith: token: ${{ secrets.X }}), and logs are masked automatically. - Output:
outputs.<id>.value: ${{ steps.S.outputs.K }}. - Referencing an action in the same repository: use the 2026 self-reference syntax (it resolves to the commit currently running, needs no prior checkout, and is not supported on GHES); the traditional
$/path/to/actionapproach./pathrelies on content checked out into the workspace, which in cross-repository calls points to the caller's workspace.
When: how to choose
| Dimension | Reusable workflow | Composite action |
|---|---|---|
| Reuse granularity | one or more jobs (can include matrix, needs dependencies, environment approvals) | a sequence of steps |
| Where it is called | jobs.<id>.uses | steps[*].uses |
| runner | declared by the called job itself runs-on | shares the caller job's runner and filesystem |
| secrets | a dedicated secrets channel, with support for inherit | can only be passed via inputs |
| Logs | each job and each step is visible separately | collapsed into a single step of the caller (expandable) |
| Best for | “standard pipelines”: build, test, release, deploy; trusted builds (SLSA L3); mandatory approvals | “building blocks”: installing toolchains, logging in, caching, common checks |
| Nesting limit | 10 levels / 50 distinct | per the docs (composite actions can also nest within each other) |
secrets: inherit “Secrets propagate all the way down” is wrong: they only go to the direct callee. ② “The caller writes env:, and the called workflow can read it” is wrong: it cannot. ③ “The called workflow can grant itself packages: write” is wrong: it can only lower permissions, not raise them, and exceeding the scope granted by the caller fails at startup. ④ “A reusable workflow can be placed in .github/workflows/shared/ subdirectories” is wrong: subdirectories are not supported. ⑤ “A run step in a composite action works without a shell” is wrong: composite run steps must specify a shell.Architecture diagram: data and permissions in one call
Comparison diagram: how secrets pass through three nested levels
Core animation: reusable workflow call chain (inputs / secrets / outputs and permission intersection)
First choose the permissions granted by the calling job and how secrets are passed, then click “Start call” to step through how GitHub resolves uses, checks access and permissions, and issues GITHUB_TOKEN, and returns outputs to the caller. The called workflow's build job always requests contents: read,packages: write,id-token: write,attestations: write, and declares REGISTRY_TOKEN as required: true.
attestations: write, to see what happens.Core syntax and commands
| Syntax / command | Purpose | Notes |
|---|---|---|
on: workflow_call: | Declare callable | can be kept alongside workflow_dispatch for easier standalone debugging |
jobs.X.uses: org/repo/.github/workflows/f.yml@ref | Cross-repository call | ref can be a SHA, tag, or branch; within the same repository it can be written ./.github/workflows/f.yml (no @ref; uses the same commit) |
secrets: inherit | Pass all secrets visible to the caller | same organization/enterprise only |
gh workflow run f.yml -f k=v | Manual trigger (requires workflow_dispatch) | Debug the reusable workflow itself |
gh run view RUN --json jobs | View the job names produced by the call | Called job names look like build / test |
gh api repos/O/R/actions/runs/ID --jq .referenced_workflows | Audit which reusable workflows and SHAs this run used | Platform team inventories usage |
Called side: platform-workflows/.github/workflows/python-build.yml
name: python-build
on:
workflow_call:
inputs:
python-version:
type: string
default: "3.12"
image-name:
type: string
required: true
push:
type: boolean
default: false
secrets:
REGISTRY_TOKEN:
required: false
outputs:
image-digest:
description: "Digest of the pushed image"
value: ${{ jobs.build.outputs.digest }}
permissions: {} # clear at file level first; each job declares its own
jobs:
test:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@v7 # example; in production, pin the SHA as well
with:
python-version: ${{ inputs.python-version }}
cache: pip
- run: pip install -r requirements.txt -r requirements-dev.txt
- run: pytest -q
build:
needs: test
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.push.outputs.digest }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN || secrets.GITHUB_TOKEN }}
- id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
push: ${{ inputs.push }}
tags: ghcr.io/${{ inputs.image-name }}:${{ github.sha }}
Caller: myapp/.github/workflows/ci.yml
name: ci
on:
push:
branches: [main]
pull_request:
permissions: {}
jobs:
build:
uses: myorg-lab/platform-workflows/.github/workflows/python-build.yml@v1
with:
image-name: ${{ github.repository }}
push: ${{ github.event_name == 'push' }}
secrets: inherit
permissions:
contents: read
packages: write
report:
needs: build
runs-on: ubuntu-24.04
permissions: {}
steps:
- env:
DIGEST: ${{ needs.build.outputs.image-digest }}
run: echo "image digest = $DIGEST" >> "$GITHUB_STEP_SUMMARY"
How to verify: The run graph shows build / test,build / build two jobs,report and the summary of Common errors: Caller written as uses: myorg-lab/platform-workflows/python-build.yml@v1 (missing .github/workflows/); or adding runs-on to the calling job. Production use: The platform team tags platform-workflows with v1/v1.2.0 tags, and application repositories track them with Dependabot (module 6).
Composite action: platform-workflows/actions/setup-myapp/action.yml
name: setup-myapp
description: Install Python and myapp dependencies with pip cache
inputs:
python-version:
description: Python version
default: "3.12"
outputs:
python-path:
description: Path of the python interpreter
value: ${{ steps.py.outputs.python-path }}
runs:
using: composite
steps:
- id: py
uses: actions/setup-python@v7
with:
python-version: ${{ inputs.python-version }}
cache: pip
- name: Install dependencies
shell: bash # composite run steps must specify a shell
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: myorg-lab/platform-workflows/actions/setup-myapp@v1
with:
python-version: "3.12"
- run: pytest -q
Lab 1: extract an organization-shared build-test workflow (about 8 min)
python-build.yml as .github/workflows/python-build.yml,action.yml as actions/setup-myapp/action.yml, then replace the setup-python + pip steps in python-build's test job with uses: $/actions/setup-myapp (same-repository self-reference, which follows the called workflow's commit).
cd ~/src/platform-workflows mkdir -p .github/workflows actions/setup-myapp # …write both files… git add . && git commit -m "feat: python-build reusable workflow and setup-myapp action" git push origin main git tag -a v1.0.0 -m "v1.0.0" && git tag -f v1 && git push origin v1.0.0 v1
First use the traditional approach of a “movable v1 tag + immutable v1.0.0” tag; module 2 covers how to adjust after enabling immutable releases.
ci.yml to replace the original CI.
cd ~/src/myapp git switch -c reuse-ci # …write .github/workflows/ci.yml… git commit -am "ci: call shared python-build workflow" && git push -u org reuse-ci gh pr create -R $ORG/myapp --fill gh run watch -R $ORG/myapp
✓ reuse-ci ci · 1234567890 Triggered via pull_request less than a minute ago JOBS ✓ build / test in 41s (ID 3141592653) ✓ build / build in 58s (ID 3141592654) ✓ report in 3s (ID 3141592655)
RUN=$(gh run list -R $ORG/myapp -L1 --json databaseId --jq '.[0].databaseId') gh api repos/$ORG/myapp/actions/runs/$RUN --jq '.referenced_workflows'
[{"path":"myorg-lab/platform-workflows/.github/workflows/python-build.yml@v1","ref":"refs/tags/v1","sha":"9f2c1e0…"}]packages: write to packages: read then push; the run fails at startup (no job runs), with an error like The nested job 'build' is requesting 'packages: write', but is only allowed 'packages: read'. Change it back and push again.env: FOO: bar at the top level of ci.yml, and in a step of python-build.yml run: echo "FOO=$FOO", after running the logs show FOO=. Conclusion: share config using vars or inputs. Delete these two changes after the lab.Case 1: unified CI template for 200 microservices
Problem: Each repository maintained its own CI; upgrading the Node runtime took a whole quarter. Approach: The platform team turned “lint → test → build → scan → push” into 4 reusable workflows, placed in a platform-workflows repository protected by rulesets; application repositories only write 15 lines of calling YAML. Configuration: Entry workflows are split by language (python-build, node-build, go-build); the shared scan and push steps are called through nesting (3 levels, far below the 10-level limit). Limitations: A calling job cannot write environment; production approval must sit in the called side's deploy job. As teams need more and more parameters, control the number of inputs so the template does not turn into a “configuration language”.
Case 2: secrets: inherit leads to over-authorization
Problem: A security audit found that a public reusable workflow maintained by a third party was used with secrets: inherit a call, meaning all organization secrets (including the production database password) were exposed to it. Approach: Stipulate that inherit is only used for the organization's own platform-workflows; external workflows must always receive explicitly passed minimal secrets and be pinned by SHA. Note: In fact, inherit cross-organization calls never pass secrets anyway, but “shadow template repositories” inside the same organization are just as dangerous. Use zizmor (module 6) to check for secrets-inherit this class of problem.
Case 3: a concurrency group name collision cancels the caller
Problem: The caller and the called workflow both wrote concurrency: group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true, so the called workflow cancelled the caller itself as soon as it started. Cause: The called side's github.workflow is the caller's name. Fix: Add a fixed prefix to the called side's concurrency group (for example python-build-${{ github.ref }}), or set concurrency only in the caller.
Common errors and fixes
error parsing called workflow ".github/workflows/ci.yml" -> "myorg-lab/platform-workflows/.github/workflows/python-build.yml@v1" : workflow was not found.
Cause: Wrong path or tag; or the called repository is private and not authorized in Settings → Actions → General → Access; or the caller is a public repository while the called one is private (public callers can only call public workflows); or the repository was renamed (redirects are not supported).
gh api repos/myorg-lab/platform-workflows/contents/.github/workflows/python-build.yml?ref=v1 --jq .path gh api repos/myorg-lab/platform-workflows/actions/permissions/access
Fix: Confirm the file is in .github/workflows/ the root directory and the tag exists; for private repositories, enable access from within the organization.
The nested job 'build' is requesting 'packages: write', but is only allowed 'packages: read'.
Cause: The called job requests permissions beyond the scope granted by the calling job (permissions can only be lowered, not raised).
Fix: Add it to the calling job's permissions block; or confirm the called side really needs it (least privilege). Note that once the calling job writes permissions, every unlisted item becomes none.
Invalid input, python_version is not defined in the referenced workflow.
Cause:with The keys in inputs do not match those of the called side (case, underscores, and hyphens). When a required input is not passed, the error is Input required and not supplied.
Fix: Check against the called side's on.workflow_call.inputs; types must match too (do not write boolean as the string "true").
The secret is empty in the called side, and the login step reports Error: Username and password required
Cause: The caller did not pass the secret (neither inherit nor explicit mapping); a middle layer of the A→B→C chain did not keep passing it; or a cross-organization call used inherit. An unpassed secret resolves to an empty string,and does not error.
Fix: Add required: true to the critical secret on the called side so that a missing value fails at startup; pass it explicitly at every level when nesting.
Unexpected value 'runs-on' / 'steps' / 'environment' (job that calls a reusable workflow)
Cause: A calling job can only use name, uses, with, secrets, strategy, needs, if, concurrency, permissions, and cache-mode.
Fix: Move runs-on, environment, timeout, etc. into the called side's job, and turn them into inputs if necessary.
1. Use one command to list the reusable workflows referenced by myapp's most recent run, along with their resolved SHAs.
gh api repos/$ORG/myapp/actions/runs/$(gh run list -R $ORG/myapp -L1 --json databaseId --jq '.[0].databaseId') --jq '.referenced_workflows[] | "\(.path) \(.sha)"'
2. Write a job that calls a reusable workflow in the same repository (file .github/workflows/lint.yml) and grants only contents: read.
jobs:
lint:
uses: ./.github/workflows/lint.yml
permissions:
contents: readThe team wants “every repository must pass the same security scan before deploying to production, and production deployment requires SRE approval.” Should this use a reusable workflow or a composite action? Where does the approval go?
Use a reusable workflow: it can contain multiple jobs (scan, build, deploy) and needs dependencies; write environment: production in the called side's deploy job and configure required reviewers in the repository environment (a calling job cannot write environment). A composite action is just a sequence of steps; it can neither span jobs nor attach an environment. Combine it with the module 7 ruleset “require workflow to pass” or an Actions policy to make sure repositories cannot bypass it.
Verified instructional videos
Official documentation
- Reuse workflows
- Reusing workflow configurations (limits, access, permissions)
- Creating a composite action
Video storyboard (about 90 seconds)
This courseware cannot generate video/MP3 directly; the storyboard below can be handed to a video tool.
Visual: 100 repository icons, each with a nearly identical ci.yml; several are marked in red as “outdated action”.
Narration: copy-pasted pipelines drift. Reusable workflows let the platform team maintain just one.
Visual: the calling job emits three colored lines—inputs, secrets, and permissions—entering the two jobs of the called workflow.
Narration: inputs and secrets flow in from the caller, and permissions can only be narrowed. If the called side asks for one extra permission, the run fails at startup.
Visual: three boxes A, B, C; secrets are fully inherited from A to B, and only one key is left from B to C.
Narration: secrets are passed only to direct callees. An unpassed secret is an empty string, so mark critical secrets as required.
Visual: on the left, a reusable workflow for a “whole set of jobs”; on the right, a composite action for a “sequence of steps”.
Narration: for cross-job flows, approvals, or trusted builds, use a reusable workflow; for a building block, use a composite action.
Module 2 · Writing custom actions (JavaScript / Docker / composite)
- Read action metadata
action.yml:name / description / inputs / outputs / runs / branding. - Write a node24 JavaScript action:
@actions/coreread inputs, write outputs, and mark failures; use@vercel/ncc(or rollup) to bundle dependencies into a singledist/index.js. - Know when Docker actions and composite actions apply, and their limitations (Docker actions only run on Linux runners).
- Be able to publish to Marketplace and understand
v1the trade-off between major-version tag conventions and immutable releases.
What: three types of actions
| Type | runs | Execution method | Advantages | Limitations |
|---|---|---|---|---|
| JavaScript | using: node24 (or node20)main, optionally pre / post and pre-if / post-if | run directly with the Node runtime built into the runner main pointing to a JS file | Fastest startup; runs on Linux / Windows / macOS; post can be used for cleanup | Dependencies must be bundled into the repository (the runner will not npm install) |
| Docker container | using: dockerimage: Dockerfile or docker:// image,args,entrypoint,env | the runner builds the Dockerfile (or pulls the image) on each run and mounts the workspace into the container to execute | can use any language and lock down the whole toolchain | Linux runners only; using a Dockerfile means building every time, which is slower |
| Composite | using: compositesteps (run needs a shell / uses other actions) | expands steps into the caller's job to execute | no code required; can compose existing actions | no pre/post; YAML is hard to maintain when logic gets complex |
Why: when it is worth writing your own
The Marketplace already has tens of thousands of actions, but organizations often have specific needs: calling internal APIs, checking internal standards, combining several public actions with default values. Another reason to write your own is security: rather than referencing a third-party action of a few dozen lines maintained by strangers, implement it in a few lines of composite or JS within the organization to reduce supply-chain exposure (the tj-actions incident in module 6 is an example).
How: how the runner passes inputs / outputs to the action
- Inputs: the runner turns each
withkey into an environment variableINPUT_<NAME>(uppercase, spaces replaced with underscores), and the actioncore.getInput('name')reads it; Docker actions can also pass arguments viaargs. - Outputs: the action appends to the
$GITHUB_OUTPUTfilekey=value(core.setOutputhelps with this); the old::set-outputworkflow commands are deprecated. - Failures: a non-zero process exit code fails the step;
core.setFailed(msg)outputs error annotations and sets exit code 1. - Logs and masking:
core.info/warning/error,core.startGroup;core.setSecret(v)lets the runner mask a runtime value in the logs.
Bundling JavaScript actions
The runner only downloads the action repository's content at the specified ref,does not run npm install. So you either node_modules commit it (not recommended) or use a bundler to combine source and dependencies into one file. The classic approach is @vercel/ncc (0.45.0, 2026-08): its input is "type": "module" the entry file inside the package .js — when it is ESM it outputs an ES module automatically; GitHub's official template actions/javascript-action has switched to rollup. @actions/core Currently 3.0.1 (ESM); the official template's engines.node is >=24.
Version and release conventions
- convention: publish
v1.2.3semantic version tags like this, while maintaining a movable major-version tagv1(and an optionalv1.2) that points to the latest compatible commit, so users who write@v1get fixes automatically. - immutable releases (2025-08 public preview,2025-10-28 GA): once enabled at the repository or organization level,tags of published Releases cannot be moved or deleted, and assets cannot be modified or deleted. After a Release is deleted its tag can be removed, but the same tag name can never be reused (even deleting and recreating the repository is not allowed, which prevents “repository resurrection” attacks); it also automatically generates release attestations, which can be verified with
gh release verifyto verify. Titles and notes remain editable. - How the two coexist (official doc “Using immutable releases and tags to manage your action's releases”): create a GitHub Release for each fixed version (for example
v1.0.0, immutable); for major and minor tagsv1,v1.1create only Git tags, not Releases, so that they can still begit tag -f+git push -fmoved. Users who want determinism should reference a SHA or an immutable version tag. - Marketplace: public repository, root directory with only one
action.yml(subdirectory ones are not listed automatically),namea globally unique name, acceptance of the Marketplace developer agreement, and checking “Publish this Action to the GitHub Marketplace” when publishing a Release; publishing requires 2FA; GitHub does no manual review.
node12,node16 has been removed; node20 is still an optional value listed in the metadata docs, but it has entered the deprecation process, so new actions should use node24 (actions/checkout has been node24 since v5). For the exact node20 retirement date, follow the GitHub Changelog.@v1 is secure”—tags can be moved by maintainers (or attackers); the strongest pinning is a SHA or lock file (module 6).Structure diagram: a JavaScript action repository
Flowchart: how the runner executes a step's uses
Interactive comparison: execution paths of the three action types on the runner
Choose an action type, then step through it. The log panel simulates the runner's real log lines (times are illustrative) and shows what the runner actually does at each step.
Core commands and files
| Command | Purpose | Notes |
|---|---|---|
npm i @actions/core | Official toolkit | getInput / setOutput / setFailed / summary |
npx @vercel/ncc build src/index.js -o dist --license licenses.txt | Bundle into a single file | ESM package automatically outputs an ES module |
npx @github/local-action . src/main.js .env | Run a JS action locally for testing | Debugging tool included in the official template |
gh release create v1.0.0 --generate-notes | Create an immutable versioned Release | Marketplace publishing must be checked on the web |
git tag -f v1 v1.0.0^{} && git push -f origin v1 | Move a major-version tag | Do not attach a Release to v1 |
gh release verify v1.0.0 | Verify a release attestation | Only immutable releases have attestations |
JavaScript action: action.yml
name: check-healthz
description: Poll an HTTP health endpoint until it returns 200
author: myorg-lab
branding:
icon: activity
color: green
inputs:
url:
description: Health endpoint URL
required: true
timeout-seconds:
description: Give up after N seconds
default: "60"
outputs:
elapsed:
description: Seconds until healthy
runs:
using: node24
main: dist/index.js
src/index.js (ESM, @actions/core 3.x)
import * as core from '@actions/core'
async function run() {
const url = core.getInput('url', { required: true })
const timeout = Number(core.getInput('timeout-seconds') || '60')
const start = Date.now()
core.startGroup(`Polling ${url}`)
while ((Date.now() - start) / 1000 < timeout) {
try {
const res = await fetch(url) // Node 24 has fetch built in
core.info(`HTTP ${res.status}`)
if (res.status === 200) {
const elapsed = Math.round((Date.now() - start) / 1000)
core.endGroup()
core.setOutput('elapsed', String(elapsed))
await core.summary.addRaw(`✅ ${url} healthy after ${elapsed}s`).write()
return
}
} catch (e) {
core.info(`not ready: ${e.message}`)
}
await new Promise(r => setTimeout(r, 3000))
}
core.endGroup()
core.setFailed(`${url} not healthy within ${timeout}s`)
}
run()
npm init -y && npm pkg set type=module engines.node=">=24" npm i @actions/core@3 npm i -D @vercel/ncc@0.45.0 npx ncc build src/index.js -o dist --license licenses.txt ls dist/
ncc: Version 0.45.0 ncc: Compiling file index.js into ESM 46kB dist/licenses.txt 210kB dist/index.js 256kB [1203ms] - ncc 0.45.0 index.js licenses.txt
Docker action (Linux runners only)
name: hadolint-lite
description: Lint a Dockerfile
inputs:
dockerfile:
default: Dockerfile
runs:
using: docker
image: docker://hadolint/hadolint:v2.12.0-debian # prebuilt image, avoids rebuilding each time; in production, use a @sha256 digest
entrypoint: hadolint
args:
- ${{ inputs.dockerfile }}
The image tag is an example; verify it on Docker Hub before use. Using image: Dockerfile makes the runner rebuild every time it runs docker build; pushing the image to GHCR in advance and referencing it with docker://ghcr.io/…@sha256:… speeds things up significantly and pins the content.
Lab 2: write a JS action and use it in myapp (about 7 min)
gh repo create $ORG/check-healthz-action --public --clone && cd check-healthz-action # write the action.yml and src/index.js from the “Commands” page npm init -y && npm pkg set type=module engines.node=">=24" npm i @actions/core@3 && npm i -D @vercel/ncc@0.45.0 npx ncc build src/index.js -o dist --license licenses.txt printf 'node_modules/\n' > .gitignore git add . && git commit -m "feat: check-healthz action" && git push origin main
name: check-dist
on: [push, pull_request]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- run: npm ci
- run: npx ncc build src/index.js -o dist --license licenses.txt
- run: git diff --exit-code dist/ || (echo "::error::dist/ is stale, run ncc build" && exit 1)gh release create v1.0.0 --title "v1.0.0" --generate-notes
git fetch --tags
git tag -f v1 v1.0.0^{} && git push -f origin v1 # v1 is only a Git tag, no Release
gh release verify v1.0.0
Resolved tag v1.0.0 to sha1:5b0e… Loaded attestation from GitHub API ✓ Release v1.0.0 verified!
Try git tag -f v1.0.0 HEAD && git push -f origin v1.0.0; the push will be rejected—this is the protection that immutable releases provide.
- run: docker compose up -d --build
- id: hc
uses: myorg-lab/check-healthz-action@v1
with:
url: http://localhost:8000/healthz
timeout-seconds: "90"
- run: echo "healthy after ${{ steps.hc.outputs.elapsed }}s"action.yml, click the banner Draft a release, and check “Publish this Action to the GitHub Marketplace”. name: check-healthz The name may already be taken, so you need a unique name. Do not actually publish lab actions; to unlist one, edit each Release and uncheck the box.Case 1: an internal deployment action replaces 3 third-party actions
Problem: The deployment process depended on 3 niche third-party actions (downloading kubectl, rendering templates, calling an internal API); their maintainers were inactive and the security team could not assess them. Approach: Use one composite action that combines GitHub's official action with 30 lines of shell, keep it in a private repository inside the organization, and share it through “Accessible from repositories in the organization”. Limitation: Once a private action repository is opened to the organization, external collaborators in other repositories can indirectly see its output through run logs.
Case 2: a Docker action slows the pipeline
Problem: A Docker action written in Python (image: Dockerfile) took 2 minutes to build on every run. Approach: In the action repository's release workflow, push the image to GHCR,action.yml and change it to image: docker://ghcr.io/org/tool@sha256:…; or rewrite it as a JS action. Result: This step dropped from 2 min 10 s to 15 s.
Case 3: the release process fails after enabling immutable releases
Problem: Following JasonEtco/build-and-tag-action the practice of “force-pushing the major-version tag to the Release commit” fails once immutable releases are enabled. Approach: Following the official advice: the versioned Release (v1.4.2) is immutable,v1 and the movable tag is moved only as a Git tag; first create a draft Release, upload all assets, then publish. Limitation: If a wrong version is published by mistake, you can only publish a new version (the same tag name cannot be reused).
Common errors and fixes
Error: Cannot find module '@actions/core' / ERR_MODULE_NOT_FOUND
Cause: the bundled dist/ was not committed, or main points to the source src/index.js.
Fix: run ncc/rollup to bundle, then commit dist/; add the check-dist workflow.
Container action is only supported on Linux
Cause: a runs.using: docker action was used on windows-latest / macos-latest.
Fix: run the job on a Linux runner instead, or rewrite it as a JS / composite action.
Required property is missing: shell
Cause: a run step in the composite action has no shell.
Fix: add shell: bash to each run step (or pwsh, etc.).
The `set-output` command is deprecated and will be disabled soon.
Cause: the old action still prints ::set-output to stdout.
Fix: upgrade @actions/core, or change it to echo "k=v" >> "$GITHUB_OUTPUT" in the shell.
! [remote rejected] v1.0.0 -> v1.0.0 (… cannot update a tag that belongs to an immutable release)
Cause: after enabling immutable releases, the tags of published Releases cannot be moved or deleted (follow the actual error text).
Fix: publish a new patch version; do not attach a Release to the major-version tag.
1. Use ncc to bundle src/index.js into dist, and include the third-party license file.
npx @vercel/ncc build src/index.js -o dist --license licenses.txt
2. Point the movable major-version tag v2 at the commit of v2.3.1 and push it.
git tag -f v2 v2.3.1^{}
git push -f origin v2You need to write an action that uploads diagnostic logs at the end of a job, whether it succeeds or fails, and it must run on a Windows runner. Which type should you choose, and why?
JavaScript action: only JS actions support post (used with post-if: always(), which defaults to always) for cleanup work, and it runs on Windows/macOS/Linux. Docker actions only run on Linux; composite actions have no pre/post.
Verified instructional videos
Official documentation
- Metadata syntax reference
- Publishing actions in GitHub Marketplace
- Using immutable releases and tags to manage your action's releases
- actions/javascript-action template
Video storyboard (about 80 seconds)
Visual: the runs.using line in action.yml is highlighted, splitting into three paths: Node, container, and expanded steps.
Narration: the runner looks at runs.using to decide how to run the action.
Visual: src and node_modules are compressed into a single dist/index.js file.
Narration: the runner does not install dependencies for you, so a JavaScript action must be bundled.
Visual: v1.0.0 is locked, and the v1 tag is moved to a new commit like a sticky note.
Narration: a versioned Release is immutable, and the major-version tag is only a Git tag, so it can keep moving.
Module 3 · Release automation: releases, tags, and changelogs
- Distinguish Git tags (lightweight / annotated) from GitHub Releases, and know the three Release states: draft, pre-release, and latest.
- Use
.github/release.ymlto classify automatically generated release notes by PR label, and usegh release create --generate-notesto publish in a workflow. - Upload release assets and checksums, and follow the order “draft → upload all assets → publish” (required with immutable releases).
- Know where release-please / semantic-release fit in this chain, and connect them to GitHub Releases on top of the configuration already set up in the Git course.
What: tags, Releases, and assets
- Git tag: a reference pointing to a commit; an annotated tag (
git tag -a) carries an author, date, and message, and can be signed. Tags alone do not create a page on GitHub. - GitHub Release: a GitHub object built on top of a tag, containing a title, notes (Markdown),assets and automatically attached source zip/tar.gz archives. Status: Draft (visible only to people with write access; the tag may not exist yet),Pre-release,Latest (determined automatically by semantic version when not specified manually).
- Automatically generated release notes: GitHub builds notes from the PRs, contributors, and new contributors merged between the previous Release tag and this tag, along with a “Full Changelog” comparison link. You can configure them in
.github/release.ymlto group by PR label, and exclude labels or authors (such asdependabot).
Why: why automate releases
The most common problems with manual releases: forgetting to upload a binary for one platform, missing notes, tagging the wrong commit, and quietly replacing assets after release (users then get files whose checksums don't match). Putting the release into a workflow, combined with immutable releases and build attestations (module 5), guarantees that “every file in this Release came from this CI build, and it will not be replaced after release.”
How: two mainstream ways to decide versions
| Manual tagging + workflow publishing | release-please | semantic-release | |
|---|---|---|---|
| Who decides the version number | a person (pushes v1.4.0 the tag) | computed from conventional commits; opens a “Release PR”, and after merging it tags and creates the Release | computed from conventional commits; tags and creates the Release directly in CI |
| Changelog | GitHub generates the notes automatically | Maintained CHANGELOG.md + Release notes | plugin generates notes; a CHANGELOG can be written |
| Review point | Tag push permission (tag ruleset) | Review of the Release PR | No manual review point; suits highly automated flows |
| see | this module | Git Hour 5 · module 6(googleapis/release-please-action v5.0.0, semantic-release) | |
Key facts about publishing from a workflow
- Creating a Release requires
GITHUB_TOKENof thecontents: write. - Use
GITHUB_TOKENa Release created or a tag pushed with does not trigger a new workflow runworkflow_dispatch(repository_dispatchandon: releaseare excepted). So the chain “release-please creates a Release → anotherrelease_createdworkflow builds the assets” will not trigger with the default token; the common fix is to continue building and uploading in the same workflow using release-please's output ( - immutable releases), or use a GitHub App token.
gh release create --draft: after release, assets cannot be added, removed, or modified. The correct order:gh release edit --draft=false→ upload all assets → release attestation. Once enabled, GitHub also generatesgh release verify TAGfor the Release (tag, commit SHA, asset digests), which users verify withandgh release verify-asset TAG FILE - Tag protection: use a tag ruleset to restrict who can create, update, or delete
v*tags (the Git course's third lesson covered rulesets), so that arbitrary contributors cannot trigger a release by pushing a tag. - Signing: tags created on the GitHub web or via API are signed by GitHub and show as Verified; for signing tags locally, see module 4 of Git Hour 5.
on: release workflow runs automatically”—not when using GITHUB_TOKEN.Flowchart: from tag to immutable Release
Diagram: how automatically generated release notes are categorized
Interactive timeline: publishing order and immutable releases
Switch between “whether immutable releases are enabled” and “publishing order”, click play, and watch which step fails and what end users finally see.
Core commands
| Command | Purpose | Key parameters |
|---|---|---|
gh release create TAG [files…] | Create a Release (when the tag does not exist, it is created as specified by --target ) | --draft,--prerelease,--generate-notes,--notes-start-tag,--verify-tag,--latest,--title,file#display name |
gh release upload TAG files… | Upload assets | --clobber overwrite same name (not valid for immutable Releases) |
gh release edit TAG --draft=false | Publish a draft | can also change the title, notes, and latest flag |
gh release view / list / download | View and download | download -p '*.whl' |
gh release verify TAG / verify-asset TAG FILE | Verify release attestations and assets | requires an immutable Release |
gh api repos/O/R/releases/generate-notes -f tag_name=v1.4.0 | Generate notes only, without publishing | Preview notes |
.github/release.yml
changelog:
exclude:
labels: [ignore-for-release]
authors: [dependabot]
categories:
- title: 💥 Breaking Changes
labels: [breaking-change]
- title: 🎉 Features
labels: [enhancement]
- title: 🐛 Fixes
labels: [bug]
- title: Other Changes
labels: ["*"]
.github/workflows/release.yml (myapp)
name: release
on:
push:
tags: ["v*.*.*"]
permissions: {}
jobs:
build:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- run: |
pip install build
python -m build # build dist/*.whl and dist/*.tar.gz
cd dist && sha256sum * > SHA256SUMS
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
publish:
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write # create the Release
steps:
- uses: actions/download-artifact@v8
with:
name: dist
path: dist
- env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
gh release create "$TAG" -R "$GITHUB_REPOSITORY" --draft --verify-tag \
--title "myapp $TAG" --generate-notes
gh release upload "$TAG" -R "$GITHUB_REPOSITORY" dist/*
gh release edit "$TAG" -R "$GITHUB_REPOSITORY" --draft=false
Note:$TAG comes from github.ref_name, passed via env into the shell instead of being written directly into the script ${{ }} into the script—this is the module 6 habit for preventing script injection. --verify-tag Make sure the tag already exists, to avoid accidentally creating a tag at the head of the default branch. Split building and publishing into two jobs: only the publish job gets contents: write.
Lab 3: push a tag to trigger a Release and upload assets (about 7 min)
.github/release.yml and release.yml workflow to main. myapp needs a pyproject.toml before you can python -m build; if it does not have one, add a minimal version first (name, version, dependencies).
gh label create breaking-change -R $ORG/myapp -c B60205 2>/dev/null gh label create ignore-for-release -R $ORG/myapp -c CCCCCC 2>/dev/null git add .github pyproject.toml && git commit -m "ci: release workflow" && git push org main
gh api repos/$ORG/myapp/releases/generate-notes -f tag_name=v0.1.0 --jq .body | head -20
git tag -s v0.1.0 -m "v0.1.0" # if signing is not set up, use -a git push org v0.1.0 gh run watch -R $ORG/myapp $(gh run list -R $ORG/myapp -w release -L1 --json databaseId --jq '.[0].databaseId') gh release view v0.1.0 -R $ORG/myapp
myapp v0.1.0 Immutable · Latest · github-actions released this less than a minute ago ## What's Changed * ci: release workflow by @YOUR-USER in #3 **Full Changelog**: https://github.com/myorg-lab/myapp/commits/v0.1.0 Assets myapp-0.1.0-py3-none-any.whl 6.12 KiB myapp-0.1.0.tar.gz 5.40 KiB SHA256SUMS 184 B
cd /tmp && gh release download v0.1.0 -R $ORG/myapp -p '*.whl' -p SHA256SUMS sha256sum -c --ignore-missing SHA256SUMS gh release verify v0.1.0 -R $ORG/myapp gh release verify-asset v0.1.0 myapp-0.1.0-py3-none-any.whl -R $ORG/myapp
gh release upload v0.1.0 README.md -R $ORG/myapp should be rejected; gh release edit v0.1.0 --notes "additional notes" -R $ORG/myapp succeeds (notes remain editable).Case 1: multi-platform release of a CLI tool
Problem: A Go CLI had to publish binaries for 6 platforms, and users complained after the arm64 build was left out. Approach: Matrix build of 6 binaries → a summary job generates SHA256SUMS → attestations (module 5) → upload to a draft Release → publish only after verifying the asset count is 7. Limitation: With immutable releases enabled, verification must happen before publishing, because assets cannot be uploaded after publishing.
Case 2: release-please created a Release, but the build workflow was not triggered
Problem: On top of the release-please configuration from the Git course, the team wrote a separate on: release: types: [published] build workflow, but it was never triggered. Cause: release-please-action uses GITHUB_TOKEN by default, and events it produces do not trigger new workflows. Approach: checking in the same workflow steps.release.outputs.release_created , then continue building and uploading; or configure a GitHub App token for release-please (actions/create-github-app-token).
Case 3: a trust crisis caused by replaced assets
Problem: A maintainer's account for an open-source project was stolen, and the attacker replaced the installer in the latest Release. Approach: Enable immutable releases at the organization level, generate all assets in CI with build attestations attached; downstream users verify with gh release verify-asset and gh attestation verify a double check. Effect: Even if the account is compromised, published assets cannot be replaced, and a new malicious Release lacks an attestation signed by the trusted workflow.
Common errors and fixes
HTTP 403: Resource not accessible by integration (https://api.github.com/repos/…/releases)
Cause: the job's GITHUB_TOKEN does not have contents: write (the organization default is read-only).
Fix: declare permissions: contents: write on the release job.
tag v0.1.0 doesn't exist in the repo (gh release create --verify-tag)
Cause: the tag has not been pushed yet, or the workflow was triggered by a branch push, and github.ref_name is a branch name.
Fix: confirm the trigger is push: tags; first git push origin TAG.
HTTP 422: Validation Failed — already_exists (uploading assets)
Cause: an asset with the same name already exists. A regular Release can use --clobber; an immutable Release cannot be replaced after publishing.
Fix: handle it at the draft stage; if already published, publish a new version.
The on: release workflow did not run
Cause: the Release was created by GITHUB_TOKEN , which does not trigger a new run; or the event type was written as created but the Release was published from a draft (publishing a draft triggers published).
Fix: switch to a GitHub App token or merge into the same workflow; check types.
The auto-generated notes are empty or include PRs that should not be there
Cause: the previous Release was determined incorrectly (the first Release includes all history), or the PRs were not labeled.
Fix: use --notes-start-tag v1.3.0 to specify the starting point; add labels; use exclude to exclude bot authors.
1. Create a draft Release for v1.4.0 starting from v1.3.0, generate notes automatically, and upload all files under dist.
gh release create v1.4.0 dist/* --draft --verify-tag --generate-notes --notes-start-tag v1.3.0
2. Download v1.4.0's SHA256SUMS, verify the local wheel, and then verify the release attestation.
gh release download v1.4.0 -p SHA256SUMS -p '*.whl' sha256sum -c --ignore-missing SHA256SUMS gh release verify v1.4.0
The team wants “after the Release PR is merged, publish automatically, and the published assets are tamper-proof and traceable to CI.” Design the pipeline.
release-please (see the Git course) maintains the Release PR on main; after merging, in the same workflow release_created == true when it is: build assets → actions/attest generate attestations (module 5) → upload to a draft Release → publish. Immutable releases are enabled for the repository; a tag ruleset blocks manual tag creation v* (set a bypass for the App used by release-please); downstream users verify with gh release verify-asset and gh attestation verify .
Verified instructional videos
Official documentation
Video storyboard (about 70 seconds)
Visual: a tag is placed on a commit like a bookmark, and a Release is a box with notes and files attached to the bookmark.
Narration: tags belong to Git; Releases belong to GitHub.
Visual: a draft box is opened, assets are placed inside one by one, and finally a lock is closed.
Narration: with immutable releases enabled, create a draft, add all assets, then publish. After publishing, the box is locked.
Visual: a user downloads a file, and the terminal shows verified.
Narration: users can run gh release verify to confirm the file is the exact one that was originally published.
Module 4 · GitHub Packages and GHCR
- Log in and push in a workflow using
GITHUB_TOKEN(packages: write), and use a classic PAT or gh token locally to pull and pushghcr.io/OWNER/IMAGE. - Understand the linkage (
org.opencontainers.image.sourcetag, or automatic linking when publishing from a workflow),permission inheritance (inherits access permissions but not visibility), and Manage Actions access. - Use buildx to build linux/amd64 + linux/arm64 multi-architecture images, and read manifest lists (image indexes).
- Use
actions/delete-package-versionsto safely clean up old versions without accidentally deleting multi-architecture child manifests and attestations.
What: GitHub Packages and the Container registry
GitHub Packages is a set of package registries: npm, Maven, Gradle, NuGet, RubyGems, and Container registry (ghcr.io). The old Docker registry (docker.pkg.github.com) has been replaced by ghcr.io. ghcr.io supports fine-grained permissions: images belong to a personal account or an organization (ghcr.io/myorg-lab/myapp), and can be linked to a repository or not.
Why: why use GHCR
- It uses the same identity system as your code: push with
GITHUB_TOKEN, with no separate registry password to manage; the token expires when the job ends. - Public images can be pulled anonymously, and public packages are free in GitHub Packages; Container registry storage and bandwidth are currently free (the official commitment is to give at least one month's notice before changes). Other package types for private packages are billed against plan quotas (Free: 500MB storage / 1GB bandwidth); see the billing docs for details.
- Integrates naturally with artifact attestations: attestations can be pushed to GHCR alongside the image (module 5).
How: authentication and permissions
| Scenario | Credential | Key points |
|---|---|---|
| A workflow pushes images linked to this repository | GITHUB_TOKEN + permissions: packages: write | When publishing from a workflow, the repository is linked automatically and the workflow gets the admin role for that package |
| A workflow pulls other private packages | GITHUB_TOKEN (packages: read) | you need to, in the package settings → Manage Actions access , add that repository as Read |
| Local developers | personal access token (classic): read:packages / write:packages / delete:packages | GitHub Packages only supports classic PATs (fine-grained PATs are not supported); ticking the web option write:packages automatically ticks the broader repo, so use https://github.com/settings/tokens/new?scopes=write:packages to select only package permissions |
| Anonymous | none | public packages only |
Linking and inheritance (most confusing)
- Link: add
LABEL org.opencontainers.image.source=https://github.com/myorg-lab/myappin the Dockerfile, or publish from a workflow in that repository withGITHUB_TOKEN. - Inheritance: for packages published after linking the repository first, access defaults to inheriting the linked repository's access permissions (people with read access to the repository also get read access to the package, and the repository's workflows automatically have access); but visibility is not inherited —a package published for the first time defaults to private private. If the package is linked after publishing, in package settings, inheritance does not happen automatically. Organization owners can turn off automatic inheritance.
- Visibility: public / private (enterprises also have internal). Once changed to public, it cannot be changed back to private. An organization can use Settings → Packages → Package Creation to restrict which visibility members may choose for new packages.
- Namespace conflicts: if a package with the same name was previously pushed from the command line without a linked repository, the
GITHUB_TOKENin the workflow will lack push permission— you need to link the repository in the package settings and grant Actions write access first.
Multi-architecture images
A multi-architecture image is an image index (manifest list), which lists the manifest of each platform image along with its digest; clients pick the one matching their platform when pulling. Build approaches: ① QEMU emulation + buildx builds all platforms on one amd64 runner (simple, but arm64 compilation is slower); ② native runner matrix (for example, a ubuntu-24.04-arm, usable with public repositories) builds each platform separately, then merges them with docker buildx imagetools create (fast, slightly more complex configuration; for arm64 hosted runner availability and billing in private repositories, follow the docs).
When: cleaning up old versions
Every push creates a new “version” (identified by digest; tags are just pointers). Use actions/delete-package-versions (v5,package-type: container) to clean up periodically. Warning: per-platform child manifests of multi-architecture images, and the attestations/signatures pushed with the image, all appear in GHCR as untagged versions; deleting them directly with delete-only-untagged-versions: true may remove child manifests that are still referenced by an index, causing pulls of that tag to fail. In production, either delete only “keep the most recent N”, or use a cleanup tool that recognizes index reference relationships, and rehearse first on a test package.
Permissions diagram: packages, repositories, and workflows
Structure diagram: multi-architecture image index
Interactive builder: how multi-architecture images are built and pulled
Choose the target platforms and build approach, click “Build and push”, and observe the per-platform manifests and the image index generated by buildx; then choose a client platform and click “Pull” to see how the registry returns the matching manifest. Times are illustrative.
Core commands
| Command | Purpose | Notes |
|---|---|---|
gh auth token | docker login ghcr.io -u USER --password-stdin | Log in to GHCR locally | the gh token needs write:packages |
docker buildx build --platform linux/amd64,linux/arm64 -t … --push . | Build and push multi-architecture images | multi-platform results cannot be --load loaded into the local classic image store (unless the containerd image store is enabled) |
docker buildx imagetools inspect IMAGE | View the index and per-platform digests | --format '{{json .Manifest}}' |
docker buildx imagetools create -t TAG IMG@sha256:a IMG@sha256:b | Merge natively built platform images | native matrix approach |
gh api /orgs/ORG/packages/container/NAME/versions | List package versions | requires read:packages |
gh api -X DELETE /orgs/ORG/packages/container/NAME/versions/ID | Delete a version | requires delete:packages and package admin |
Workflow: build and push multi-architecture images to GHCR
name: publish-image
on:
push:
branches: [main]
tags: ["v*.*.*"]
permissions: {}
jobs:
image:
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ghcr.io/${{ github.repository }} # metadata-action lowercases the name
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs:
digest: ${{ steps.push.outputs.digest }}
How to verify:docker buildx imagetools inspect ghcr.io/myorg-lab/myapp:latest shows two platforms. Notes: The metadata generated by metadata-action labels already includes org.opencontainers.image.source (pointing to the current repository), so the first publish links the repository; annotations makes the multi-architecture image show a description on the package page. steps.push.outputs.digest is the digest of the index, which module 5 uses to generate attestations.
Cleanup: keep the most recent 20 versions
name: ghcr-cleanup
on:
schedule: [{cron: "17 3 * * 0"}]
workflow_dispatch:
permissions: {}
jobs:
prune:
runs-on: ubuntu-24.04
permissions:
packages: write
steps:
- uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0
with:
package-name: myapp
package-type: container
min-versions-to-keep: 20
ignore-versions: '^v\d+\.\d+\.\d+$' # never delete semantic versions (matched by version name; follow the README)
The repository needs a Admin role on the package (automatically granted to packages published from that repository's workflows). The ability for workflows to delete/restore packages via the REST API is currently in public preview. For the untagged-version issue with multi-architecture images and attestations, see “Theory”.
Lab 4: push amd64 + arm64 images and set visibility (about 7 min)
gh auth token | docker login ghcr.io -u "$(gh api user --jq .login)" --password-stdin docker buildx create --name multi --use 2>/dev/null || docker buildx use multi docker buildx build --platform linux/amd64,linux/arm64 \ --label org.opencontainers.image.source=https://github.com/$ORG/myapp \ -t ghcr.io/$ORG/myapp:local-test --push . docker buildx imagetools inspect ghcr.io/$ORG/myapp:local-test
Name: ghcr.io/myorg-lab/myapp:local-test
MediaType: application/vnd.oci.image.index.v1+json
Digest: sha256:9a1f…
Manifests:
Name: ghcr.io/myorg-lab/myapp:local-test@sha256:3c7e…
Platform: linux/amd64
Name: ghcr.io/myorg-lab/myapp:local-test@sha256:b04d…
Platform: linux/arm64
Name: ghcr.io/myorg-lab/myapp:local-test@sha256:77aa…
Platform: unknown/unknown
Annotations:
vnd.docker.reference.type: attestation-manifest
unknown/unknown is the provenance attestation manifest that buildx attaches by default (BuildKit's own SLSA provenance, which differs from the GitHub artifact attestation in module 5).
cd ~/src/myapp && git add .github/workflows/publish-image.yml git commit -m "ci: publish multi-arch image to GHCR" && git push org main gh run watch -R $ORG/myapp $(gh run list -R $ORG/myapp -w publish-image -L1 --json databaseId --jq '.[0].databaseId')
gh api /orgs/$ORG/packages/container/myapp --jq '{name, visibility, repository: .repository.full_name}'
gh api /orgs/$ORG/packages/container/myapp/versions --jq '.[] | {id, name, tags: .metadata.container.tags}' | head -20
{"name":"myapp","repository":"myorg-lab/myapp","visibility":"private"}
{"id":512345678,"name":"sha256:9a1f…","tags":["latest","sha-1a2b3c4"]}
{"id":512345671,"name":"sha256:3c7e…","tags":[]}
…docker logout ghcr.io
docker pull --platform linux/arm64 ghcr.io/$ORG/myapp:latest
docker image inspect ghcr.io/$ORG/myapp:latest --format '{{.Architecture}}'
arm64
local-test this one index, to demonstrate the API):
VID=$(gh api /orgs/$ORG/packages/container/myapp/versions --jq '.[] | select(.metadata.container.tags | index("local-test")) | .id')
gh api -X DELETE /orgs/$ORG/packages/container/myapp/versions/$VIDCase 1: migrating from Docker Hub to GHCR
Problem: Docker Hub pull rate limits caused occasional CI failures, and team account passwords were scattered across the secrets of multiple repositories. Approach: Switch image pushes to GHCR, with the workflow using GITHUB_TOKEN; the deployment repository gets read-only access via Manage Actions access; delete all Docker Hub password secrets. Limitation: A Kubernetes cluster pulling private GHCR images still needs an imagePullSecret (a classic PAT or a bot account), or the image must be made public.
Case 2: exec format error on Graviton nodes
Problem: After arm64 nodes were added to EKS, some Pods reported exec /usr/local/bin/gunicorn: exec format error. Cause: the image was only built for amd64. Approach: Change the build to platforms: linux/amd64,linux/arm64; for services where arm64 compilation is very slow, switch to a native arm64 runner matrix + imagetools create.
Case 3: a cleanup script deleted the latest tag by mistake
Problem: To save space, a rule to “delete all untagged versions” was configured; the next day, pulling latest failed with manifest unknown. Cause: the platform sub-manifests referenced by the multi-architecture index are untagged versions in GHCR, and were deleted along with it. Approach: switch to keeping a fixed number of versions, and rehearse with a test package; afterward, rebuild and push the affected tags.
Common errors and fixes
denied: installation not allowed to Write organization package
Cause: the job is missing packages: write; or a package with the same name already exists but is not linked to this repository, or this repository is not Write/Admin in the package's Manage Actions access.
Fix: add the permission; link the repository in the package settings or add Actions access; before the first publish, add a org.opencontainers.image.source label to the image.
ERROR: failed to push ghcr.io/myorg-lab/MyApp:latest: invalid reference format: repository name must be lowercase
Cause:github.repository the name contains uppercase letters.
Fix: use metadata-action to generate the tags (it lowercases them), or convert in the shell with ${GITHUB_REPOSITORY,,} .
unauthorized: unauthenticated: User cannot be authenticated with the token provided.
Cause: a fine-grained PAT was used locally, the token expired, or the classic PAT lacks read:packages; when organization SAML SSO is enabled, the token is not authorized for SSO.
Fix: switch to a classic PAT and authorize SSO; or gh auth refresh -s read:packages.
docker exporter does not currently support exporting manifest lists
Cause: a multi-platform build used --load (or build-push-action's load: true).
Fix: for multi-platform builds use --push; for local single-platform testing, --platform linux/amd64 --load, or enable the containerd image store.
exec /bin/sh: exec format error (during the QEMU build stage)
Cause: QEMU binfmt is not installed (setup-qemu-action is missing), but a non-native platform is being built.
Fix: Before setup-buildx, add docker/setup-qemu-action, or switch to a native runner.
1. List which platforms ghcr.io/myorg-lab/myapp:latest contains.
docker buildx imagetools inspect ghcr.io/myorg-lab/myapp:latest
2. List all version IDs and tags of the organization's container package myapp.
gh api --paginate /orgs/myorg-lab/packages/container/myapp/versions --jq '.[] | "\(.id) \(.metadata.container.tags|join(","))"'deploy-repo's workflow reports denied when pulling myapp's private image, while myapp's own workflows push and pull normally. Why? How do you fix it with least privilege?
The package inherits the access permissions of the myapp repository, so myapp's workflows automatically have access; deploy-repo is not included. Fix: in package settings → Manage Actions access, add deploy-repo with the Read role; in deploy-repo's job, declare packages: read and log in with GITHUB_TOKEN . Do not create a long-lived PAT for this.
Verified instructional videos
Official documentation
- Working with the Container registry
- Configuring a package's access control and visibility
- Docker Docs: Multi-platform image with GitHub Actions
Video storyboard (about 80 seconds)
Visual: a “link” line between the repository and the package; permissions flow along the line, but the “visibility” switch exists separately.
Narration: a package can inherit the repository's access permissions, but visibility must be set separately, and once public it cannot be changed back to private.
Visual: one tag points to an index, which branches into amd64 and arm64 manifests; the arm64 client downloads only its own.
Narration: a multi-architecture image is a list of manifests, and clients pick by platform.
Visual: a cleanup script sweeps through untagged versions; after a child manifest is accidentally deleted, latest turns red.
Narration: be careful when cleaning up—child manifests and attestations are also untagged versions.
Module 5 · Artifact attestations and the supply chain (SLSA)
- Use
actions/attestto generate SLSA build provenance and SBOM attestations for binaries and container images, correctly declaringid-token: write,attestations: writeand other permissions. - Explain the attestation generation chain: OIDC token → Sigstore Fulcio short-lived certificate → signed in-toto statement → transparency log (public repositories) → stored in the GitHub attestations API / pushed to the image registry.
- Use
gh attestation verifyto verify, and use--signer-workflow,--source-ref,--deny-self-hosted-runnersand similar options to tighten the policy. - Know that artifact attestations separately provide SLSA v1.0 Build L2, which, combined with reusable workflow builds, can reach Build L3; understand how they relate to cosign / Notation.
What: what an artifact attestation is
An in-toto statement: subject (artifact name + SHA-256 digest) + predicate (assertions about it). actions/attest Three modes are supported:
| Mode | Trigger condition | predicate |
|---|---|---|
| Provenance (default) | not passed sbom-path / predicate input | generated automatically SLSA build provenance v1: build workflow, repository, ref, commit, triggering event, runner environment |
| SBOM | pass sbom-path (SPDX or CycloneDX JSON, ≤16MB) | SBOM content |
| Custom | pass predicate-type + predicate/predicate-path | custom predicates (such as test reports or scan results) |
Version notes (verified 2026-11-15): actions/attest v4.2.2 is the recommended entry point; actions/attest-build-provenance from v4 onward it is only its wrapper (latest v4.2.2), so old code can continue to be used; actions/attest-sbom (v4.1.0) is marked deprecated, migrating to actions/attest of sbom-path. Up to 1024 subjects per call.
Why: what else to prove beyond signing
Traditional signing only shows “whose private key signed this file”. Supply-chain attacks (SolarWinds, Codecov, tj-actions) often happen during the build: the source is fine, but the build environment is tampered with. Attestations bind the artifact to the build process: verifiers can require that only images built by myorg-lab/platform-workflows/.github/workflows/python-build.yml on GitHub-hosted runners, from refs/heads/main are accepted. The whole process requires no long-lived private key to manage—identity comes from the workflow's OIDC token.
How: generation chain
- After the job obtains
id-token: write, the actionactions/attestrequests an ID token from the GitHub OIDC provider (audience sigstore), which containsrepository,job_workflow_ref,sha,ref,runner_environmentand other claims. - The action generates an ephemeral key pair and hands the ID token to Fulcio (certificate authority). Fulcio verifies the token and issues a code-signing certificate valid for about 10 minutes, with the workflow identity written into the certificate extension fields.
- Signs the in-toto statement with DSSE using the ephemeral private key, which is then discarded.
- Public repositories: they use the public Sigstore instance, and signature records are written to a public, append-only transparency log Rekor; Private/internal repositories (requires GitHub Enterprise Cloud): they use GitHub's own Sigstore instance,no transparency log, and it federates only with GitHub Actions.
- The result is packaged as Sigstore bundle (certificate + signature + log/timestamp proof), uploaded to the repository's attestations API (indexed by subject digest, visible on the repository's Actions → Attestations page);
push-to-registry: truefor images, it is also pushed to the image registry as an OCI artifact; the local path is written to$RUNNER_TEMP/created_attestation_paths.txt.
Verification flow (gh attestation verify)
- computes the digest of a local file or
oci://image (the image must be accessible to resolve the digest). - fetches the attestation by digest from the GitHub API (or uses a local file, or reads from the image registry with
--bundle,--bundle-from-ocifor offline or isolated environments). - uses the Sigstore trust root to verify the certificate chain, signature, and transparency log / timestamp (the certificate only needs to have been valid at signing time; expiry does not affect it).
- checks the identity in the certificate against the policy you provide:
--owneror--repo(one is required),--signer-workflow/--signer-repo(where the build definition came from),--source-ref,--cert-oidc-issuer,--deny-self-hosted-runners;--predicate-typethe default is SLSA provenance v1; when verifying an SBOM, specify it explicitly.
SLSA level
| SLSA v1.0 Build level | Requirement (simplified) | How GitHub meets it |
|---|---|---|
| L1 | Has build provenance | generating provenance satisfies it |
| L2 | Hosted build platform + platform-signed provenance | artifact attestations alone provide Build L2 (GitHub-hosted runners + Sigstore signing) |
| L3 | Hardened build platform: builds are isolated from each other, signing material is not accessible to build steps, and provenance cannot be forged | in an organization-shared reusable workflow, building and attesting there keeps the build definition isolated from the caller; during verification, use --signer-workflow to pin that reusable workflow |
Relationship with cosign / Notation
- cosign (Sigstore project CLI, currently v3.1.4): the same Sigstore infrastructure. GitHub attestations use the standard Sigstore bundle format, so in theory they can be verified with Sigstore ecosystem tools; but
gh attestation verifyhas GitHub's trust root and identity policies built in, and is the officially recommended approach. cosign can also sign images on its own in a workflow using keyless mode (cosign sign), and the two can coexist. - Notation (Notary Project): a signing scheme based on X.509 certificates and an organization-managed CA (often paired with Azure Key Vault / ACR), a separate system from Sigstore. GitHub attestations do not produce Notation signatures; if the deployment side (such as AKS + Ratify) only trusts Notation, you need extra signing.
- Kubernetes enforcement: GitHub's documentation describes how to verify GitHub attestations with Sigstore policy-controller at cluster admission time (including configuring the GitHub trust root).
Scope
all current GitHub plans for public repositories are supported; private/internal repositories on Free / Pro / Team plans are not supported (GitHub Enterprise Cloud required); GitHub Enterprise Server is not supported; legacy Bronze/Silver/Gold plans are not supported.
--owner is enough”—any repository and any workflow in the organization (including compromised ones) can produce attestations that match the owner; in production, add --signer-workflow and --source-ref. ③ “The provenance built into buildx is the GitHub attestation”—BuildKit's provenance is not signed with a GitHub identity and cannot be verified with gh attestation verify . ④ “Verifying an image by tag”—attestations are bound to the digest, and tags can move.Architecture diagram: attestation generation and verification
Comparison diagram: build topology for SLSA Build L2 vs. L3
Core animation: generating and verifying build attestations (OIDC → Sigstore → storage → gh attestation verify)
First choose the repository visibility and click “Generate attestation” to step through the process; then choose an “attack / error” scenario, click “Verify”, and see gh attestation verify at which step it fails.
Core commands
| Command | Purpose | Notes |
|---|---|---|
gh attestation verify FILE -R OWNER/REPO | Verify a local artifact | or --owner ORG |
gh attestation verify oci://IMAGE:TAG --owner ORG | verify an image | requires access to the image registry |
--signer-workflow O/R/.github/workflows/f.yml | pin the workflow that signed it | key for L3 verification |
--source-ref refs/heads/main | restrict the build source branch/tag | reject artifacts built from feature branches |
--deny-self-hosted-runners | reject artifacts built on self-hosted runners | |
--predicate-type https://spdx.dev/Document/v2.3 | Verify an SBOM attestation | only verifies SLSA provenance v1 by default |
--format json --jq '.[].verificationResult.statement.predicate' | View attestation contents | |
gh attestation download FILE -R O/R / gh attestation trusted-root | Preparing for offline verification | Together with --bundle,--custom-trusted-root |
workflow: image provenance + SBOM attestations
permissions:
contents: read
packages: write # push images and push-to-registry
id-token: write # request a certificate from Sigstore
attestations: write # write to the attestations API
artifact-metadata: write # create storage records in the organization repository (with push-to-registry)
steps:
# …checkout / login / build-push (id: push) same as module 4…
- name: Attest build provenance
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }} # do not include a tag; must be all lowercase
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Generate SBOM
uses: anchore/sbom-action@fffec3d851af758d56fee099cf3fbf8aa8779843 # v0.24.3
with:
image: ghcr.io/${{ github.repository }}@${{ steps.push.outputs.digest }}
format: spdx-json
output-file: sbom.spdx.json
- name: Attest SBOM
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
sbom-path: sbom.spdx.json
push-to-registry: true
artifact-metadata: write from the actions/attest README (2026-11): push-to-registry creates a “storage record” by default (organization repositories only; can be turned off with create-storage-record: false ), viewable on the organization's Linked Artifacts page. If the github.repository contains uppercase letters,subject-name convert it to lowercase first.
Verification
gh attestation verify oci://ghcr.io/myorg-lab/myapp:latest \ --repo myorg-lab/myapp \ --signer-workflow myorg-lab/platform-workflows/.github/workflows/python-build.yml \ --source-ref refs/heads/main \ --deny-self-hosted-runners
Loaded digest sha256:9a1f… for oci://ghcr.io/myorg-lab/myapp:latest Loaded 1 attestation from GitHub API The following policy criteria will be enforced: - Predicate type must match:................ https://slsa.dev/provenance/v1 - Source Repository Owner URI must match:... https://github.com/myorg-lab - Source Repository URI must match:......... https://github.com/myorg-lab/myapp - Source repository ref must match:......... refs/heads/main - Subject Alternative Name must match regex: (?i)^https://github.com/myorg-lab/platform-workflows/.github/workflows/python-build.yml - OIDC Issuer must match:................... https://token.actions.githubusercontent.com - Action workflow Runner Environment must match: github-hosted ✓ Verification succeeded! The following 1 attestation matched the policy criteria - Attestation #1 - Build repo:..... myorg-lab/myapp - Build workflow:. .github/workflows/ci.yml@refs/heads/main - Signer repo:.... myorg-lab/platform-workflows - Signer workflow: .github/workflows/python-build.yml@refs/tags/v1
Lab 5: generate and verify attestations for an image (about 8 min)
python-build.yml of platform-workflows: the build job's permissions add id-token: write,attestations: write,artifact-metadata: write, and after build-push add the three steps from the “Commands” page (run only when inputs.push is true: if: inputs.push). Push a new tag:
cd ~/src/platform-workflows git commit -am "feat: attest provenance and SBOM" && git push git tag -a v1.1.0 -m v1.1.0 && git tag -f v1 && git push origin v1.1.0 && git push -f origin v1
permissions:
contents: read
packages: write
id-token: write
attestations: write
artifact-metadata: write
cd ~/src/myapp && git commit -am "ci: grant attestation permissions" && git push org main gh run watch -R $ORG/myapp $(gh run list -R $ORG/myapp -w ci -L1 --json databaseId --jq '.[0].databaseId')
DIGEST=$(docker buildx imagetools inspect ghcr.io/$ORG/myapp:latest --format '{{json .Manifest}}' | jq -r .digest)
gh api repos/$ORG/myapp/attestations/$DIGEST --jq '.attestations | length'gh attestation verify oci://ghcr.io/$ORG/myapp:latest --repo $ORG/myapp \ --signer-workflow $ORG/platform-workflows/.github/workflows/python-build.yml gh attestation verify oci://ghcr.io/$ORG/myapp:latest --repo $ORG/myapp \ --predicate-type https://spdx.dev/Document/v2.3 --format json \ --jq '.[0].verificationResult.statement.predicate.packages | length'
latest), then verify again:
docker buildx build --platform linux/amd64 -t ghcr.io/$ORG/myapp:latest --push . gh attestation verify oci://ghcr.io/$ORG/myapp:latest --repo $ORG/myapp
Loaded digest sha256:e41b… for oci://ghcr.io/myorg-lab/myapp:latest ✗ Loading attestations from GitHub API failed Error: no attestations found for subject sha256:e41b…
Conclusion: in deployment, reference the image by digest, and verify before deploying. After the lab, re-run CI to restore latest.
Case 1: mandatory verification before deployment
Problem: An audit requires that “production only runs images built by a trusted pipeline.”Approach: The deployment workflow runs kubectl set image before gh attestation verify oci://…@sha256:… --owner org --signer-workflow org/platform-workflows/.github/workflows/build.yml --source-ref refs/heads/main --deny-self-hosted-runners, and stops on failure. On the cluster side, Sigstore policy-controller adds a second admission check. Limitation: Private repositories require GHEC; verification needs access to the GitHub API (for offline environments, use --bundle + trusted-root).
Case 2: downstream verification for an open-source CLI
Problem: Users download binaries from the Release page and cannot tell whether they were replaced. Approach: The release workflow generates subject-path: dist/* provenance for all binaries, and the README provides gh attestation verify ./tool -R org/tool; combined with immutable releases. Effect: Attestations for public repositories are also recorded in the public Rekor log, so anyone can audit them.
Case 3: the risk of verifying only with --owner
Problem: A company verified only with --owner . An attacker built a malicious image in a low-privilege experimental repository inside the organization, and it passed verification as well. Approach: Add --signer-workflow to pin the platform team's reusable workflow, and protect the platform-workflows repository with a ruleset (module 7).
Common errors and fixes
Error: Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable
Cause: the job is missing id-token: write; or in a fork PR's pull_request run (it cannot obtain an OIDC token).
Fix: declare the permissions; run the attestation steps only on trusted events such as push / tag / release.
Error: Failed to persist attestation: Resource not accessible by integration
Cause: missing attestations: write; or the private repository is not on a GHEC plan.
Fix: add the permission; Free/Team private repositories cannot use this—switch to a public repository or upgrade.
✗ Verification failed — expected SourceRepositoryOwnerURI to be https://github.com/other-org
Cause:--owner/--repo it does not match the repository that actually built it; or the image came from a fork.
Fix: check the --format json build repo in the output; if the policy is wrong, correct the policy; if the source is wrong, reject the artifact.
no attestations found for subject sha256:…
Cause: the tag was re-pushed (the digest changed); the attestation subject used a platform child manifest instead of the index digest; or the attestation was written to another repository (the -R argument was wrong during verification).
Fix: verify by digest; when attesting, use the output of build-push-action; digest confirm the build repository.
expected SAN to match regex …platform-workflows… but was …/myapp/.github/workflows/ci.yml
Cause: the attestation was generated by the application repository's own workflow, so it does not satisfy the --signer-workflow policy.
Fix: run building and attesting in the shared reusable workflow; confirm that the caller actually went through the shared workflow.
1. Verify that the local dist/myapp-0.1.0-py3-none-any.whl was built by myorg-lab/myapp and comes from the v0.1.0 tag.
gh attestation verify dist/myapp-0.1.0-py3-none-any.whl -R myorg-lab/myapp --source-ref refs/tags/v0.1.0
2. Prepare offline verification material for an isolated network environment.
gh attestation download dist/app.tar.gz -R myorg-lab/myapp # generates sha256:….jsonl gh attestation trusted-root > trusted_root.jsonl # in the isolated environment: gh attestation verify dist/app.tar.gz -R myorg-lab/myapp --bundle sha256-….jsonl --custom-trusted-root trusted_root.jsonl
The security team asks: “We already sign images with cosign. Do we still need GitHub artifact attestations?” How would you answer?
It depends on what the signature answers. cosign keyless signing is also based on Sigstore and OIDC identity, so in essence it can also prove “which workflow signed it”; GitHub attestations additionally provide standardized SLSA provenance content (build parameters, source commit, runner environment), storage and retrieval integrated with the GitHub API/UI,gh attestation verify built-in policies, and SBOM attestations. The two can coexist: existing cosign verification paths (such as Kyverno policies) stay as they are, and verification policies can gradually move to provenance content (signer workflow, source ref). If the deployment side only supports Notation, Notation signatures are still needed.
Verified instructional videos
Official documentation
- Artifact attestations (concepts, SLSA levels, Sigstore instances)
- Using artifact attestations
- Achieve SLSA v1 Build Level 3 with reusable workflows
- actions/attest
- gh attestation verify
Video storyboard (about 90 seconds)
Visual: an image box has a digest label on it, with a “birth certificate” beside it.
Narration: the attestation states where the artifact with this digest came from and who built it.
Visual: the runner takes an OIDC token to Fulcio and exchanges it for a certificate valid for 10 minutes; after signing, the certificate is discarded and the signature record enters the Rekor ledger.
Narration: there is no long-lived private key; identity comes from the workflow, and the signature record is written to a public ledger.
Visual: a verifier checks off items one by one: digest, certificate chain, log, repository, workflow, branch, hosted runner.
Narration: verification does not only check that the signature is valid; it also checks whether a workflow you trust built the artifact.
Visual: an attacker overwrites the latest tag, and verification shows “no attestations found”.
Narration: tags can be overwritten; digests and attestations do not lie.
Module 6 · Actions security hardening
- Use SHA pinning or workflow dependency lock files (
gh actions-lock) to pin third-party actions, and keep them updated with Dependabot. - Default
permissions: {}, grant least privilege per job; understandpersist-credentials. - Explain
pull_request_target/workflow_runthe “pwn request” risk of, and the checkout v7 protections and GitHub's default event policy. - Identify and fix script injection: pass
${{ github.event.* }}throughenvenv first, then reference it in the script. - Use zizmor and OpenSSF Scorecard to audit workflows, and be able to review the tj-actions/changed-files incident.
What: the Actions threat model
| Attack surface | Typical technique | Protection |
|---|---|---|
| Third-party actions / reusable workflows | A maintainer's account or token is stolen, and a tag is repointed to a malicious commit (tj-actions) | SHA pinning or lock files; organization allowlists; fewer dependencies |
| Untrusted input | shell commands embedded in PR titles, branch names, or comments (script injection) | pass expressions via env; use action inputs instead of inline scripts |
| Privileged triggers executing untrusted code | pull_request_target checking out fork code and then npm install/make (pwn request) | Switch to pull_request; checkout v7 blocks by default; Actions event policy |
| excessive token permissions | injected steps use a write token to push code or modify Releases | permissions: {} + least-privilege permissions per job; organization default is read-only |
| leftover credentials | later steps or uploaded artifacts read the token saved by checkout (artipacked) | persist-credentials: false; do not upload the entire workspace |
| cache poisoning | a low-trust run writes to the cache, which a high-trust run then restores | pull_request_target default-branch caches are read-only for other runs (GitHub default); zizmor cache-poisoning |
| self-hosted runners | fork PRs from public repositories execute on internal-network runners | do not use self-hosted runners with public repositories; ephemeral runners; Hour 7 |
Pin dependencies: SHAs, lock files, and Dependabot
- SHA pinning:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1. A full 40-character SHA cannot be moved (forging one would require a SHA-1 collision with a valid object). Make sure the SHA belongs to the original repository, not a fork (zizmor'simpostor-commitaudit specifically checks this). - workflow dependency lock files (new in 2026, verified in the docs 2026-11):
.github/workflows/actions.lock, generated by the GitHub CLI extensiongh actions-lock(gh extension install github/gh-actions-lock). It records the commit SHA each action reference resolves to, plus the source repository'sowner_id/repo_id,including transitive dependencies (actions used inside the actions you use). At runtime it verifies that the commit is reachable from the recorded tag or branch and that the repository identity has not changed. Official wording: repositories that adopt lock files no longer need to write SHAs in workflow files, and the lock file satisfies the organization's “SHA pinning required” policy. does not cover reusable workflow calls (jobs.<id>.uses; these must use a SHA or their own lock file in their repository), and also do not cover./local actions (it is recommended to change them to$/). - Dependabot:
package-ecosystem: github-actionsDependabot will open upgrade PRs for tag and SHA pins (with# vX.Y.Zcomments). However, Dependabot vulnerability alerts only apply to actions that use semantic versions, not to SHA-pinned actions—SHA-pinned repositories must rely on version-update PRs or zizmorknown-vulnerable-actionsto find vulnerable versions. zizmor also providesdependabot-cooldownaudits; we recommend setting a cooldown period for updates to avoid pulling in a newly poisoned version right away.
Minimize permissions
Write permissions: {} at the top level of the workflow, then list only the permissions each job needs. Once a job declares permissions, anything unlisted becomes none. Common combinations: testing contents: read; pushing images packages: write; attestations id-token: write + attestations: write; publishing a Release contents: write; PR comments pull-requests: write; uploading SARIF security-events: write. actions/checkout Default persist-credentials: true (from v6 it is saved in $RUNNER_TEMP a separate file rather than .git/config, but later steps can still use it); jobs that do not need git push should set it to false.
pull_request_target and workflow_run
pull_request(fork PRs): runs the workflow in the PR merge commit, with a read-only token and no secrets—the safe default.pull_request_target: runs the base repository's default branch workflows, with secrets and a writable token. It is safe in itself; the danger is when the author pointsactions/checkoutto the PR head (ref: ${{ github.event.pull_request.head.sha }}) and then executes the checked-out code (building, testing, installing dependencies, reading its config files)—this is the “pwn request”.workflow_run: runs with privileges after another workflow completes; if it downloads artifacts uploaded by a fork PR run and executes or trusts their contents, that is also a pwn request. Artifacts are untrusted data.- GitHub's new protections (2026, verified): ①
actions/checkoutstarting from v7.0.0, forpull_request_target/workflow_runworkflows triggered by , checkout denies fork PR code by default, and when truly needed, explicitly setallow-unsafe-pr-checkout: true(the name is deliberately conspicuous to aid review and static analysis); this protection does not covergit fetch,gh pr checkout, downloading artifacts, or other ways of fetching code. ② Default event policy in Actions policies: for public repositories without an applicable event policy, GitHub has added a default policy that blockspull_request_target(currently in evaluate mode); from 2026-12-02 it will be enforced for affected repositories that used the default policy before GA; private/internal repositories are not affected. Repositories that need it must create an explicit event policy that allowspull_request_target. ③pull_request_targetRun-level caches are scoped to the default branch and read-only for other runs, preventing cache poisoning.
Script injection
run: : the ${{ … }} expressions in are text-substituted by the runner before the script file is generated, and the result is then handed to bash for execution. If the value comes from an attacker (PR title or body, branch name head_ref, commit message, comment, issue title, author name or email, and so on), it effectively lets the attacker write your script. Fix: put the expression into env: the env block, and in the script use "$VAR" to reference it—the value is then passed in as an environment variable, and bash treats it only as data. An even better approach is to pass the value as an with input to a JS action. GITHUB_ENV/GITHUB_OUTPUT Writing untrusted multi-line content is equally dangerous (zizmor github-env).
Audit tool
| Tool | What it does | verified 2026-11 |
|---|---|---|
| zizmor | static analysis of workflows / actions: template-injection,excessive-permissions,unpinned-uses,artipacked,dangerous-triggers,dangerous-checkout,cache-poisoning,secrets-inherit,impostor-commit,known-vulnerable-actions,dependabot-cooldown and 40+ other checks; can output SARIF to code scanning | v1.32.0 (2026-11-02); zizmorcore/zizmor-action v0.8.1 |
| OpenSSF Scorecard | scores the repository's supply-chain practices (0–10): Dangerous-Workflow, Token-Permissions, Pinned-Dependencies, Branch-Protection, Code-Review, Signed-Releases, Dependency-Update-Tool, etc. | ossf/scorecard-action v2.5.0 |
| CodeQL (actions language) | code scanning can also analyze injection and dangerous patterns in workflows (Hour 6) | free for public repositories |
Case review: tj-actions/changed-files (CVE-2025-30066 / GHSA-mrrh-fwg8-r2c3)
- What happened: on 2025-03-14/15, attackers repointed multiple version tags of the action to a malicious commit; the malicious code read secrets from the Runner.Worker process memory on the runner and printed them in encoded form to the build logs—public repositories logs are readable by anyone, so a large number of secrets were exposed. Upstream investigation points to a chain of token leaks as the entry point (related to the same-period poisoning of
reviewdog/action-setup, CVE-2025-30154); follow the official advisory for details. - Impact: every repository that referenced it by a tag (such as
@v45) executed the malicious code during that window; repositories pinned by SHA to an older commit were not affected (unless they happened to pin the malicious SHA). The fixed version is 46.0.1. - Lessons: ① mutable tags → SHA pinning / lock files; ② public logs → even when secrets are masked, encoded values can still leak, so all potentially exposed secrets must be rotated afterwards; ③ use the organization's allowlist
!syntax to quickly block an action; ④ use few niche third-party actions—if a few lines of shell or an official action can do the job, implement it yourself; ⑤ a Dependabot cooldown period prevents pulling in a malicious new version right away.
@v4 is safe”—official actions carry low risk, but third-party action tags can be moved by anyone who gets write access. ② “Secrets are masked in logs, so they cannot leak”—masking only matches the raw value; encoded or split values are not recognized. ③ “pull_request_target is itself a vulnerability”—the danger is executing untrusted code inside it. ④ “Quoting the expression "${{ … }}" makes it safe”—an attacker can close the quotes first.Comparison diagram: pull_request vs. pull_request_target
Flowchart: at which step script injection happens
Interactive simulator: script injection attack and defense
Enter a “PR title”, choose a workflow style, and click “Run”. The simulator shows the real runner order: expression substitution → the generated script file → the commands bash actually executes.
Core commands and configuration
| Command | Purpose | Notes |
|---|---|---|
git ls-remote https://github.com/OWNER/REPO refs/tags/vX.Y.Z | Look up the SHA for a tag | for annotated tags, also check ^{} line |
gh extension install github/gh-actions-lock → gh actions-lock | Generate a lock file | --migrate-local-actions Pass ./ Change to $/ |
uvx zizmor .github/workflows/ | offline audit | can also be used pipx run zizmor,brew install zizmor |
GH_TOKEN=$(gh auth token) uvx zizmor . | enable online audit | impostor-commit, known-vulnerable-actions, ref-confusion |
uvx zizmor --fix=safe . | automatically fix some issues | availability is determined by --help the installed version |
scorecard --repo=github.com/ORG/REPO | Scorecard CLI | requires GITHUB_AUTH_TOKEN |
a before-and-after comparison
on: pull_request_target
permissions: write-all
jobs:
greet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # check out fork code
- run: npm ci && npm test # running it = pwn request
- run: echo "Thanks for ${{ github.event.pull_request.title }}" # script injection
- uses: tj-actions/changed-files@v45 # mutable tag
on: pull_request # use pull_request if no secrets are needed
permissions: {}
jobs:
test:
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: npm ci && npm test
- env:
TITLE: ${{ github.event.pull_request.title }}
run: echo "Thanks for $TITLE"
- id: changed # compute with git itself, without depending on a third-party action
env:
BASE: ${{ github.event.pull_request.base.sha }}
run: |
git fetch --no-tags --depth=1 origin "$BASE"
git diff --name-only "$BASE" HEAD > changed.txt
.github/dependabot.yml
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7 # open PRs only 7 days after a new version is released (follow the Dependabot docs for the field names)
groups:
actions:
patterns: ["*"]
.github/workflows/audit.yml (zizmor + Scorecard)
name: audit
on:
push:
branches: [main]
schedule: [{cron: "30 4 * * 1"}]
permissions: {}
jobs:
zizmor:
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write # upload SARIF to code scanning (free for public repositories)
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
scorecard:
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
id-token: write # needed for publish_results
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ossf/scorecard-action@46dc3187a971a9febf3aeb7f94ccde489f7bb46a # v2.5.0
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- uses: github/codeql-action/upload-sarif@v4 # in production, pin the SHA as well
with:
sarif_file: results.sarif
Lab 6: scan and fix myapp with zizmor (about 9 min)
.github/workflows/bad.yml (you can scan without pushing).cd ~/src/myapp uvx zizmor@1.32.0 .github/workflows/
error[dangerous-triggers]: use of fundamentally insecure workflow trigger --> .github/workflows/bad.yml:1:1 error[template-injection]: code injection via template expansion --> .github/workflows/bad.yml:11:14 warning[excessive-permissions]: overly broad permissions --> .github/workflows/bad.yml:2:1 error[unpinned-uses]: unpinned action reference --> .github/workflows/bad.yml:12:15 warning[artipacked]: credential persistence through GitHub Actions artifacts --> .github/workflows/bad.yml:6:9 … N findings (…): X high, Y medium …
GH_TOKEN=$(gh auth token) uvx zizmor@1.32.0 .github/workflows/bad.yml
should additionally show known-vulnerable-actions: tj-actions/changed-files@v45 is affected by GHSA-mrrh-fwg8-r2c3.
rm .github/workflows/bad.yml gh extension install github/gh-actions-lock gh actions-lock --migrate-local-actions git diff --stat; cat .github/workflows/actions.lock | head -20 uvx zizmor@1.32.0 .github/workflows/
dependabot.yml and audit.yml, then after running, check the zizmor and Scorecard results under Security → Code scanning:
git add .github && git commit -m "ci: dependabot, lockfile, zizmor and scorecard" && git push org main gh api repos/$ORG/myapp/code-scanning/alerts --jq '.[] | "\(.tool.name)\t\(.rule.id)\t\(.state)"' | head
Case 1: incident response on the day of the tj-actions event
Problem: 40 of the company's 300 repositories used tj-actions/changed-files@v4x. Approach:① immediately add !tj-actions/changed-files@* to the organization allowlist to block it; ② use code search and referenced_workflows/run logs to find repositories that executed it during the incident window; ③ rotate all secrets accessible to those repositories (including organization-level secrets); ④ for public repositories, check whether encoded secrets appear in the logs; ⑤ switch to SHA pinning + a Dependabot cooldown period, or replace it with git commands. Lesson: SHA pinning beforehand is far cheaper than emergency response afterward.
Case 2: a pwn request in a labeling bot
Problem: An open-source project used pull_request_target to label PRs automatically; later someone added a checkout of the PR head plus npm ci to “run lint along the way”, and a malicious postinstall PR stole the npm publish token. Approach: Split into two workflows: pull_request run lint/test (no secrets); pull_request_target only call the API to apply labels, without checking out code. After upgrading to checkout v7, similar mistakes are blocked by default.
Case 3: branch name injection
Problem: In a workflow, run: ./deploy.sh ${{ github.head_ref }}, someone created a branch named a;curl${IFS}…|sh (branch names allow these characters). Approach: Change it to env: REF: ${{ github.head_ref }} + ./deploy.sh "$REF"; add zizmor blocking to CI template-injection.
Common errors and fixes
checkout fails in pull_request_target with: refusing to check out fork pull request code (allow-unsafe-pr-checkout)
Cause: checkout v7 blocks by default checking out fork PR code in pull_request_target/workflow_run workflows (follow the actual error text).
Fix: Preferably switch to pull_request; only if you confirm the code is only inspected as data and never executed, set allow-unsafe-pr-checkout: true, and add least-privilege permissions and pass no secrets.
Event 'pull_request_target' is not allowed to trigger Actions workflows. Workflow file: '.github/workflows/label.yml'.
Cause: an Actions policy (an event rule or the public-repository default policy) blocked the event.
Fix: Assess whether it is really needed; if so, a repository or organization administrator should create an explicit policy that allows this event in Settings → Actions → Policies; first observe the impact in evaluate mode with policy insights.
Error: Unable to resolve action `owner/repo@<sha>`, unable to find version `<sha>`
Cause: the SHA was copied wrong, a short SHA was used, or the commit exists only in a fork (impostor commit).
Fix: Use git ls-remote to fetch the full SHA again from the original repository; run zizmor online checks impostor-commit.
lockfile missing pin for octo-org/setup-tool@v2.0.0
Cause: the workflow is in the lock file, but the referenced action (or an action used inside a local action) has no lock entry.
Fix: Re-run gh actions-lock; for local actions, use --migrate-local-actions to change to $/.
Dependabot does not raise security alerts for SHA-pinned actions
Cause: According to the docs, Dependabot alerts only apply to actions referenced by semantic version.
Fix: keep # vX.Y.Z comments so Dependabot version updates work; run zizmor regularly known-vulnerable-actions.
1. Find the full commit SHA for docker/login-action v4.8.0.
git ls-remote https://github.com/docker/login-action refs/tags/v4.8.0 'refs/tags/v4.8.0^{}'2. Rewrite the script below in a safe way: run: echo "${{ github.event.issue.title }}" | ./triage.sh
- env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: printf '%s\n' "$ISSUE_TITLE" | ./triage.shA public repository needs to run integration tests on fork PRs, and the tests must access a private package repository (which requires a secret). How can this be done without introducing a pwn request?
Option 1: pull_request run the tests that need no secret; move the integration tests that need the secret to manual triggers after a maintainer reviews the PR (triggered by a label, or workflow_dispatch by specifying the PR number), and run them in a controlled environment (environment + required reviewers). Option 2: change the private dependencies to public mirrors or cached artifacts. Avoid: pull_request_target checking out the PR head and executing it. If you really must use pull_request_target, an explicit event policy must allow it,allow-unsafe-pr-checkout and you must ensure the code is never executed—this basically cannot satisfy the requirement to “run the tests”.
Verified instructional videos
Official documentation
- Secure use reference
- Securely using pull_request_target
- Workflow dependency lockfiles
- zizmor docs
- ossf/scorecard-action
- GHSA-mrrh-fwg8-r2c3
Video storyboard (about 90 seconds)
Visual: the v45 tag is peeled off like a sticky note and stuck onto a red commit; thousands of repositories turn red at once.
Narration: tags can be moved. In the tj-actions incident, attackers delivered malicious code into tens of thousands of pipelines this way.
Visual: PR title text is “pasted” into a shell script, and a curl appears after a semicolon.
Narration: expressions are substituted before the shell runs, so an attacker's title becomes your script. Put it in env, and it is just data.
Visual: zizmor outputs a column of red and yellow alerts; they turn green as each one is fixed, and a lock-file icon appears.
Narration: least privilege, pinned dependencies, and auditing tools—once these three are done, the cost of an attack rises dramatically.
Module 7 · Organization-level governance: required workflows / rulesets
- Configure the organization's allowed actions and reusable workflows policy (including
!block syntax and the “must pin SHA” option). - Set organization default
GITHUB_TOKENpermissions, the toggle for PR creation/approval, and approval for fork PR runs. - Understand where legacy required workflows went: organization/enterprise rulesets with “Require workflows to pass before merging”; understand the Actions policy (workflow execution protection) added in 2026 Actions policies.
- Manage repository access scope for organization secrets and variables, and access control for runner groups.
What: the organization-level Actions control plane
| Control | Location (organization Settings) | Purpose | Plan / notes (verified 2026-11) |
|---|---|---|---|
| Allowed actions and reusable workflows | Actions → General → Policies | allow all / only this organization / this organization + selected (GitHub official, Marketplace verified creators, specified list) | all plans; the specified list holds up to 1000 entries; “only this organization” also actions/checkout disables |
| Require actions to be pinned to a full-length commit SHA | same as above | all actions (including official and this organization's) must use a full SHA; reusable workflows can still be referenced by tag | workflows included in a lock file satisfy this automatically |
| Workflow permissions | Actions → General | Default GITHUB_TOKEN: read/write for all (permissive) or read-only for contents/packages only (restricted); whether Actions can create or approve PRs | new organizations do not allow creating or approving PRs by default |
| Fork PR workflows | Actions → General | public repositories: which contributors need approval to run; private repositories: whether fork PRs run, whether they get write tokens or secrets, and whether approval is needed | “Only first-time contributors need approval” can be bypassed by first merging a small change |
| Actions policies (workflow execution protection) | Actions → Policies (separate from General) | targeted by repository (visibility, deployment status, custom properties) and workflow path; Actor rules (who can trigger),Event rules (which events are allowed); Require lockfile protection | added in 2026; three levels: enterprise / organization / repository; Evaluate mode is GHEC only; public repositories block by default pull_request_target (enforced from 2026-12-02) |
| Ruleset: Require workflows to pass before merging | Repository → Rulesets (organization level) | for the target branches of target repositories, forces the specified workflow from a central repository to run and pass before merging | replaces legacy required workflows; for plan requirements, follow the official docs (the GitHub blog says it applies to GHEC) |
| Organization secrets / variables | Secrets and variables → Actions | access policy: all repositories / private repositories / selected repositories | Private repositories in a GitHub Free organization cannot use organization-level secrets/variables |
| Runner groups | Actions → Runner groups | control which repositories (optionally which workflows) can use a group of self-hosted runners | Each organization has one default group; creating additional groups requires Team or above |
Why: why organization-level control
Every hardening step in module 6 relies on “each repository maintainer remembering to do it.” Organization policy turns the key baseline into a mandatory requirement: even if a repository's workflow uses uses: random/action@main, it fails at startup because it is not on the allowlist; even if a maintainer forgets to write permissions , the default is read-only; and even if a repository deletes its own scanning workflow, the central workflow required by the ruleset still runs on PRs.
How: several key mechanisms
1. Allowlist matching syntax
- actions:
OWNER/REPO@TAG-OR-SHA, such asdocker/login-action@*,actions/javascript-action@v1.0.1. - Reusable workflows:
OWNER/REPO/PATH/FILENAME@REF, such asmyorg-lab/platform-workflows/.github/workflows/python-build.yml@*. - Wildcards:
myorg-lab/*; blocking:!prefix, such as*, !tj-actions/changed-files@*(everything allowed but one action blocked). By default, only items on the list are allowed. - Workflows in a lock file match by the locked commit SHA matching: entries in the list
actions/checkout@v6such tag entries will not match locked dependencies; writeactions/checkout@*or a full SHA.
2. Layering
Enterprise policy → organization policy → repository policy: lower layers can only tighten further within what the layer above allows (for example, the enterprise allows everything while the organization allows only a selected list; the organization sets a restricted token, and repositories cannot loosen it back). Actions policies and rulesets stack the same way: when several policies apply, any one that blocks will block.
3. Current state of required workflows
The 2023 Actions “required workflows” beta feature has been retired (the GHES docs explicitly state “GitHub no longer supports required workflows for GitHub Actions”); the replacement is organization/enterprise rulesets under Require workflows to pass before merging: in the ruleset, select a workflow file from a central repository (it can be pinned to a branch, tag, or SHA), and it runs on PRs in the target repositories. Key points: the required workflow only supports pull_request,pull_request_target,merge_group events (when using a merge queue, add merge_group); it does not run for GITHUB_TOKEN events triggered by; PRs opened before the rule was created need a new commit or a reopen to trigger it; the visibility of the repository containing the workflow determines which repositories it can apply to (public → all, internal → internal and private, private → private); in Evaluate mode it runs but does not block. In the UI, Actions → Policies can also scope a policy to “required workflows”.
4. Access scope for organization secrets
An organization secret can be scoped to All repositories,Private repositories,Selected repositories. It ties into module 1: only secrets the calling repository can see can be passed through secrets: inherit to a reusable workflow. Production credentials should be placed in environment secrets (with required reviewers and a deployment branch policy) rather than organization secrets; for cloud credentials, prefer OIDC (Hours 3 and 4).
5. Runner groups
Self-hosted runners registered to an organization join the default group. Team and above can create custom groups, restrict which repositories can access them, and further restrict them to “only selected workflows” (for example, allow only the deployment workflow in platform-workflows to use runners on the production network; follow the docs for details). By default, only private repositories can use runners in a group; public repositories must enable this explicitly—this prevents fork PRs from running on your internal machines.
actions/checkout disablesLayering diagram: the gates a workflow must pass before it starts
Organization baseline sketch (myorg-lab)
Interactive calculator: organization allowlist and SHA pinning policy
Set the organization policy, then click “Evaluate” to see the following uses: references, whether each one is allowed or blocked when the workflow starts, and why. Matching logic follows the docs: * wildcards,! blocking, GitHub official = actions/* and github/*, and reusable workflows are not subject to the SHA pinning requirement.
REST API and gh commands
| Command | Purpose |
|---|---|
gh api -X PUT orgs/ORG/actions/permissions -f enabled_repositories=all -f allowed_actions=selected | Set the allowed-actions policy to “selected” |
gh api -X PUT orgs/ORG/actions/permissions/selected-actions --input sel.json | Set the official / verified creators / pattern list |
gh api -X PUT orgs/ORG/actions/permissions/workflow -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false | Default read-only token, and prohibit approving PRs |
gh secret set NAME --org ORG --visibility selected --repos myapp,platform-workflows | Restrict an organization secret to repositories |
gh variable set NAME --org ORG --visibility all --body VALUE | Organization variables |
gh api orgs/ORG/actions/runner-groups | List runner groups |
gh api orgs/ORG/rulesets | List organization rulesets |
gh api orgs/ORG/actions/permissions --jq .sha_pinning_required | View the SHA pinning requirement (field names follow the API docs) |
{
"github_owned_allowed": true,
"verified_allowed": true,
"patterns_allowed": [
"ossf/scorecard-action@*",
"zizmorcore/*",
"anchore/sbom-action@*",
"!tj-actions/changed-files@*"
]
}
export ORG=myorg-lab gh api -X PUT orgs/$ORG/actions/permissions -f enabled_repositories=all -f allowed_actions=selected gh api -X PUT orgs/$ORG/actions/permissions/selected-actions --input sel.json gh api orgs/$ORG/actions/permissions/selected-actions
{"github_owned_allowed":true,"verified_allowed":true,"patterns_allowed":["ossf/scorecard-action@*","zizmorcore/*","anchore/sbom-action@*","!tj-actions/changed-files@*"]}
This organization's actions and reusable workflows are automatically allowed in “this organization + selected” mode. Whether the API accepts ! the blocking pattern and the field names for the SHA pinning requirement, please refer to the REST docs; when unsure, use the web settings.
Workflow required by the ruleset: platform-workflows/.github/workflows/audit.yml
name: org-audit
on:
pull_request:
merge_group: # needed by repositories that use a merge queue
permissions:
contents: read
jobs:
zizmor:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: pipx run zizmor==1.32.0 --min-severity high .github/workflows/ # follow zizmor --help for options
Lab 7: configure a governance baseline for myorg-lab (about 8 min)
tj-actions/changed-files@v46.0.1, push, then observe the run failing:
Error: tj-actions/changed-files@v46.0.1 is not allowed to be used in myorg-lab/myapp. Actions in this workflow must be: within a repository owned by myorg-lab, created by GitHub, verified in the GitHub Marketplace, or matching the following: ossf/scorecard-action@*, zizmorcore/*, …
Then change a step that has a pinned SHA back to actions/checkout@v7, and observe the failure caused by the SHA pinning requirement (workflows already in the lock file are unaffected). Delete the branch after verifying.
gh api -X PUT orgs/$ORG/actions/permissions/workflow -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false echo -n "demo-value" | gh secret set DEMO_TOKEN --org $ORG --visibility selected --repos myapp gh secret list --org $ORG
NAME UPDATED VISIBILITY DEMO_TOKEN less than a minute ago Visible to 1 selected repository
myapp the default branch, check “Require workflows to pass before merging”, and add platform-workflows the .github/workflows/audit.yml. If this option is not available on your plan, use an alternative: call audit.yml as a reusable workflow in myapp, then set its check as a required status check in the ruleset.no-prt-public, target “public repositories”, event rule disallowing pull_request_target. If Evaluate is available, observe insights in Evaluate first; otherwise go straight to Active (myapp does not use this event anyway).Case 1: Actions baseline at a financial company
Problem: Regulation requires that “the build toolchain is controlled and changes are auditable.”Approach: At the enterprise level, only this enterprise + GitHub official + about 40 reviewed third-party actions are allowed (all @SHA entries, updated by the platform team via Dependabot PRs); SHA pinning is required and lock files are rolled out gradually (Require lockfile in Evaluate for one month first); the default token is read-only; the production deployment workflow is restricted to the SRE team via Actions policy actor rules. Limitation: Maintaining an allowlist has a cost and requires a clear request and review process.
Case 2: migrating from required workflows to rulesets
Problem: Organizations that had used the Actions required workflows beta lost mandatory scanning after the feature was retired. Approach: Move the same workflow configuration to the organization ruleset “Require workflows to pass before merging”, adding merge_group triggers; first confirm with Evaluate (GHEC) that nothing is wrongly blocked, then switch to Active. Note: PRs created by GITHUB_TOKEN (such as some bots) do not trigger the required workflow; for those bots, use a GitHub App token instead.
Case 3: organization secret over-sharing
Problem: An organization-level cloud credential visible to “All repositories” was printed to the logs by a workflow in a newly created lab repository. Approach: Cloud credentials were switched to OIDC (Hours 3/4); all remaining organization secrets were changed to Selected repositories and audited by repository custom properties; production secrets were moved to environment secrets with required reviewers.
Common errors and fixes
The action owner/repo@v1 is not allowed in myorg-lab/myapp because all actions must be from a repository owned by myorg-lab …
Cause: the organization/enterprise allowlist does not include the action (or it is ! blocked).
Fix: Request that the platform team add it to the list (with a security review), or switch to an allowed alternative. Repository admins cannot loosen organization restrictions at the repository level.
The action actions/checkout@v7 is not allowed … must be pinned to a full-length commit SHA
Cause: SHA pinning is required (follow the actual error text).
Fix: Change to a full SHA, or use gh actions-lock to include it in the lock file. Reusable workflows are not subject to this restriction.
Resource not accessible by integration (many workflows failed after the organization switched to a restricted token)
Cause: The workflow relied on the previously permissive default write permissions.
Fix: Explicitly declare permissions in the relevant jobs; before switching, use zizmor excessive-permissions/undocumented-permissions to audit.
The workflow required by the ruleset keeps showing “Expected — Waiting for status to be reported”
Cause: the workflow does not pull_request/merge_group trigger; the PR was opened before the rule was created; the PR was created by GITHUB_TOKEN ; the central repository's visibility is insufficient to apply to the target repository.
Fix: Add the trigger; push a new commit or reopen the PR; switch to an App token; adjust the central repository's visibility.
No runner matching the specified labels was found: self-hosted, prod
Cause: The runner group is not open to this repository (or this workflow); public repositories cannot use group runners by default.
Fix: Add the repository/workflow to the runner group; use self-hosted runners carefully with public repositories.
1. Set the organization default GITHUB_TOKEN to read-only, and prohibit Actions from approving PRs.
gh api -X PUT orgs/myorg-lab/actions/permissions/workflow -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false
2. Create an organization secret NPM_TOKEN visible only to the myapp and api repositories.
gh secret set NPM_TOKEN --org myorg-lab --visibility selected --repos myapp,api
The platform team wants: ① every PR in every repository must pass the organization security scan; ② production deployments can only be triggered by SRE; ③ no unreviewed third-party actions are allowed. Which mechanism should be used for each?
① an organization ruleset “Require workflows to pass before merging” (pointing to the scanning workflow in platform-workflows, including merge_group); ② Actions policy actor rules (scoped to the deployment workflow path) + environment required reviewers; ③ set allowed actions to “this organization + GitHub official + specified list”, where the specified list contains only reviewed actions, and enable the SHA pinning requirement or Require lockfile.
Verified instructional videos
Official documentation
- Disabling or limiting GitHub Actions for your organization
- About Actions policies · Governing execution of workflows
- Creating rulesets for repositories in your organization
- Managing access to self-hosted runners using groups
Video storyboard (about 80 seconds)
Visual: three concentric circles: enterprise, organization, repository; the further in, the narrower.
Narration: organization policy is the baseline; lower layers can only be stricter.
Visual: a uses reference passes the allowlist and SHA checks in turn; an action marked with an exclamation point is stopped.
Narration: the allowlist decides what can be used; the exclamation mark can block a problematic action with one click.
Visual: the organization scan check appears automatically on the PR; when it fails, the merge button is greyed out.
Narration: the workflow required by the ruleset ensures every repository runs the same set of checks.
Module 8 · Recap, self-check, and cleanup of the first five hours
- Use one diagram to retell the full platform path of “a commit from push to production”, and identify which lesson's mechanism protects each step.
- Use the troubleshooting tree to quickly locate this lesson's common failures: reusable workflow call failures, secrets not passed, GHCR 403, attestation verification failures, and actions blocked by policy.
- Complete cleanup: test package versions, test Releases, extra token scopes, lab branches, and organization settings.
Five-hour knowledge thread
| Lesson | Core question | Key mechanisms | How it is used in this lesson |
|---|---|---|---|
| Lesson 1 | How code safely enters main | PRs, reviews, rulesets, CODEOWNERS, merge methods | protecting platform-workflows; tag rulesets; the ruleset requiring workflows |
| Lesson 2 | What happens automatically once code is in | events → workflow → job → runner; matrix, caching, artifacts, environments | basic syntax for all workflows |
| Lesson 3 / Lesson 4 | How to deploy to the cloud without stored keys | OIDC token exchange, federated credentials / IAM roles, immutable subjects | the same OIDC token mechanism is used for Sigstore signing (module 5) |
| Lesson 5 (this lesson) | How to be reusable, traceable, and trustworthy at organization scale | reusable workflows, custom actions, Releases, GHCR, attestations, hardening, governance | — |
A complete production pipeline
- Developers push a branch and open a PR → the ruleset requires review and organization audit workflow (M7) to pass.
- Merge into main → myapp's ci.yml calls platform-workflows' python-build (M1); its steps use the setup-myapp composite action and the check-healthz JS action (M2).
- The build job uses
packages: writeto push multi-architecture images to GHCR (M4), and usesactions/attestto generate provenance + SBOM attestations (M5). - Push a
v*tag → the release workflow builds assets, creates a draft Release, uploads them, and publishes it as an immutable Release (M3). - The deployment job first
gh attestation verify --signer-workflow …, then logs in to the cloud platform with OIDC (Lessons 3/4) to deploy the image digest. - Throughout: all actions pinned by SHA or lock file, jobs with least-privilege permissions, continuous zizmor/Scorecard auditing (M6), with the organization allowlist and Actions policies as the safety net (M7).
Next lesson preview
Hour 6: enterprise security and governance in practice—GHAS (code scanning, secret scanning and push protection, dependency review), security configuration, audit logs, enterprise accounts and EMU. The zizmor/Scorecard results from this lesson feed into the code-scanning alert workflow there.
Panorama: myapp's delivery pipeline five hours later
Interactive replay: all checkpoints a release passes through
Click “Next” to replay the full path of v0.2.0 from PR to production; tick “Inject fault” to see which checkpoint stops it.
Cleanup commands
| Command | Purpose |
|---|---|
gh api /orgs/ORG/packages/container/myapp/versions --jq '.[].id' | List package versions |
gh api -X DELETE /orgs/ORG/packages/container/myapp | Delete an entire package (cannot be recovered after the recovery window) |
gh release delete v0.1.0 -R ORG/myapp --cleanup-tag -y | Delete a Release and its tag (the name of an immutable Release's tag cannot be reused) |
gh secret delete DEMO_TOKEN --org ORG | Delete an organization secret |
gh auth refresh -h github.com -r admin:org,delete:packages,write:packages | Revoke extra scopes |
gh repo delete ORG/check-healthz-action --yes | Delete a lab repository (requires delete_repo scope) |
docker buildx rm multi && docker logout ghcr.io | Local cleanup |
Lab 8: self-check and cleanup (about 6 min)
gh run list -R $ORG/myapp -L5 gh api repos/$ORG/myapp/actions/runs/$(gh run list -R $ORG/myapp -w ci -L1 --json databaseId --jq '.[0].databaseId') --jq '.referenced_workflows[].path' gh attestation verify oci://ghcr.io/$ORG/myapp:latest --repo $ORG/myapp --signer-workflow $ORG/platform-workflows/.github/workflows/python-build.yml gh release view --json tagName,isImmutable -R $ORG/myapp 2>/dev/null || gh release view -R $ORG/myapp uvx zizmor@1.32.0 .github/workflows/ --min-severity medium
isImmutable Field names follow the help of gh release view --json .
myorg-lab,myapp, and platform-workflows, so we recommend keeping; you can delete check-healthz-action (if no longer needed), the test tag local-test, the organization secret DEMO_TOKEN.
gh secret delete DEMO_TOKEN --org $ORG # Optional: delete the lab action repository gh auth refresh -h github.com -s delete_repo gh repo delete $ORG/check-healthz-action --yes
gh auth refresh -h github.com -r admin:org,delete:packages,write:packages,delete_repo gh auth status
docker buildx rm multi; docker logout ghcr.io; docker image prune -f. If you created a classic PAT for GHCR, delete it under Settings → Developer settings → Personal access tokens.Case: a platform team's 90-day roadmap
Days 1–30: organization default read-only token; switch the allowlist from “all” to “this organization + official + verified + specified” (first export current usage: referenced_workflows and dependency graph); add zizmor to all repositories (non-blocking). Days 31–60: release platform-workflows v1 (build, push, attest), migrate 10 pilot repositories; enable immutable releases; use Dependabot to manage action versions. Days 61–90: the ruleset requires the audit workflow; Require lockfile switches from Evaluate to Active; mandatory gh attestation verify --signer-workflow before deployment. Lesson learned: At each step, “observe” first and then “enforce”; otherwise you will break hundreds of repositories at once.
Interactive troubleshooting tree: common failures in this lesson
Choose step by step based on the symptom to get the diagnostic command and the fix.
1. Use one command to view the failed step log of the most recent failed run.
gh run view -R myorg-lab/myapp $(gh run list -R myorg-lab/myapp -s failure -L1 --json databaseId --jq '.[0].databaseId') --log-failed
2. Delete the v0.1.0 Release and its tag.
gh release delete v0.1.0 -R myorg-lab/myapp --cleanup-tag -y
A new colleague asks: “OIDC is used in Lessons 3 and 4 to log in to the cloud, and in this lesson to sign attestations—is it the same thing?” Please explain.
It is the same ID token issued by the GitHub OIDC provider, except that audience the audience and the receiver differ: when logging in to the cloud, it goes to Azure Entra ID / AWS STS, which validate issuer/audience/subject and then issue short-lived cloud credentials; when generating attestations, it goes to Sigstore Fulcio, which validates it and issues a short-lived signing certificate containing the workflow identity. Both require the job's id-token: write, and both avoid long-lived keys.
Verified instructional videos (comprehensive review)
Official documentation
Video storyboard (about 60 seconds)
Visual: five checkpoints light up in turn: PR, calling the shared pipeline, pushing images, attestations, deployment verification.
Narration: over five hours, we turned a single commit into reusable, traceable, and verifiable delivery.
Visual: the cleanup checklist is ticked off item by item, and token scopes shrink.
Narration: remember to clean up after labs, especially by revoking extra token permissions.
Command cheat sheet
on:
workflow_call:
inputs: { env: { type: string, required: true } }
secrets: { TOKEN: { required: true } }
outputs: { digest: { value: ${{ jobs.b.outputs.d }} } }
---
jobs:
call:
uses: org/repo/.github/workflows/f.yml@<sha|tag>
with: { env: prod }
secrets: inherit # same organization; reaches only direct callees
permissions: { contents: read }
Limits: 10 levels of nesting · 50 distinct workflows · env does not propagate · permissions can only be lowered, not raised
runs: { using: node24, main: dist/index.js }
runs: { using: docker, image: docker://ghcr.io/o/i@sha256:… }
runs:
using: composite
steps:
- run: echo hi
shell: bash
- uses: $/actions/other # same-repository self-reference
npx @vercel/ncc build src/index.js -o dist --license licenses.txt
git tag -f v1 v1.2.0^{} && git push -f origin v1gh release create v1.2.0 --draft --verify-tag --generate-notes gh release upload v1.2.0 dist/* gh release edit v1.2.0 --draft=false gh release verify v1.2.0 gh release verify-asset v1.2.0 dist/app.whl gh api repos/O/R/releases/generate-notes -f tag_name=v1.2.0
gh auth token | docker login ghcr.io -u USER --password-stdin docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/o/app:1 --push . docker buildx imagetools inspect ghcr.io/o/app:1 gh api /orgs/O/packages/container/app/versions gh api -X DELETE /orgs/O/packages/container/app/versions/ID
workflow: packages: write + GITHUB_TOKEN; LABEL org.opencontainers.image.source
permissions: { id-token: write, attestations: write, packages: write, artifact-metadata: write }
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with: { subject-name: ghcr.io/o/app, subject-digest: ${{ steps.push.outputs.digest }}, push-to-registry: true }
- uses: actions/attest@… # sbom-path: sbom.spdx.json
gh attestation verify oci://ghcr.io/o/app:1 --repo o/app \ --signer-workflow o/platform-workflows/.github/workflows/build.yml \ --source-ref refs/heads/main --deny-self-hosted-runners gh attestation verify f --repo o/app --predicate-type https://spdx.dev/Document/v2.3
permissions: {}
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: { persist-credentials: false }
- env: { TITLE: ${{ github.event.pull_request.title }} }
run: echo "$TITLE"
git ls-remote https://github.com/O/R refs/tags/vX.Y.Z gh extension install github/gh-actions-lock && gh actions-lock uvx zizmor .github/workflows/ GH_TOKEN=$(gh auth token) uvx zizmor .
gh api -X PUT orgs/O/actions/permissions -f enabled_repositories=all -f allowed_actions=selected gh api -X PUT orgs/O/actions/permissions/selected-actions --input sel.json gh api -X PUT orgs/O/actions/permissions/workflow -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false gh secret set NAME --org O --visibility selected --repos a,b gh api orgs/O/rulesets gh api orgs/O/actions/runner-groups
gh run view RUN --log-failed gh run view RUN --json jobs --jq '.jobs[] | "\(.name) \(.conclusion)"' gh api repos/O/R/actions/runs/RUN --jq .referenced_workflows gh api repos/O/R/attestations/sha256:… gh run rerun RUN --failed --debug
Integrated lab + final quiz
myorg-lab/platform-workflows and myorg-lab/myapp , and self-verify with the acceptance checklist.cd ~/src/platform-workflows tree -a -I .git
.
├── .github
│ ├── dependabot.yml
│ └── workflows
│ ├── container-build.yml # reusable workflow created in this lab
│ ├── python-build.yml # modules 1/5
│ └── audit.yml # module 7 (required by ruleset)
└── actions
└── setup-myapp
└── action.yml # composite actionname: container-build
on:
workflow_call:
inputs:
python-version: { type: string, default: "3.12" }
platforms: { type: string, default: "linux/amd64,linux/arm64" }
push: { type: boolean, default: false }
outputs:
digest:
value: ${{ jobs.image.outputs.digest }}
image:
value: ${{ jobs.image.outputs.image }}
permissions: {}
jobs:
test:
runs-on: ubuntu-24.04
permissions: { contents: read }
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: { persist-credentials: false }
- uses: $/actions/setup-myapp
with: { python-version: "${{ inputs.python-version }}" }
- run: pytest -q
image:
needs: test
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
attestations: write
artifact-metadata: write
outputs:
digest: ${{ steps.push.outputs.digest }}
image: ${{ steps.name.outputs.image }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: { persist-credentials: false }
- id: name
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- if: inputs.push
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
- id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ steps.name.outputs.image }}
tags: |
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
- if: inputs.push
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-name: ${{ steps.name.outputs.image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- if: inputs.push
uses: anchore/sbom-action@fffec3d851af758d56fee099cf3fbf8aa8779843 # v0.24.3
with:
image: ${{ steps.name.outputs.image }}@${{ steps.push.outputs.digest }}
format: spdx-json
output-file: sbom.spdx.json
- if: inputs.push
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-name: ${{ steps.name.outputs.image }}
subject-digest: ${{ steps.push.outputs.digest }}
sbom-path: sbom.spdx.json
push-to-registry: true
git add . && git commit -m "feat: container-build reusable workflow" && git push
git tag -a v2.0.0 -m v2.0.0 && git tag -f v2 && git push origin v2.0.0 && git push -f origin v2
V2_SHA=$(git rev-parse v2.0.0^{}); echo $V2_SHAname: cicd
on:
push: { branches: [main] }
pull_request:
permissions: {}
jobs:
build:
uses: myorg-lab/platform-workflows/.github/workflows/container-build.yml@<V2_SHA> # v2.0.0
with:
push: ${{ github.event_name == 'push' }}
permissions:
contents: read
packages: write
id-token: write
attestations: write
artifact-metadata: write
verify:
if: github.event_name == 'push'
needs: build
runs-on: ubuntu-24.04
permissions: { contents: read, attestations: read, packages: read }
steps:
- env:
GH_TOKEN: ${{ github.token }}
IMAGE: ${{ needs.build.outputs.image }}
DIGEST: ${{ needs.build.outputs.digest }}
run: |
gh attestation verify "oci://$IMAGE@$DIGEST" --repo "$GITHUB_REPOSITORY" \
--signer-workflow myorg-lab/platform-workflows/.github/workflows/container-build.yml \
--source-ref refs/heads/main --deny-self-hosted-runners
echo "✅ verified $IMAGE@$DIGEST" >> "$GITHUB_STEP_SUMMARY"
Delete the old ci.yml / publish-image.yml to avoid duplicate builds. verify After the job comes the OIDC deployment job from Lessons 3/4 (deploy by digest).
cd ~/src/myapp && git add -A .github && git commit -m "ci: use org container-build workflow" && git push org main RUN=$(gh run list -R $ORG/myapp -w cicd -L1 --json databaseId --jq '.[0].databaseId'); gh run watch -R $ORG/myapp $RUN docker buildx imagetools inspect ghcr.io/$ORG/myapp:latest | grep Platform gh attestation verify oci://ghcr.io/$ORG/myapp:latest --repo $ORG/myapp --predicate-type https://spdx.dev/Document/v2.3 >/dev/null && echo SBOM-OK
for d in ~/src/platform-workflows ~/src/myapp; do (cd $d && GH_TOKEN=$(gh auth token) uvx zizmor@1.32.0 .github/); done cd ~/src/myapp && gh actions-lock && git add .github/workflows/actions.lock && git commit -m "ci: lock action deps" && git push org main
Commit dependabot.yml (github-actions ecosystem, with cooldown) and audit.yml (zizmor + Scorecard), and confirm there are no high-severity alerts under Security → Code scanning.
v* tags).latest , then run the verification command and confirm it fails; ② on a new myapp branch add tj-actions/changed-files@v46.0.1, and confirm it is blocked by organization policy; ③ in cicd.yml, remove the calling job's id-token: write is removed, confirm the run fails at startup. After restoring everything, re-run CI.Open-ended self-test (answer on your own first, then expand the reference answers)
1. What passing rules do secrets, env, and permissions each follow in reusable workflows?
secrets must be passed explicitly or inherit (same organization/enterprise), reaching only direct callees; workflow-level env propagates in neither direction, so use inputs/outputs or vars; GITHUB_TOKEN permissions can only be kept or lowered; if a called job requests more than the calling job grants, the run fails at startup.
2. After enabling immutable releases, how is the action's major-version tag v1 still maintained?
Create a Release for each fixed version (v1.2.3) (immutable); v1 and v1.2 exist only as Git tags, not linked to a Release, and can be force-moved. Users who want determinism should reference a SHA or an immutable version.
3. Why are both “deploying images by tag” and “verifying only with --owner” insufficient?
tags can be overwritten, and attestations are bound to the digest, so deploy and verify by digest; --owner proving only that something came from some workflow in some repository within the organization can be satisfied by any compromised or low-privilege repository, so add --signer-workflow (pinning the platform reusable workflow),--source-ref,--deny-self-hosted-runners.
4. Which SLSA level do artifact attestations reach? How do you get to L3?
On their own, they provide SLSA v1.0 Build L2; putting the build and attestation into an organization-shared reusable workflow isolates the build definition from the caller, and pinning that workflow during verification satisfies Build L3.
5. Explain the pwn request, and the two protections GitHub added in 2026.
Checking out or downloading fork code and executing it in privileged triggers with secrets or write tokens (pull_request_target,workflow_run,issue_comment etc.). Protections: actions/checkout v7 denies by default checking out fork code in pull_request_target/workflow_run (requires allow-unsafe-pr-checkout); the Actions policy adds a default event policy that blocks pull_request_target for public repositories, enforced from 2026-12-02.
6. What are the pros and cons of SHA pinning compared with workflow dependency lock files?
SHA pinning is simple and works everywhere, but workflows are harder to read, it does not cover transitive dependencies, it does not record repository identity, and Dependabot vulnerability alerts do not cover SHA references. Lock files cover transitive dependencies, record owner/repo IDs and verify them at runtime, let workflows keep tag syntax, and satisfy the organization's SHA pinning policy, but require gh actions-lock a toolchain, and do not cover reusable workflow calls and ./ local actions; they are not supported on GHES $/.
Final quiz (12 questions, covering all modules)
Sources and version notes
| Topic | Verified conclusion | Source (accessed 2026-11-15) |
|---|---|---|
| Reusable workflow limits | Up to 10 levels; a single workflow file can call up to 50 distinct reusable workflows (including the nested tree); env does not propagate; keywords usable in the calling job (including cache-mode); permissions can only be kept or lowered; hosted runners are allocated and billed to the caller; re-run behavior for non-SHA references | Reusing workflow configurations |
| secrets passing | inherit limited to the same organization/enterprise; secrets go only to direct callees; an unpassed secret resolves to an empty string, and can be used required: true | Reuse workflows |
$/ self-reference | resolves to the commit currently running, needs no checkout, cannot take @ref, and is not supported on GHES | Workflow syntax |
| JS action runtime | runs.using node20 / node24 are optional; the official template uses node24,@actions/core ^3 (latest npm 3.0.1), rollup bundling; ncc 0.45.0 (2026-08-13) automatically outputs ESM for ESM packages | Metadata syntax · javascript-action · vercel/ncc |
| Marketplace | Public repository, a single action.yml in the root, unique name, accepts the developer agreement, 2FA required for publishing, no manual review | Publishing actions in GitHub Marketplace |
| Immutable releases | 2025-08-26 public preview, 2025-10-28 GA; tags locked, assets immutable, tag names cannot be reused after deletion, release attestations generated automatically; titles and notes editable; recommended order draft → assets → publish; major-version tags not linked to a Release | Changelog · Immutable releases · Action releases |
| Release notes | .github/release.yml exclude / categories configuration of | Automatically generated release notes |
| GHCR | only classic PATs and GITHUB_TOKEN are supported; publishing from a workflow links automatically and grants admin; inherits access permissions but not visibility; private on first publish; cannot be changed back once public; public packages can be pulled anonymously; Container registry storage and bandwidth are currently free | Container registry · Access control · Packages billing |
| Artifact attestations | actions/attest v4.2.2 (2026-08-04); attest-build-provenance v4.2.2 is the wrapper; attest-sbom v4.1.0 being deprecated; permissions id-token / attestations / artifact-metadata; public repositories use the Sigstore public instance + Rekor, private repositories use the GitHub instance (no transparency log, requires GHEC); SLSA v1.0 Build L2 is provided alone, and reusable workflows reach L3 | actions/attest · Artifact attestations · Using attestations |
| gh CLI | v2.104.0 (2026-11-12); gh attestation verify parameters: --owner/--repo, --signer-workflow, --signer-repo, --source-ref, --deny-self-hosted-runners, --predicate-type, --bundle, --bundle-from-oci, --custom-trusted-root, etc.; gh release verify / verify-asset | cli/cli releases · manual |
| Security hardening | pull_request_target risks and the default event policy (evaluate; enforced 2026-12-02), read-only caches; checkout v7 blocks fork PR checkout by default,allow-unsafe-pr-checkout; lock files .github/workflows/actions.lock and gh actions-lock; Dependabot alerts do not cover SHA-pinned actions | Securely using pull_request_target · actions/checkout · Lockfiles · Secure use |
| Audit tools | zizmor v1.32.0 (2026-11-02), zizmor-action v0.8.1; ossf/scorecard-action v2.5.0 (2026-10-12) | zizmor · scorecard-action |
| Docker actions | build-push v7.4.0, setup-buildx v4.4.1, setup-qemu v4.4.0, login v4.8.0, metadata v6.2.0; delete-package-versions v5.0.0; anchore/sbom-action v0.24.3; SHAs obtained by git ls-remote fetching | each repository's GitHub Releases |
| Organization governance | Allowlist syntax and ! blocking, the 1000-entry limit, the SHA pinning requirement (reusable workflows excepted), lock files matched by SHA; restricted token = contents/packages read-only; Actions policies (actor/event rules, Require lockfile, Evaluate GHEC only); private repositories in Free organizations cannot use organization secrets; additional runner groups require Team | Limiting Actions · Actions policies · Secrets · Runner groups |
| Required workflows | Legacy Actions required workflows are no longer supported; use the organization/enterprise ruleset “Require workflows to pass before merging” instead; events limited to pull_request / pull_request_target / merge_group | GHES 3.10 notes · GitHub Blog |
| tj-actions incident | CVE-2025-30066 / GHSA-mrrh-fwg8-r2c3; 2025-03-14/15 tags repointed; fixed in 46.0.1 | GitHub Advisory |
Video verification notes
All videos listed in this lesson were verified on 2026-11-15 via the YouTube oEmbed endpoint (https://www.youtube.com/oembed?url=…&format=json), checking titles and channels: CoderDave (lRypYtmbKMs, zc19mR3O4a4, p9ismkYDxWQ, WjzA9dfk5w4), Mickey Gousset (gDBZGCGSs6E, zQdEsIBbVjE, 4dnniFk5i2Q, sXDBEofeMcY), Colby Fayock (Ef0gPGUh9oo), Yankee Maharjan (w8ZALhqoHgs), GitHub (88FWrfHCIqo, zTIHb-9c868, dNl3qpJZ12w), Ana's Dev Scribbles (70YgbPh6pXA), Brian Morrison (RgZyX-e6W9E), Cloud Native Skunkworks (hAcMGttHCFw), NDC Conferences (hF95PiItWtM), William Woodruff (WF0HgaH-qtY), Black Hat (-BCngzJC1Rc), The Linux Foundation (YTHqoST99oE), freeCodeCamp.org (Tz7FsunBbfQ), DevOps Directive (Xwpi0ITkL3U). Some videos were recorded earlier; version numbers and limit figures follow the body of this lesson.
Voice narration notes
The “Voice” page uses the browser Web Speech API (speechSynthesis, en-US) to read the narration script aloud in real time; English terms are pronounced with en-US; the result depends on the voices installed on the system. This courseware does not embed MP3s; for offline audio, give the narration script to any TTS tool.
Known limitations
- Run IDs, digests, SHAs (except explicitly labeled action version SHAs), times, and counts in “Expected output” are example values.
- The action version SHAs were looked up on 2026-11-15 using
git ls-remote; re-query before use. Examples without pinned SHAs (such asactions/setup-python@v7,github/codeql-action/upload-sarif@v4) are marked “also pin the SHA in production”. - GitHub UI paths and some REST fields (such as
sha_pinning_required,gh release view --json isImmutable) change quickly; the courseware marks them as “follow the docs”. - The plan requirements for the “Require workflows to pass before merging” rule and Actions policies could not be found stated explicitly on the current docs.github.com pages; the courseware offers an alternative (reusable workflow + required status check).
- Exact error messages follow actual runs; text marked “follow the actual result” in the troubleshooting pages is typical wording inferred from the mechanism.
- Times and flows in the animations are illustrative, to explain the mechanisms, and do not represent actual durations.