# Access rules

Each rule applies to an exact hostname, a listed HTTP method, and a path matching its regular expression. A matching request must supply valid HTTP Basic credentials for a user with _at least one_ of the rule’s roles. Missing credentials, an incorrect password, or no allowed role returns HTTP 401 with a Basic authentication challenge.

Access rule fields

| Field | Type / default | Behavior |
| --- | --- | --- |
| priority | Integer, 0–255; required | Rules are evaluated in ascending order: 0 first. Use a distinct priority for each rule. |
| hosts | Array of hostnames; required | Exact hostnames on which the rule applies. Include both built-in and custom hostnames when both should be protected. Empty means no match. |
| methods | Array of strings; required | HTTP methods to protect, such as `["GET", "POST"]`. Methods are case-sensitive. List HEAD and OPTIONS explicitly if they should also be protected. Empty means no match. |
| path | Regular-expression string; required | Matches the URL path, excluding the query string. Anchor it when you need a complete path match. For example, `^/admin(?:/.*)?$` matches /admin and its children, but not /administrator. |
| roles | Array of role names; required | Any listed role permits the authenticated user. An empty array makes the rule inactive; it does not deny requests. |

**Unmatched requests are public.** A rule for GET does not protect POST. A rule for a custom hostname does not protect the built-in hostname unless both are listed. To require authentication across a hostname, use `^/.*$` and list every HTTP method your application accepts.

Use Rust regex syntax for paths, with JSON escaping: a literal dot in a pattern is written `\\.` in JSON. Look-around and backreferences are not supported.

**Keep rules from overlapping.** Evaluation continues after a successful match; priority does not make a rule override later rules. Authentication consumes the Authorization header, so a second matching rule cannot reuse those credentials and returns 401. Combine alternative roles and hostnames into one rule, or use disjoint path and method matches. Rules with the same priority and host set are treated as duplicates, even if their paths differ.
