-
Notifications
You must be signed in to change notification settings - Fork 409
Validate Content product impact in pull requests #2520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e7606c7
Add advisory Content conformance pilot
3mdistal a2ace92
Fix snapshot validation root
3mdistal e2fb64f
Isolate Content validation snapshots
3mdistal d36f556
Use revision-consistent Content baselines
3mdistal bcbaa6b
Complete Content conformance perimeter
3mdistal 6ff1f1a
Enforce Content workflow security policy
3mdistal 7d47894
Close Content workflow override paths
3mdistal 820a248
Finish Content snapshot credential boundaries
3mdistal 77b8c28
Constrain Content conformance execution
3mdistal 87e6c60
Pin Content conformance execution surface
3mdistal 03caa13
Separate Content checker source repository
3mdistal 8943be3
Use immutable Content conformance controller
3mdistal bd30850
Fetch Content conformance base revision
3mdistal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: Content product conformance | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| types: | ||
| [ | ||
| opened, | ||
| synchronize, | ||
| reopened, | ||
| edited, | ||
| ready_for_review, | ||
| labeled, | ||
| unlabeled, | ||
| ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: content-product-conformance-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check: | ||
| name: Advisory Content product impact | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Check out immutable conformance controller | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | ||
| with: | ||
| ref: 03caa13fd5bf6176ee01ab223452db9932b7ca8c | ||
| path: controller | ||
| fetch-depth: 1 | ||
| persist-credentials: false | ||
|
|
||
| - name: Check out candidate as inert data | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | ||
| with: | ||
| repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| path: candidate | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Fetch exact target revision | ||
| run: git -C candidate fetch --no-tags https://github.com/BuilderIO/agent-native.git ${{ github.event.pull_request.base.sha }} | ||
|
|
||
| - uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0 | ||
| with: | ||
| package_json_file: controller/package.json | ||
|
|
||
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | ||
| with: | ||
| node-version: "22" | ||
| cache: pnpm | ||
| cache-dependency-path: controller/pnpm-lock.yaml | ||
|
|
||
| - run: pnpm --dir controller install --frozen-lockfile --ignore-scripts | ||
|
|
||
| - name: Check Content product impact | ||
| env: | ||
| CONTENT_IMPACT_REPOSITORY: ../candidate | ||
| CONTENT_IMPACT_BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| CONTENT_IMPACT_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: pnpm --dir controller exec tsx scripts/validate-content-product-impact.ts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
scripts/validate-content-product-impact-workflow.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { describe, it } from "node:test"; | ||
|
|
||
| import { validateContentProductImpactWorkflow } from "./validate-content-product-impact-workflow.ts"; | ||
|
|
||
| const workflow = readFileSync( | ||
| ".github/workflows/content-product-conformance.yml", | ||
| "utf8", | ||
| ); | ||
|
|
||
| describe("Content product conformance workflow boundary", () => { | ||
| it("keeps the pilot read-only, exact-revision, and broadly observable", () => { | ||
| assert.deepEqual(validateContentProductImpactWorkflow(workflow), { | ||
| ok: true, | ||
| issues: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects pull_request_target and write permissions", () => { | ||
| const unsafe = workflow | ||
| .replace(" pull_request:", " pull_request_target:") | ||
| .replace("contents: read", "contents: write"); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert( | ||
| result.issues.some((issue) => issue.includes("pull_request_target")), | ||
| ); | ||
| assert(result.issues.some((issue) => issue.includes("permissions"))); | ||
| }); | ||
|
|
||
| it("rejects path filtering or a candidate checkout with credentials", () => { | ||
| const unsafe = workflow | ||
| .replace(" types:", ' paths: ["templates/content/**"]\n types:') | ||
| .replace("persist-credentials: false", "persist-credentials: true"); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("path filters"))); | ||
| assert(result.issues.some((issue) => issue.includes("credentials"))); | ||
| }); | ||
|
|
||
| it("requires declaration and label edits to rerun the pilot", () => { | ||
| const unsafe = workflow.replace(" edited,\n", ""); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("recalibration"))); | ||
| }); | ||
|
|
||
| it("does not hide checker infrastructure failures", () => { | ||
| for (const value of ["true", "${{ true }}"]) { | ||
| const unsafe = workflow.replace( | ||
| " run: pnpm --dir controller exec tsx scripts/validate-content-product-impact.ts", | ||
| ` continue-on-error: ${value}\n run: pnpm --dir controller exec tsx scripts/validate-content-product-impact.ts`, | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("infrastructure"))); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects dot and bracket references to the secrets context", () => { | ||
| for (const expression of [ | ||
| "${{ secrets.DEPLOY_KEY }}", | ||
| "${{ secrets['DEPLOY_KEY'] }}", | ||
| "${{ toJSON(secrets) }}", | ||
| ]) { | ||
| const unsafe = workflow.replace( | ||
| " timeout-minutes:", | ||
| ` env:\n LEAK: "${expression}"\n timeout-minutes:`, | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("secrets"))); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects job-level permission overrides and explicit GitHub tokens", () => { | ||
| const unsafe = workflow | ||
| .replace( | ||
| " name: Advisory Content product impact", | ||
| " name: Advisory Content product impact\n permissions:\n contents: write", | ||
| ) | ||
| .replace( | ||
| " timeout-minutes:", | ||
| ` env:\n GH_TOKEN: "\${{ github['token'] }}"\n timeout-minutes:`, | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("permissions"))); | ||
| assert(result.issues.some((issue) => issue.includes("credentials"))); | ||
| }); | ||
|
|
||
| it("rejects serialization of the full GitHub context", () => { | ||
| for (const expression of [ | ||
| "${{ toJSON(github) }}", | ||
| "${{ TOJSON( GITHUB ) }}", | ||
| ]) { | ||
| const unsafe = workflow.replace( | ||
| " timeout-minutes:", | ||
| ` env:\n GITHUB_CONTEXT: "${expression}"\n timeout-minutes:`, | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("credentials"))); | ||
| } | ||
| }); | ||
|
|
||
| it("requires the check job and impact checker step to be unconditional", () => { | ||
| const unsafe = workflow | ||
| .replace( | ||
| " name: Advisory Content product impact", | ||
| " name: Advisory Content product impact\n if: false", | ||
| ) | ||
| .replace( | ||
| " - name: Check Content product impact", | ||
| " - name: Check Content product impact\n if: false", | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert.equal( | ||
| result.issues.filter((issue) => issue.includes("unconditionally")).length, | ||
| 2, | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects extra jobs and additional checkout steps", () => { | ||
| const unsafe = workflow | ||
| .replace( | ||
| "jobs:\n", | ||
| "jobs:\n leak:\n runs-on: ubuntu-latest\n environment: production\n steps: []\n", | ||
| ) | ||
| .replace( | ||
| " - uses: pnpm/action-setup@", | ||
| " - uses: actions/checkout@unsafe\n\n - uses: pnpm/action-setup@", | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("only"))); | ||
| assert(result.issues.some((issue) => issue.includes("two checkout"))); | ||
| }); | ||
|
|
||
| it("rejects self-hosted runners and arbitrary additional steps", () => { | ||
| const unsafe = workflow | ||
| .replace("runs-on: ubuntu-latest", "runs-on: self-hosted") | ||
| .replace( | ||
| " - uses: pnpm/action-setup@", | ||
| " - uses: arbitrary/action@unsafe\n\n - uses: pnpm/action-setup@", | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("GitHub-hosted"))); | ||
| assert(result.issues.some((issue) => issue.includes("exactly match"))); | ||
| }); | ||
|
|
||
| it("rejects a candidate-controlled controller or package script", () => { | ||
| const unsafe = workflow | ||
| .replace( | ||
| "ref: 03caa13fd5bf6176ee01ab223452db9932b7ca8c", | ||
| "ref: ${{ github.event.pull_request.head.sha }}", | ||
| ) | ||
| .replace( | ||
| "pnpm --dir controller exec tsx scripts/validate-content-product-impact.ts", | ||
| "pnpm --dir candidate content-product-impact", | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("trusted revision"))); | ||
| assert(result.issues.some((issue) => issue.includes("standalone"))); | ||
| }); | ||
|
|
||
| it("requires the exact upstream base revision for fork pull requests", () => { | ||
| const unsafe = workflow.replace( | ||
| "git -C candidate fetch --no-tags https://github.com/BuilderIO/agent-native.git ${{ github.event.pull_request.base.sha }}", | ||
| "git -C candidate fetch origin main", | ||
| ); | ||
| const result = validateContentProductImpactWorkflow(unsafe); | ||
| assert.equal(result.ok, false); | ||
| assert(result.issues.some((issue) => issue.includes("target revision"))); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.