worldmonitor icon indicating copy to clipboard operation
worldmonitor copied to clipboard

chore(proto): auto-commit generated artifacts for internal PRs

Open lspassos1 opened this issue 7 months ago • 3 comments

Summary

Moves generated proto/OpenAPI artifact churn out of normal internal PR review by teaching the proto freshness workflow to run make generate and push generated artifacts back to same-repository PR branches. Fork PRs keep a safe validation-only path with an explicit failure message because CI cannot safely push to contributor branches.

cc @koala73

Closes #3340

Type of change

  • [x] CI / Build / Infrastructure
  • [x] Documentation

Affected areas

  • [x] Other: proto generation workflow and contributor docs

Root cause

The existing proto freshness check could detect stale generated files, but contributors still had to include generated artifacts manually in every PR. That creates noisy reviews and makes code changes harder to evaluate.

Changes

  • Run make generate in .github/workflows/proto-check.yml.
  • For internal PRs, auto-commit changes under src/generated/ and docs/api/ back to the PR branch.
  • For fork PRs, keep validation-only behavior with clear instructions to run make generate locally.
  • Quote the PR head ref through an environment variable before pushing.
  • Add job-level concurrency to cancel stale proto freshness runs for the same PR.
  • Document the generated artifact contract in CONTRIBUTING.md.

Validation

  • ruby -e "require 'yaml'; YAML.load_file('.github/workflows/proto-check.yml'); puts 'yaml ok'"
  • git diff --check
  • Fork PR CI: lspassos1/worldmonitor#27

Risk

Moderate. The workflow gets write permissions for internal PR branches only. Forks remain validation-only, and the push target is quoted to avoid shell evaluation of branch names.

lspassos1 avatar Apr 28 '26 16:04 lspassos1

@lspassos1 is attempting to deploy a commit to the World Monitor Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Apr 28 '26 16:04 vercel[bot]

Greptile Summary

This PR teaches the proto freshness workflow to auto-commit generated artifacts back to internal PR branches via git push, while keeping fork PRs on a validation-only path. The CONTRIBUTING.md update accurately documents the new contract.

  • P1 — untrusted fork code now executes on CI runners: Removing the job-level if guard means make install-buf install-plugins and make generate run against the fork's own Makefile for every external contributor PR; the original design prevented this entirely by gating the whole job.
  • The bot commit will trigger a second redundant workflow run per PR (no diff found, exits 0) that wastes CI minutes.
  • contents: write is declared at workflow scope rather than job scope, giving every step broader declared permissions than needed.

Confidence Score: 3/5

Not safe to merge as-is — fork PRs now run untrusted Makefile code on CI runners, reversing the intentional security gate of the original workflow.

A P1 security regression (fork code execution) is present in the core changed file; the fix is straightforward but requires restructuring the job or adding per-step guards before the issue is resolved.

.github/workflows/proto-check.yml — specifically the missing if guards on the Install buf and protoc plugins and Run proto generation steps

Security Review

  • Arbitrary code execution from fork PRs (.github/workflows/proto-check.yml, lines 44–51): The job-level fork guard was removed, so make install-buf install-plugins and make generate now execute the fork contributor's Makefile on a CI runner. A malicious PR can run arbitrary shell commands (network calls, resource abuse, environment probing) before any push restriction takes effect.
  • contents: write at workflow scope (line 12–13): Write permission is declared globally, applying to all steps including those serving fork PRs. GitHub's runtime restriction mitigates this for fork pull_request events today, but the declared scope is wider than necessary.

Important Files Changed

Filename Overview
.github/workflows/proto-check.yml Adds auto-commit of generated artifacts for internal PRs and splits checkout/verify steps by repo origin; security regression: removing the job-level fork guard now runs untrusted fork Makefile code on CI runners
CONTRIBUTING.md Adds documentation section explaining the generated-artifact auto-commit contract for internal vs. fork PRs; accurate and consistent with the workflow changes

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pull_request event] --> B{Internal PR?}
    B -- Yes --> C[Checkout branch with token]
    B -- No --> D[Checkout fork merge commit]
    C --> E[setup-go + cache]
    D --> E
    E --> F[make install-buf install-plugins]
    F --> G[make generate]
    G --> H{Internal PR?}
    H -- Yes --> I{Generated files changed?}
    I -- No --> J[Exit 0 — up to date]
    I -- Yes --> K[git add + commit + push to PR branch]
    K --> L[Bot commit triggers new sync event → 2nd workflow run]
    H -- No --> M{git diff exit-code?}
    M -- Clean --> N[Exit 0 — up to date]
    M -- Dirty --> O[Fail with fork instructions]

    style D fill:#f99,stroke:#c00
    style F fill:#f99,stroke:#c00
    style G fill:#f99,stroke:#c00
    style L fill:#ffd,stroke:#aa0

Comments Outside Diff (1)

  1. .github/workflows/proto-check.yml, line 44-51 (link)

    P1 security Fork PR code execution — security regression

    The original workflow guarded the entire job with if: github.event.pull_request.head.repo.full_name == github.repository, so fork PRs never ran any steps. After this PR, the job-level gate is gone, meaning make install-buf install-plugins (line 45) and make generate (line 51) execute the fork's version of the Makefile on a CI runner for every external contributor PR. A malicious fork PR could modify Makefile to run arbitrary shell commands — network exfiltration, resource abuse, or probing the runner environment — none of which is prevented by the contents: read token restriction that fork PRs receive.

    The fork-PR verification steps at lines 69–94 correctly block pushing, but they run after the untrusted code has already executed. If the intent is to keep validation-only behaviour for forks, the safe pattern is to add if: github.event.pull_request.head.repo.full_name == github.repository to the Install buf and protoc plugins and Run proto generation steps (or restore the job-level condition and use a separate job with a pull_request_target trigger for forks).

Reviews (1): Last reviewed commit: "fix(ci): serialize proto freshness runs" | Re-trigger Greptile

greptile-apps avatar Apr 28 '26 16:04 greptile-apps

Follow-up pushed in ddac6715 to address the workflow safety review.

Changes:

  • Restored top-level workflow permissions to contents: read.
  • Split fork PR handling from internal PR handling. Fork PRs no longer execute the PR's Makefile, buf.gen.yaml, or generator configuration.
  • Kept auto-generation for internal PRs only, with job-scoped contents: write.
  • Added an internal merge-result freshness job so generated artifacts are checked against the actual PR merge result when no artifact commit was pushed.
  • Updated CONTRIBUTING.md to document the fork/internal contract.

Validation:

  • Parsed .github/workflows/proto-check.yml with Ruby YAML.
  • Ran git diff --check on the workflow and contributing guide.

lspassos1 avatar Apr 28 '26 16:04 lspassos1