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
103 changes: 92 additions & 11 deletions .github/scripts/native-queue-policy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const BLOCKED_LABEL = /^(hold|needs-human|release-in-progress|do-not-merge(?:\/.
const MAX_QUEUE_PAGES = 10;
const POLICY_CHECK_NAME = 'native-queue-policy';
const POLICY_CHECK_SOURCE = ['native-queue-policy.yml', ['pull_request_target']];
// Decision B on #17030: a v5β†’v6 forward-merge opened by v6-topup.yml carries
// commits that already passed v5's DCO gate, and probot DCO cannot be repaired
// PR-side. Only that exact shape may substitute prow's `dco` status.
const FORWARD_MERGE = {
head: 'sync/v5-to-v6', base: 'v6', source: 'v5',
author: { login: 'github-actions[bot]', id: 41898282, type: 'Bot' },
};
const PROW = { login: 'kubestellar-prow[bot]', id: 208851060, context: 'dco' };
// REST pull-request commit listing stops at 250; a longer list is unverifiable.
const MAX_PR_COMMITS = 250;
const PROBOT_DCO_PATH = 'DCO path: probot DCO (App 1861)';

const closedNoop = (pr) => `PR #${pr.number} is closed; nothing to evaluate`;

Expand Down Expand Up @@ -148,15 +159,83 @@ async function assertActionsProvenance(github, repo, number, head, run, source,
}
}

async function assertEvidence(github, repo, number, head, checks) {
async function reachableFrom(github, repo, branch, commit) {
const { data } = await github.rest.repos.compareCommitsWithBasehead({
...repo, basehead: `${branch}...${commit}`,
});
return ['behind', 'identical'].includes(data.status);
}

// Returns null when the PR is not the top-up shape at all, otherwise whether
// the narrow prow path applies and why. Any doubt keeps probot DCO required.
async function forwardMergeDCOPath(github, repo, pr, head) {
const author = FORWARD_MERGE.author;
if (pr?.head?.ref !== FORWARD_MERGE.head || pr.base?.ref !== FORWARD_MERGE.base ||
pr.head.repo?.full_name !== `${repo.owner}/${repo.repo}` ||
pr.user?.login !== author.login || pr.user.id !== author.id || pr.user.type !== author.type) {
return null;
}
const commits = await github.paginate(github.rest.pulls.listCommits, {
...repo, pull_number: pr.number, per_page: 100,
});
const fallback = why => ({ prow: false, path: `${PROBOT_DCO_PATH}; ${FORWARD_MERGE.head} fallback: ${why}` });
if (commits.length === 0 || commits.length >= MAX_PR_COMMITS) {
return fallback(`commit list unverifiable (${commits.length} commits)`);
}
for (const commit of commits) {
if (!SHA.test(commit.sha)) return fallback('malformed commit list');
// The tip is v6-topup.yml's own `--no-ff` merge of origin/v5 onto v6, so it
// is never on v5 itself: its parents must be v6 and v5 history exactly.
if (commit.sha === head) {
const [ours, theirs] = (commit.parents || []).map(p => p.sha);
if (commit.parents?.length !== 2 || !SHA.test(ours) || !SHA.test(theirs) ||
!await reachableFrom(github, repo, FORWARD_MERGE.base, ours) ||
!await reachableFrom(github, repo, FORWARD_MERGE.source, theirs)) {
return fallback(`head ${head} is not a merge of ${FORWARD_MERGE.source} into ${FORWARD_MERGE.base}`);
}
} else if (!await reachableFrom(github, repo, FORWARD_MERGE.source, commit.sha)) {
return fallback(`${commit.sha} is not reachable from ${FORWARD_MERGE.source}`);
}
}
if (!commits.some(c => c.sha === head)) return fallback(`head ${head} is not in the commit list`);
return {
prow: true,
path: `DCO path: prow ${PROW.context} for ${FORWARD_MERGE.source}-reachable ${FORWARD_MERGE.head} forward-merge (#17030)`,
};
}

async function assertProwDCO(github, repo, head) {
const statuses = await github.paginate(github.rest.repos.listCommitStatusesForRef, {
...repo, ref: head, per_page: 100,
});
// Any workflow token can post a `dco` status; only prow's own is evidence.
const status = statuses
.filter(s => s.context === PROW.context && s.creator?.login === PROW.login && s.creator.id === PROW.id)
.sort((a, b) => b.id - a.id)[0];
if (!status) throw new PendingEvidence(`Missing prow ${PROW.context} on ${head}`);
if (status.state === 'pending') throw new PendingEvidence(`prow ${PROW.context} is pending`);
if (status.state !== 'success') throw new Error(`prow ${PROW.context}: ${status.state}`);
}

async function assertEvidence(github, repo, number, head, checks, pr) {
const dco = Object.hasOwn(checks, 'DCO') ? await forwardMergeDCOPath(github, repo, pr, head) : null;
const required = { ...checks };
if (dco?.prow) delete required.DCO;
const runs = await github.paginate(github.rest.checks.listForRef, {
...repo, ref: head, per_page: 100, filter: 'latest',
});
const workflows = new Map();
for (const { run, source } of evidenceForHead(runs, head, checks)) {
if (!source) continue; // Probot DCO is deliberately not impersonated.
await assertActionsProvenance(github, repo, number, head, run, source, workflows);
try {
for (const { run, source } of evidenceForHead(runs, head, required)) {
if (!source) continue; // Probot DCO is deliberately not impersonated.
await assertActionsProvenance(github, repo, number, head, run, source, workflows);
}
if (dco?.prow) await assertProwDCO(github, repo, head);
} catch (error) {
if (dco && !(error instanceof ProviderUnavailable)) error.message += ` [${dco.path}]`;
throw error;
}
return dco?.path || PROBOT_DCO_PATH;
}

async function assertReviews(github, repo, number, head) {
Expand Down Expand Up @@ -268,13 +347,14 @@ async function replayLastVerdict({ github, context, currentCheckRunId }) {
// A DCO enumeration UNKNOWN also falls through: the full wait re-raises it
// once and renders the runbook job summary, so operators see the same
// surface whichever event fired.
let path;
try {
await assertEvidence(github, repo, pr.number, pr.head.sha, POLICY_CHECKS);
path = await assertEvidence(github, repo, pr.number, pr.head.sha, POLICY_CHECKS, pr);
} catch (error) {
if (error instanceof PendingEvidence || error instanceof ProviderUnavailable) return null;
throw error;
}
return `PR #${pr.number}: replayed ${POLICY_CHECK_NAME} run ${prior.id} (success) on ${pr.head.sha}`;
return `PR #${pr.number}: replayed ${POLICY_CHECK_NAME} run ${prior.id} (success) on ${pr.head.sha}; ${path}`;
}

async function evaluateOnce({ github, context }) {
Expand All @@ -285,17 +365,18 @@ async function evaluateOnce({ github, context }) {
// Post-merge label/comment edits re-fire this event; a closed PR has nothing to gate.
if (pr.state === 'closed') return closedNoop(pr);
assertEligible(pr, event.head.sha, event.base.ref);
await assertEvidence(github, repo, pr.number, pr.head.sha, POLICY_CHECKS);
const path = await assertEvidence(github, repo, pr.number, pr.head.sha, POLICY_CHECKS, pr);
const { data: current } = await github.rest.pulls.get({ ...repo, pull_number: event.number });
if (current.state === 'closed') return closedNoop(current);
assertEligible(current, event.head.sha, event.base.ref);
return `PR #${pr.number}: five existing policy providers succeeded on ${pr.head.sha}`;
return `PR #${pr.number}: five existing policy providers succeeded on ${pr.head.sha}; ${path}`;
}
if (context.eventName !== 'merge_group' || context.payload.action !== 'checks_requested') {
throw new Error('Unsupported policy event');
}
const group = context.payload.merge_group;
const members = await readQueue(github, repo, group);
const paths = [];
for (const entry of members) {
const { number, headRefOid: head } = entry.pullRequest;
const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: number });
Expand All @@ -307,7 +388,7 @@ async function evaluateOnce({ github, context }) {
throw new Error(`#${number}: current PR head is not contained in the tested group`);
}
await assertReviews(github, repo, number, head);
await assertEvidence(github, repo, number, head, { ...POLICY_CHECKS, ...BUILD_CHECKS });
paths.push(`#${number} ${await assertEvidence(github, repo, number, head, { ...POLICY_CHECKS, ...BUILD_CHECKS }, pr)}`);
}
// Re-read both membership and mutable gates after all evidence reads. This
// bounds TOCTOU, but GitHub/Hive reconciliation is not an atomic transaction.
Expand All @@ -324,14 +405,14 @@ async function evaluateOnce({ github, context }) {
...repo, ref: group.head_ref.slice('refs/'.length),
});
if (ref.object?.sha !== group.head_sha) throw new Error('Synthetic group ref moved');
return `Group ${group.head_sha}: validated all ${members.length} member heads`;
return `Group ${group.head_sha}: validated all ${members.length} member heads (${paths.join('; ')})`;
}

module.exports = {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL,
ProviderUnavailable,
ProviderUnavailable, FORWARD_MERGE, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT, DCO_PROVIDER_RUNBOOK,
};
95 changes: 94 additions & 1 deletion .github/scripts/native-queue-policy.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict,
ProviderUnavailable,
ProviderUnavailable, FORWARD_MERGE, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX,
DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT,
Expand Down Expand Up @@ -206,6 +206,99 @@ test('UNKNOWN reporting requires trusted exact-head completed DCO and the specif
error => !(error instanceof ProviderUnavailable) && error.message === 'DCO: failure');
});

