Skip to content

Workflow token drift

github-actions[bot] edited this page Nov 9, 2026 · 1 revision

token-drift

What it does. Fails when a file vendored from another repository (brand design tokens, for example) is not the bytes its lock pinned and, if you ask, when the lock no longer equals the source repository's file at the commit its ref points to now. It is read-only and holds no secret.

Why it exists. Two sites share brand tokens: the blog owns brand/tokens.json, the link page vendors a pinned copy. A hand edit of the copy, or a change at the source nobody re-vendored, is a visual drift no test of either site notices. The check is the same for any pair of repositories, so it lives here instead of being copied into both. It reads the same lock file as vendored-drift; use that workflow when a generator's output must also be checked.

The lock file

{
  "vendored": "vendor/brand/tokens.json",
  "sha256": "<64 lowercase hex characters>",
  "source": {"repo": "owner/name", "path": "brand/tokens.json", "commit": "<40 hex characters>"}
}

Exactly those keys. Paths are relative and must stay inside the repository after symbolic links are followed.

What fails the job

  1. A lock that is missing, unreadable or malformed, or an empty lock-file: nothing checked is not a pass.
  2. A lock that disagrees with vendored-path, source-repo or source-path when you give them. Put the values in the caller's workflow file and an edit of the lock alone cannot point the check at something else.
  3. A vendored file that is not a regular file inside the repository (a directory, a FIFO, a symlink out), is larger than 16 MiB, or whose SHA-256 differs from the pin. The message names the file and prints both hashes.
  4. With check-live: true: the source file at the resolved commit differs from the pin. The message names the file, the repository, the commit and both hashes.

Every problem is listed before the job fails.

How the live check resolves the source

source-ref (empty means the default branch) is resolved once to a commit through api.github.com, then the file is fetched at exactly that commit, so a push between two requests cannot make them disagree. The file's hash is compared, not the commit id: the source may move on without touching the file, and that is not drift. The commit it checked is printed next to the lock's own.

A moving ref (or the default branch) is allowed on purpose: noticing that the source changed is the whole point. Pin source-ref to a commit when you only want to prove the lock tells the truth about its own commit. A ref is a plain name (letters, digits, ., _, -, /, no .., no leading - or /); anything else fails before a request is made.

The job token goes to api.github.com only, a redirect is refused (never followed), and at most 16 MiB is read. The job token cannot read another private repository, so the source must be public. check-live is off by default so a pull request depends on nothing outside your repository; run it on a schedule.

The egress list

allowed-endpoints defaults to api.github.com:443 github.com:443: github.com for the checkout, api.github.com for the commit and the file (the contents API answers the raw bytes directly). No other host is allowed, so a redirect to one fails instead of leaking a request. The fixture job in this repository's CI runs the live check in block mode and goes red if that list is not enough.

A minimal caller

on:
  pull_request:
  push:
    branches: [main]
  schedule:
    - cron: "17 5 * * 1"

permissions:
  contents: read

jobs:
  token-drift:
    uses: ChiefGyk3D/git-your-ship-together/.github/workflows/token-drift.yml@<sha> # vX.Y.Z
    permissions:
      contents: read
    with:
      lock-file: vendor/brand/tokens.lock.json
      vendored-path: vendor/brand/tokens.json
      source-repo: owner/name
      source-path: brand/tokens.json
      check-live: ${{ github.event_name == 'schedule' }}

To re-vendor: copy the new file, update sha256 and source.commit in the lock, and commit both together.

Running it locally

python3 -I scripts/check_token_drift.py --lock vendor/brand/tokens.lock.json [--check-live] runs the same checks (standard library only). The workflow carries a byte-identical copy, because a reusable workflow cannot read files from its own repository; tests/test_token_drift.py fails if the copy differs.

The fixtures prove it can fail

ci.yml calls this workflow on fixture/token-drift/: a passing pin, a passing live check against this repository's LICENSE, and two planted ones (an edited vendored file; a lock that no longer equals the source) run with advisory: true. advisory turns drift, never a malformed input, into a warning. The drifted output is false on a clean run and true on advisory drift, and empty whenever the job fails; token-drift-control fails unless both planted jobs report drifted=true. Leave advisory off in a real caller.

Inputs (12), read from token-drift.yml:

Input Type Default Meaning
lock-file string empty Repository-relative path of the lock file (JSON with vendored, sha256 and source). Required; an empty value fails the job rather than passing with nothing checked.
vendored-path string empty Optional. The vendored file's path as the caller's own workflow file states it; the job fails when the lock says something else, so an edit of the lock alone cannot retarget the check. Empty skips the comparison.
source-repo string empty Optional. The source repository (owner/name) as the caller states it; same comparison against the lock's source.repo. Empty skips it.
source-path string empty Optional. The source file's path in the source repository; same comparison against the lock's source.path. Empty skips it.
source-ref string empty With check-live, the branch, tag or commit of the source repository to compare against. Empty means the default branch. Whatever it is, it is resolved to ONE commit and both fetches use that commit. Plain names only (letters, digits, ., _, -, /); anything else fails before a request is made.
check-live boolean false Also fetch the source file at the resolved commit and require its SHA-256 to equal the pin. Needs a public source repository. Off by default so a pull request depends on nothing outside the caller's repository.
advisory boolean false Report drift as a warning and set the drifted output instead of failing the job. For fixtures that must prove the check fires; a malformed lock or input still fails. Leave off in a real caller.
egress-policy string block harden-runner egress policy - audit logs outbound connections, block allows only allowed-endpoints. This job passes the read-only job token to the GitHub API for the live check, so it always follows this input (EX-0001 lets only jobs that hold nothing follow the secretless input).
egress-policy-secretless string block Accepted so a caller can pass the same egress inputs to every workflow here, and validated like the other (exactly audit or block). It changes nothing in this workflow, whose one job passes the read-only job token to the GitHub API and so follows egress-policy.
allowed-endpoints string api.github.com:443 github.com:443 harden-runner allow-list for block, space-separated host:port entries. The default is what the checkout and the live check need (the live check talks to api.github.com only, because the contents API answers the raw bytes directly, and a redirect to another host is refused rather than followed, so no other host is allowed); wildcards are not supported.
extra-allowed-endpoints string empty Appended to allowed-endpoints, for hosts only the install command or the generator reaches (a package index, for example). Same format.
timeout-minutes number 10 Job timeout.

Outputs a caller job can read:

Output Meaning
drifted false when the vendored file (and with check-live the source) agrees with the pin; true when drift was found and advisory kept the job green. Empty when the job failed (a malformed lock or input, a fetch error, or drift without advisory).

What it refuses to do

It never writes anything, never holds a credential beyond the read-only job token, never follows a redirect, and never passes when no lock file was given.

Clone this wiki locally