Webhooks
A service that calls your app (GitLab’s push events, a payment provider’s status updates)
signs in as nobody, so the portal would treat its call like any anonymous request: refused,
or on a portal with anonymous access, answered 503 while
the machine is suspended. Most services don’t retry, and the call is lost.
A webhook is a secret address of the portal for such a service:
https://<portal address>/_wake/<secret>/<your path>A POST or PUT to it resumes the machine when it is suspended, waits for it, and reaches
your service as a request for /<your path>, with the query string, headers and body the
service sent. The secret never reaches your service. Your service sees an anonymous
request (no x-agentspaces-identity), so it still checks the sender as before: GitLab’s
X-Gitlab-Token, a payment provider’s signature.
Making one
In the portal app, on the portal’s page, Webhooks, Add webhook: name it after the
service that will call it. The dialog shows the webhook’s address once; copy it and add
your app’s path, such as /hooks/gitlab. AgentSpaces keeps only a hash of the secret: a
lost address can’t be shown again, so revoke the webhook and make a new one.
From the machine behind the portal, as the user it works for (an owner or admin of the organization):
space-env web-portal webhook add gitlab --path /hooks/gitlab
space-env web-portal webhook list
space-env web-portal webhook revoke <id>add prints the address with --path appended, also only once.
Owners and admins of the organization make, see and revoke webhooks; members don’t see them. A portal has at most 20.
On the canvas
The machine behind the portal shows its webhooks on its card, where its schedules and topics are: on a machine’s card a tag on its upper left, on an agent’s card a pill over it on the left. It says the webhook’s name when there is one, and how many when there are more (2 webhooks). Rest the pointer on it for the list; click it to open the portal’s Webhooks tab. Only those who may see a portal’s webhooks see them there.
What it does and doesn’t do
- Only
POSTandPUT; any other method gets405. An unknown or revoked secret gets404, like an unknown address. - A webhook resumes the machine at most 30 times an hour; your organization’s resume rate counts too. A call to a running machine resumes nothing and counts nothing, unless the machine was just being suspended: then the call resumes it again.
- A call waits until your app takes it, up to 20 seconds after the machine is up: after a slow resume your app may still be starting. Only then does the call reach it, once.
- A refused call (too many resumes, or the machine didn’t come up in time) gets
503withRetry-After, and the organization gets an alert: Webhook name missed a call. The alert clears once a call gets through again, or after a day. The Webhooks tab shows when each webhook was last used, and marks one that missed a call. - Resuming takes about a second from a recent snapshot, longer after a platform update. Services with a short timeout (GitLab gives up after about 10 seconds) may give up on a slow resume.
- Revoking takes effect within a minute.
For requests your own pages make in a visitor’s browser, use the wake script instead.