# An approval gate before automatic response in Wazuh

> Analyst approval before Active Response: PUT /active-response, RBAC on agents, and a single-use approval record with an expiry time, plus a gate script.

Published: 2026-11-12. Category: Configuration. Tags: Wazuh 4. URL: https://wazuh.blog/en/blog/response-approval-gate/ Polish original: https://wazuh.blog/blog/bramka-zatwierdzen-reakcji/

Active Response runs a command on an agent without asking anyone, so a faulty rule or a false alert can block legitimate traffic or isolate a host. An approval gate separates the decision from the execution: the system proposes, an analyst approves, and the command reaches the agent through the API only when the approval matches it character for character.

## Two ways to trigger a response

The documentation describes the `active-response` block in `ossec.conf`, which binds a command to rules. The `level`, `rules_group` and `rules_id` options work together as a sum of conditions: the response starts whenever any of them matches. The configuration and custom scripts are covered in the post [Active Response in Wazuh](/en/blog/wazuh-active-response/).

The second way is the API: `PUT /active-response` runs a command on the chosen agents on demand. This is the one suited to a gate, because the call can be preceded by any check.

| Feature | Block in ossec.conf | PUT /active-response |
| --- | --- | --- |
| trigger | rule match | API call |
| place for an analyst decision | none | before the call |
| scope limit | location, agent_id | agents_list and RBAC |
| audit trail | Wazuh log | Wazuh log and own approval record |

Recommendation: for commands with effects that are hard to undo, do not add an `active-response` block triggered by a rule. Keep it only for reversible actions, with a `timeout`.

## The API call

You get the token from `POST /security/user/authenticate`, and the `?raw=true` parameter returns the bare token as text. The token expires after `auth_token_exp_timeout` seconds (900 by default), which you change through `PUT /security/config`. The port in the documentation examples is 55000.

```bash
TOKEN=$(curl -s -k -u "$WAZUH_API_USER:$WAZUH_API_PASSWORD" -X POST \
  "https://wazuh.example.com:55000/security/user/authenticate?raw=true")

curl -s -k -X PUT "https://wazuh.example.com:55000/active-response?agents_list=001" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"command":"!example-block","arguments":["203.0.113.7"]}'
```

The `-k` option skips verification of the manager certificate and is only suitable for a lab. In production use `--cacert` with the CA certificate that signed the API certificate.

The API specification (version 4.14.0) describes the request like this:

| Element | Meaning |
| --- | --- |
| `agents_list` | comma-separated agent identifiers, without the parameter all agents are selected |
| `command` | required, the command run on the agent, and a value starting with `!` means a script name |
| `arguments` | array of strings with arguments |
| `alert.data` | object with alert data, depending on the command |

A 200 response contains `affected_items`, `total_affected_items`, `failed_items` and `message`. Omitting `agents_list` sends the command to all agents, so the gate must reject requests without an explicit list.

## RBAC: who can call it

The RBAC action `active-response:command` has one resource: `agent:id`. An example from the specification:

```json
{"actions":["active-response:command"],"resources":["agent:id:001"],"effect":"allow"}
```

The RBAC documentation shows three steps: a policy (`POST /security/policies`), a role (`POST /security/roles`) and the binding (`POST /security/roles/{role_id}/policies?policy_ids=` and `POST /security/users/{user_id}/roles?role_ids=`). With conflicting policies the last one on the list wins, and the order is set by the `position` parameter. The actual permissions of an account are shown by `GET /security/users/me/policies`.

Recommendations:

- The account the gate uses to call the API gets only `active-response:command` on the chosen agents. It gets no permission to read agents or to manage RBAC.
- The accounts of the people who approve have no `active-response:command` at all. An approval is a record in another system.
- The only resource is `agent:id`, so RBAC will not restrict the command name or the arguments. The gate has to draw that line.

## The approval record

The `fingerprint` field ties the record to the incident from the post [correlation fingerprint](/en/blog/correlation-fingerprint/), so approval for one series of alerts does not cover another.

```json
{
  "id": "apr-0001",
  "fingerprint": "3a42337915f61caa",
  "command": "!example-block",
  "agents_list": ["001"],
  "arguments": ["203.0.113.7"],
  "approved_by": "analyst-02",
  "expires_at": "2026-11-12T21:00:00Z",
  "used": false
}
```

Record rules (a design recommendation):

- The approval covers exactly one command, one agent list and one argument list. Any difference means a refusal.
- The approval expires. A short validity period limits the risk of using a stale decision.
- The approval is single-use: `used` changes to `true` before the request is sent, not after, so that a failure halfway does not allow the execution to be repeated.
- The approver and the requester are different identities.
- A triage result from a model can fill in the request, but an analyst enters the approval. The post [triage with an LLM](/en/blog/ai-triage-wazuh/) describes writing such a result as an additional alert, without overwriting the original.

## The gate script

The script checks the record and only then calls the API. It was tested with a stubbed `curl` command on synthetic data: a valid record produced a PUT call, and reuse of the same record and a record with a different argument produced a refusal. It was not checked against a running manager.

