Client ID rules
A client ID rule decides how the gateway identifies the caller of a request. The identifier is the key used by usage control: each caller has its own count.
Client ID rules are defined under Rules.ClientIDRules and bound by name with ClientIDRule on GlobalConfig, a server or a route. The closest scope wins: route, then server, then global. There is no default rule: a route with no authentication method and no client ID rule at any scope has unidentified callers, so usage control can’t count its requests. To limit by IP, define a rule with Modes: [IP] and bind it, for example on GlobalConfig.
Rules: ClientIDRules: by-customer-header: Modes: [CustomHeader] HeaderCustomValue: "X-Customer-Id"
token-then-ip: Modes: [BearerToken, IP]
by-query-key: Modes: [CustomQueryString] QueryStringCustomValue: "client_token"Options
Section titled “Options”| Key | Description |
|---|---|
Modes |
List of ways to identify the caller. See the table below. Required, at least one mode. |
HeaderCustomValue |
Name of the header to read. Required when Modes contains CustomHeader. |
QueryStringCustomValue |
Name of the query string parameter to read. Required when Modes contains CustomQueryString. |
IfMissingUseIP |
true or false (default false). When none of the Modes finds a value, identify the caller by IP instead of refusing the request. See When no identifier is found. |
| Mode | Identifier |
|---|---|
IP |
The caller’s IP address. |
BearerToken |
The value of the Authorization header. |
QueryStringApiKey |
The apiKey query string parameter, e.g. ?apiKey=value. The name is fixed; for another name use CustomQueryString. |
CustomHeader |
The header named in HeaderCustomValue, e.g. X-Customer-Id: value. |
CustomQueryString |
The query string parameter named in QueryStringCustomValue, e.g. ?client_token=value. |
How modes are used
Section titled “How modes are used”- Every mode in
Modesthat finds a value in the request is counted. A caller therefore has one count per identifier found. - The IP of the caller is counted only when
IPis one of theModes. With any other mode, the same identifier shares one count across all IPs. - A mode that finds no value in the request is skipped, as long as another mode found one.
When no identifier is found
Section titled “When no identifier is found”If none of the Modes finds a value in the request, the gateway refuses it with 401 and the body Missing identification value. The request is not counted against any usage control rule and never reaches the backend.
| Rule | Request without any identifier |
|---|---|
Modes: [CustomHeader] (any mode except IP) |
401. |
Modes: [IP, CustomHeader] |
Counted by IP (the IP always has a value). |
any Modes with IfMissingUseIP: true |
Counted by IP. |
| no client ID rule applies | Nobody is identified: the request is not refused and not counted (usage control rules on such a route are an error, see Validation). |
To let anonymous callers through but still limit them, list IP in Modes or set IfMissingUseIP: true. To require the identifier, leave both out.
Caller identity
Section titled “Caller identity”The first identifier found that is not the IP becomes the caller of the request: it is written to the access log as caller_id and used as the key in metrics. Like with authentication, it is stored as a short fingerprint, never as the raw value, so keys and tokens don’t leak into logs. The fingerprint is stable, the same value always gives the same caller_id.
When only the IP identifies the request (Modes: [IP], or the IfMissingUseIP fallback), caller_id is left empty and the IP is in caller_ip.
Authenticated routes
Section titled “Authenticated routes”When an authentication method applies to a route, the caller is identified by the token (the claim named in IdClaimName), and the client ID rule is not used for that route. The IP is not counted either.
The exception is a request without a credential on a method with AllowAnonymous: it is counted by its client IP, apart from authenticated callers, and the client ID rule is still not used.
Validation
Section titled “Validation”-
An unknown mode is an error.
-
CustomHeaderwithoutHeaderCustomValue, orCustomQueryStringwithoutQueryStringCustomValue, is an error. -
Binding a client ID rule that does not exist is an error.
-
Having no client ID rules at all is a warning: callers of routes without authentication are not identified.
-
A client ID rule without
Modesis an error: it could not identify anyone, so nothing would be limited. -
A route that has usage control rules but whose callers can’t be identified is an error, because the limit would never run. A route can be identified by an authentication method or a client ID rule, from the route, its server or
GlobalConfig. Rules are checked on the routes they reach:- rules on a route: that route must be identifiable;
- rules on a server: every route of the server must be identifiable, except routes with
UsageControlMode: Strict, which ignore server rules; - rules on
GlobalConfig: every route must be identifiable, except routes withUsageControlMode: Strictand routes of a server withUsageControlMode: Strict, which ignore global rules.
The error lists the routes to fix. Add an authentication method, or bind a client ID rule (for example
Modes: [IP]) to the route, its server orGlobalConfig.
