Repository navigation
[RFC] Cross-Repository CI Relay for PyTorch Out-of-Tree Backends - #90
Conversation
albanD
left a comment
There was a problem hiding this comment.
Great proposal!
Left a few comments, but the general architecture sounds great to me.
Most of my comments are about setting up the specific rules and doesn't block the first steps!
|
|
||
| The allowlist is designed to naturally support gradual progression from experimental participation to mature participation. The table below lists the requirements for advancing to each level. | ||
|
|
||
| | Phase | Level | Requirements | |
There was a problem hiding this comment.
For the requirements, it might be helpful to separate Infra availability vs legitimate test breakage.
I think the requirement we want to have here is both:
- Very strong requirement on Infra availability.
- More relaxed requirement on test breakage
We want to encourage both for sure, but they will be managed very differently so we most likely want to provide signal to backend writers independently.
There was a problem hiding this comment.
Excellent point. Will update the requirements to separate two dimensions
Hi @albanD, so happy to get your approval, thank you. The initial code for L1 and L2 is complete, and I will submit a PR soon. I'll let you know when it's finished. |
|
Hey @albanD, the new commit is ready, please help to review it again, thank you. |
|
@fffrog @can-gaa-hou, a couple follow up clarifications after looking at the pytorch/test-infra#7847 in addition to the comments left on the PR
Phase 2 should expose:
|
albanD
left a comment
There was a problem hiding this comment.
Sounds good to me!
Also I agree with Zain about splitting to make sure we can land L1 asap!
@albanD, thank you for your approval. We have been quite busy lately, but we will do our best to complete L1 by March 28th, and sorry again for the delay. |
|
Hey @ZainRizvi
Got it, thank you. We will implement the L1 plan as soon as possible. We sincerely apologize for any delays caused by our busy internal affairs.
Gotcha, thank you. Phase 2 should expose:
I knew, thank you for the detailed explanation, and we will start the L2 developement once the L1 is completed |
|
Merging! |
All PRs for L1 of this RFCTo implement L1 of this RFC, we have submitted the following three PRs across different repositories to set up the necessary infrastructure and features:
These PRs are interconnected and collectively fulfill the implemetation outlined in the RFC. |
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. ghstack-source-id: a936347 Pull-Request: #178681
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. ghstack-source-id: b187886 Pull-Request: #178681
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. ghstack-source-id: 90e2e71 Pull-Request: #178681
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. ghstack-source-id: 052e046 Pull-Request: #178681
## Author - @can-gaa-hou - @KarhouTam # Summary Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. This PR implements the initial version of the cross-repository CI relay described in [[RFC] Cross-Repository CI Relay for PyTorch Out-of-Tree Backends](pytorch/rfcs#90). The current implementation focuses on the first two levels defined in the RFC: - `L1`: downstream repos can be onboarded and triggered through the relay Higher-level behaviors for `L2`, `L3`, and `L4` are intentionally left for follow-up work. # Architecture The relay is split into two AWS Lambda functions: - `webhook_handler` - [x] receives GitHub webhook PR and push events from the upstream repo - [x] validates webhook signatures and authenticates with AWS Secret Manager - [x] reads the downstream whitelist from the URL and stores it in Redis - [x] for `create`/`reopen`/`synchronize` actions, forwards repository_dispatch events to downstream repos # Changes ```md .github/workflows/ ├── cross-repo-ci-relay-tests.yml # CI workflow for cross-repo-ci-relay └──_lambda-do-release-runners.yml # Add cross-repo-ci-relay release workflow aws/lambda/cross_repo_ci_relay/ ├── tests/ # Unit tests for cross-repo-ci-relay ├── README.md # project overview, env vars, build/deploy, and callback usage ├── Makefile # build, package, deploy, and clean commands for Lambda ├── allowlist.py # Functions to handle the allowlist from GitHub ├── config.py # shared runtime config loading ├── utils.py # shared utility helpers and common exceptions ├── redis_helper.py # Redis helpers for whitelist cache ├── lambda_function.py # Lambda entrypoint for GitHub webhook requests ├── gh_helper.py # GitHub App / repository_dispatch client helpers ├── event_handler.py # Functions to handle PR and push events ├── local_server.py # For local tests, see README.md └── requirements.txt # Python dependencies for the webhook Lambda package ``` # Usage See README.md for more details. # Verification We performed the following scenario verification on our AWS Lambda instance: - [x] Test with Upstream PR create/reopen/synchronize and push events triggering webhook, then redispatching to the Downstream CI (different organization) workflow. # Terraform configuration pytorch/ci-infra#415 # Unit Tests - [x] Unit Tests (Mock) cc @fffrog --------- Co-authored-by: KarhouTam <[email protected]> Co-authored-by: fffrog <[email protected]>
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. Pull Request resolved: #178681 Approved by: https://github.com/ZainRizvi, https://github.com/albanD
| - **Upstream/downstream decoupling:** Downstream repos **only need to install this App to join the cross-repo CI coordination**. Downstream repos do not need an upstream token, and the upstream does not need to know about the downstream. All interactions are bridged through the GitHub App and Relay Server. | ||
|
|
||
| > \[!NOTE\] | ||
| > This GitHub App should be created under the `pytorch` organization and owned by the PyTorch team or the LF AI & Data Foundation team, to ensure credibility. An App created by a third party will face trust issues during installation and adoption. |
There was a problem hiding this comment.
LF AI & Data Foundation should be "LF Pytorch Foundation" team.
LF AI & Data Foundation is a different foundation under the LF separate from the PyTorch Foundation.
There was a problem hiding this comment.
So sorry for the mistake, and I will fix it ASAP
## Note Due to the restrictions on secret injection in the fork Repo scenario on GitHub, a new PR needs to be created to replace the old one (#415). Please refer to the old PR for a detailed discussion. ## Summary Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. - Add Terraform infrastructure for CRCR (Cross-Repository CI Relay), a GitHub webhook relay service for PyTorch out-of-tree backends that receives upstream webhook events via a GitHub App and forwards `repository_dispatch` events to registered downstream repositories - Infrastructure includes: Lambda function (webhook handler), ElastiCache Redis (allowlist caching), dedicated VPC, IAM roles, and Lambda Function URL - Add two GitHub Actions workflows: `crcr-on-pr.yml` and `crcr-deploy-prod.yml` **Notes:** This PR need to wait [this](pytorch/test-infra#7847) merged first for purpose of updating tag field in Terrafile. ## Architecture GitHub App → Lambda webhook (Function URL) → `repository_dispatch` → downstream repos **AWS Resources (us-east-1, account 391835788720):** - Lambda function (`cross_repo_ci_webhook`) with Python 3.10 runtime - ElastiCache Redis replication group for allowlist caching - VPC with private subnets for Lambda ↔ Redis connectivity - IAM role with Secrets Manager, VPC networking, and CloudWatch Logs permissions - S3 backend for Terraform state ## Test Multiple deployments and verifications have been completed on personal AWS environment. --------- Co-authored-by: can-gaa-hou <[email protected]>
## Author - @KarhouTam - @can-gaa-hou - @fffrog ## Summary - This PR implements the L2 levels of the cross-repository CI relay described in pytorch/rfcs#90. - For the previous L1 implementation, please refer to #7847. - Please refer to pytorch/rfcs#90 (comment) for the overall implementation. - Please refer to pytorch/rfcs#96 for the design of HUD side. - Please refer to #8069 for the implementation of HUD side. Higher-level behaviors for `L3` and `L4` are intentionally left for follow-up work. ## Architecture The relay is split into two AWS Lambda functions: - `webhook` lambda function (Updated) - [x] receives GitHub webhook PR and push events from the upstream repo - [x] validates webhook signatures and authenticates with AWS Secret Manager - [x] reads the downstream whitelist from the URL and stores it in Redis - [x] for `opened`/`reopened`/`synchronized`/`closed` actions, forwards repository_dispatch events to downstream repos - `callback` lambda function (Added) - [x] receives downstream callback payload through a public lambda function URL - [x] validates callback payload with OIDC - [x] reads the downstream whitelist from the URL and stores it in Redis - [x] extracts CI result information from the payload and uploads to PyTorch HUD - [x] records `queue time` and `execute time` for evolution to `L3` repo ## Changes ```md ..github/ ├── workflows/ │ └── _lambda-do-release-runners.yml # Updates the Lambda release workflow to include cross-repo-ci-relay packaging/release │ └── actions/ └── cross-repo-ci-relay-callback/ └── action.yml # Composite action used by downstream workflows to report status back to the relay/result endpoint aws/lambda/cross_repo_ci_relay/ ├── tests/ # Unit tests for allowlist/config/webhook/result/redis behavior ├── README.md # Project overview, local development, callback flow, and result-side validation steps ├── Makefile # Top-level local developer entrypoint for test / deploy / clean ├── local_server.py # FastAPI wrapper for local end-to-end testing of both webhook and result endpoints ├── requirements.txt # Python dependencies required by the relay Lambdas │ ├── utils/ │ ├── allowlist.py # Loads, parses, and queries the downstream allowlist by rollout level │ ├── config.py # Shared runtime config loading and cached get_config() helper │ ├── gh_helper.py # GitHub App, repository_dispatch, and GitHub file access helpers │ ├── hud.py # HUD write helpers for downstream result reporting │ ├── jwt_helper.py # Helpers for minting/verifying relay callback tokens │ ├── redis_helper.py # Redis helpers for allowlist cache, OOT state, and timing data │ └── misc.py # Shared TypedDict definitions and HTTPException │ ├── webhook/ │ ├── Makefile # Build/package/deploy commands for the webhook Lambda │ ├── lambda_function.py # Webhook Lambda entrypoint: verifies GitHub webhook requests and routes events │ └── event_handler.py # Handles PR/push events, resolves allowlist targets, and dispatches to downstream repos │ └── callback/ ├── Makefile # Build/package/deploy commands for the result Lambda ├── lambda_function.py # Result Lambda entrypoint: verifies callback token and GitHub OIDC token └── callback_handler.py # Validates callback payloads, checks L2+ eligibility, stores state, and writes to HUD ``` ## Usage See [README.md](https://github.com/KarhouTam/test-infra/blob/crcr-L2/aws/lambda/cross_repo_ci_relay/README.md) for more details. ## Verification We performed the following scenario verification on our AWS Lambda instance: - [x] Test with Upstream PR create/reopen/synchronize and push events triggering webhook, then redispatching to the Downstream CI (different organization) workflow. - [x] Test with Downstream workflow send callback payload through the added action to the result lambda, then extract CI result information and send to PyTorch HUD. ## Terraform configuration - pytorch/ci-infra#446 ## Unit Tests - [x] Unit Tests (Mock) ## Security - **Callback payload carries full upstream webhook data back to HUD** — `action.yml` builds the callback body by mutating `github.event.client_payload` (which contains the entire original webhook payload: PR metadata, commits, author info) and adding `status`/`conclusion`/`workflow_name`/`workflow_url` on top. This full blob is forwarded verbatim by `hud.py` to HUD with no relay-side filtering. HUD receives both relay-trusted `verified_repo` and an unvalidated body — if HUD trusts self-reported fields inside the body over `verified_repo`, a manipulated dispatch payload could tamper with HUD records. - **Lambda callback URL is public and hardcoded** — The endpoint is hardcoded in `action.yml and exposed in a public action, making it trivially discoverable. OIDC verification blocks unauthorized HUD writes, but the endpoint has no rate limiting; request flooding can cause Lambda concurrency exhaustion or Redis connection saturation. - **Only OIDC is used for verification** — The callback lambda relies solely on GitHub OIDC token verification for authentication, without additional application-level secrets or signatures. If an attacker compromises a downstream repo's GitHub Actions permissions, they could forge authenticated requests to the callback endpoint. Besides, OIDC has its own limitations (e.g., token expiration, potential misconfigurations) that could lead to unauthorized access if not carefully managed. ## HUD Interaction - **Design Principle: Transparent Relay & Decoupling** The Relay Server acts as a **lightweight data passthrough layer**. It does not define or parse specific CI data formats; instead, it offloads data interpretation and validation to the HUD. This ensures complete decoupling between the relay infrastructure and business-specific data. - **Security & Risk Mitigation** The relay uses **OIDC authentication** to guarantee the authenticity of the data source (**Verified Repo**). Its core responsibility is to ensure the data originates from the claimed repository, while security filtering and content compliance are enforced at the HUD level. --------- Co-authored-by: can-gaa-hou <[email protected]> Co-authored-by: fffrog <[email protected]>
…8119) # Summary - The current implementation focuses on L3/L4 levels defined in the RFC: pytorch/rfcs#90 - For detailed design for L3/L4, please refer to pytorch/rfcs#93 # Architecture - `webhook` function: - [x] Create PR label handling function for L3 repo (refer to the 3 scenario cases mentioned in pytorch/rfcs#93) - **Scenario 1**: Label arrives before the downstream workflow job is triggered. So we cached this information in Redis using `mark_check_run_wanted` and let the `callback` lambda create this check run. - **Scenario 2**: Label arrives during the downstream workflow job is running. The `callback` lambda will cache workflow information beforehand so it can immediately create the `in_progress` check run. - **Scenario 3**: Label arrives after the downstream workflow job is done. If the cached workflow information is still alive in Redis (3 days by default, could be set by `CRCR_STATUS_TTL`), it will create a `completed` check run immediately. Otherwise, it will not create a check run. - [x] Dispatch function will check for L3 label or L4, and store this information in Redis for the `callback` to check whether a check run is needed. - [x] Create check run and check suite handling functions for the downstream workflow jobs re-run mechanism within the check run. - `callback` function: - [x] Handle upstream check-run creation/update for L3/L4 - **Scenario 1 & L4**: Check in Redis by calling `is_check_run_wanted` to see if this PR needs a check run. If so, immediately create one. - **All Scenarios**: Store workflow information in Redis for check run creation in the `webhook`. - [x] Set "in_progress" zombie check-runs to "time_out" through a sweeper periodically # Changes ```md .github/actions/cross-repo-ci-relay └── action.yml # Add a step to capture job-name for re-run aws/lambda/cross_repo_ci_relay/ ├── tests/ # Add more unit tests ├── allowlist.py # Update utils function for L3 ├── redis_helper.py # Set more keys for L3 ├── gh_helper.py # Update utils function for L3 ├── misc.py # Update utils function for L3 ├── event_handler.py # Create PR label/check run/check suites handling function ├── cleanup_handler.py # Handle zombie check-run └── callback_handler.py # Handle upstream check-run creation ``` # Verification We performed the following scenario verification on our AWS Lambda instance: - L3: - [x] L3 labels named `ciflow/crcr/{device}` are added immediately after the PR is created, and show up in the corresponding check-run on the PR with the name `crcr/{repo}/{workflow_name}/{job_name}`. - [x] After clicking into the check-run, the corresponding information is correct. - [x] L3 labels are added while the workflow job is running, which should show up the `in_progress` check-run. - [x] L3 labels are added after the workflow job is done, which should show up the `completed` check-run. - [x] Check run is updated when the PR with L3 labels is reopened or synchronized. - L4: - [x] Check run should be created after the PR is opened. - [x] Check run is updated when the PR is reopened or synchronized. - Re-run - [x] Clicking the `Re-run` button in each failed check run will trigger the corresponding downstream workflow failed jobs to re-run and update the check run status to `in_progress`. - [x] Clicking the `Re-run all jobs` or `Re-run all failed jobs` button will trigger the corresponding downstream workflow jobs in the check suite and update the corresponding check run status to `in_progress`. # Unit Tests - [x] Unit Tests (Mock) # TODO - Modify PyTorchBot for L3 non-blocking merge: pytorch/pytorch#185612 - Add a new feature in PyTorchBot that automatically mentions related on-call maintainers in L3/L4 repos when check-run fails: #8183 cc @albanD @fffrog @KarhouTam @atalman @huydhn @zxiiro @subinz1 @jewelkm89
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. Pull Request resolved: pytorch#178681 Approved by: https://github.com/ZainRizvi, https://github.com/albanD
Please refer to this [comment](pytorch/rfcs#90 (comment)) for the overall implementation. The PyTorch repository should be the preferred location for storing the allowlist.yml file. Downstream repositories are essentially extensions (or plugins) of the PyTorch repository, so they should only need to be aware of PyTorch itself. Infrastructure repositories such as test-infra and ci-infra should remain transparent to downstream repositories and not be directly exposed. Pull Request resolved: pytorch#178681 Approved by: https://github.com/ZainRizvi, https://github.com/albanD
This RFC has been under discussion for several weeks, you can visit this link to see previous discussions if you are interesed in.
And thanks a lot @ZainRizvi, @seemethere, @afrittoli, @zxiiro, @mikaylagawarecki, and @jewelkm89 for the valuable suggestions.
Click here to see a preview of this RFC.