# Send signals

> Push signed security events to the systems that rely on your realm, the moment an agent is stopped, a session ends or a credential changes.

A security tool, a SIEM or a partner app that relies on your realm should learn at once when something here changes:
an agent is stopped, a user's session ends, a password is reset. With the realm's transmitter on, such a system
registers a **stream**, names the users and agents it cares about, and from then on receives a signed event, pushed to
its address, each time one of those changes happens.

To act on events another provider sends *you*, see [Receive signals](../receive-signals/).

## Before you begin

- **Who can do it:** a realm administrator (a group holding `RealmOwner`) turns the transmitter on and registers each
  receiving system's client; `RealmViewer` can read both. The receiving system manages its own streams with its own
  token.
- **Where:** today this is set through the API ([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`).
- **First:** the receiving system can take a push at a public `https` address and answer `202`.

## How it works

### What the realm sends

| Change in the realm | Event sent |
|---|---|
| An agent is killed or quarantined | RISC `account-disabled`, with the reason |
| An agent's quarantine is lifted | RISC `account-enabled` |
| A session ends, by any path | CAEP `session-revoked` |
| A user's password is set, or an authenticator app or passkey added, disabled or removed, by any writer | CAEP `credential-change`, naming the credential and the change |

`credential-change` names the credential as `password`, `app` for an authenticator app, or `fido2-platform` or
`fido2-roaming` for a passkey.

Each event is a signed token with the media type `application/secevent+jwt`, pushed to the stream's address. The
receiver answers `202`.

### Streams

The receiving system authenticates as an `oauth2Client` of your realm, with a token carrying the scope `ssf.manage`
for the resource `https://foobar.cvyuh.com/ssf`. It reads what the realm sends at
`https://foobar.cvyuh.com/.well-known/ssf-configuration/oauth2`, then makes its stream:

```sh
curl https://foobar.cvyuh.com/oauth2/ssf/stream \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "delivery": {
          "method": "urn:ietf:rfc:8935",
          "endpoint_url": "https://siem.example.com/ssf/events",
          "authorization_header": "Bearer 8f2c1d…" },
        "events_requested": [
          "https://schemas.openid.net/secevent/risc/event-type/account-disabled",
          "https://schemas.openid.net/secevent/caep/event-type/session-revoked" ] }'
```

The answer is `201`, with the stream's `stream_id`, and `events_delivered`: the events asked for that the realm sends.
The receiver then names each subject it cares about, by the stream's issuer and the user's or agent's id:

```sh
curl https://foobar.cvyuh.com/oauth2/ssf/subjects/add \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "stream_id": "3b0c6f2e-5d7a-4c1e-9a8b-2f6d1e0c4a7b",
        "subject": { "format": "iss_sub", "iss": "https://foobar.cvyuh.com/oauth2",
                     "sub": "9d4e2a71-0c3b-4f5e-8a6d-1b7c9e2f0a34" } }'
```

The stream endpoints:

| Endpoint | What it does |
|---|---|
| `GET https://foobar.cvyuh.com/.well-known/ssf-configuration/oauth2` | What the realm sends, and where. `404` while `ssfEnabled` is off |
| `POST https://foobar.cvyuh.com/oauth2/ssf/stream` | Makes a stream |
| `GET https://foobar.cvyuh.com/oauth2/ssf/stream` | Reads one stream, by `stream_id`, or all of the caller's |
| `DELETE https://foobar.cvyuh.com/oauth2/ssf/stream?stream_id=…` | Deletes a stream |
| `GET https://foobar.cvyuh.com/oauth2/ssf/status?stream_id=…` | A stream's status |
| `POST https://foobar.cvyuh.com/oauth2/ssf/status` | Sets a stream's `status` to `enabled`, `paused` or `disabled`, with an optional `reason` |
| `POST https://foobar.cvyuh.com/oauth2/ssf/subjects/add`, `POST https://foobar.cvyuh.com/oauth2/ssf/subjects/remove` | Names, or stops naming, one subject |
| `POST https://foobar.cvyuh.com/oauth2/ssf/verify` | Sends the stream a verification event, carrying the `state` you give |

## Set it up

Each call sends your session as `$CVYUH_SESSION` ([Call the API](/develop/api/)).

1. Turn the transmitter on:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "ssfEnabled": true }'
   ```

2. Register the receiving system as a client with `"scopes": ["ssf.manage"]`, and `https://foobar.cvyuh.com/ssf` in
   its `allowedResources` and as its `defaultAudience`.
3. Give the receiving system its credentials. It makes its own stream and names its subjects.

[Share security signals](../../guides/share-security-signals/) walks through it.

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| The transmitter (`ssfEnabled`) | Off | On or off |
| Subjects per stream | None until named | Up to 10,000 |
| A new stream's `status` | `enabled` | `enabled`, `paused` or `disabled` |
| Delivery | Push, to a public `https` address | Push only |
| Retries | One more try after a server error or a timeout | Fixed; an event lost after that isn't sent again |
| Events while a stream is paused | Dropped | Not held |

## See your streams

A realm administrator reads every stream in the realm, whoever made it, as `ssfStream` objects:

```sh
curl https://foobar.cvyuh.com/api/v0/am/objects/v1/ssfStream   -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Each shows the receiver's client (`aud`), the address (`endpointUrl`), the events asked for, its `status` and the
`statusReason` the receiver gave. The delivery header is never returned.

## Troubleshooting

The realm doesn't yet show you whether each push was delivered, so check from the receiving side.

| Symptom | Cause | Fix |
|---|---|---|
| Nothing arrives at all | The stream isn't `enabled`, it names no subjects, or the events asked for aren't among `events_delivered` | Read its status at `https://foobar.cvyuh.com/oauth2/ssf/status`; add subjects; check `events_delivered` in the stream's answer |
| Nothing arrives, though the stream looks right | The receiver's address doesn't answer `202` to a push from the internet: a `4xx`, such as a wrong `authorization_header`, is never retried | Ask for a verification event at `https://foobar.cvyuh.com/oauth2/ssf/verify` and watch the receiver's own records for it |
| Events stopped for a while, then resumed | The stream was `paused`; events in between were dropped | Re-read the subjects' state from the realm after a pause |
| The same event arrives twice | A push answered with a server error is sent once more | Drop any event whose `jti` you've seen |
| `404` at the configuration address | `ssfEnabled` is off | Turn the transmitter on |

## Audit record

- **Streams:** each stream made, paused, re-enabled or deleted is a change to an `ssfStream` object, in the change
  history with before and after: **Audit → Config** in the dashboard. Subjects added or removed aren't recorded.
- **Events:** the change that set off each event has its own record: a session ending (`LOGOUT`, `LOGOUT_ALL`), an
  agent's status move (`AGENT_QUARANTINED`, `AGENT_KILLED`, `AGENT_RELEASED`), a credential's change. Each push and
  whether the receiver took it isn't recorded yet.

## Good to know

- **A receiver sees only its own.** It manages only its own streams, and hears only about the subjects it named, up to
  10,000 a stream. Adding a subject twice adds it once.
- **Only an `enabled` stream is sent events.** An event while a stream is `paused` is dropped, not held.
- **Public `https` only.** Events are pushed only to `https` addresses at public hosts.
- **Drop duplicates by `jti`.** A push the receiver answers with a server error is sent once more, so a receiver may get
  the same event twice. An event lost beyond that isn't sent again.
- **A credential change is recorded where it happens**, in the same write as the password or the device, so no change
  goes unrecorded.
- **Not everything is sent.** A passkey whose kind wasn't recorded at registration sends nothing, rather than a guess.
  Recovery codes, and the secrets of clients and registration tokens, are never sent. A revoked signing key sends no
  event.
- **The delivery header is sealed.** The `authorization_header` a receiver gives is stored sealed and never returned.

## Reference

### Fields

| Where | Field | What it sets |
|---|---|---|
| Realm, `oauth2Settings` | `ssfEnabled` | Turns the transmitter on (default off) |
| Receiver's client | scope `ssf.manage`, resource `https://foobar.cvyuh.com/ssf` | Lets it manage its streams |
| `ssfStream`, made by the receiver | `endpointUrl`, `eventsRequested`, `authorizationHeader` | Where events go, which ones, and the `Authorization` header to push with |
| `ssfStream` | `status` | `enabled` (default), `paused` or `disabled` |

## Coming next

- **Poll delivery**, and **changing a stream in place**: see [What's next for signals](../whats-next/).

## Related

- [Share security signals](../../guides/share-security-signals/): the task, both directions.
- [Receive signals](../receive-signals/): act on events from your workforce provider.
- [What can be revoked](/gateway/revocation/what-can-be-revoked/): what stopping an agent or ending a session does to tokens.