// #17030: v6-topup.yml's PR whose probot DCO rejects a commit already on v5.
function forwardMergeFixture() {
const f = fixture('pull_request_target');
Object.assign(f.state.prs[0], {
head: { sha: sha(11), ref: 'sync/v5-to-v6', repo: { full_name: 'acme/widget' } },
base: { ref: 'v6' }, user: { ...FORWARD_MERGE.author },
});
f.context.payload.pull_request = clone(f.state.prs[0]);
f.state.runs.get(sha(11)).find(r => r.name === 'DCO').conclusion = 'action_required';
// sha(201) is the v5 commit probot rejects; sha(11) is the top-up merge of
// v5 (sha(201)) onto v6 (sha(300)).
f.state.commits = [
{ sha: sha(201), parents: [{ sha: sha(200) }] },
{ sha: sha(11), parents: [{ sha: sha(300) }, { sha: sha(201) }] },
];
f.state.reachable = new Set([`v5...${sha(201)}`, `v6...${sha(300)}`]);
f.state.statuses = [
{ id: 1, context: 'dco', state: 'success', creator: { login: PROW.login, id: PROW.id } },
];
f.github.rest.pulls.listCommits = 'commits';
f.github.rest.repos.listCommitStatusesForRef = 'statuses';
f.github.rest.repos.compareCommitsWithBasehead = async ({ basehead }) => {
f.state.seen.push(basehead);
return { data: { status: f.state.reachable.has(basehead) ? 'behind' : 'diverged' } };
};
const basePaginate = f.github.paginate;
f.github.paginate = async (method, args) => {
if (method === 'commits') return clone(f.state.commits);
if (method === 'statuses') return clone(f.state.statuses);
return basePaginate(method, args);
};
return f;
}

