Repository navigation
fix(tekton): require the create event's ref_type on every create trigger - #5569
Conversation
GitHub delivers branch creation and tag creation as the same `create` event. `body.ref` carries the bare name in both cases, so `body.ref_type` is the only discriminator — but only `tidbcloud/serverless/tag-create.yaml` tested it. Every release trigger therefore fired on a *branch* whose name happens to match the tag regex (`v9.0.0`, `v26.3.1`, `^v.+` for tiflow-operator), and `bindings/github-tag-create.yaml` passes `body.ref` as both `git-ref` and `git-revision`, so the branch was fetched and built exactly like the tag: with `gcp-classic-build-params`, i.e. the official `hub` registry and live publisher URLs. Branch push rights are a much wider population than tag-cut rights. The mirror case is the branch-creation triggers, which also fire on tag creation. Add a first interceptor to all 23 tag-creation triggers (`body.ref_type == 'tag'`) and all 3 branch-creation triggers (`body.ref_type == 'branch'`), so the event kind is decided before any name or repository filter runs. Verified: - `tekton/tests/trigger-security.test.ts` gains a structural check that every create-event trigger carries the matching `ref_type` predicate (so a new trigger cannot be added without it) and a behavioural pair: a tag-shaped `ref` with `ref_type: branch` no longer passes the tiproxy release trigger, and a tag creation no longer passes the tikv branch trigger; - all 26 changed files parse, and `deno test -A tekton/tests/` is green (39 passed).
|
/approve |
1 similar comment
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wuhuizuo The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
1 similar comment
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wuhuizuo The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
I have already done a preliminary review for you, and I hope to help you do a better job.
Summary
This pull request addresses a critical security issue where GitHub create events for both branches and tags could inadvertently trigger incorrect pipelines due to the lack of a discriminator for ref_type. The fix introduces ref_type checks (tag or branch) for all 26 create-event triggers to ensure only the appropriate pipelines are executed. The approach is robust, adding explicit CEL interceptors to enforce ref_type validation and including structural and behavioral tests to guarantee future compliance. The PR is well-structured, but a few areas could benefit from improvement in maintainability and edge case handling.
Critical Issues
- Test Coverage for Edge Cases:
- File:
tekton/tests/trigger-security.test.ts, Lines 35-66. - Issue: The behavioral test covers only a single
tag-shaped branch and a singlebranch-shaped tag. Other potential edge cases, such as malformed or unexpectedref_typevalues (e.g.,null, empty string, invalid strings) are not tested. - Suggestion: Extend the behavioral test to include cases for invalid or missing
ref_typevalues. For example:Deno.test("invalid ref_type values do not trigger any pipelines", () => { const tagTrigger = load<NamedTrigger>( `${triggerDirectory}pingcap/tiproxy/git-create-tag.yaml`, ); const invalidEvent = payload("pingcap/tiproxy", "create"); invalidEvent.ref_type = "invalid"; // Unexpected value assertEquals(filter(tagTrigger, invalidEvent), false); invalidEvent.ref_type = ""; // Empty string assertEquals(filter(tagTrigger, invalidEvent), false); delete invalidEvent.ref_type; // Missing value assertEquals(filter(tagTrigger, invalidEvent), false); });
- File:
Code Improvements
-
Centralize
ref_typeValidation Logic:- Files: Multiple YAML files (e.g.,
git-create-tag.yaml,git-create-branch.yaml). - Issue: The
body.ref_typefilter logic (body.ref_type == 'tag'orbody.ref_type == 'branch') is duplicated across all triggers, increasing maintenance overhead and risk of future inconsistencies. - Suggestion: Abstract this common filter logic into a reusable CEL interceptor template or shared function. For instance:
Then, use this template in individual trigger files with parameter substitution for
interceptors: - name: validate-ref-type ref: { name: cel } params: - name: filter value: "body.ref_type == '{{ expected_ref_type }}'"
expected_ref_type.
- Files: Multiple YAML files (e.g.,
-
Error Handling for Missing
ref_type:- Files: Multiple YAML files (e.g.,
git-create-tag.yaml,git-create-branch.yaml). - Issue: The CEL filter assumes
body.ref_typeis always present, but there’s no safeguard for cases where it might be missing (e.g., due to malformed payload). - Suggestion: Update CEL filters to explicitly check for the presence of
body.ref_typebefore comparison:value: "has(body.ref_type) && body.ref_type == 'tag'"
- Files: Multiple YAML files (e.g.,
Best Practices
-
Improve Test Descriptions:
- File:
tekton/tests/trigger-security.test.ts, Lines 35-66. - Issue: Test descriptions like
"a branch named like a release tag does not drive a release build"could be more concise and specific. - Suggestion: Use descriptions that focus on the key behavior being validated, e.g.,
"validate ref_type prevents incorrect pipeline execution".
- File:
-
Reduce Code Duplication in Tests:
- File:
tekton/tests/trigger-security.test.ts, Lines 35-66. - Issue: The test code for loading triggers and applying filters is repeated. This can lead to harder-to-maintain tests.
- Suggestion: Abstract common logic into reusable helper functions:
function validateTrigger(triggerPath: string, payload: object, expected: boolean): void { const trigger = load<NamedTrigger>(triggerPath); assertEquals(filter(trigger, payload), expected); }
- File:
-
Documentation for New Structural Test:
- File:
tekton/tests/trigger-security.test.ts. - Issue: The purpose of the structural test checking all
create-event triggers is not documented in the code itself, though it’s described in the PR description. - Suggestion: Add a brief comment explaining the goal of the test, e.g.:
// Ensure all create-event triggers include a ref_type filter to prevent incorrect pipeline executions.
- File:
Summary of Recommendations
Critical Issues
- Add edge case tests for invalid or missing
ref_type.
Code Improvements
- Centralize
ref_typefilter logic across YAML files to reduce duplication. - Enhance CEL filters to handle missing
body.ref_typeexplicitly.
Best Practices
- Use more concise and specific test descriptions.
- Refactor test code to reduce duplication using helper functions.
- Document the purpose of the structural tests to improve maintainability.
These changes will improve the robustness, maintainability, and test coverage of the PR.
…5570) ## Problem `pull-verify-tekton-yaml` reads `.apiVersion`, `.kind` and `.metadata.name` once per file. A file holding **two** documents (`_/git-create-branch.yaml` holds two `Trigger`s) makes `yq` print `Trigger\n---\nTrigger`, which the kind allowlist rejects: ``` unknown or missing kind: 'Trigger --- Trigger' ``` So the check fails on a valid file the moment that file is touched — which is what happened in #5569. Two kinds of file it could never accept either: - `kustomization.yaml` — not a Tekton manifest, yet it was flagged for `Kustomization` + empty `metadata.name`; - `StepAction` — a Tekton resource missing from the allowlist, so every `tekton/v1/step-actions/*` change failed. ## Change Evaluate **every document** and report the ones that are not a named Tekton resource; skip `kustomization.yaml`; add `StepAction` to the allowlist. A file's document count no longer matters. ## Verification - Ran the check against **every** Tekton manifest in the repository (`PULL_BASE_SHA=<empty tree>`): 119 files, exit 0. - Negative case: a fixture whose first document is a valid `Trigger` and whose second is `kind: NotATektonThing` reports `invalid document: apiVersion="v1" kind="NotATektonThing" name="bad"` and exits 1 (and the valid document produces no noise).
|
/retest pull-verify-tekton-yaml |
|
/retest |
…ry (#5591) ## Why Since #5474 removed the `ce-paramGithubRepo` allowlist bypass, the devbuild filters have also required `ce-paramProduct` to equal `body.repository.name`. That equality is neither a security boundary nor a routing input: - the repository allowlist is body-only, keyed on `body.repository.full_name`; no product header widens it; - every non-Serverless route derives `component` from the allowlisted repository (`repository.name`, plus the `tidbcloud/*` and `pingcap/ticse` overrides), so the header cannot change what is built either. What it did do was reject legitimate builds. tibuild labels a component that lives in a repository with another name, and `githubRepo` may be passed explicitly: | product | repository | | --- | --- | | `ticdc-newarch` | `pingcap/ticdc` | | `br`, `dumpling`, `tidb-lightning` | `pingcap/tidb` | | `drainer`, `pump` | `pingcap/tidb-binlog` | | `dm` | `pingcap/tiflow` | A rejected event creates no `PipelineRun` and the listener logs nothing, so the devbuild stays `PENDING` forever. Five of them are stuck right now (every devbuild since 2026-11-06 whose product does not equal its repository name; all 120 that do match have real statuses): | devbuild | created (UTC) | product | repository | ref | kind | | --- | --- | --- | --- | --- | --- | | 3030009 | 2026-11-13 09:35 | `ticdc-newarch` | `pingcap/ticdc` | `tag/v8.5.4-20261113-5691a52` | hotfix | | 2970069 | 2026-11-11 08:11 | `br` | `pingcap/tidb` | `tag/v8.5.4-20261111-4d32ecb` | hotfix | | 3030012 | 2026-11-13 10:53 | `ticdc` | `pingcap/tiflow` | `branch/master` | devbuild | | 2970059 | 2026-11-10 09:55 | `ticdc` | `pingcap/tiflow` | `pull/12954` | devbuild | | 2970060 | 2026-11-10 09:56 | `ticdc` | `pingcap/tiflow` | `pull/12954` | devbuild | The last `ticdc-newarch` hotfix that actually ran is 2880034 (2026-11-03), i.e. before the merge. ## Change Drop the product/repository equality from all nine `fake-github-*` routes (`branch-push`, `pr`, `tag-create` × plain, `-darwin`, `-single-platform`). The Serverless routes keep it: there the product *is* the component (`extensions.build.serverless ? extensions.build.product : ...`), so it still has to name the Serverless repository. `tekton/tests/trigger-security.test.ts` now asserts the replacement invariant — whatever the header says, the route and the component come from the repository: ``` ACCEPT pingcap/ticdc product=ticdc-newarch component=ticdc ACCEPT pingcap/tidb product=br component=tidb ACCEPT pingcap/tiflow product=ticdc component=tiflow REJECT attacker/evil product=tidb component=- ``` Note the third line: with the product decoupled, `ticdc` on `pingcap/tiflow` builds the **tiflow** component. Nothing about the request's product label influences the build, which is the point. ## Security Unchanged and unaffected: - the allowlist is still `body.repository.full_name in [...]`, and `trigger-security.test.ts` still asserts that no route reads `ce-paramGithubRepo`, keys the allowlist on `repository.name`, or binds `repository.clone_url`; - a forged event for a non-allowlisted repository is still rejected with arbitrary product headers; - a Serverless product still cannot route a non-Serverless repository (that branch takes the component from the header, so it keeps the equality). The `fake-github-*` triggers are only selected by `el-tibuild`, which verifies tibuild's CloudEvent HMAC (PingCAP-QE/ee-ops#2619). ## Verification ``` kustomize build tekton/v1/triggers/triggers/env-gcp -> OK deno test --frozen --lock=tekton/tests/deno.lock --allow-read --allow-write \ --allow-env --allow-run=git,sh,deno tekton/tests/*.test.ts -> ok | 43 passed (302 steps) | 0 failed ``` ## Second commit (please review separately) `deno test tekton/tests/*.test.ts` is red on `main`, independent of this change — I reproduced it on a clean `origin/main` worktree (3f2c3d0). The second commit repairs the TiCSE formal-route assertions: - #5533 added `pingcap/ticse` to `cseRepositories`, so the tag and branch-creation assertions ran with a `branch-push` payload; those triggers require `body.ref_type` (#5569) and threw `field not found: ref_type`. They now get payloads that carry it. - #5588 raised `tidbcloud/cloud-storage-engine` to `1h` on the branch-push route only, while the test asserted a single `30m` for both routes. It now asserts each route's own value. If you would rather land that as its own PR, say so and I will split it out. ## Follow-ups (not in this PR) - **tibuild (PingCAP-QE/ee-apps)**: a devbuild whose CloudEvents produced no `PipelineRun` stays `PENDING` forever — 80 such records are in the database, the oldest from 2026-08-10. A watchdog (`PENDING` + `triggersEventIDs` non-empty + `pipelines` empty after N minutes → error) would have turned this incident into a visible failure instead of a stalled queue. - **`git-create-tag-build-ng.yaml`**: the tag route still carries the old `30m` budget for `tidbcloud/cloud-storage-engine` while the branch-push route has `1h` after #5588. Looks unintended; worth a one-line follow-up.
Problem
GitHub delivers branch creation and tag creation as the same
createevent.body.refcarries the bare short name in both cases;body.ref_type(
"tag"/"branch") is the only discriminator. Of the 26 create-event triggersonly
tidbcloud/serverless/tag-create.yamltested it.So every release trigger fired on a branch whose name happens to match the
tag regex —
v9.0.0,v26.3.1, and^v.+fortiflow-operator. Andbindings/github-tag-create.yamlpassesbody.refas bothgit-refandgit-revision, with the pipeline's default+refs/heads/*:refs/heads/*refspec, so the branch was fetched and built exactly like the tag: with
gcp-classic-build-params— the official…/hubregistry and live publisherURLs, under the image-releaser ServiceAccount.
Someone who can push a branch to an allow-listed product repository (a much wider
population than those who may cut release tags) could therefore drive the release
build path. The mirror case exists too: the branch-creation triggers
(OWNERS-sync, README placeholder bump) also fire on tag creation.
Change
Add a first CEL interceptor deciding the event kind, before any name or
repository filter runs:
body.ref_type == 'tag'body.ref_type == 'branch'Verification
ref_typepredicate, so a trigger added later cannot silently omit it.ref(v1.2.3-alpha.0) passes thepingcap/tiproxyrelease trigger withref_type: tagand is refused withref_type: branch; thetikv/tikvbranch trigger behaves the other way round.deno test -A tekton/tests/green (39 passed).