Skip to content

fix(tekton/triggers): stop coupling ce-paramProduct with the repository - #5591

Merged
ti-chi-bot[bot] merged 2 commits into
mainfrom
fix/devbuild-product-is-not-a-repo-check
Nov 13, 2026
Merged

ti-chi-bot[bot] merged 2 commits into
mainfrom
fix/devbuild-product-is-not-a-repo-check

Conversation

@wuhuizuo

Copy link
Copy Markdown
Contributor

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:

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 chore(tekton): drop task retries and raise build timeouts #5588. Looks unintended; worth a one-line follow-up.

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.

@ti-chi-bot ti-chi-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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-paramProduct header is missing or malformed. This could lead to unexpected behavior or silent failures.
    • Suggestion: Explicitly handle cases where ce-paramProduct is 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 [...])
  2. 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-paramProduct header 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-paramProduct for any non-allowlisted repository.

Code Improvements

  1. Overlay Function Duplication

    • File/Lines: trigger-test-utils.ts (lines 110-140), serverless-builds.test.ts (lines 506-518)
    • Issue: The overlay function is duplicated in trigger-test-utils.ts and serverless-builds.test.ts, violating DRY principles.
    • Suggestion: Remove the duplicate overlay function from serverless-builds.test.ts and import it from trigger-test-utils.ts.
    // serverless-builds.test.ts
    import { overlay } from './trigger-test-utils.ts';
  2. 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.
  3. 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.

Best Practices

  1. 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-paramProduct header 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);
    });
  2. Documentation in Shared Utility Functions

    • File/Lines: trigger-test-utils.ts (lines 110-140)
    • Issue: The overlay function lacks sufficient documentation about its parameters and expected outputs.
    • Suggestion: Add JSDoc comments to the overlay function 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 = "") { ... }
  3. 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.
  4. README Clarifications

    • File/Lines: tekton/v1/triggers/README.md (lines 46-73)
    • Issue: The README could better explain the purpose of decoupling ce-paramProduct and its implications for future development.
    • Suggestion: Add a summary section about the expected behavior and examples of valid/invalid scenarios for ce-paramProduct.

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.

@ti-chi-bot ti-chi-bot Bot added the size/L label Nov 13, 2026

@wuhuizuo wuhuizuo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@ti-chi-bot

ti-chi-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the approved label Nov 13, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit 73ade8f into main Nov 13, 2026
8 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the fix/devbuild-product-is-not-a-repo-check branch November 13, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant