diff --git a/.github/actions/setup-just/action.yml b/.github/actions/setup-just/action.yml index fc50341..7d6ff5e 100644 --- a/.github/actions/setup-just/action.yml +++ b/.github/actions/setup-just/action.yml @@ -1,9 +1,24 @@ name: Set up shared tooling description: Install the locked published package and declared base tools. +inputs: + profile: + description: Full tooling, or security scanners without Cargo and paper tools. + default: full + runs: using: composite steps: + - name: Validate tooling profile + shell: bash + env: + TOOLING_PROFILE: ${{ inputs.profile }} + run: | + case "$TOOLING_PROFILE" in + full|security) ;; + *) echo "Unsupported tooling profile: $TOOLING_PROFILE" >&2; exit 1 ;; + esac + - name: Install declared uv uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0 with: @@ -14,8 +29,10 @@ runs: uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ~/.cache/research-repo-tools - key: managed-tools-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pyproject.toml','rust-toolchain.toml','.python-version','tooling/papers.toml') }} - restore-keys: managed-tools-${{ runner.os }}-${{ runner.arch }}- + key: >- + managed-tools-${{ runner.os }}-${{ runner.arch }}-${{ inputs.profile }}-${{ + hashFiles('pyproject.toml','rust-toolchain.toml','.python-version','tooling/papers.toml') }} + restore-keys: managed-tools-${{ runner.os }}-${{ runner.arch }}-${{ inputs.profile }}- - name: Install the locked tooling package shell: bash @@ -28,9 +45,17 @@ runs: run: uv run --locked --no-sync --no-python-downloads research-repo-tools toolchain sync-binaries - name: Install and export declared base tools + if: inputs.profile == 'full' shell: bash run: | set -euo pipefail uv run --locked --managed-python --only-group tooling research-repo-tools toolchain sync uv sync --locked --managed-python --group dev --group papers uv run --locked --no-sync --no-python-downloads research-repo-tools toolchain export + + - name: Install security Python tools + if: inputs.profile == 'security' + shell: bash + run: | + set -euo pipefail + uv sync --locked --managed-python --only-group security diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 06ed70a..b56f6a0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,12 +9,6 @@ updates: groups: actions: patterns: ['*'] - - package-ecosystem: uv - directory: / - schedule: - interval: weekly - cooldown: - default-days: 7 - groups: - python: - patterns: ['*'] +# Hosted uv updates reject the inherited Python >=3.15 baseline. Restore this +# ecosystem after dependabot/dependabot-core#16524 is resolved. Keep the +# dependency graph and OSV scans enabled; use just update-python-dependencies. diff --git a/.github/settings/actions-selected.json b/.github/settings/actions-selected.json index 15472f5..e192562 100644 --- a/.github/settings/actions-selected.json +++ b/.github/settings/actions-selected.json @@ -2,10 +2,12 @@ "github_owned_allowed": false, "verified_allowed": false, "patterns_allowed": [ + "acgetchell/research-repo-tools/.github/workflows/dependabot-approve.yml@*", "actions/cache@*", "actions/checkout@*", "actions/upload-artifact@*", "astral-sh/setup-uv@*", + "dependabot/fetch-metadata@*", "github/codeql-action/analyze@*", "github/codeql-action/init@*", "github/codeql-action/upload-sarif@*" diff --git a/.github/settings/main-ruleset.json b/.github/settings/main-ruleset.json index 66cd152..5aac37b 100644 --- a/.github/settings/main-ruleset.json +++ b/.github/settings/main-ruleset.json @@ -28,6 +28,8 @@ "do_not_enforce_on_create": true, "strict_required_status_checks_policy": true, "required_status_checks": [ + {"context": "Analyze (actions)", "integration_id": 15368}, + {"context": "Analyze (python)", "integration_id": 15368}, {"context": "Tooling validation", "integration_id": 15368}, {"context": "Gitleaks secret scan", "integration_id": 15368}, {"context": "OSV dependency scan", "integration_id": 15368}, @@ -36,6 +38,18 @@ {"context": "CodeRabbit", "integration_id": 347564} ] } + }, + { + "type": "code_scanning", + "parameters": { + "code_scanning_tools": [ + { + "tool": "CodeQL", + "alerts_threshold": "errors", + "security_alerts_threshold": "high_or_higher" + } + ] + } } ] } diff --git a/.github/settings/workflow-permissions.json b/.github/settings/workflow-permissions.json new file mode 100644 index 0000000..5458c59 --- /dev/null +++ b/.github/settings/workflow-permissions.json @@ -0,0 +1,4 @@ +{ + "default_workflow_permissions": "read", + "can_approve_pull_request_reviews": true +} diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 0000000..594ecc7 --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,38 @@ +name: Dependabot approval and auto-merge + +# Trusted base-branch policy; the shared job never checks out or runs PR code. +on: # zizmor: ignore[dangerous-triggers] + pull_request_target: + types: [opened, reopened, ready_for_review, synchronize] + branches: [main] + +permissions: {} + +concurrency: + group: dependabot-auto-merge-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + approve-and-enable-auto-merge: + permissions: + contents: write + pull-requests: write + # Exact published research-repo-tools v0.2.3 source, reviewed for this caller. + uses: acgetchell/research-repo-tools/.github/workflows/dependabot-approve.yml@4085125526e21b2855eb7c61a52ee312782ae31a + with: + repository: acgetchell/Papers + policy: >- + {"github_actions": { + "files": [ + ".github/actions/setup-just/action.yml", + ".github/workflows/ci.yml", + ".github/workflows/codeql.yml", + ".github/workflows/dependabot-auto-merge.yml", + ".github/workflows/gitleaks.yml", + ".github/workflows/osv.yml", + ".github/workflows/papers.yml", + ".github/workflows/zizmor.yml" + ] + }, "uv": { + "files": ["pyproject.toml", "uv.lock"] + }} diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml index b91096d..21943f9 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks.yml @@ -27,9 +27,11 @@ jobs: fetch-depth: 0 persist-credentials: false - uses: $/.github/actions/setup-just + with: + profile: security - name: Scan reachable history and current files id: scan - run: just security-secrets + run: uv run --locked --no-sync just security-secrets - name: Retain redacted security reports if: ${{ !cancelled() && steps.scan.outcome != 'skipped' }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/.github/workflows/osv.yml b/.github/workflows/osv.yml index 5acfc35..361dace 100644 --- a/.github/workflows/osv.yml +++ b/.github/workflows/osv.yml @@ -26,9 +26,11 @@ jobs: with: persist-credentials: false - uses: $/.github/actions/setup-just + with: + profile: security - name: Audit the root Python lockfile id: scan - run: just security-osv + run: uv run --locked --no-sync just security-osv - name: Retain dependency scan reports if: ${{ !cancelled() && steps.scan.outcome != 'skipped' }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml index 6a304d1..bd19612 100644 --- a/.github/workflows/zizmor.yml +++ b/.github/workflows/zizmor.yml @@ -29,12 +29,14 @@ jobs: with: persist-credentials: false - uses: $/.github/actions/setup-just + with: + profile: security - name: Audit Actions using the shared tooling env: GH_TOKEN: ${{ github.token }} run: | mkdir -p target/security - just security-workflows --require-online --format sarif > target/security/zizmor.sarif + uv run --locked --no-sync just security-workflows --require-online --format sarif > target/security/zizmor.sarif - name: Upload workflow security analysis if: >- always() && hashFiles('target/security/zizmor.sarif') != '' && diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4a9a4d..807ae4e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,10 @@ for native auto-merge. It fails on selection or compilation failure. When no paper is affected it passes without compiling; the remaining required reviews, CI, and security checks still apply. +The CodeQL Actions and Python analysis jobs are required. Hosted code-scanning +protection also blocks CodeQL error-level alerts and high or critical security +alerts; a successful analysis job alone does not mean its findings are accepted. + The hosted ruleset requires CODEOWNER approval for `.coderabbit.yaml`, `.coderabbit.yml`, and `.github/**`, including CODEOWNERS itself. Paper files have no human ownership requirement, so eligible paper PRs can still receive @@ -76,9 +80,27 @@ Run `just security` to compose the root lockfile and full-history/current-input scans, or select `just security-osv` and `just security-secrets` individually. They use the shared managed scanners. Use `just security-workflows --require-online` for authenticated workflow-security auditing. -Workflows use read-only repository permissions and pinned external actions. -Dependabot proposes Python and Actions updates; maintainers review them before -merging. CodeRabbit is configured for automatic PR and incremental review, +Gitleaks, OSV, and zizmor use the lightweight `security` dependency group and +the shared verified binary installer. Their CI setup does not install Cargo +tools or paper dependencies. Full tooling and paper jobs keep their existing +setup profile. + +Workflows use read-only permissions by default and pinned external actions. +Dependabot proposes Actions updates. The pinned shared approval workflow +verifies Dependabot identity, signed commits, exact changed-file policy, and +the current head before approving and enabling native auto-merge. Required +checks, resolved threads, and human CODEOWNER review still apply; an Actions +approval does not satisfy the human owner requirement for `.github/**`. + +Hosted uv updates are paused because Dependabot rejects the inherited Python +3.15 baseline. Use `just update-python-dependencies` and `just ci` for Python +maintenance, and the shared adoption commands for shared-package upgrades. +Keep the dependency graph, security alerts, and OSV scans enabled. Graph-update +jobs may still report the same upstream limitation. Restore uv updates after +[Python 3.15 support](https://github.com/dependabot/dependabot-core/issues/16524) +is available; do not lower the inherited baseline to accommodate the updater. + +CodeRabbit is configured for automatic PR and incremental review, including drafts, and approves eligible low merge-risk PRs after its findings are addressed and the latest commit is reviewed. Automatic approval is disabled for PRs changing `.github/**`; the hosted CODEOWNER rule also protects approval diff --git a/docs/SECURING.md b/docs/SECURING.md index d2c0de0..f2b69c5 100644 --- a/docs/SECURING.md +++ b/docs/SECURING.md @@ -8,8 +8,10 @@ policy files document the expected configuration and validate workflow changes. - Enable secret scanning, secret push protection, Dependabot alerts/security updates, and private vulnerability reporting. -- Set the default Actions token permissions to read and disable Actions-created - pull request approvals. Jobs elevate only the permissions they need. +- Set default Actions token permissions to read. Permit Actions-created PR + approvals for the trusted shared Dependabot workflow using + [workflow-permissions.json](../.github/settings/workflow-permissions.json); + jobs elevate only the permissions they need. - Permit only the explicit action patterns in [actions-selected.json](../.github/settings/actions-selected.json), with verified publishers and GitHub-owned actions not broadly allowed. Require full commit SHA pins. @@ -38,12 +40,9 @@ Paper files have no CODEOWNER entry. Their existing one-approval requirement can still be satisfied by CodeRabbit, subject to its low merge-risk policy and all required checks. No blanket human approval is required for ordinary papers. -PR #3 introduces the ownership map, so path-specific enforcement begins after -it is merged into `main`. The hosted requirement is enabled before that merge; -it cannot assign an owner while the base branch has no CODEOWNERS file. `@acgetchell` is currently the only human collaborator. GitHub does not permit -self-approval, so maintainer-authored control changes, including this bootstrap -PR, require deliberate manual review and use of the existing administrator +self-approval, so maintainer-authored control changes require deliberate manual +review and use of the existing administrator bypass, or an additional trusted human code owner. Automation must not use that bypass. See [GitHub's CODEOWNERS documentation](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners). @@ -51,6 +50,8 @@ that bypass. See [GitHub's CODEOWNERS documentation](https://docs.github.com/en/ | Check | Provider | | --- | --- | +| Analyze (actions) | GitHub Actions | +| Analyze (python) | GitHub Actions | | Changed paper builds | GitHub Actions | | CodeRabbit | CodeRabbit GitHub App | | GitHub Actions Security Analysis | GitHub Actions | @@ -66,6 +67,13 @@ Changes to shared paper tooling, including the root Justfile, rebuild all standalone sources. This required check applies to native auto-merge as well as manual merging. +The hosted ruleset also requires CodeQL scanning results. It blocks error-level +alerts and high or critical security alerts, independently of the analysis jobs' +success status. CodeQL already runs for Actions and Python, so this adds +enforcement without another scanner. Review severity exceptions deliberately; +the rule applies to alerts introduced on changed lines in PRs. See +[GitHub's merge-protection documentation](https://docs.github.com/en/code-security/concepts/code-scanning/merge-protection). + ## Security workflows Gitleaks and OSV run on PRs, `main` pushes, weekly schedules, and manual dispatch @@ -74,6 +82,14 @@ inputs; OSV scans the root `uv.lock`. Validated JSON/SARIF security reports are retained for seven days, including on findings. These are security reports, not LaTeX build artifacts. +Scanner jobs select the composite setup action's `security` profile. It installs +the locked `security` Python group and uses `research-repo-tools toolchain +sync-binaries` to verify native scanner pins without Rust/Cargo builds, full +tooling, or paper dependencies. Just is provided by the inherited shared Python +tools. Tooling validation and paper compilation retain the default `full` +profile. Both profiles use the same root manifest, lockfile, and inherited +Python/tool versions. + The zizmor workflow uses the shared authenticated, required-online command and uploads SARIF to code scanning. CodeQL covers Actions and Python; no Rust crate or notebook workload is run in this repository. Workflow checking also enforces @@ -98,6 +114,31 @@ on correctness and build plumbing. Review does not publish papers or refresh their reviewer PDFs. [Blog publishing](https://github.com/acgetchell/Papers/issues/2) has a separate scope and approval path. +## Dependency updates + +Dependabot's weekly GitHub Actions updates and seven-day cooldown remain +enabled. Hosted uv version updates are paused until its updater supports the +inherited Python 3.15 baseline. Keep the dependency graph enabled: its separate +uv graph jobs may still fail until upstream support lands. OSV continues to +audit the actual root lockfile. Use `just update-python-dependencies` for +deliberate Python updates and the shared adoption flow for shared-package +upgrades, followed by `just ci`. + +The Dependabot caller reuses the approval workflow at the exact +`research-repo-tools` v0.2.3 commit. It runs from trusted base-branch policy, +never checks out PR code, verifies signed Dependabot commits and current-head +identity, and accepts only explicitly listed dependency files. It then approves +and enables native squash auto-merge; CI, code scanning, thread resolution, and +human CODEOWNER requirements still gate the merge. The optional approval job is +not a required check because it intentionally skips ordinary PRs. + +The hosted Actions allowlist includes the shared reusable workflow and its +pinned `dependabot/fetch-metadata` action. Default tokens remain read-only; +write permissions are limited to the approval job. Its bot approval cannot +replace `@acgetchell`'s owner approval for GitHub controls. The caller becomes +active after merging into `main`; a later Dependabot open, reopen, or push event +uses it. Rerunning an older job does not load a newly deployed caller. + ## Applying settings Enable native auto-merge with the committed repository setting: @@ -110,7 +151,8 @@ gh api --method PATCH repos/acgetchell/Papers \ Enabling this repository setting does not arm every PR. Maintainers enable auto-merge separately on each ready PR in GitHub or with `gh pr merge NUMBER --repo acgetchell/Papers --auto --merge`. Drafts remain -unmergeable. No workflow grants itself approval or bypasses the ruleset. +unmergeable. The shared workflow approves only verified Dependabot updates; +it never approves ordinary PRs or bypasses the ruleset. After reviewing a policy change, repository administrators can apply the action allowlist with the GitHub CLI: @@ -121,7 +163,7 @@ gh api --method PUT repos/acgetchell/Papers/actions/permissions \ gh api --method PUT repos/acgetchell/Papers/actions/permissions/selected-actions \ --input .github/settings/actions-selected.json gh api --method PUT repos/acgetchell/Papers/actions/permissions/workflow \ - -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false + --input .github/settings/workflow-permissions.json ``` For the ruleset, read `gh api repos/acgetchell/Papers/rulesets`, then update the diff --git a/pyproject.toml b/pyproject.toml index f9a82a0..4049678 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,14 +8,16 @@ requires-python = ">=3.15" [dependency-groups] tooling = ["research-repo-tools[python-tools]==0.2.3"] dev = [ + { include-group = "security" }, + # The shared setup command requires this direct include. { include-group = "tooling" }, "actionlint-py==1.7.12.25", "shellcheck-py==0.11.0.1", "shfmt-py==4.2.0", "yamllint==1.38.0", - "zizmor==1.31.1", ] papers = ["research-repo-tools[papers,python-tools]==0.2.3"] +security = [{ include-group = "tooling" }, "zizmor==1.31.1"] [tool.uv] package = false diff --git a/uv.lock b/uv.lock index 9770f0b..9d5dbd7 100644 --- a/uv.lock +++ b/uv.lock @@ -110,13 +110,18 @@ dev = [ papers = [ { name = "research-repo-tools", extra = ["papers", "python-tools"] }, ] +security = [ + { name = "research-repo-tools", extra = ["python-tools"] }, + { name = "zizmor" }, +] tooling = [ { name = "research-repo-tools", extra = ["python-tools"] }, ] [package.group-requires-python] -dev = ">=3.15" +dev = ">=3.15,>=3.15" papers = ">=3.15" +security = ">=3.15" tooling = ">=3.15" [package.metadata] @@ -131,6 +136,10 @@ dev = [ { name = "zizmor", specifier = "==1.31.1" }, ] papers = [{ name = "research-repo-tools", extras = ["papers", "python-tools"], marker = "python_full_version >= '3.15'", specifier = "==0.2.3" }] +security = [ + { name = "research-repo-tools", extras = ["python-tools"], marker = "python_full_version >= '3.15'", specifier = "==0.2.3" }, + { name = "zizmor", specifier = "==1.31.1" }, +] tooling = [{ name = "research-repo-tools", extras = ["python-tools"], marker = "python_full_version >= '3.15'", specifier = "==0.2.3" }] [[package]]