# POST /security/jails

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the security group.

Create a custom ban rule

- Who may call it: administrator
- Token scope, any of: security, all
- Answers: 201 Created

Supply name, log, and pattern. The name must be unique across built-in and custom rules, use 1 to 32 lowercase letters, digits, or hyphens, and start with a letter or digit. Fail2ban reserves default and includes. Supply the absolute path to an existing log file in log, such as /path/to/log. Path components can contain letters, digits, dots, hyphens, and underscores. A .. component is invalid. Supply a single-line regular expression of 1 to 500 printable ASCII characters in pattern, with <HOST> where the IP address appears.

The tries field sets how many matches for one IP address within window trigger a ban. It accepts 1 to 1000 and defaults to 5. The window field accepts 10 seconds to 30 days and defaults to 10m. The bantime field accepts 10 seconds to 366 days and defaults to 1h. Use whole seconds or a duration with a unit, such as 10s, 10m, 1h, 2d, or 1w.

Set scope to all for all ports, mail for mail ports, or web for web ports. It defaults to all. The rule is enabled by default. Set enabled to false to create it disabled. The API returns 201 on creation and 400 for invalid name, log path syntax, pattern, tries, window, bantime, or scope values.

## As a command

- [urbestack-jail-add](https://urbestack.com/docs/commands/urbestack-jail-add.md): Adds a custom ban rule.

## Request body

JSON, the type [JailCreate](https://urbestack.com/docs/api/types/JailCreate.md).

- `log` (string, up to 255 characters, required): Absolute path to an existing log file.
- `name` (string, matching ^[a-z0-9][a-z0-9-]{0,31}$, required)
- `pattern` (string, up to 500 characters, required): Regular expression with <HOST> where the IP address appears in the log line.
- `bantime` (string, up to 16 characters): Ban duration expressed in seconds or with a unit suffix, as in 10m, 1h, 2d, or 1w.
- `enabled` (boolean)
- `scope` (string, one of all, mail, web): Scope of the ban. The value all blocks all traffic from the IP address. The values mail and web limit the ban to the ports the rule protects.
- `tries` (integer, 1 to 1000)
- `window` (string, up to 16 characters): Time window during which failures count toward a ban, expressed in seconds or with a unit suffix, as in 10m, 1h, 2d, or 1w.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/security/jails" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "bantime": "text",
    "enabled": true,
    "log": "",
    "name": "alice",
    "pattern": "text",
    "scope": "all",
    "tries": 1,
    "window": "text"
  }'
```

Response, 201 Created:

```
{
  "jail": {
    "active": true,
    "bans_week": 1,
    "bantime": 1,
    "created_at": "2026-09-09T10:15:00Z",
    "enabled": true,
    "filter": "text",
    "inactive_reason": "text",
    "journal": "text",
    "log": "",
    "name": "alice",
    "pattern": "text",
    "scope": "all",
    "service": "text",
    "shipped": true,
    "tries": 1,
    "what": "text",
    "window": 1
  }
}
```

## Errors

- 400: '<n>' is a name fail2ban keeps for itself
- 400: <what> is a number of seconds, or with a unit: 10m, 1h, 2d, 1w
- 400: <what> must be between 
- 400: A log is an absolute path of letters, digits, dots, dashes and underscores
- 400: A log path may not contain ..
- 400: A pattern is 1 to 500 printable characters on one line
- 400: A pattern needs <HOST> where the address is
- 400: A rule name is 1 to 32 lowercase letters, digits and dashes
- 400: A scope is all, mail or web
- 400: Invalid boolean
- 400: The log <log> does not exist
- 400: The pattern is not a regular expression: 
- 400: Tries must be a number from 1 to 1000
- 401: Authentication required
- 409: A rule named <name> exists
