Skip to content

ci(skills): ratchet stack-specific code fences in skill bodies and amend ADR 0101 #3195

ci(skills): ratchet stack-specific code fences in skill bodies and amend ADR 0101

ci(skills): ratchet stack-specific code fences in skill bodies and amend ADR 0101 #3195

name: Intake Label Outside Actor Activity
# Flags an issue or pull request when someone outside the organization opens
# or edits it, or comments or reviews on it. Outside actors are the security
# boundary the owner keeps: such an item goes to a person (`needs-human`).
# The rules are in .github/scripts/security-outside-actor/flag.mjs.
#
# A removal of `security: outside-actor` always starts the job, whoever sent
# it: flag.mjs puts the label back unless the sender is a person on the
# trusted-actor list. Removing any other label starts none. For every other
# event, two skips run in the job's `if`, before a runner starts, so most
# events cost nothing:
# - the content's author has `author_association` OWNER or MEMBER, unless the
# event is an edit, a push to a pull request or a reopen by someone other
# than that author: flag.mjs then judges the sender by id alone, so anyone
# not on the trusted list, an organization member included, who edits
# another's text or pushes to another's pull request is flagged;
# - the event's sender is a Bot. Only a GitHub App installed on this
# repository acts as a Bot here, which means one of ours, so lane traffic
# starts no job. A fork pull request is the exception: an App installed on
# the fork can act there, so a Bot's `pull_request_target` event of any
# action on a pull request whose head repository is not this one still
# runs (the job reads that repository's name from the payload and never
# checks the head out).
# Machine-user accounts are type User and are still checked.
# Everything that runs is judged by the default branch's trusted-actor list,
# matched by numeric id: a listed id is trusted, any other author is flagged,
# and an unreadable list flags too.
#
# No model, no secret and no App token: the job's GITHUB_TOKEN adds the
# `security: outside-actor` label, sets an issue's Work status to needs-human
# (a pull request gets the `needs-human` label), and posts one comment per
# outside actor, naming their login without a mention and quoting none of
# their text. `security: outside-actor` is a hold of its own (merge-holds.mjs
# OUTSIDE_ACTOR_LABEL): the merge queue, auto-merge arming, babysit, intake
# triage, the work-unblock sweep and each activity whose labels-absent lists
# needs-human skip it. The script reads the event payload itself; no event
# text reaches a shell. The lanes kill switch does not stop this check: it
# would silence the boundary it guards.
#
# Accepted exposure: `issues`, `issue_comment` and `pull_request_target` run
# this file from the default branch with a write token. `pull_request_review`
# and `pull_request_review_comment` run from the pull request's merge ref, and
# on a pull request from a fork GitHub gives them a read-only token, so a
# review or diff comment on a fork pull request is logged as a failed run, not
# flagged. Every fork pull request is an outsider's, and its opening is
# flagged through `pull_request_target`; the review and comment triggers catch
# an outsider writing on one of this repository's own pull requests.
on:
# Runs from the default branch; checks out main only and passes no event
# text to a shell.
issues: # zizmor: ignore[dangerous-triggers]
types: [opened, edited, reopened, unlabeled]
issue_comment: # zizmor: ignore[dangerous-triggers]
types: [created, edited]
pull_request_review:
types: [submitted, edited]
pull_request_review_comment:
types: [created, edited]
# Never checks out the pull request head.
pull_request_target: # zizmor: ignore[dangerous-triggers]
types: [opened, edited, synchronize, reopened, unlabeled]
permissions: {}
jobs:
label-outside-actor:
# The author is the comment's, else the review's, else the pull
# request's, else the issue's, the order flag.mjs reads them in.
name: Label Outside Actor
if: >-
(github.event.action == 'unlabeled'
&& github.event.label.name == 'security: outside-actor')
|| (github.event.action != 'unlabeled'
&& (github.event.sender.type != 'Bot'
|| (github.event_name == 'pull_request_target'
&& github.event.pull_request.head.repo.full_name != github.repository))
&& ((contains(fromJSON('["edited", "synchronize", "reopened"]'), github.event.action)
&& github.event.sender.id != (github.event.comment.user.id
|| github.event.review.user.id
|| github.event.pull_request.user.id
|| github.event.issue.user.id))
|| !contains(fromJSON('["OWNER", "MEMBER"]'),
github.event.comment.author_association
|| github.event.review.author_association
|| github.event.pull_request.author_association
|| github.event.issue.author_association)))
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read # check out main
issues: write # label and comment on an issue
pull-requests: write # label and comment on a pull request
# Runs on one item wait in line (`queue: max`) so none is dropped.
concurrency:
group: security-outside-actor-${{ github.event.issue.number || github.event.pull_request.number }}
queue: max
env:
API_BUDGET_TOKEN: github-token
npm_config_audit: "false"
npm_config_fetch_timeout: "60000"
npm_config_fund: "false"
# npm's fetch timeout and retries, from the one file that sets them.
npm_config_globalconfig: ${{ github.workspace }}/.base/.github/npm-fetch.npmrc
steps:
- name: Resolve main's tip
id: tip
env:
TIP_BRANCH: main
GIT_TERMINAL_PROMPT: "0"
run: |
until sha=$(timeout 60 git -C "$RUNNER_TEMP" ls-remote "https://github.com/$GITHUB_REPOSITORY.git" "refs/heads/$TIP_BRANCH" |
awk -v ref="refs/heads/$TIP_BRANCH" '$2 == ref { print $1 }') && [[ $sha =~ ^[0-9a-f]{40}$ ]]; do
((++i < 3)) || { echo "::error::the tip of $TIP_BRANCH did not resolve"; exit 1; }
sleep "$((RANDOM % (2 * i + 1)))"
done
echo "sha=$sha" >>"$GITHUB_OUTPUT"
- name: Check out the default branch tip
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.tip.outputs.sha }}
path: .base
persist-credentials: false
- name: Set up Node
uses: ./.base/.github/actions/setup-pinned-node # zizmor: ignore[self-repository]
with:
node-version-file: .base/.node-version
# flag.mjs writes an issue's Work status through resolve-config.mjs,
# whose packages only the resolve-config action installs, and this job
# does not run that action. The label and comment must land without them,
# so a failed install continues; on an issue the field write then fails
# the run visibly.
- name: Install resolve-config's packages
continue-on-error: true
timeout-minutes: 3
run: npm ci --ignore-scripts --omit=dev --prefix .base/.github/actions/resolve-config
- name: Flag an outside actor
env:
GITHUB_TOKEN: ${{ github.token }}
TRUSTED_ACTORS_PATH: .base/.github/standards/trusted-actors/trusted-actors.json
run: node .base/.github/scripts/security-outside-actor/flag.mjs
- name: Log the API budget at the end
if: always()
continue-on-error: true
timeout-minutes: 1
uses: ./.base/.github/actions/log-api-budget # zizmor: ignore[self-repository]
with:
tokens: github-token