Remove runtime realm owner escalation in webhook handler#4214
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d9ca8bfd0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| // Run as the realm owner so they have write permissions in the target realm | ||
| let runAs = webhook.username as string; |
There was a problem hiding this comment.
Preserve compatibility for webhooks registered before this change
This handler now always runs the command as webhook.username. On upgrade, existing incoming_webhooks rows keep the account that originally created them, while the new register-github-webhook.ts logic only affects future registrations. For any already-registered GitHub webhook owned by a user like @submissionbot or a human account, run-command will now reject the event once it targets /submissions/ because run-command.ts requires runAs to already have realm permissions. Without a migration/backfill or a compatibility fallback here, deploying this commit breaks existing webhook integrations until each webhook is manually recreated under submission_realm.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Intended, we will update the incoming webhook record to be the realm user who should have the write permission (@submission_realm:xxx ) in the github webhook use case
Host Test Results 1 files ± 0 1 suites ±0 1h 54m 27s ⏱️ - 9m 32s Results for commit 068b0f4. ± Comparison against base commit 86cb8e6. This pull request removes 1 and adds 185 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull request overview
This PR removes runtime “realm owner” privilege escalation when executing webhook-triggered commands by ensuring webhooks are registered under a user that already has the required permissions (intended to be submission_realm), and adds more explicit failure signaling when webhook command enqueueing fails.
Changes:
- Stop looking up the target realm owner on each webhook and run commands as the webhook’s registered user instead.
- Track “matched” vs “executed” webhook commands and return HTTP 500 if none of the matched commands were enqueued.
- Update the GitHub webhook registration script to default to
submission_realmcredentials and registercheck_suiteevents.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/realm-server/handlers/handle-webhook-receiver.ts | Removes realm-owner escalation and adds a 500 response when all matched commands fail to enqueue. |
| packages/matrix/scripts/register-github-webhook.ts | Attempts to default authentication to submission_realm (derived password) and adds check_suite event registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2d9ca8b to
3c765b1
Compare
3c765b1 to
24f2f4a
Compare
| // Step 1: Authenticate | ||
| // Step 1: Authenticate as submission_realm user by default | ||
| if (!process.env.MATRIX_USERNAME) { | ||
| process.env.MATRIX_USERNAME = 'submission_realm'; |
There was a problem hiding this comment.
why is this defaulting to 'submission_realm'?
if you want to register-github-webhook-for-submission-realm. Just write that script. You don't have to pollute this to fit your use-case.
There was a problem hiding this comment.
@tintinthong last week we discussed that the submission_realm@xxx user should be the one registering incoming webhook commands, since it is the owner and has write access. That avoids any permission issues when the command writes cards into the submission realm.
Do you mean whether other users can use this base script to register webhooks under their own realm in their local environment?
There was a problem hiding this comment.
We called and verified the implementation is fine, but perhaps rename the script to register-github-webhook-for-submission-realm
What is changing