> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/pam/administration/access/command-filtering.md).

# Command inspection

Inspect commands before they run inside a session, and block, allow, queue for approval, or alarm on them.

## What this is and when to use it

Command inspection sits between the user and the target. Every command typed in a session is intercepted **before execution**, compared against the rules that apply to that user, asset, and account, and then allowed, blocked, queued for approval, or allowed with an alert.

It is the control that turns "this person has shell access" into "this person has shell access, minus the things nobody should do on this host".

Use it on production assets, on shared administrative accounts, and wherever a single mistyped command is expensive.

{% hint style="info" %}
Inspection is enforced on the server, not in the client. It also applies to commands run through **adhoc** automations, not only to interactive sessions, and every attempt is written to the audit trail whether it ran or not.
{% endhint %}

## How it works

Two objects, and they are easy to confuse:

| Object             | What it is                                                                                                          |
| ------------------ | ------------------------------------------------------------------------------------------------------------------- |
| **Command group**  | A catalog of commands or patterns — *what* to look for                                                              |
| **Command filter** | A rule that applies groups to a set of users, assets, and accounts, with an action — *who, where, and what happens* |

A group on its own does nothing. A filter is what puts it into force.

The sequence on every command:

1. The user types a command during a session
2. The solution intercepts it before execution
3. It looks for a filter matching that user, asset, and account combination
4. It compares the command against the groups attached to that filter
5. It applies the filter's action
6. It records the attempt for auditing

## The four actions

| Action     | What happens                                                                     | When to use it                                       |
| ---------- | -------------------------------------------------------------------------------- | ---------------------------------------------------- |
| **Reject** | Blocked immediately and never reaches the target. The user is told it was denied | Commands nobody should run on that host              |
| **Accept** | Allowed and executed normally                                                    | Carving exceptions out of a broader restrictive rule |
| **Review** | Held in an approval queue. A designated approver is notified and decides         | Critical but legitimate commands                     |
| **Alarm**  | Executed normally, but raises an alert to administrators                         | Watching suspicious activity without stopping work   |

## Steps

### 1. Create the command group

1. Open **Policies › Command inspection**, and go to the **Command group** tab.
2. Click **Create**.
3. Give it a **Name** that says what it catches — *Destructive commands*, *Network changes*.
4. Choose the **Type**:
   * **Command** — literal commands
   * **Regular expression** — a pattern, for families of commands
5. Fill **Content**, one command per line:

```bash
rm
reboot
hostname
sudo df -h
```

6. Decide whether to **ignore case**.
7. Save.

{% hint style="warning" %}
With **Type = Command**, matching is literal, **spaces included**. `sudo df -h` and `sudo df -h` are different strings and the second will not match. When spacing or arguments vary, use a regular expression instead.
{% endhint %}

### 2. Create the filter

1. Go to the **Command filter** tab and click **Create**.
2. Set the **Name** and the **Priority** — numeric, lower is processed first, default 50.
3. Choose the **User** scope: all users, specific users, or filtered by attribute.
4. Choose the **Asset** scope the same way.
5. Attach the command groups and choose the **action**.
6. Save.

## What you should see

![The Command filter ACL tab, listing the filters](https://1085357737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7xzJyi9JVzRwnV6JzUho%2Fuploads%2Fgit-blob-cf94d2bf9b80b376b8ec05369df2a52f5609f139%2Fcommand-inspection.png?alt=media)

**1** How many filters exist. **2** One filter, with its priority. The Command group tab holds the catalogs the filters apply.

The filter appears in the list with its priority. Priority matters as soon as two filters can apply to the same session — the lower number is processed first.

## How to verify it worked

The rule list proves nothing. Test it from a session:

1. Open a session to a covered asset, as a covered user, using a covered account.
2. Type one of the commands in the group.
3. The expected outcome depends on the action:
   * **Reject** — the command does not run and the user is told it was denied
   * **Review** — the session waits, and the approver is notified
   * **Alarm** — the command runs, and an alert is raised
4. Open the audit trail and confirm the attempt was recorded, including when it was blocked.

If nothing happens, the usual cause is that the filter's user, asset, or account scope does not actually cover the session you just opened.

## Common errors

| Symptom                                    | Cause                                                                              | Fix                                                                                                   |
| ------------------------------------------ | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| The command runs although it is in a group | The group is not attached to any filter, or the filter's scope misses this session | Check that a filter attaches the group and that its user, asset, and account scope covers the session |
| A command matches sometimes and not others | Literal matching, and the spacing or arguments vary                                | Switch the group to a regular expression                                                              |
| A blocked command should have been allowed | A broader filter has higher priority                                               | Lower the number on the more specific filter                                                          |
| Nothing is blocked for one user            | Another filter with **Accept** and a lower number matches first                    | Review priorities across filters, not one at a time                                                   |

## Field reference

### Command group

| Field       | What it does                                                              |
| ----------- | ------------------------------------------------------------------------- |
| Name        | Identifies the group                                                      |
| Type        | **Command** for literal strings, **Regular expression** for patterns      |
| Content     | One command or pattern per line. Literal matching respects spaces exactly |
| Ignore case | Makes matching case-insensitive                                           |

### Command filter

| Field    | What it does                                          |
| -------- | ----------------------------------------------------- |
| Name     | Identifies the rule                                   |
| Priority | Numeric. Lower is processed first. Default 50         |
| User     | All users, specific users, or filtered by attribute   |
| Asset    | All assets, specific assets, or filtered by attribute |
| Action   | Reject, Accept, Review, or Alarm                      |

## Ready-made command catalogs

DataDike publishes maintained lists of commands worth blocking, by platform, at [DataDike-commands-block](https://github.com/DataDike/DataDike-commands-block) — with folders for AIX, Cisco, Fortinet, Linux, Oracle, and Windows.

They are a starting point, not a policy. Read them before applying them.

## Related pages

* [Authorizations](https://wiki.datadike.com/pam/administration/access/authorizations.md) — granting the session that inspection then restricts
* [Approval workflows](https://wiki.datadike.com/pam/administration/access/approvals.md) — where **Review** sends the command
* [Audit trail](https://wiki.datadike.com/pam/administration/audit/audit-trail.md) — where every attempt is recorded
