Skip to main content

Module platform

Module platform 

Source
Expand description

Requests from the Encore platform — cron jobs, the dashboard’s API calls — and the x-encore-auth MAC it signs them with.

A cron job’s run also says why it runs (CRON_TRIGGER_HEADER) and which run it is (CRON_EXECUTION_HEADER). The MAC covers neither.

The header is v2. followed by the unpadded standard base64 of the signing key’s id (a big-endian u32) and HMAC-SHA256(key, "v2\0" date "\0" method "\0" service "\0" path "\0" query): the request’s Date header, its method, the service its x-encore-service names (empty when absent), its path percent-decoded, as bytes, which need not be UTF-8, and its query as sent, without the ? (empty when absent). A request is accepted within MAX_SKEW of its date.

The path is signed decoded, as in v1, so a proxy re-encoding it on the way does not break the MAC; %2F and / sign the same.

The v1 MAC, over the date and path alone, is not accepted: it does not cover the service a request names, so a captured request could be sent to another one. Neither covers the body.

Structs§

Signed
What a platform request’s MAC covers.

Enums§

VerifyError

Constants§

AUTH_HEADER
The header a platform request’s MAC is in.
CALLER
The caller a platform request is made as, in x-encore-meta-caller, once verified.
CRON_EXECUTION_HEADER
The header the platform names a cron job’s run in: the same id each time it sends that run, so the job’s endpoint can use it as an idempotency key.
CRON_TRIGGER_HEADER
The header the platform says why it runs a cron job in: scheduled, or manual.
MAX_SKEW
How far a request’s date may be from the verifier’s clock.

Functions§

is_cron_header
Whether name, lowercase, is one of the headers the platform describes a cron job’s run with. Only the platform may send them: a gateway removes them from every request it has not verified as the platform’s.
sign
The x-encore-auth value for req, signed with the key key_id.
verify
Verifies that header, a request’s x-encore-auth, signs req with one of keys, at most MAX_SKEW from now.