From 4f3d4c92e554f8c7b5003ce17213224f393ef551 Mon Sep 17 00:00:00 2001 From: Logic <241731638@m.gduf.edu.cn> Date: Tue, 17 Nov 2026 16:32:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?ci(codeql):=20=E6=98=BE=E5=BC=8F=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E9=95=BF=E6=9C=9F=E5=88=86=E6=94=AF=E5=B9=B6=E8=A1=94?= =?UTF-8?q?=E6=8E=A5=E5=8F=91=E5=B8=83=E9=97=A8=E7=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 CodeQL 触发范围固定为 main、agent 推送与目标为 main 的 PR,保留三种语言分析。发布门禁改为只认可显式工作流的同分支同提交成功记录,补充旧动态记录和 PR 记录不可替代发布扫描的回归,并同步扫描与合并规则文档。 --- .github/scripts/verify-release.cjs | 4 +- .github/scripts/verify-release.test.cjs | 24 ++++++++++- .github/workflows/codeql.yml | 43 +++++++++++++++++++ ...01\347\273\255\351\233\206\346\210\220.md" | 32 +++++++++----- 4 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/scripts/verify-release.cjs b/.github/scripts/verify-release.cjs index 5f8fab7..38dc391 100644 --- a/.github/scripts/verify-release.cjs +++ b/.github/scripts/verify-release.cjs @@ -6,9 +6,9 @@ const REQUIREMENTS = [ jobs: ['Backend lint, types and tests', 'Frontend lint, types, build and regressions'], }, { - path: 'dynamic/github-code-scanning/codeql', + path: '.github/workflows/codeql.yml', name: 'CodeQL', - events: ['dynamic'], + events: ['push', 'workflow_dispatch'], jobs: ['Analyze (actions)', 'Analyze (javascript-typescript)', 'Analyze (python)'], }, ] diff --git a/.github/scripts/verify-release.test.cjs b/.github/scripts/verify-release.test.cjs index c697a49..94356bb 100644 --- a/.github/scripts/verify-release.test.cjs +++ b/.github/scripts/verify-release.test.cjs @@ -11,7 +11,7 @@ const NAMES = { function fixture(branch = 'main') { const runs = [ { id: 10, path: '.github/workflows/checks.yml', event: 'push' }, - { id: 20, path: 'dynamic/github-code-scanning/codeql', event: 'dynamic' }, + { id: 20, path: '.github/workflows/codeql.yml', event: 'push' }, ].map(run => ({ ...run, head_sha: SHA, head_branch: branch, run_attempt: 1, head_repository: { full_name: 'example/project' }, @@ -99,6 +99,28 @@ test('CodeQL 缺失不放行', async () => { assert.deepEqual(state.outputs, {}) }) +for (const change of [ + { path: 'dynamic/github-code-scanning/codeql', event: 'dynamic' }, + { path: 'dynamic/github-code-scanning/codeql', event: 'push' }, + { event: 'pull_request' }, { event: 'schedule' }, { event: 'dynamic' }, +]) { + test(`CodeQL 非可信路径或事件成功不能放行 ${JSON.stringify(change)}`, async () => { + const state = fixture() + Object.assign(state.runs[1], change) + await assert.rejects(verifyRelease(state.args), /CodeQL 缺少/) + assert.deepEqual(state.outputs, {}) + }) +} + +for (const branch of ['main', 'agent']) { + test(`允许 ${branch} 同提交的 CodeQL 手动检查成功发布`, async () => { + const state = fixture(branch) + state.runs[1].event = 'workflow_dispatch' + await verifyRelease(state.args) + assert.deepEqual(state.outputs, { sha: SHA }) + }) +} + for (const [status, conclusion] of [ ['completed', 'failure'], ['completed', 'cancelled'], ['completed', 'skipped'], ['completed', 'neutral'], ['completed', 'timed_out'], ['queued', null], diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..d98dfa1 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,43 @@ +name: CodeQL + +on: + push: + branches: [main, agent] + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: codeql-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + runs-on: ubuntu-24.04 + timeout-minutes: 30 + permissions: + actions: read + contents: read + packages: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [actions, javascript-typescript, python] + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + with: + languages: ${{ matrix.language }} + build-mode: none + - name: Perform CodeQL analysis + uses: github/codeql-action/analyze@v4 + with: + category: /language:${{ matrix.language }} diff --git "a/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" "b/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" index c8cce0f..0b4c407 100644 --- "a/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" +++ "b/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" @@ -41,7 +41,7 @@ Pages 仍由 `Deploy to GitHub Pages` 手动触发,仅接受 `main`、`agent` | 检查 | 可信工作流与事件 | 必需任务 | | --- | --- | --- | | Code checks | `.github/workflows/checks.yml` 的 push 或 workflow_dispatch | 后端 lint/types/tests、前端 lint/types/build/regressions | -| CodeQL 默认设置 | `dynamic/github-code-scanning/codeql` 的 dynamic | actions、javascript-typescript、python 分析 | +| CodeQL Advanced | `.github/workflows/codeql.yml` 的 push 或 workflow_dispatch | actions、javascript-typescript、python 分析 | 先选择最新创建的合格运行,再要求整体和必需任务全部 `completed/success`。 不能用旧成功覆盖新失败或排队中的运行,也不接受其他分支、PR 或其他工作流的成功。 @@ -105,13 +105,25 @@ Node 语法检查和两份工作流的 actionlint 检查通过。 50 项发布门禁回归和前端完整检查通过。main 的默认 CodeQL 运行 44034730315 成功。 只读 API 门禁已放行 main;agent 因缺少本提交 CodeQL 被拒绝,未使用 main 的扫描替代。 -## agent 自动扫描范围 +## CodeQL 扫描与合并策略 -agent 曾只有代码质量 ruleset,88ddecc 推送后没有产生该分支的默认 CodeQL 运行。 -经用户授权,为 agent 新建精确匹配的传统分支保护:required_status_checks、 -required_pull_request_reviews、restrictions 均为空,enforce_admins 为 false。 -它使 agent 进入默认 CodeQL 的受保护分支扫描范围,不增加普通直接推送的 CI 或 PR 前置条件。 -现有代码质量 ruleset 继续生效;传统保护默认禁止强推和删除长期分支。 -该项属于 GitHub 仓库设置,不由工作流 YAML 自动创建;重建仓库时需同步配置。 -以配置后的下一次正常 push 是否产生同分支同 SHA 的 dynamic CodeQL 运行作为验收, -不能仅以 branches API 的 protected 布尔值认定已经扫描,也不承诺补扫已有 SHA。 +`.github/workflows/codeql.yml` 使用 Advanced setup,扫描 main、agent 的 push,以及所有目标为 main 的 PR,另保留手动触发入口。 +普通开发分支的单独 push 不运行 CodeQL;Code checks 仍对所有分支的 push 和 PR 运行。 +三项矩阵任务分别分析 actions、javascript-typescript、python,使用无构建模式,不安装应用依赖或读取个人配置。 +任务权限限定为源码、Actions、包读取与安全扫描结果写入,不使用 pull_request_target。 + +仓库默认 CodeQL 设置须关闭,避免与显式工作流冲突。agent 过去为默认扫描添加过传统分支保护; +在新工作流验证成功后移除该保护,扫描范围由 YAML 决定。现有独立代码质量 ruleset 保持原配置。 + +main Ruleset 27438512 要求 GitHub Actions 提供以下全部必需检查: +Analyze (actions)、Analyze (javascript-typescript)、Analyze (python)。 +缺失、等待、失败或取消都不能满足成功要求;另要求 CodeQL 扫描结果阻止错误级别告警和高危及以上安全告警合并。 +这些规则仅适用于 main;保留既有 PR、禁止强推和删除规则及其他设置,不添加 bypass。 +扫描任务执行成功与安全告警阈值是两项独立条件,不能只凭 Analyze 成功认定不存在阻断告警。 + +Pages 门禁只认可新工作流在同分支、同 SHA 上的 push 或 workflow_dispatch 结果,不用 PR 扫描替代发布版本扫描。 +Default setup 的旧 dynamic 成功记录不能替代新工作流。工作流必须同步存在于 main 和 agent。 + +验收包括门禁回归和 actionlint、目标为 main 的真实 PR CodeQL/CI、合入后两条长期分支的 push 扫描、 +main Ruleset 配置回读,以及删除 agent 传统保护后的 protection API 404。 +配置变更不触发实际 Pages 部署。 From 8dc376b08db6351a16f9b1f098f10ea3ee29371e Mon Sep 17 00:00:00 2001 From: Logic <241731638@m.gduf.edu.cn> Date: Tue, 17 Nov 2026 16:43:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ci(codeql):=20=E4=B8=A5=E6=A0=BC=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=AE=9E=E9=99=85=E5=88=86=E6=9E=90=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=B8=8E=20PR=20=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补齐 PR 改目标到 main 的扫描事件。新增始终执行的 CodeQL required 检查,拒绝分析任务跳过或中立结果,并核对同引用同提交的三类实际分析记录;发布门禁复用分析校验并保留状态变化复核,增加安全结果读取权限及回归。 --- .github/scripts/verify-codeql.cjs | 19 +++ .github/scripts/verify-release.cjs | 7 +- .github/scripts/verify-release.test.cjs | 132 +++++++++++++++++- .github/workflows/codeql.yml | 40 ++++++ .github/workflows/deploy.yml | 2 + ...01\347\273\255\351\233\206\346\210\220.md" | 10 +- 6 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 .github/scripts/verify-codeql.cjs diff --git a/.github/scripts/verify-codeql.cjs b/.github/scripts/verify-codeql.cjs new file mode 100644 index 0000000..3ce39d9 --- /dev/null +++ b/.github/scripts/verify-codeql.cjs @@ -0,0 +1,19 @@ +const LANGUAGES = ['actions', 'javascript-typescript', 'python'] + +async function requireCodeQLAnalyses({ github, owner, repo, sha, ref }) { + const analyses = await github.paginate(github.rest.codeScanning.listRecentAnalyses, { + owner, repo, ref, tool_name: 'CodeQL', per_page: 100, + }) + for (const language of LANGUAGES) { + const latest = analyses.filter(analysis => analysis.ref === ref + && analysis.commit_sha === sha && analysis.tool?.name === 'CodeQL' + && analysis.analysis_key === '.github/workflows/codeql.yml:analyze' + && analysis.category === `/language:${language}`) + .sort((a, b) => b.id - a.id)[0] + if (!latest || latest.error !== '') { + throw new Error(`CodeQL 分析 ${language} 缺失或处理失败,禁止通过检查`) + } + } +} + +module.exports = requireCodeQLAnalyses diff --git a/.github/scripts/verify-release.cjs b/.github/scripts/verify-release.cjs index 38dc391..b74c7ac 100644 --- a/.github/scripts/verify-release.cjs +++ b/.github/scripts/verify-release.cjs @@ -1,3 +1,5 @@ +const requireCodeQLAnalyses = require('./verify-codeql.cjs') + const REQUIREMENTS = [ { path: '.github/workflows/checks.yml', @@ -9,7 +11,8 @@ const REQUIREMENTS = [ path: '.github/workflows/codeql.yml', name: 'CodeQL', events: ['push', 'workflow_dispatch'], - jobs: ['Analyze (actions)', 'Analyze (javascript-typescript)', 'Analyze (python)'], + jobs: ['Analyze (actions)', 'Analyze (javascript-typescript)', 'Analyze (python)', + 'CodeQL required'], }, ] @@ -75,6 +78,8 @@ async function verifyRelease({ github, context, core }) { selected.push({ required, run }) } + await requireCodeQLAnalyses({ github, owner, repo, sha, ref: context.ref }) + const latestRuns = await listRuns() for (const { required, run } of selected) { assertUnchanged(required, run, latestRun(latestRuns, required)) diff --git a/.github/scripts/verify-release.test.cjs b/.github/scripts/verify-release.test.cjs index 94356bb..850c822 100644 --- a/.github/scripts/verify-release.test.cjs +++ b/.github/scripts/verify-release.test.cjs @@ -1,11 +1,13 @@ const assert = require('node:assert/strict') const { test } = require('node:test') const verifyRelease = require('./verify-release.cjs') +const requireCodeQLAnalyses = require('./verify-codeql.cjs') const SHA = 'a'.repeat(40) const NAMES = { 10: ['Backend lint, types and tests', 'Frontend lint, types, build and regressions'], - 20: ['Analyze (actions)', 'Analyze (javascript-typescript)', 'Analyze (python)'], + 20: ['Analyze (actions)', 'Analyze (javascript-typescript)', 'Analyze (python)', + 'CodeQL required'], } function fixture(branch = 'main') { @@ -21,9 +23,14 @@ function fixture(branch = 'main') { names.map(name => ({ name, head_sha: SHA, run_attempt: 1, status: 'completed', conclusion: 'success' })), ])) + const analyses = ['actions', 'javascript-typescript', 'python'].map((language, index) => ({ + id: 100 + index, ref: `refs/heads/${branch}`, commit_sha: SHA, + tool: { name: 'CodeQL' }, analysis_key: '.github/workflows/codeql.yml:analyze', + category: `/language:${language}`, error: '', + })) const outputs = {} const requests = [] - const state = { runs, jobs, outputs, requests, current: run => run } + const state = { runs, jobs, analyses, outputs, requests, current: run => run } const actions = { listWorkflowRunsForRepo: 'runs', listJobsForWorkflowRun: 'jobs', getWorkflowRun: async ({ run_id }) => ({ @@ -38,10 +45,14 @@ function fixture(branch = 'main') { ref: `refs/heads/${branch}`, eventName: 'workflow_dispatch' }, core: { info() {}, setOutput(name, value) { outputs[name] = value }, summary }, github: { - rest: { actions }, + rest: { actions, codeScanning: { listRecentAnalyses: 'analyses' } }, async paginate(endpoint, params) { requests.push([endpoint, params]) if (state.error) throw state.error + if (endpoint === 'analyses') { + if (state.analysisError) throw state.analysisError + return structuredClone(state.analyses) + } return structuredClone(endpoint === 'runs' ? state.runs : state.jobs[params.run_id]) }, }, @@ -58,6 +69,14 @@ for (const branch of ['main', 'agent']) { owner: 'example', repo: 'project', branch, head_sha: SHA, per_page: 100, }]) assert.equal(state.requests[1][1].filter, 'all') + const analysisIndex = state.requests.findIndex(([endpoint]) => endpoint === 'analyses') + assert.deepEqual(state.requests[analysisIndex], ['analyses', { + owner: 'example', repo: 'project', ref: `refs/heads/${branch}`, + tool_name: 'CodeQL', per_page: 100, + }]) + assert.deepEqual(state.requests.slice(0, analysisIndex).map(([endpoint]) => endpoint), + ['runs', 'jobs', 'jobs']) + assert.equal(state.requests[analysisIndex + 1][0], 'runs') }) } @@ -271,3 +290,110 @@ for (const id of [10, 20]) { assert.deepEqual(state.outputs, {}) }) } + +test('所有 jobs 成功但 CodeQL 分析记录为空仍拒绝发布', async () => { + const state = fixture() + state.analyses = [] + await assert.rejects(verifyRelease(state.args), /CodeQL 分析 actions 缺失或处理失败/) + assert.deepEqual(state.outputs, {}) +}) + +for (const language of ['actions', 'javascript-typescript', 'python']) { + test(`所有 jobs 成功但缺少 ${language} 分析仍拒绝发布`, async () => { + const state = fixture() + state.analyses = state.analyses.filter(analysis => analysis.category !== `/language:${language}`) + await assert.rejects(verifyRelease(state.args), new RegExp(`CodeQL 分析 ${language} 缺失`)) + assert.deepEqual(state.outputs, {}) + }) +} + +for (const change of [ + { commit_sha: 'b'.repeat(40) }, { ref: 'refs/heads/agent' }, + { analysis_key: 'dynamic/github-code-scanning/codeql:analyze' }, + { analysis_key: '.github/workflows/codeql.yml:other' }, + { tool: { name: 'Other' } }, { tool: null }, { category: '/language:other' }, +]) { + test(`CodeQL 分析不匹配提交、引用或来源必须拒绝 ${JSON.stringify(change)}`, async () => { + const state = fixture() + Object.assign(state.analyses[0], change) + await assert.rejects(verifyRelease(state.args), /CodeQL 分析 actions 缺失/) + assert.deepEqual(state.outputs, {}) + }) +} + +for (const error of ['fixture processing failed', null, undefined]) { + test(`CodeQL 分析 error 非空字符串必须拒绝 ${String(error)}`, async () => { + const state = fixture() + state.analyses[0].error = error + await assert.rejects(verifyRelease(state.args), /CodeQL 分析 actions 缺失或处理失败/) + assert.deepEqual(state.outputs, {}) + }) +} + +test('CodeQL 分析 API 异常必须阻止发布', async () => { + const state = fixture() + state.analysisError = new Error('fixture code scanning forbidden') + await assert.rejects(verifyRelease(state.args), /code scanning forbidden/) + assert.deepEqual(state.outputs, {}) +}) + +test('CodeQL 最新分析失败不能使用旧成功记录', async () => { + const state = fixture() + state.analyses.unshift({ ...state.analyses[0], id: 200, error: 'fixture processing failed' }) + await assert.rejects(verifyRelease(state.args), /CodeQL 分析 actions 缺失或处理失败/) + assert.deepEqual(state.outputs, {}) +}) + +test('CodeQL 最新分析成功可以替代旧失败记录', async () => { + const state = fixture() + state.analyses.push({ ...state.analyses[0], id: 99, error: 'fixture processing failed' }) + await verifyRelease(state.args) + assert.deepEqual(state.outputs, { sha: SHA }) +}) + +test('分析 helper 使用调用者传入的 PR 合并引用与合并提交', async () => { + const state = fixture() + const ref = 'refs/pull/21/merge' + const sha = 'b'.repeat(40) + state.analyses = state.analyses.map(analysis => ({ ...analysis, ref, commit_sha: sha })) + await requireCodeQLAnalyses({ github: state.args.github, + owner: 'example', repo: 'project', sha, ref }) + assert.deepEqual(state.requests, [['analyses', { + owner: 'example', repo: 'project', ref, tool_name: 'CodeQL', per_page: 100, + }]]) +}) + +for (const conclusion of ['skipped', 'neutral', 'missing']) { + test(`CodeQL required 任务 ${conclusion} 必须拒绝发布`, async () => { + const state = fixture() + if (conclusion === 'missing') state.jobs[20].pop() + else state.jobs[20].find(job => job.name === 'CodeQL required').conclusion = conclusion + await assert.rejects(verifyRelease(state.args), /必需任务 CodeQL required 缺失或未成功/) + assert.deepEqual(state.outputs, {}) + }) +} + +for (const id of [10, 20]) { + for (const change of ['new run', 'rerun']) { + test(`分析 API 查询期间工作流 ${id} 出现 ${change} 必须被末尾复核拒绝`, async () => { + const state = fixture() + const paginate = state.args.github.paginate + state.args.github.paginate = async (endpoint, params) => { + const result = await paginate(endpoint, params) + if (endpoint === 'analyses') { + const index = state.runs.findIndex(run => run.id === id) + if (change === 'new run') { + state.runs.push({ ...state.runs[index], id: id + 1, + status: 'queued', conclusion: null }) + } else { + state.runs[index] = { ...state.runs[index], run_attempt: 2, + status: 'in_progress', conclusion: null } + } + } + return result + } + await assert.rejects(verifyRelease(state.args), /检查状态已变化/) + assert.deepEqual(state.outputs, {}) + }) + } +} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d98dfa1..89882b2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -5,6 +5,7 @@ on: branches: [main, agent] pull_request: branches: [main] + types: [opened, synchronize, reopened, edited, ready_for_review] workflow_dispatch: permissions: @@ -41,3 +42,42 @@ jobs: uses: github/codeql-action/analyze@v4 with: category: /language:${{ matrix.language }} + wait-for-processing: true + + verify: + name: CodeQL required + needs: analyze + if: ${{ always() }} + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + actions: read + security-events: read + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Require successful analyses and uploaded results + uses: actions/github-script@v7 + env: + ANALYZE_RESULT: ${{ needs.analyze.result }} + with: + script: | + if (process.env.ANALYZE_RESULT !== 'success') { + throw new Error('CodeQL analysis did not succeed'); + } + const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, { + ...context.repo, run_id: context.runId, filter: 'all', per_page: 100, + }); + for (const language of ['actions', 'javascript-typescript', 'python']) { + const candidates = jobs.filter(job => job.name === `Analyze (${language})`); + const attempt = Math.max(...candidates.map(job => job.run_attempt)); + const latest = candidates.filter(job => job.run_attempt === attempt); + if (latest.length !== 1 || latest[0].status !== 'completed' + || latest[0].conclusion !== 'success') { + throw new Error(`CodeQL ${language} must complete successfully`); + } + } + const requireAnalyses = require('./.github/scripts/verify-codeql.cjs'); + await requireAnalyses({github, ...context.repo, sha: context.sha, ref: context.ref}); diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a9bc341..23385d1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,7 @@ on: permissions: contents: read actions: read + security-events: read concurrency: group: pages @@ -64,6 +65,7 @@ jobs: permissions: contents: read actions: read + security-events: read pages: write id-token: write environment: diff --git "a/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" "b/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" index 0b4c407..618f5cc 100644 --- "a/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" +++ "b/docs/\346\265\213\350\257\225\344\270\216\346\214\201\347\273\255\351\233\206\346\210\220.md" @@ -111,18 +111,22 @@ Node 语法检查和两份工作流的 actionlint 检查通过。 普通开发分支的单独 push 不运行 CodeQL;Code checks 仍对所有分支的 push 和 PR 运行。 三项矩阵任务分别分析 actions、javascript-typescript、python,使用无构建模式,不安装应用依赖或读取个人配置。 任务权限限定为源码、Actions、包读取与安全扫描结果写入,不使用 pull_request_target。 +PR 的 edited 活动也触发扫描,覆盖已有 PR 将目标改为 main 的情况。 仓库默认 CodeQL 设置须关闭,避免与显式工作流冲突。agent 过去为默认扫描添加过传统分支保护; 在新工作流验证成功后移除该保护,扫描范围由 YAML 决定。现有独立代码质量 ruleset 保持原配置。 main Ruleset 27438512 要求 GitHub Actions 提供以下全部必需检查: -Analyze (actions)、Analyze (javascript-typescript)、Analyze (python)。 -缺失、等待、失败或取消都不能满足成功要求;另要求 CodeQL 扫描结果阻止错误级别告警和高危及以上安全告警合并。 +Analyze (actions)、Analyze (javascript-typescript)、Analyze (python)、CodeQL required。 +GitHub 的单项必需检查接受 skipped、neutral,因此 CodeQL required 无条件运行,严格核对三项实际任务均 completed/success, +并核对同 ref、同 SHA、同工作流的三类 CodeQL 分析记录齐全且无处理错误。PR 使用测试合并提交的 SHA 与 refs/pull/.../merge。 +另要求 CodeQL 扫描结果阻止错误级别告警和高危及以上安全告警合并。 这些规则仅适用于 main;保留既有 PR、禁止强推和删除规则及其他设置,不添加 bypass。 扫描任务执行成功与安全告警阈值是两项独立条件,不能只凭 Analyze 成功认定不存在阻断告警。 Pages 门禁只认可新工作流在同分支、同 SHA 上的 push 或 workflow_dispatch 结果,不用 PR 扫描替代发布版本扫描。 -Default setup 的旧 dynamic 成功记录不能替代新工作流。工作流必须同步存在于 main 和 agent。 +Default setup 的旧 dynamic 成功记录不能替代新工作流;发布时同样核对三类实际分析记录。工作流必须同步存在于 main 和 agent。 +这些校验依赖仓库中的工作流与校验脚本受信任,拥有修改其权限的人仍能改写策略。 验收包括门禁回归和 actionlint、目标为 main 的真实 PR CodeQL/CI、合入后两条长期分支的 push 扫描、 main Ruleset 配置回读,以及删除 agent 传统保护后的 protection API 404。