feat(agent_api_keys): one-call webhook-trigger setup endpoint#329
Conversation
fdadd80 to
6ca6f70
Compare
✱ Stainless preview buildsThis PR will update the openapi python typescript
|
|
Will we want a rotate path as well should we want to rotate the api key? |
Good call — deferring a dedicated rotate path to a follow-up, keeping this PR to the create flow. Today rotation works by delete + recreate: the forward URL/path is derived from agent name + forward_path (not the secret), so deleting the key and re-creating the trigger yields a new secret to paste while the webhook URL stays the same. A dedicated |
f3a13f8 to
949cc2d
Compare
|
@danielmillerp can you address the greptile comments, then good to go |
Add POST /agent_api_keys/webhook-trigger: registers a github/slack signature key for an agent and returns the ready-to-paste forward webhook URL + secret in one call. Bundles the existing key-create with webhook-URL composition so a UI (or a curl) can wire a trigger in a single step; the webhook then flows through the existing /agents/forward ingress that verifies the signature against this key. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Slack signs requests with the app's existing Signing Secret, not a per-webhook secret we can generate. Auto-generating one for a Slack trigger stored a random value that would never match, so every real Slack delivery failed signature verification. Now Slack requires the caller to supply 'secret'; GitHub still auto-generates. Addresses Greptile P1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
949cc2d to
de85c65
Compare
|
Addressed the latest Greptile comments in de85c65.
|
be8a6ab to
88fcebd
Compare
What
Adds
POST /agent_api_keys/webhook-trigger— wires a webhook trigger in one call:github/slacksignature-verification key for the agent (auto-generates the signing secret if not provided),Why
The pieces to trigger an agent from a webhook already exist (the
/agents/forwardingress verifies the signature against an agent key, andPOST /agent_api_keysregisters keys). This bundles key-create + webhook-URL composition so a UI (or a curl) can set up a trigger in a single step instead of two — the backend for the self-serve "Add trigger" button. The webhook then flows through the existing forward ingress unchanged.Before — wiring a trigger was two manual steps, and the caller had to know the agent's internal id, invent a secret, and hand-compose the forward URL:
After — one call, by agent name, returns the URL + secret ready to paste:
No new ingress, no migration — built on the existing
agent_api_keys+ forward mechanism.On the signing secret
This matches how GitHub webhooks actually work. A GitHub webhook's Secret is a value you supply (GitHub doesn't generate one) — you type a high-entropy string into the webhook's Secret field, and GitHub uses it to HMAC each payload into
X-Hub-Signature-256: sha256=…, which the receiver re-computes and compares. It's a shared secret that must exist on both sides (GitHub's config + the verifying server), and it's optional-but-recommended (no secret → no signature header at all). Refs: GitHub docs validating-webhook-deliveries, creating-webhooks.Given that, the endpoint's
secrethandling is deliberate:secret(default) → the endpoint generates a strong one (secrets.token_hex(32)), stores it on the agent's verification key, and returns it once to paste into GitHub's Secret field — so the caller never has to invent entropy.secret→ for when the GitHub webhook already has a secret set and the agent side just needs to match it.Testing
🤖 Generated with Claude Code
Greptile Summary
This PR adds
POST /agent_api_keys/webhook-trigger, a single-call convenience endpoint that registers a GitHub or Slack signature-verification key for an agent and returns the ready-to-paste forward webhook URL and signing secret. It builds on the existingagent_api_keysstore and/agents/forwardingress without any new migration or routing.urllib.parse.quote, and checks for control characters inforward_pathbefore the DB write — all issues from earlier review rounds have been addressed.Confidence Score: 5/5
Safe to merge — all validation (source check, Slack secret requirement, control-char rejection) runs before the DB write, URL components are correctly percent-encoded, and the 409 response no longer leaks internal identifiers.
All issues raised in earlier review rounds have been addressed: input validation precedes the key creation call, the is not None guard preserves empty-string secrets without silent coercion, Slack requires the caller to supply the Signing Secret, and the forward path is properly encoded. The unit tests exercise all meaningful branches including the fixed edge cases.
No files require special attention.
Important Files Changed
Reviews (7): Last reviewed commit: "Merge branch 'main' into dm/agentex-webh..." | Re-trigger Greptile