Event streams
An event stream posts each event a tenant records to an HTTPS endpoint as it happens. A security team can use one to collect events in a SIEM (security information and event management system), a tool that gathers security logs in one place.
- Manage streams in
/manage: open Settings, then the Activity tab, then Streams. - You can also manage them through the manage API.
- Changing a stream needs
masks:manage:securityormasks:manage. See manage roles.
Create a stream
Section titled “Create a stream”A stream has these parts:
key |
A short ID for the stream, in lowercase letters, digits, and dashes. |
name |
A name for people to read. |
url |
The address of the HTTPS endpoint that receives events. |
| Signing secret | Signs each delivery so the receiver can verify it. |
actions |
Optional. The kinds of event to send. An empty list sends every action. |
organization |
Optional. An organization’s key. When set, the stream sends only that organization’s events. A customer’s activity can then go to that customer’s SIEM. |
createEventStream and rotateEventStreamSecret return the secret once. It cannot be read again.
curl -s "$MASKS/manage/graphql" -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"query":"mutation { createEventStream(key: \"siem\", name: \"SIEM\", url: \"https://siem.example.com/masks\", actions: [\"session.started\", \"actor.deleted\"]) { secret } }"}'Other mutations act on a stream once it exists:
updateEventStreamchanges its name, address, actions, or organization. An emptyorganizationsends every organization’s events again.testEventStreamposts a test delivery and returnsdeliveredandfailure. It also records astream.testedevent, which streams like any other.archiveEventStreamstops delivery. Deliveries already waiting are dropped.restoreEventStreamstarts delivery again.
What is sent
Section titled “What is sent”Each event is a POST request with a JSON body.
| Field | Meaning |
|---|---|
id |
The event’s ID. Also sent as the Masks-Delivery header. |
tenant |
The tenant’s subdomain. |
action |
The action, such as session.started. Also sent as the Masks-Event header. |
created_at |
When it happened, in UTC. |
actor |
The UUID of the account it happened to, or null. |
by |
The UUID of the account that did it, or null. |
client |
The client_id involved, or null. |
organization |
The key of the organization the event belongs to, or null. |
ip_address, user_agent |
Where it came from. |
details |
Fields specific to the action. |
A test delivery holds id set to null, tenant, action set to stream.tested, and
created_at. Its Masks-Delivery header is empty.
How delivery works:
- Any response with a status code from 200 to 299 counts as delivered.
- masks does not follow redirects.
- Each event is delivered at least once, so the same event can arrive more than once. Use
idto discard a repeat. - Events can arrive out of order.
Verify a delivery
Section titled “Verify a delivery”Each delivery has a Masks-Signature header. It reads t=<unix time>,v1=<hex>.
tis the timestamp.v1is an HMAC-SHA256 of the timestamp, a period, and the raw request body. It is keyed with the stream’s secret and written in hexadecimal.
To verify a delivery on the receiver:
- Recompute the HMAC-SHA256 from the timestamp, a period, and the raw request body.
- Compare it with
v1in constant time. - Refuse the request if its timestamp is more than five minutes from the current time.
Failures
Section titled “Failures”A delivery that gets no response from 200 to 299 is tried up to eight times. The wait between tries grows each time. Each try waits 5 seconds to connect and 10 seconds for an answer.
- After the last try, masks records a
stream.failedevent. This event is never streamed. - The stream’s
lastFailureshows the latest error. - The stream’s
lastDeliveredAtshows the latest success.
What masks refuses
Section titled “What masks refuses”- An address that does not use HTTPS.
- An address that includes a username or password.
- An address that resolves to a private, loopback, link-local, or other reserved network. masks
checks this when the stream is saved, and again on every delivery.
MASKS_OUTBOUND_ALLOWEDlists ranges masks may call anyway. - An action masks does not record.
In development and test, masks also accepts http addresses and private networks.