Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/agent/action-allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"aquasecurity/trivy-action",
"github/codeql-action",
"raven-actions/actionlint"
]
],
"approved_unused": []
}
1 change: 1 addition & 0 deletions changelog.d/1206.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The action allowlist now carries `approved_unused`, a reviewed pre-approval for an action that is on the list while no workflow uses it yet, so the documented order — list entry first, workflow second — can be executed instead of failing in either direction. An entry names the issue that approved it and a minor release version by which it expires; the suite fails at that version and again when the exempted action is first used, and both messages name the entry, its issue and its expiry with the two legal moves: delete it, or renew it with a comment on the issue. An empty `approved_unused` stays green on any version, and a tree is bounded as the minor checkout it is (`0.5.1` as `0.5.0`), so the daily patch releases neither red an empty list nor kill a valid entry.
23 changes: 22 additions & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,25 @@ different action. `readAllowlist` refuses to load a malformed file rather than
returning an empty list, and a name in the list that no workflow uses is a test
failure too — drift in either direction is how a list stops describing the tree.

One state is not drift. `approved_unused` in the same file holds entries of
exactly `name`, `issue` and `expires_at`: an action this project has pre-approved
by a reviewed decision while no workflow uses it yet. That is the only legal way
to land a list entry before its use, and it is bounded rather than open-ended —
`expires_at` is a minor release version (`x.y.0`), a tree whose minor is at or
past that version fails its suite, and the message names the entry, its issue and
its expiry plus both legal moves: delete it, or renew it with a comment on the
issue saying why the pre-approval still stands. The tree is read as the checkout
it is: any released `x.y.z` counts, and it is bounded as the minor it belongs to,
so `0.5.1` is bounded as `0.5.0` — a valid entry does not die on the patch
releases the daily cadence produces (`docs/decisions/0008-release-cadence.md`).
The bound only applies once there is an entry to bound: an empty
`approved_unused` stays green on any version, so the check cannot red a release
over a list it did not add to. The entry also expires on first use: a workflow
that uses an exempted action while the entry is still listed fails the suite, and
the change that adds the use deletes the entry. Until the check moves into the
base checker, this rule lives in the tree's own suite, so removing it is a
reviewed change but not yet one the base branch can compel.

CI enforces the list in the `action-pins` required job. The checker is read from
the base branch, so the list it reads is the one already reviewed there; a pull
request therefore cannot grant itself an action in the same commit that uses it.
Expand Down Expand Up @@ -1080,7 +1099,9 @@ Procedure for adding an action:
2. Add one line to `.github/agent/action-allowlist.json` in its own reviewed
change, with the justification in the pull request body. The suite's
both-directions test must still pass, so a list entry that no workflow uses
cannot ride along.
cannot ride along — unless it is pre-approved in `approved_unused`, naming this
issue and a release version by which it expires. Pre-approval is what makes the
entry and its first use two changes by construction.
3. Land it, then open the workflow change that uses the action. The gate reads the
list from the base branch, so reversing the order reds the newer pull request
until the list is on `main`.
Expand Down
13 changes: 10 additions & 3 deletions scripts/action-pins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Supply-chain gate 1, wired into CI: scan the real workflow tree and fail the
// job on any action reference that is not a 40-hex pin with its tag comment, or
// that names an action outside the reviewed allowlist.
import { ALLOWLIST_FILE, defaultAllowlistPath, readAllowlist, scanActorGates, scanWorkflows } from './lib/action-pins.mjs'
import { ALLOWLIST_FILE, defaultAllowlistPath, readAllowlistFile, scanActorGates, scanWorkflows } from './lib/action-pins.mjs'

