Repository navigation
Conversation
…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.
Contributor
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Hardens the custard workflows so that pull request code no longer runs in a privileged
workflow_runcontext.Problem
custard-run.yamlandcustard-run-dev.yamlwere triggered byworkflow_runwhen the "Custard CI" pull_request workflow started. Those runs execute in the base repository context withid-token: write, check out the pull request head commit, authenticate to Google Cloud, and runmake teston 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 theworkflow_runtrigger. Both still run on push tomainand throughworkflow_dispatch.custard-run.yaml: pass the test timeout and package path throughenv:instead of interpolating${{ }}into the shell script (custard-run-dev.yamlalready did this).custard-run.yaml,custard-run-dev.yaml:persist-credentials: falseon checkouts.custard-ci.yaml: addpermissions: contents: read; pin thecloud-samples-toolscheckout to the v0.3.2 commit SHA; move${{ }}expressions out of the lint, CI Setup, environment export and test script bodies intoenv:.Effect on pull requests
Custard CI / tests,Custard CI / lintand(dev) Custard CI / testscommit statuses are no longer posted on pull requests. None of them is a required check.lintjob incustard-ci.yamland the workflow nameCustard CIare unchanged.custard-ci.yamlandcustard-ci-dev.yaml.workflow_dispatchwith a reviewed ref.Testing
The three files parse as YAML.
actionlintwas not run locally. This is a draft so the checks on this pull request can confirm thatlintand 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 toinputs.ref/github.sha; they will be cleaned up separately.Checklist
npm test(see Testing)npm run lint(see Style)GoogleCloudPlatform/nodejs-docs-samples. Not a fork.