KoskenDocs Open the app

Signed webhook

Send each Kosken event as signed JSON to your own HTTPS endpoint, read the payload, and check the signature.

3 min readUpdated on Español

On this page
  1. Connect a webhook
  2. The request
  3. The payload
  4. Check the signature
  5. Your answer and the retries

After you read this guide, you can receive Kosken events on your own endpoint and check that each request comes from Kosken.

Connect a webhook

Only an owner of the workspace can connect a channel. Your endpoint must use HTTPS on a public host. Kosken refuses localhost, names that end in .local or .internal, and addresses of private networks.

  1. In the sidebar, select Channels.
  2. Under Add a channel, on Signed webhook, select Connect.
  3. In Name, write a name for the channel, for example ops-hook.
  4. In Endpoint address, write the URL of your endpoint, for example https://hooks.example.com/kosken.
  5. Select Connect. The page Webhook signing key shows the key.
  6. Select Copy and store the key in your receiver. Then select Done.

Kosken shows the signing key one time. It stores the key and the address sealed and does not show them again. When you lose the key, delete the channel and connect it again to get a new key.

Then select Send test on the new row, and add a rule with this channel in Channel. See Send an event to a channel or to members.

The request

For each event, Kosken sends one POST request with these headers:

Content-Type
application/json; charset=utf-8
X-Kosken-Timestamp
The time of the send, in Unix seconds, for example 1795354800.
X-Kosken-Signature
sha256= and the HMAC-SHA256 of the request, in hexadecimal. See Check the signature.

The payload

An example body for an incident that opened:

{"body":"Kosken opened INC-12 on web-01. Severity: warning.","event":"incident.opened","link":"https://acme.workspace.kosken.ai/incidents/01936f0e-5a7b-7c1d-9e2f-3a4b5c6d7e8f","quoted":[{"label":"title","value":"nginx is not running"}],"subject":"INC-12 opened on web-01","v":1}
v
The version of the format. It is 1.
event
The kind of event, for example incident.opened or approval.requested. A test message has test.
subject and body
The title and the text of the event, in English.
quoted
A list of quoted data. Each item has a label, such as title or cause, and a value. The value comes from your machines and tools. Treat it as untrusted text.
link
The page in Kosken. The field is missing when the event has no page.

Check the signature

Kosken signs the timestamp, a dot and the raw body with the signing key. Use the key exactly as Kosken showed it.

  1. Read the header X-Kosken-Timestamp and the raw bytes of the body. Do not parse and write the JSON again before you check it.
  2. Join them: the timestamp, a ., then the body.
  3. Compute the HMAC-SHA256 of the result with the signing key, in hexadecimal.
  4. Compare sha256= and your result with X-Kosken-Signature. Use a constant-time comparison.
  5. Refuse the request when the signatures differ, or when the timestamp is too old, for example older than 5 minutes.

To test by hand, with the values in shell variables:

printf '%s.%s' "$TS" "$BODY" | openssl dgst -sha256 -hmac "$KEY"

Your answer and the retries

  • 2xx: Kosken records the message as sent.
  • 429: Kosken waits for the time in Retry-After, or 30 seconds, and sends again.
  • 401, 403, 404 or 410: Kosken marks the channel Broken and stops sending to it. Delete the channel and connect it again.
  • Another answer, or no answer: Kosken sends again later, with a longer wait each time, up to 8 attempts in total. Each attempt has a new timestamp and a new signature.

Something here does not match the app? Tell us