# Active response

> Block an IP address, deny a host, or disable a local account on your Linux devices, for a time you choose, after which the device undoes it.

When an alert shows an address hammering a server's SSH, or a local account being used where it shouldn't be, you
stop it on the device itself. Pick the devices, pick the response, give it its address or account, and choose how
long it lasts. When the time is up, the device takes the response back on its own.

What's limited today: three responses, all on Linux devices; a response is sent when you ask, never automatically;
there's no early undo, and no record of the responses sent.

## Before you begin

- **Who:** an administrator of the realm, in a group holding `RealmOwner` on the realm or a realm above it (see
  [Delegated administration](../../../platform/realms/delegated-administration/)). Any administrator can respond on
  every device of the realm. Detection & Response doesn't yet tell `RealmViewer` apart from `RealmOwner`: a viewer can
  send responses too, so give `RealmViewer` only to people you'd trust to.
- **Where:** the API.
- **First:** the devices' sensor ids, and the devices connected (`active`).

## How it works

| Response | `response` | `argument` | What the device does |
|---|---|---|---|
| Block an IP address | `blockIp` | One IP address, v4 or v6 | Drops the address's traffic at the device's firewall |
| Deny a host | `denyHost` | One IP address | Adds the address to the system's host access deny list, which the services that honor it refuse |
| Disable an account | `disableAccount` | A local username: lowercase letters, digits, `_` and `-`, starting with a letter or `_`, up to 32 long | Locks the local account's password |

Each lasts for one of these timeouts (`timeout`, in seconds): `60`, `900`, `3600` (the default), `14400`, `43200` or
`86400`, that is, a minute, 15 minutes, an hour, 4 hours, 12 hours or a day. All three run on Linux devices.

The realm checks the response, its argument and its timeout before anything is sent, and sends it only to the
devices your realm holds that are connected now. Each device runs it as soon as it arrives, and undoes it by itself
when the timeout runs out.

## Set it up

Through the API ([Call the API](../../../develop/api/)), name the devices by their sensor ids:

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/respond \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"agents": ["<sensor id>", "<sensor id>"], "response": "blockIp", "argument": "203.0.113.24", "timeout": 3600}'
```

```json
{ "done": ["<sensor id>"], "failed": [{ "agent": "<sensor id>", "reason": "<why>" }] }
```

`done` lists the devices it was sent to; `failed` lists each one it wasn't, with the reason.

### Confirm it ran

`done` means sent: the device received the response, not that it has finished running it. Confirm it from the effect:

- **Block an IP address:** a connection from the address to the device gets no answer.
- **Deny a host:** the address is refused by the device's services that honor the deny list.
- **Disable an account:** a password sign-in as the account fails.

There's no call that reports a response's outcome on the device.

## What the user sees

- **Block an IP address, Deny a host:** connections from the address go unanswered or are refused, for the timeout.
  Nothing shows on the device's screen.
- **Disable an account:** the local account can't sign in with its password until the timeout ends. A session it
  already has stays open, and sign-in with an SSH key may still work. Nothing tells the user why.

## What happens when it fails

| Answer | Why | What to do |
|---|---|---|
| `400` "the response is one of …" | A response other than the three | Use `blockIp`, `denyHost` or `disableAccount` |
| `400` "this response takes one IP address" or "a local username" | An argument the response doesn't take | Check the argument column above |
| `400` "the timeout is one of …" | A timeout not in the list | Pick one of the six |
| `400` "an action names 1 to 100 agents" | No devices, or more than 100 | Send 1 to 100 sensor ids |
| In `failed`: `not an agent of this realm` | The id isn't your realm's | Nothing was sent to it; check the id |
| In `failed`: the device isn't active | The device is offline | Nothing waits for it: send the response again once it's `active` |

## Limits and defaults

| Limit | Value |
|---|---|
| Responses | Three: block an IP address, deny a host, disable an account |
| Operating systems | Linux; on macOS a response is accepted and sent but has no effect |
| Timeouts | 60, 900, 3600 (default), 14400, 43200 or 86400 seconds |
| Devices per response | 1 to 100 |
| Offline devices | Not queued: answered in `failed` |
| Early undo | None: the response lasts its timeout |

## Good to know

- **Three responses, nothing else.** You can't send a device an arbitrary command, through a response or through the
  [group configuration](../../sensors/group-configuration/).
- **Extend by sending again.** To keep a block past its timeout, send it again before the time runs out.
- **Prefer Block an IP address to Deny a host.** Many current Linux services don't consult the host access deny
  list, so a denied host may still reach them; a firewall block stops every service.
- **When you ask.** Responses run when you send them; a response triggered by an alert is
  [planned](../whats-next/#automatic-response).

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The device is in `failed` as not active | It's offline | Send again once it's `active` |
| `done`, but the address still connects | The device isn't Linux; or, for Deny a host, the service doesn't honor the deny list | Use Block an IP address on a Linux device |
| `done`, but the user still signs in | The user signs in with an SSH key, or already had a session | Also block their address, or revoke the device |
| You need to lift a block early | There's no early undo | Wait for the timeout; next time start short |

## Audit record

None yet. Responses aren't recorded in the realm's audit trail, and there's no list of responses sent. Keep your own
note of each response: who, which devices, what and for how long.

## Related

- [Handle an alert on a device](../../guides/handle-an-alert/): the task, start to finish.
- [Device view](../../security-log/device-view/): respond on one device.
- [Device revocation](../../../endpoint-management/revoke-and-remove/revocation/): when the device itself can't be trusted.
