diff --git a/components/runner-policy/README.md b/components/runner-policy/README.md index d5f2a88d..ededf5c0 100644 --- a/components/runner-policy/README.md +++ b/components/runner-policy/README.md @@ -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 diff --git a/components/runner-policy/THREAT-MODEL.md b/components/runner-policy/THREAT-MODEL.md index 8a0db672..1ba3708f 100644 --- a/components/runner-policy/THREAT-MODEL.md +++ b/components/runner-policy/THREAT-MODEL.md @@ -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`; diff --git a/components/runner-policy/policy.json b/components/runner-policy/policy.json index 02b4f707..cfb00ec6 100644 --- a/components/runner-policy/policy.json +++ b/components/runner-policy/policy.json @@ -299,7 +299,7 @@ "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", @@ -307,6 +307,7 @@ "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-])" diff --git a/components/runner-policy/policy.schema.json b/components/runner-policy/policy.schema.json index 2d99b3b3..e4210448 100644 --- a/components/runner-policy/policy.schema.json +++ b/components/runner-policy/policy.schema.json @@ -16,6 +16,7 @@ "approvedHostedRunnerLabels", "hostedMatrixExpressions", "governedReusableRunnerInput", + "fallbackLabelAllowlist", "forbiddenHostedRunnerLabels", "managedLabelPatterns", "hostedExceptionReasons", @@ -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" }, diff --git a/components/runner-policy/runner-policy.mjs b/components/runner-policy/runner-policy.mjs index e46cf873..33f5b46e 100755 --- a/components/runner-policy/runner-policy.mjs +++ b/components/runner-policy/runner-policy.mjs @@ -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( diff --git a/components/runner-policy/runner-policy.test.mjs b/components/runner-policy/runner-policy.test.mjs index 41062682..793723f7 100644 --- a/components/runner-policy/runner-policy.test.mjs +++ b/components/runner-policy/runner-policy.test.mjs @@ -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, @@ -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: {