test('v5-reachable sync/v5-to-v6 forward-merge passes on prow dco without probot DCO', async () => {
const f = forwardMergeFixture();
assert.match(await evaluate(f),
/five existing policy providers succeeded.*DCO path: prow dco for v5-reachable sync\/v5-to-v6 forward-merge/);
assert.deepEqual(f.state.seen, [`v5...${sha(201)}`, `v6...${sha(300)}`, `v5...${sha(201)}`]);
});

test('one commit unreachable from v5 keeps the forward-merge on probot DCO', async () => {
const unreachable = forwardMergeFixture();
unreachable.state.reachable.delete(`v5...${sha(201)}`);
await assert.rejects(evaluate(unreachable), /DCO: action_required.*probot DCO.*not reachable from v5/);
const extra = forwardMergeFixture();
extra.state.commits.splice(1, 0, { sha: sha(202), parents: [{ sha: sha(201) }] });
await assert.rejects(evaluate(extra), new RegExp(`DCO: action_required.*${sha(202)} is not reachable from v5`));
for (const parents of [[{ sha: sha(201) }], [{ sha: sha(301) }, { sha: sha(201) }], [{ sha: sha(300) }, { sha: sha(202) }]]) {
const notMerge = forwardMergeFixture();
notMerge.state.commits[1].parents = parents;
await assert.rejects(evaluate(notMerge), /DCO: action_required.*is not a merge of v5 into v6/);
}
const truncated = forwardMergeFixture();
truncated.state.commits = Array.from({ length: 250 }, (_, i) => ({ sha: sha(1000 + i), parents: [] }));
await assert.rejects(evaluate(truncated), /DCO: action_required.*commit list unverifiable/);
// Probot DCO succeeding still admits through the unchanged path.
unreachable.state.runs.get(sha(11)).find(r => r.name === 'DCO').conclusion = 'success';
assert.match(await evaluate(unreachable), /DCO path: probot DCO \(App 1861\); sync\/v5-to-v6 fallback/);
});

