Kanon

Kanon API

The machine-readable description is at /api/v1/openapi.json (OpenAPI 3.1).

Getting started

curl -X POST https://kanon.pistoslabs.com/api/v1/ingest/hr-system/assets \
  -H "Authorization: Bearer $KEY" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"asset_class":"person","complete":true,"records":[{"external_id":"e-1","name":"Ada","attributes":{"email":"ada@example.com","employment_status":"active"}}]}'

Endpoints

post/api/v1/ingest/{sourceKey}/assets

Send a batch of asset records

Upserts up to 1000 records (5 MB) of one asset class from the system called {sourceKey}. Valid records are accepted and invalid ones are listed in the response; the batch is then written to the inventory in the background (poll the batch). With "complete": true the batch is the whole current set for this source and class, so records left out are marked deleted; a complete batch with any invalid record is refused as a whole.

Needs the ingest:write permission.

  • sourceKey (path, required)
  • Idempotency-Key (header, required)
Request body (application/json)
{
  "$ref": "#/components/schemas/IngestAssetsRequest"
}

Responses: 202 Accepted. status is "queued" until the worker has written it. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 409 The Idempotency-Key was used with a different body. · 413 Larger than 5 MB. · 422 Nothing was valid, or a complete batch had invalid records. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

post/api/v1/ingest/{sourceKey}/events

Send append-only events

Stores up to 1000 events (training completions, offboarding tickets...). Events cannot be changed afterwards. An event with an "id" that was already stored is ignored.

Needs the ingest:write permission.

  • sourceKey (path, required)
  • Idempotency-Key (header, required)
Request body (application/json)
{
  "$ref": "#/components/schemas/IngestEventsRequest"
}

Responses: 202 Accepted and stored (status "complete"). · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 409 The Idempotency-Key was used with a different body. · 413 Larger than 5 MB. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

get/api/v1/ingest/batches/{batchId}

Check on a batch

Needs the ingest:write permission.

  • batchId (path, required)

Responses: 200 The batch and, once finished, its counts. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 404 No such batch. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

post/api/v1/evidence

Upload an evidence file

Stores a file (up to 25 MB) as evidence, uploaded by this key. If control_id is given, the link between the evidence and the control starts as "proposed": a reviewer in the app decides whether it counts, as with every link.

Needs the evidence:write permission.

  • Idempotency-Key (header, required)
Request body (multipart/form-data)
{
  "type": "object",
  "properties": {
    "file": {
      "type": "string",
      "format": "binary"
    },
    "title": {
      "type": "string",
      "minLength": 2,
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "maxLength": 5000
    },
    "control_id": {
      "type": "string",
      "format": "uuid"
    }
  },
  "required": [
    "file",
    "title"
  ]
}

Responses: 201 Stored. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 404 No such control. · 409 The Idempotency-Key was used with a different request. · 413 Larger than 25 MB. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

get/api/v1/checks

List live checks with their latest result

Needs the checks:read permission.

  • cursor (query)
  • limit (query)

Responses: 200 A page of checks. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

get/api/v1/checks/{key}/results

Per-asset results of a check's latest evaluation

Needs the checks:read permission.

  • key (path, required)
  • cursor (query)
  • limit (query)

Responses: 200 A page of results. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 404 No live check has that key. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

get/api/v1/inventory/assets

List assets

Needs the inventory:read permission.

  • cursor (query)
  • limit (query)
  • asset_class (query)
  • source (query)
  • include_deleted (query)

Responses: 200 A page of assets. · 400 The request is not valid. · 401 The key is missing, wrong, revoked or expired. · 403 The key lacks the permission, or is not allowed from this address. · 429 Rate limited. Wait for the number of seconds in the Retry-After header.

post/api/v1/hooks/{hookId}

Call an inbound hook

Authenticated by signature, not by API key. Send X-Kanon-Timestamp (unix seconds, within 5 minutes of now), X-Kanon-Nonce (8 to 200 characters, never reused) and X-Kanon-Signature: v1=<hex HMAC-SHA256 of "<timestamp>.<nonce>.<raw body>" with the hook's secret>. A hook either queues a re-sync of one connection or records an event. A hook made for pistos.io is called by pistos.io itself: it is signed with Pistos-Signature: t=<unix>,v1=<hex HMAC-SHA256 of "<t>.<raw body>"> using the whsec_ secret pistos.io showed, Pistos-Event-Id is its nonce, and it re-syncs every pistos.io connection.

Authenticated by signature, not by key.

  • hookId (path, required)
  • X-Kanon-Timestamp (header, required)
  • X-Kanon-Nonce (header, required)
  • X-Kanon-Signature (header, required)
Request body (application/json)
{
  "type": "object",
  "additionalProperties": {}
}

Responses: 202 Accepted. · 401 Unknown hook, bad signature or stale timestamp (all look alike). · 409 This nonce was already used. · 413 Larger than 256 KB. · 429 Rate limited.

Webhooks

Outbound. Each delivery is a POST of { id, type, created_at, org_id, data } with X-Kanon-Event, X-Kanon-Delivery, X-Kanon-Timestamp and X-Kanon-Signature: v1=…. Answer with any 2xx. Failures are retried after 1, 5, 15 and 60 minutes, then 3, 6 and 12 hours, and given up on after 24 hours; every attempt is in the delivery log, where you can send one again.

// Node: verify a delivery from Kanon
import { createHmac, timingSafeEqual } from 'node:crypto';
function verify(secret, headers, rawBody) {
  const ts = headers['x-kanon-timestamp'];
  const expected = createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex');
  const got = (headers['x-kanon-signature'] || '').replace(/^v1=/, '');
  const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;       // reject old deliveries
  return fresh && got.length === expected.length && timingSafeEqual(Buffer.from(got), Buffer.from(expected));
}

Inbound. A hook either syncs one connection now or records an event. Sign <timestamp>.<nonce>.<body>; the timestamp must be within five minutes and a nonce can be used once.

# Sign a call to an inbound hook
TS=$(date +%s); NONCE=$(uuidgen); BODY='{"subject":"person@example.com"}'
SIG=$(printf '%s.%s.%s' "$TS" "$NONCE" "$BODY" | openssl dgst -sha256 -hmac "$HOOK_SECRET" -hex | sed 's/^.* //')
curl -X POST "$APP_URL/api/v1/hooks/$HOOK_ID" \
  -H "X-Kanon-Timestamp: $TS" -H "X-Kanon-Nonce: $NONCE" -H "X-Kanon-Signature: v1=$SIG" \
  -H 'Content-Type: application/json' -d "$BODY"
API documentation | Kanon