```bash
#!/usr/bin/env bash
# Run PUT /active-response only if the approval matches the request exactly.
# Usage: gate.sh approval.json command agent_id argument
set -euo pipefail
rec="$1"; cmd="$2"; agent="$3"; arg="$4"
: "${TOKEN:?TOKEN must be set before the approval is consumed}"
: "${WAZUH_CA:?path to the CA certificate of the Wazuh API}"
now=$(date -u +%Y-%m-%dT%H:%M:%SZ)
jq -e --arg c "$cmd" --arg a "$agent" --arg g "$arg" --arg n "$now" '
  .used == false
  and .command == $c
  and .agents_list == [$a]
  and .arguments == [$g]
  and .expires_at > $n
  and (.approved_by | length > 0)' "$rec" >/dev/null || { echo "DENIED" >&2; exit 1; }
# Mark used before sending (single use); a real service does this atomically.
jq '.used = true' "$rec" > "$rec.tmp" && mv -f "$rec.tmp" "$rec"
curl -s --cacert "$WAZUH_CA" -X PUT "https://wazuh.example.com:55000/active-response?agents_list=${agent}" \
  -H "Authorization: Bearer ${TOKEN}" -H "Content-Type: application/json" \
  -d "$(jq -n --arg c "$cmd" --arg g "$arg" '{command:$c,arguments:[$g]}')"
```

The comparison `expires_at > $n` works on ISO 8601 strings in UTC, so both times must use the same format. Storing the record in a file is for illustration only. The target needs a store with an atomic field change, for example a document in an index with a `create` operation and an update with version control.

## The script on the agent side

A script run on the agent receives JSON on STDIN: `command` has the value `add` or `delete`, and the alert data is in `parameters`. A stateful script (with `timeout_allowed` set to `yes`) sends a `check_keys` message with keys that identify the action and waits for a `continue` or `abort` reply from `wazuh-execd`. This way a repeated request for the same action can be aborted on the agent, independently of the gate.

```json
{
  "version": 1,
  "origin": { "name": "example-block", "module": "active-response" },
  "command": "check_keys",
  "parameters": { "keys": ["203.0.113.7"] }
}
```

The documentation warns that reading from STDIN ends at a newline character, and the write to STDOUT must contain one. Otherwise a deadlock can occur. Scripts are placed in `/var/ossec/active-response/bin` with permissions `750` and owner `root:wazuh`.

## From alert to execution

The order below is a recommendation. Each step has one place where it can be stopped.

| Step | Actor | Result |
| --- | --- | --- |
| 1. Alert and fingerprint | Wazuh rule and the correlation process | one incident with a counter |
| 2. Request | analyst or automation | a record with pending status, no execution |
| 3. Notification | integrator | a message with the command, agent and arguments |
| 4. Approval | a second analyst | a record with the approver and expiry fields |
| 5. Call | gate script | PUT /active-response with an explicit agents_list |
| 6. Verification | gate script or analyst | reading the response and the agent log |

Step 2 is the only one that automation, including a model, can perform.

## Reading the result and revoking

The API response confirms only that the command was sent to the agents. The `failed_items` field lists the agents the send failed for, and `total_failed_items` gives their number. The gate should treat a non-empty `failed_items` as an error and record it in the record. It should not retry the request with the same approval, because that approval is already used up.

The result of the action on the agent shows in the `active-responses.log` log: `/var/ossec/logs/active-responses.log` on Linux, `/Library/Ossec/logs/active-responses.log` on macOS and `C:\Program Files (x86)\ossec-agent\active-response\active-responses.log` on Windows. Recommendation: after the call, the gate or the analyst checks the entry in this log before marking the request as executed.

Revoking an action depends on the kind of script. A stateful script (`timeout_allowed` equal to `yes`) reverses the action after the time from the `timeout` option, and a stateless script reverses nothing. The `repeated_offenders` option takes an increasing list of times in minutes, at most five entries, and in this mode `timeout` applies only to the first offense. For commands called by the gate, set a script with a reversal, and a request to revert goes through the same gate with a new record.

## Common mistakes in such a gate

- An approval without exact argument matching. Approving "block the source" without an address lets the target be swapped after the fact.
- A gate account with a broader role than needed. An account with `active-response:command` on many agents can run any script on each of them.
- A token that expires during the procedure. A long approval process should not hold a token, but log in just before the call.

## Notification about a request

The request has to reach the approver in a channel the approver reads. The integrator notification mechanism is covered in the post [integrator notifications](/en/blog/wazuh-integrator-notifications/). Recommendation: the notification text contains the command, the agent, the arguments and the incident fingerprint, and the approval link points to the record, not to the command itself.

## What the documentation does not specify

- Wazuh has no approval mechanism, no confirmations and no two-person rule for Active Response. The whole gate is an external solution.
- The documentation does not say whether a command run through `PUT /active-response` must also have a `command` entry in `ossec.conf`, or how names with the `!` prefix are resolved. Check this on your version before deployment.

## Sources

- https://documentation.wazuh.com/current/user-manual/capabilities/active-response/custom-active-response-scripts.html
- https://documentation.wazuh.com/current/user-manual/capabilities/active-response/index.html
- https://documentation.wazuh.com/current/user-manual/capabilities/active-response/how-to-configure.html
- https://documentation.wazuh.com/current/user-manual/api/rbac/index.html
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/active-response.html
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/commands.html
- https://documentation.wazuh.com/current/user-manual/api/getting-started.html
- https://documentation.wazuh.com/current/user-manual/api/rbac/configuration.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/api/api/spec/spec.yaml
