mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
The label sync was the only workflow that read PULSE_TRIAGE_APP_PRIVATE_KEY. That key belongs to an App installation that can administer the repository, and as a repository-level Actions secret any workflow run on any branch could read it. Everything the helper does (read the issue, create, add and remove labels) is covered by the run's own GITHUB_TOKEN with issues: write, so the App key can now be deleted from Actions. The policy test now requires issue-mutating workflows to use the scoped GITHUB_TOKEN and to reference no secrets, and still requires the parser tests to run before the label write. Silent labels are applied as github-actions[bot]; AI_TRANSPARENCY.md says so.
58 lines
2.3 KiB
JavaScript
58 lines
2.3 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
const workflowDir = path.resolve(__dirname, "../workflows");
|
|
const issueMutationPatterns = [
|
|
/github\.rest\.issues\.createComment/,
|
|
/github\.rest\.pulls\.createReviewComment/,
|
|
/addDiscussionComment/,
|
|
/post(?:Eligible)?RetestComments?/,
|
|
/syncLabels/,
|
|
];
|
|
|
|
// The triage App installation can administer the repository, so its key must
|
|
// not be an Actions secret any workflow on any branch could read. Workflow
|
|
// issue mutations use the run's own GITHUB_TOKEN, scoped to issues.
|
|
test("automated workflow issue mutations use an issues-scoped GITHUB_TOKEN, not a secret", () => {
|
|
const publishers = [];
|
|
|
|
for (const name of fs.readdirSync(workflowDir)) {
|
|
if (!name.endsWith(".yml") && !name.endsWith(".yaml")) continue;
|
|
const workflow = fs.readFileSync(path.join(workflowDir, name), "utf8");
|
|
if (!issueMutationPatterns.some((pattern) => pattern.test(workflow))) continue;
|
|
|
|
publishers.push(name);
|
|
assert.match(
|
|
workflow,
|
|
/^permissions:\n contents: read\n issues: write\n(?! )/m,
|
|
`${name} must grant exactly contents: read and issues: write`
|
|
);
|
|
assert.doesNotMatch(workflow, /^\s+permissions:/m, `${name} must not override permissions per job`);
|
|
assert.match(
|
|
workflow,
|
|
/github-token: \$\{\{ github\.token \}\}/,
|
|
`${name} must pass the run's GITHUB_TOKEN to github-script`
|
|
);
|
|
assert.doesNotMatch(workflow, /secrets\./, `${name} must not read repository secrets`);
|
|
assert.doesNotMatch(workflow, /create-github-app-token/, `${name} must not mint an App token`);
|
|
}
|
|
|
|
assert.deepEqual(publishers.sort(), [
|
|
"issue-version-label-sync.yml",
|
|
]);
|
|
});
|
|
|
|
|
|
test("version-only posting and timeout closure workflows are retired", () => {
|
|
for (const name of ["issue-version-retest-comment.yml", "close-needs-retest-timeout.yml"]) {
|
|
assert.equal(fs.existsSync(path.join(workflowDir, name)), false, name);
|
|
}
|
|
for (const name of fs.readdirSync(workflowDir)) {
|
|
if (!/\.ya?ml$/.test(name)) continue;
|
|
const source = fs.readFileSync(path.join(workflowDir, name), "utf8");
|
|
assert.doesNotMatch(source, /post(?:Eligible)?RetestComments?|issue-version-triage:v1|buildTimeoutCloseCommentBody/, name);
|
|
}
|
|
});
|