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
8 changes: 8 additions & 0 deletions components/runner-policy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ label validation. The selector still receives `CI_HOSTED_RUNNER` as its normal
validated input; only the caller's failure fallback is frozen to
`ubuntu-24.04`.

The frozen literal is the governed `default`, and that default must appear in
`fallbackLabelAllowlist` — a set deliberately narrower than
`approvedHostedRunnerLabels`. A label may be an approved explicit `runs-on`
target yet still be barred from becoming the silent recovery fallback, so a
costlier hosted tier cannot slip in as the default that fires whenever the
selector fails. Configuration fails closed when the default is absent from the
allowlist.

The `self-hosted-label` input may be either `${{ vars.CI_SELF_HOSTED_LABEL }}`
(the default fleet tier) or `${{ vars.CI_REVIEW_SELF_HOSTED_LABEL }}` (the
dedicated capped review tier). A review-lane caller passes the latter from a
Expand Down
5 changes: 4 additions & 1 deletion components/runner-policy/THREAT-MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ not duplicate those changing inventories.
platform behavior, not all future control-plane interpretation.
- The literal hosted fallback preserves scheduling availability but spends
hosted capacity and does not make a failed selector healthy. Operational
monitoring must still surface selector failures.
monitoring must still surface selector failures. Its label is bounded to
`fallbackLabelAllowlist`, narrower than `approvedHostedRunnerLabels`, so the
fallback cannot silently escalate to a costlier hosted tier; the residual
spend is that of the single allowlisted default.
- The zero-cost rejection sentinel intentionally delays terminal failure until
GitHub's 24-hour unmatched self-hosted queue limit. Its safety also depends on
the external runner inventory never assigning `ci-runner-selection-failed`;
Expand Down
3 changes: 2 additions & 1 deletion components/runner-policy/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,15 @@
"canonicalSelectorSecrets": {
"observer-private-key": "${{ secrets.CI_RUNNER_OBSERVER_PRIVATE_KEY }}"
},
"approvedHostedRunnerLabels": ["ubuntu-24.04", "ubuntu-slim", "windows-2025"],
"approvedHostedRunnerLabels": ["ubuntu-24.04", "windows-2025"],
"hostedMatrixExpressions": ["${{ matrix.os }}", "${{ matrix.runner }}"],
"governedReusableRunnerInput": {
"name": "runner",
"expression": "${{ inputs.runner }}",
"default": "ubuntu-24.04",
"failureSentinel": "ci-runner-selection-failed"
},
"fallbackLabelAllowlist": ["ubuntu-24.04"],
"forbiddenHostedRunnerLabels": ["macos-latest", "ubuntu-latest", "windows-latest"],
"managedLabelPatterns": [
"(?:^|[^a-z0-9-])(?:melodic|kyle)-(?:[a-z0-9]+-)*ubuntu-24\\.04-x64(?:-[a-z0-9-]+)?(?:$|[^a-z0-9-])"
Expand Down
2 changes: 2 additions & 0 deletions components/runner-policy/policy.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"approvedHostedRunnerLabels",
"hostedMatrixExpressions",
"governedReusableRunnerInput",
"fallbackLabelAllowlist",
"forbiddenHostedRunnerLabels",
"managedLabelPatterns",
"hostedExceptionReasons",
Expand Down Expand Up @@ -72,6 +73,7 @@
"failureSentinel": { "const": "ci-runner-selection-failed" }
}
},
"fallbackLabelAllowlist": { "$ref": "#/$defs/nonEmptyUniqueStringArray" },
"forbiddenHostedRunnerLabels": { "$ref": "#/$defs/nonEmptyUniqueStringArray" },
"managedLabelPatterns": { "$ref": "#/$defs/nonEmptyUniqueStringArray" },
"hostedExceptionReasons": { "$ref": "#/$defs/nonEmptyUniqueStringArray" },
Expand Down
5 changes: 5 additions & 0 deletions components/runner-policy/runner-policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ function validatePolicy(value) {
"policy.governedReusableRunnerInput.default must be an approved hosted runner label",
);
}
if (!new Set(value.fallbackLabelAllowlist).has(value.governedReusableRunnerInput.default)) {
throw new ConfigurationError(
"policy.governedReusableRunnerInput.default must be in policy.fallbackLabelAllowlist",
);
}
if (
approvedHostedRunnerLabels.has(value.governedReusableRunnerInput.failureSentinel) ||
forbiddenHostedRunnerLabels.has(
Expand Down
76 changes: 76 additions & 0 deletions components/runner-policy/runner-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ test("selector recovery derives its literal fallback from the governed default",
const alternateDefault = "ubuntu-22.04";
const policyOverrides = {
approvedHostedRunnerLabels: [...BASE_POLICY.approvedHostedRunnerLabels, alternateDefault],
fallbackLabelAllowlist: [...BASE_POLICY.fallbackLabelAllowlist, alternateDefault],
governedReusableRunnerInput: {
...BASE_POLICY.governedReusableRunnerInput,
default: alternateDefault,
Expand Down Expand Up @@ -6263,6 +6264,81 @@ test("policy schema fixes the reserved sentinel literal", async () => {
await assert.rejects(() => audit(root), /governedReusableRunnerInput\.failureSentinel/);
});

test("fallback label allowlist policy remains required", async () => {
const root = await repository({
policyOverrides: { fallbackLabelAllowlist: undefined },
});
await assert.rejects(
() => audit(root),
(error) =>
error instanceof ConfigurationError &&
error.message === "policy must have required property 'fallbackLabelAllowlist'",
);
});

test("governed fallback default must be listed in the fallback label allowlist", async () => {
const root = await repository({
policyOverrides: {
governedReusableRunnerInput: {
...BASE_POLICY.governedReusableRunnerInput,
default: "windows-2025",
},
},
workflows: { "ci.yml": "jobs:\n test:\n runs-on: ubuntu-24.04\n steps: []\n" },
});
await assert.rejects(
() => audit(root),
(error) =>
error instanceof ConfigurationError &&
error.message ===
"policy.governedReusableRunnerInput.default must be in policy.fallbackLabelAllowlist",
);
});

test("a hosted label removed from the approved set can no longer be the fallback default", async () => {
const root = await repository({
policyOverrides: {
governedReusableRunnerInput: {
...BASE_POLICY.governedReusableRunnerInput,
default: "ubuntu-slim",
},
},
workflows: { "ci.yml": "jobs:\n test:\n runs-on: ubuntu-24.04\n steps: []\n" },
});
await assert.rejects(
() => audit(root),
(error) =>
error instanceof ConfigurationError &&
error.message ===
"policy.governedReusableRunnerInput.default must be an approved hosted runner label",
);
});

test("the shipped fallback default satisfies the fallback label allowlist", async () => {
const root = await repository({
workflows: {
"ci.yml": `permissions: read-all\njobs:\n choose:\n${SELECTOR} test:\n needs: choose\n if: \${{ !cancelled() }}\n runs-on: \${{ needs.choose.outputs.runner || 'ubuntu-24.04' }}\n steps: []\n`,
},
});
assert.deepEqual(await audit(root), []);
});

test("the fallback label allowlist can be extended to admit another approved default", async () => {
const root = await repository({
policyOverrides: {
fallbackLabelAllowlist: [...BASE_POLICY.fallbackLabelAllowlist, "windows-2025"],
governedReusableRunnerInput: {
...BASE_POLICY.governedReusableRunnerInput,
default: "windows-2025",
},
},
workflows: {
"ci.yml": `permissions: read-all\njobs:\n choose:\n${SELECTOR} test:\n needs: choose\n if: \${{ !cancelled() }}\n runs-on: \${{ needs.choose.outputs.runner || 'windows-2025' }}\n steps: []\n`,
},
});
assert.deepEqual(await audit(root), []);
});

test("sentinel is not a general local reusable runner value", async () => {
const root = await repository({
workflows: {
Expand Down