Repository navigation
fix(tekton/triggers): stop coupling ce-paramProduct with the repository - #5591
Conversation
The devbuild filters have required `ce-paramProduct` to equal `body.repository.name` since #5474 removed the header allowlist bypass. That equality is not a security property and it is not a routing input: - the repository allowlist is body-only, keyed on `repository.full_name`, and no product header can widen it; - every non-Serverless route derives `component` from the allowlist (`repository.name`, plus the `tidbcloud/*` and `pingcap/ticse` overrides), so the header cannot change what is built either. What the equality did do was drop legitimate builds. tibuild labels a component that lives in a repository with another name — `ticdc-newarch` in `pingcap/ticdc`, `br` / `dumpling` / `tidb-lightning` in `pingcap/tidb`, `drainer` / `pump` in `pingcap/tidb-binlog`, `dm` in `pingcap/tiflow` — and `githubRepo` may be passed explicitly. A rejected event creates no PipelineRun and the listener logs nothing, so those devbuilds sat in PENDING: five of them between 2026-11-06 and 2026-11-13 (3030009 `ticdc-newarch` hotfix, 2970069 `br` hotfix, 3030012 and 2970059/2970060 `ticdc` on `pingcap/tiflow`), while every build whose product matched its repository name kept working. Drop the equality from all nine fake-github routes. Serverless keeps it: there the product *is* the component, so it still has to name the Serverless repository. The tests assert the replacement invariant instead: whatever the header says, the route and the component come from the repository, and a Serverless product cannot route a repository it does not name.
`deno test tekton/tests/*.test.ts` is red on main; this commit makes it green again without changing any trigger. - #5533 added `pingcap/ticse` to `cseRepositories`, and the loops that follows reuse one `branch-push` payload for the tag and branch-creation triggers. Those triggers require `body.ref_type` (#5569), so every assertion threw `field not found: ref_type`. Give the tag and branch cases payloads that carry it. - #5588 raised `tidbcloud/cloud-storage-engine` to 1h on the branch-push route only. The test still asserted a single 30m budget for both routes; assert each route's own value and note that the tag route keeps 30m.
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 decouples the ce-paramProduct header from the repository name in the Tekton triggers, addressing a regression that blocked legitimate builds for components residing in repositories with different names. The approach simplifies the filtering logic by removing redundant equality checks and enforces that the component is solely derived from the allowlisted repository. Overall, the PR is well-documented and fixes a critical issue affecting build pipelines. However, while the changes are functional, there are areas for improvement in modularity, testing, and edge-case handling.
Critical Issues
-
Edge Case: Missing Product Header (Multiple Locations)
- File/Lines:
tekton/v1/triggers/triggers/env-gcp/_/fake-github/*,trigger-security.test.ts(lines 214-306) - Issue: There's no clear fallback behavior defined if the
ce-paramProductheader is missing or malformed. This could lead to unexpected behavior or silent failures. - Suggestion: Explicitly handle cases where
ce-paramProductis missing by either logging a warning and rejecting the request or providing clear documentation about the expected behavior.
# Example: Add a check for missing or empty ce-paramProduct in filter - name: filter value: >- (header.canonical('ce-paramProduct') != '' && body.repository.full_name in [...])
- File/Lines:
-
Security Assertion Logic Needs Strengthening
- File/Lines:
trigger-security.test.ts,Deno.test("ce-paramProduct cannot select...")(lines 214-306) - Issue: Although the PR claims that the
ce-paramProductheader cannot influence the repository or component, the tests do not explicitly validate this for all possible adversarial combinations of headers and repository names. - Suggestion: Add more comprehensive security tests to ensure no route can be matched with a forged
ce-paramProductfor any non-allowlisted repository.
- File/Lines:
Code Improvements
-
Overlay Function Duplication
- File/Lines:
trigger-test-utils.ts(lines 110-140),serverless-builds.test.ts(lines 506-518) - Issue: The
overlayfunction is duplicated intrigger-test-utils.tsandserverless-builds.test.ts, violating DRY principles. - Suggestion: Remove the duplicate
overlayfunction fromserverless-builds.test.tsand import it fromtrigger-test-utils.ts.
// serverless-builds.test.ts import { overlay } from './trigger-test-utils.ts';
- File/Lines:
-
Inline Filter Logic Complexity
- File/Lines:
fake-github-*.yaml(multiple lines) - Issue: The inline filter logic in the YAML files is verbose and difficult to maintain, especially with long conditions.
- Suggestion: Move the conditions to a shared utility or a script that generates the filter expressions for better readability and maintainability.
- File/Lines:
-
Modularize Platform-Specific Tests
- File/Lines:
trigger-security.test.ts(lines 214-306) - Issue: The same test logic is repeated for multiple platforms (
linux/amd64,darwin/arm64, etc.). - Suggestion: Parametrize the tests to reduce duplication and improve maintainability.
- File/Lines:
Best Practices
-
Testing Coverage for Edge Cases
- File/Lines:
trigger-security.test.ts(lines 214-306) - Issue: The tests do not explicitly cover scenarios where the
ce-paramProductheader contains invalid, unexpected, or empty values. - Suggestion: Add tests for invalid or empty product headers to ensure the system handles these cases gracefully.
Deno.test("invalid ce-paramProduct headers are rejected", () => { const header = { "ce-type": "net.pingcap.tibuild.devbuild.push", "ce-paramProduct": "non-existent-product", }; const body = payload("pingcap/ticdc", "branch-push"); assertEquals(filter(route, body, header), false); });
- File/Lines:
-
Documentation in Shared Utility Functions
- File/Lines:
trigger-test-utils.ts(lines 110-140) - Issue: The
overlayfunction lacks sufficient documentation about its parameters and expected outputs. - Suggestion: Add JSDoc comments to the
overlayfunction for better clarity.
/** * Evaluates one overlay of the last interceptor in the trigger. * * @param trigger - The trigger object containing interceptor definitions. * @param key - The key to evaluate in the overlay expressions. * @param body - The event body payload. * @param header - The event headers. * @param field - Optional field to extract from the evaluated expression. * @returns The evaluated value of the overlay expression. */ export function overlay(trigger, key, body, header, field = "") { ... }
- File/Lines:
-
Consistency in Test Data
- File/Lines:
trigger-security.test.ts(lines 214-306) - Issue: The test cases use inconsistent naming conventions for repositories and products (e.g.,
"tidb"vs"tikv"). - Suggestion: Use a standardized naming convention for test data to improve readability and maintainability.
- File/Lines:
-
README Clarifications
- File/Lines:
tekton/v1/triggers/README.md(lines 46-73) - Issue: The README could better explain the purpose of decoupling
ce-paramProductand its implications for future development. - Suggestion: Add a summary section about the expected behavior and examples of valid/invalid scenarios for
ce-paramProduct.
- File/Lines:
Conclusion
The PR resolves a critical issue and includes thorough testing and documentation. However, addressing the above feedback will enhance the clarity, security, and maintainability of the code. Specifically, handling edge cases for missing headers, reducing code duplication, and strengthening security tests should be prioritized.
|
[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 |
Why
Since #5474 removed the
ce-paramGithubRepoallowlist bypass, the devbuild filters have also requiredce-paramProductto equalbody.repository.name. That equality is neither a security boundary nor a routing input:body.repository.full_name; no product header widens it;componentfrom the allowlisted repository (repository.name, plus thetidbcloud/*andpingcap/ticseoverrides), 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
githubRepomay be passed explicitly:ticdc-newarchpingcap/ticdcbr,dumpling,tidb-lightningpingcap/tidbdrainer,pumppingcap/tidb-binlogdmpingcap/tiflowA rejected event creates no
PipelineRunand the listener logs nothing, so the devbuild staysPENDINGforever. 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):ticdc-newarchpingcap/ticdctag/v8.5.4-20261113-5691a52brpingcap/tidbtag/v8.5.4-20261111-4d32ecbticdcpingcap/tiflowbranch/masterticdcpingcap/tiflowpull/12954ticdcpingcap/tiflowpull/12954The last
ticdc-newarchhotfix 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.tsnow asserts the replacement invariant — whatever the header says, the route and the component come from the repository:Note the third line: with the product decoupled,
ticdconpingcap/tiflowbuilds the tiflow component. Nothing about the request's product label influences the build, which is the point.Security
Unchanged and unaffected:
body.repository.full_name in [...], andtrigger-security.test.tsstill asserts that no route readsce-paramGithubRepo, keys the allowlist onrepository.name, or bindsrepository.clone_url;The
fake-github-*triggers are only selected byel-tibuild, which verifies tibuild's CloudEvent HMAC (PingCAP-QE/ee-ops#2619).Verification
Second commit (please review separately)
deno test tekton/tests/*.test.tsis red onmain, independent of this change — I reproduced it on a cleanorigin/mainworktree (3f2c3d0). The second commit repairs the TiCSE formal-route assertions:pingcap/ticsetocseRepositories, so the tag and branch-creation assertions ran with abranch-pushpayload; those triggers requirebody.ref_type(fix(tekton): require the create event's ref_type on every create trigger #5569) and threwfield not found: ref_type. They now get payloads that carry it.tidbcloud/cloud-storage-engineto1hon the branch-push route only, while the test asserted a single30mfor 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)
PipelineRunstaysPENDINGforever — 80 such records are in the database, the oldest from 2026-08-10. A watchdog (PENDING+triggersEventIDsnon-empty +pipelinesempty 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 old30mbudget fortidbcloud/cloud-storage-enginewhile the branch-push route has1hafter chore(tekton): drop task retries and raise build timeouts #5588. Looks unintended; worth a one-line follow-up.