test('another head branch, base, fork or author keeps requiring probot DCO', async () => {
for (const change of [
pr => { pr.head.ref = 'sync/v5-to-v6-extra'; },
pr => { pr.head.repo.full_name = 'fork/widget'; },
pr => { pr.user = { login: 'clubanderson', id: 1, type: 'User' }; },
pr => { pr.user.id = 1; },
pr => { pr.user.login = 'hivecommons-hive[bot]'; },
]) {
const f = forwardMergeFixture();
change(f.state.prs[0]);
await assert.rejects(evaluate(f), error => error.message === 'DCO: action_required');
assert.equal(f.state.seen.length, 0);
}
const v5 = forwardMergeFixture();
v5.state.prs[0].base.ref = 'v5';
v5.context.payload.pull_request.base.ref = 'v5';
await assert.rejects(evaluate(v5), error => error.message === 'DCO: action_required');
});

test('forward-merge path fails without a successful prow-created dco status', async () => {
const failed = forwardMergeFixture();
failed.state.statuses.push({ id: 2, context: 'dco', state: 'failure', creator: { login: PROW.login, id: PROW.id } });
await assert.rejects(evaluate(failed), /prow dco: failure.*DCO path: prow dco/);
// Any workflow token can post a `dco` status; it never stands in for prow.
const forged = forwardMergeFixture();
forged.state.statuses = [{ id: 3, context: 'dco', state: 'success', creator: { login: 'github-actions[bot]', id: 41898282 } }];
await assert.rejects(evaluate(forged), error => error instanceof PendingEvidence && /Missing prow dco/.test(error.message));
const pending = forwardMergeFixture();
pending.state.statuses[0].state = 'pending';
await assert.rejects(evaluate(pending), error => error instanceof PendingEvidence);
});

test('draft, closed, held and moved-head/base PRs cannot pass', () => {
for (const change of [
{ draft: true }, { state: 'closed' }, { head: { sha: sha(99) } }, { base: { ref: 'v6' } },
Expand Down
15 changes: 14 additions & 1 deletion src/docs/native-merge-queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ metadata, not a fabricated last-member PR event.
this bridge does not turn its underlying implementation into a strict
content validator. Dependabot runs that same trusted PR-target verifier
rather than skipping it; skipped policy evidence is never exempted by actor.
- One narrow exception replaces probot `DCO` (#17030): a PR whose head
branch is exactly `sync/v5-to-v6` in this repository, whose base is `v6`,
and which was opened by `github-actions[bot]` (the `v6-topup.yml`
identity). Every PR commit except the head must be reachable from `v5`
(compare API `v5...<sha>` is `behind`/`identical`), the head must be the
top-up's two-parent merge of `v5` history onto `v6` history, and the list
must stay under the REST 250-commit cap. Those commits already passed v5's
DCO gate and probot cannot be repaired PR-side, so the latest prow `dco`
commit status created by `kubestellar-prow[bot]` must be `success` instead;
a `dco` status from any other creator is ignored. Any unmet condition falls
back to requiring probot `DCO`. The check output names the DCO path taken
and, on fallback, why.
- Draft/held PRs, changes requested, dismissed approvals and approvals on an
old head fail closed. A `pull_request_target` run on an already closed or
merged PR (re-fired by a post-merge label or comment edit) passes as a
Expand Down Expand Up @@ -390,7 +402,8 @@ handles rejected/broken heads; there is no second fixer or merge engine.
history, admission reports **DCO provider unavailable / verdict UNKNOWN**
and remains blocked. Follow the [provider diagnosis and recovery runbook](operator-reference/dco-provider-unavailable.md);
a provider enumeration failure does not request a PR source change or permit
substitution of the lowercase prow `dco` status.
substitution of the lowercase prow `dco` status outside the narrow
`sync/v5-to-v6` forward-merge path above.
- Inspect the PR's exact-head checks and the **group SHA** checks separately.
A green member head does not establish green integration evidence.
`native-queue-policy` logs the failing provider, provenance, membership,
Expand Down
4 changes: 4 additions & 0 deletions src/docs/operator-reference/dco-provider-unavailable.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ Preserve the true merge ancestry of #16378. Splitting/rebasing the forward
merge, adding empty commits, accepting the lowercase prow `dco` status, or
weakening protection does not repair this provider failure. Until authoritative
current-head DCO success exists, the correct admission outcome remains blocked.
The only exception is the narrow `sync/v5-to-v6` forward-merge path in
[native-merge-queue.md](../native-merge-queue.md#required-checks-and-provider-boundaries)
(#17030), where every carried commit is already on `v5`; any other PR, or a
top-up carrying a commit not reachable from `v5`, still needs App-1861 DCO.
Loading