// #640: the checker runs from the base branch, but the workflows it reads are
// the pull request's own — they are the data under test, so the directory is an
Expand All @@ -17,9 +17,15 @@ const directory = argument('--workflows', '.github/workflows')
// #650: the list is read relative to this script, which in CI is the base
// checkout, so a pull request cannot add its own action to the list.
const allowlistPath = argument('--allowlist', defaultAllowlistPath())
// #1206: the file carries two halves. The list admits an action; `approved_unused`
// names actions pre-approved for a follow-up change, and the report says how many
// there are so an exemption never reads as an ordinary entry.
let allowlist
let approvedUnused
try {
allowlist = readAllowlist(allowlistPath)
const file = readAllowlistFile(allowlistPath)
allowlist = file.allowed_actions
approvedUnused = file.approved_unused
} catch (error) {
console.error(`action-pins: ${error.message}`)
process.exit(1)
Expand Down Expand Up @@ -75,4 +81,5 @@ if (gates.findings.length > 0) {
process.exit(1)
}

console.log(`action-pins: ok (${report.checked} pinned references across ${report.files.length} workflow files, all on the ${allowlist.length}-action allowlist; ${gates.checked} actions: write job(s) gated on the actor)`)
const preApproved = approvedUnused.length === 0 ? '' : `, ${approvedUnused.length} action(s) pre-approved and not used yet`
console.log(`action-pins: ok (${report.checked} pinned references across ${report.files.length} workflow files, all on the ${allowlist.length}-action allowlist${preApproved}; ${gates.checked} actions: write job(s) gated on the actor)`)
18 changes: 18 additions & 0 deletions scripts/lib/action-pins.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ export declare function defaultAllowlistPath(): string
/** Throws on a malformed file: an unreadable list must not allow everything. */
export declare function readAllowlist(path?: string): string[]

/** One reviewed pre-approval: an action on the list that no workflow uses yet. */
export interface ApprovedUnusedEntry {
name: string
issue: number
expires_at: string
}

export interface AllowlistFile {
allowed_actions: string[]
approved_unused: ApprovedUnusedEntry[]
}

/** Both halves of the file; a missing `approved_unused` reads as an empty one. */
export declare function readAllowlistFile(path?: string): AllowlistFile

/** One message per exemption the tree's own version puts out of bounds. */
export declare function approvedUnusedExpiryProblems(entries: ApprovedUnusedEntry[], version: string, path?: string): string[]

/** `github/codeql-action/init@sha` -> `github/codeql-action`. */
export declare function repositoryOf(value: string): string

Expand Down
122 changes: 121 additions & 1 deletion scripts/lib/action-pins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ const TAG_COMMENT = /(^|\s)#\s*\S+/
export const ALLOWLIST_FILE = '.github/agent/action-allowlist.json'
const ACTION_REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/

// #1206, ADR 0027: an action may be pre-approved in one reviewed change and used
// in the next. The exemption is data — `name`, `issue`, `expires_at` — so granting
// it is a one-line reviewed diff, and a release version bounds it: the release
// pull request that reaches `expires_at` is where a person has to decide, so a
// lapse lands in front of a human instead of on a date nobody scheduled.
const RELEASE_VERSION = /^(\d+)\.(\d+)\.0$/
// A checkout is any released tree, including the patch releases the daily cadence
// produces (ADR 0008 bumps the patch on every day but the week's first). Its bound
// is the minor it belongs to: `0.5.1` is bounded as `0.5.0`.
const TREE_VERSION = /^(\d+)\.(\d+)(?:\.\d+)?$/
const APPROVED_UNUSED_FIELDS = 'expires_at,issue,name'

// Resolved from this file, never from the working directory: the checker runs
// from the base checkout, so the list it reads is the one already reviewed on
// the base branch. A pull request therefore cannot widen the list for itself in
Expand All @@ -39,6 +51,14 @@ export function defaultAllowlistPath() {
// Throws on a malformed file instead of returning an empty list: a gate that
// silently allows everything when its data is unreadable is worse than no gate.
export function readAllowlist(path = defaultAllowlistPath()) {
return readAllowlistFile(path).allowed_actions
}

// The same file, both halves. `allowed_actions` is what admits an action;
// `approved_unused` names actions this project has pre-approved for a follow-up
// change that no workflow uses yet. The exemption is validated like the list it
// sits beside — an unvalidated exemption would be the one soft spot in the gate.
export function readAllowlistFile(path = defaultAllowlistPath()) {
let parsed
try {
parsed = JSON.parse(readFileSync(path, 'utf8'))
Expand All @@ -58,7 +78,107 @@ export function readAllowlist(path = defaultAllowlistPath()) {
if (duplicates.length > 0) {
throw new Error(`${path}: ${duplicates.join(', ')} appears more than once`)
}
return list
return { allowed_actions: list, approved_unused: readApprovedUnused(parsed?.approved_unused, list, path) }
}

// A missing key is an empty one: every tree that predates this rule keeps working,
// and the first exemption is the change that writes the key.
function readApprovedUnused(value, allowedActions, path) {
if (value === undefined) return []
if (!Array.isArray(value)) {
throw new Error(`${path}: approved_unused must be an array of {name, issue, expires_at} entries`)
}
const allowed = new Set(allowedActions.map((entry) => entry.toLowerCase()))
const approved = []
const seen = new Set()
value.forEach((entry, index) => {
const problem = approvedUnusedProblem(entry, allowed, path, index)
if (problem !== null) throw new Error(problem)
const key = entry.name.toLowerCase()
if (seen.has(key)) throw new Error(`${path}: ${entry.name} appears more than once in approved_unused`)
seen.add(key)
approved.push({ name: entry.name, issue: entry.issue, expires_at: entry.expires_at })
})
return approved
}

// An entry is exactly three fields, because a field the reader ignores is a field
// a reviewer may believe was checked. `name` has to be on the list it sits beside:
// an exemption for an action the gate still refuses pre-approves nothing.
function approvedUnusedProblem(entry, allowed, path, index) {
const where = `${path}: approved_unused[${index}]`
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) {
return `${where} must be an object with exactly name, issue and expires_at`
}
const fields = APPROVED_UNUSED_FIELDS.split(',')
const extra = Object.keys(entry).filter((key) => !fields.includes(key))
if (extra.length > 0) {
return `${where}: ${extra.join(', ')} is not a field of an entry (exactly name, issue and expires_at)`
}
const missing = fields.filter((key) => !(key in entry))
if (missing.length > 0) return `${where} is missing ${missing.join(', ')}`
if (typeof entry.name !== 'string' || !ACTION_REPOSITORY.test(entry.name)) {
return `${where}: ${JSON.stringify(entry.name)} is not an exact owner/repo name (wildcards are not allowed)`
}
if (!allowed.has(entry.name.toLowerCase())) {
return `${where}: ${entry.name} is not in allowed_actions, so the exemption would pre-approve an action the gate still refuses`
}
if (!Number.isInteger(entry.issue) || entry.issue <= 0) {
return `${where}.issue must be the number of the issue that pre-approved it`
}
if (typeof entry.expires_at !== 'string' || !RELEASE_VERSION.test(entry.expires_at)) {
return `${where}.expires_at must be a minor release version (x.y.0); there is no "no expiry" value`
}
return null
}

function releaseVersion(value) {
const match = RELEASE_VERSION.exec(String(value))
if (match === null) return null
return Number(match[1]) * 1000 + Number(match[2])
}

// The minor a checkout belongs to, whatever its patch. A tree that is not a
// version at all cannot bound anything, and the caller says so instead of guessing.
function treeMinor(value) {
const match = TREE_VERSION.exec(String(value))
if (match === null) return null
return Number(match[1]) * 1000 + Number(match[2])
}

// The bound, as failures rather than prose. Equality fails deliberately: the
// release pull request that bumps the tree to `expires_at` is exactly the moment a
// person has to delete or renew the entry, so that pull request cannot go green
// while the exemption is still there. An expiry more than two minors ahead would
// outlive the review that justified it, and one minor would lapse before a single
// release could carry the follow-up.
export function approvedUnusedExpiryProblems(entries, version, path = ALLOWLIST_FILE) {
// With no entries there is nothing to bound, so a tree that is not a release has
// no problem to report. Failing here would red every patch release (ADR 0008 bumps
// the patch on all but the week's first day) over an empty list the project ships,
// which is how a check gets deleted instead of read.
if (entries.length === 0) return []
const current = treeMinor(version)
if (current === null) {
return [`${path}: ${JSON.stringify(version)} is not a release version (x.y.z), so no exemption can be bounded against it`]
}
const problems = []
for (const entry of entries) {
const expires = releaseVersion(entry.expires_at)
if (expires === null) {
problems.push(`${path}: ${entry.name} (#${entry.issue}) has expires_at ${JSON.stringify(entry.expires_at)}, which is not a minor release version (x.y.0)`)
continue
}
const moves = `Delete the entry, or renew it with a new expires_at and a comment on #${entry.issue} saying why the pre-approval still stands`
if (current >= expires) {
problems.push(`${path}: ${entry.name} was pre-approved on #${entry.issue} and expires at ${entry.expires_at}; this tree is ${version}. ${moves}.`)
continue
}
if (expires - current > 2) {
problems.push(`${path}: ${entry.name} is pre-approved until ${entry.expires_at} (#${entry.issue}), more than two minors beyond this tree's ${version}; the bound may not outlive the review that justified it. ${moves}.`)
}
}
return problems
}

// `github/codeql-action/init@<sha>` belongs to `github/codeql-action`: the
Expand Down
Loading
Loading