Skip to content

fix(ci): stop running pull request code from workflow_run in custard workflows - #4522

Draft
iennae wants to merge 2 commits into
mainfrom
fix/custard-workflow-hardening
Draft

iennae wants to merge 2 commits into
mainfrom
fix/custard-workflow-hardening

Conversation

@iennae

@iennae iennae commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Hardens the custard workflows so that pull request code no longer runs in a privileged workflow_run context.

Problem

custard-run.yaml and custard-run-dev.yaml were triggered by workflow_run when the "Custard CI" pull_request workflow started. Those runs execute in the base repository context with id-token: write, check out the pull request head commit, authenticate to Google Cloud, and run make test on that code. The only safeguard was the repository's "approve workflow runs" setting; nothing in the workflow files enforced it.

Changes

  • custard-run.yaml, custard-run-dev.yaml: remove the workflow_run trigger. Both still run on push to main and through workflow_dispatch.
  • custard-run.yaml: pass the test timeout and package path through env: instead of interpolating ${{ }} into the shell script (custard-run-dev.yaml already did this).
  • custard-run.yaml, custard-run-dev.yaml: persist-credentials: false on checkouts.
  • custard-ci.yaml: add permissions: contents: read; pin the cloud-samples-tools checkout to the v0.3.2 commit SHA; move ${{ }} expressions out of the lint, CI Setup, environment export and test script bodies into env:.

Effect on pull requests

  • The Custard CI / tests, Custard CI / lint and (dev) Custard CI / tests commit statuses are no longer posted on pull requests. None of them is a required check.
  • The required lint job in custard-ci.yaml and the workflow name Custard CI are unchanged.
  • Pull requests from branches in this repository are still tested by the existing jobs in custard-ci.yaml and custard-ci-dev.yaml.
  • Fork pull requests no longer get credentialed test runs automatically. A maintainer can run "Custard run" through workflow_dispatch with a reviewed ref.

Testing

The three files parse as YAML. actionlint was not run locally. This is a draft so the checks on this pull request can confirm that lint and the legacy test jobs still run before review.

Follow-up

The remaining github.event.workflow_run.* expressions in the custard-run workflows now evaluate to empty and fall through to inputs.ref / github.sha; they will be cleaned up separately.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

…workflows

Problem:
custard-run.yaml and custard-run-dev.yaml were triggered by `workflow_run`
whenever the "Custard CI" pull_request workflow started. Those runs execute
in the base repository context with `id-token: write`, check out the pull
request head commit, authenticate to Google Cloud through Workload Identity
Federation, and then run `make test` on that code. The only thing standing
between a fork pull request and those credentials was the repository's
"approve workflow runs" setting; nothing in the workflow files enforced it.

In addition:
- custard-run.yaml and custard-ci.yaml interpolated `${{ }}` expressions
  (package paths, ci-setup values) directly into shell and github-script
  bodies, which allows script injection through values derived from the
  pull request.
- Checkouts in the custard-run workflows left the job token in the git
  config while code under test ran.
- custard-ci.yaml declared no workflow-level permissions, so three jobs ran
  with the repository default token permissions, and it checked out
  cloud-samples-tools by mutable tag.

Solution:
- Remove the `workflow_run` trigger from custard-run.yaml and
  custard-run-dev.yaml. They still run on push to main and through
  workflow_dispatch, so a maintainer can run them for a reviewed ref.
  Pull requests from branches in this repository continue to be tested by
  the existing jobs in custard-ci.yaml and custard-ci-dev.yaml.
- Pass the test timeout and package path through `env:` in custard-run.yaml
  (custard-run-dev.yaml already did this), and do the same for the lint,
  CI Setup, environment export and test steps in custard-ci.yaml.
- Set `persist-credentials: false` on the checkouts in both custard-run
  workflows.
- Add `permissions: contents: read` at the top of custard-ci.yaml.
- Pin the cloud-samples-tools checkout in custard-ci.yaml to commit
  9ee708234e240605d96e78f652c333ed6aa95a23 (v0.3.2).

Effect on pull requests:
The "Custard CI / tests", "Custard CI / lint" and "(dev) Custard CI / tests"
commit statuses are no longer posted on pull requests. None of them is a
required check. The `lint` job in custard-ci.yaml, which is required, and
the workflow name "Custard CI" are unchanged.

The remaining `github.event.workflow_run.*` expressions in the custard-run
workflows now evaluate to empty and fall through to `inputs.ref` or
`github.sha`; they are left for a follow-up cleanup.

Testing:
The three files parse as YAML. actionlint was not available locally and the
workflows have not yet been exercised on GitHub Actions.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@product-auto-label product-auto-label Bot added samples Issues that are directly related to samples. api: workflows Issues related to the Workflows API. labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants