Rules
Rules allow any endpoint (services, specific API endpoints, an entire cluster) to ratelimit or alert on a variety of different filters and groupings.
Function
As Command receives telemetry, it evaluates these rules in realtime. Once a threshold has been met, any traffic matching this rule for a given actor (as determined in the by
field) is blocked for a set period of time (timespan_secs
) if the action
is block
, or alert_block
. Alerts are recorded and shown in the Command dashboard.
Notably, rules do not get evaluated by LeakAgent and are only available in Command.
If the sidecar proxy loses connection to Command, all block rules are terminated until connection can be re-established.
Format
Rules are specified in the top-level rules
field of the policy.
Fields:
grouping
:per_inbound_service
,per_outbound_service
,per_endpoint
, orglobal
-- specifies the grouping of inbound data for rule execution. I.e. aper_inbound_service
rule byip
looks at the rate of traffic of each ip for each service, and evaluates the rule.by
:ip
(default),token
,service
, or an object with a single fieldheader
signifying a header name -- the unique ID to be used for the rule. Note that response-derived tokens will still let the initial request through.count_by
: Same asby
, optional. If set, only unique values for this field will increment the counter in a given timespan.action
:block
(default),alert_block
,alert
, ornothing
-- the action to take upon the rule conditions being met.timespan_secs
: The timespan over which requests/responses are counted for rule evaluation. This effectively means that a client is limited tolimit
/timespan_secs
requests per second.limit
: The maximum number of requests withintimespan_secs
before the rule is triggeredfilter
: The evaluation filter of the rule, see below.severity
: The Rule Severity.muted
: boolean for if the rule has been muted or not
Rule Severity
Routine
Notable
Concern
(default)Immediate
Rule Filter
Each filter has exactly one of the following keys:
endpoint
: Takes one of more Path Globs and requires that any of them match the endpointexclude_endpoint
: Takes one of more Path Globs and requires that all of them do not match the endpointpolicy_path
: Takes one of more Path Globs and requires that any of them match the policy pathexclude_policy_path
: Takes one of more Path Globs and requires that all of them do not match the policy pathpeer_service
: Takes one or more Service Filter and requires that any of them match the peer_serviceexclude_peer_service
: Takes one or more Service Filter and requires that all of them do not match the peer_servicelocal_service
: Takes one or more Service Filter and requires that any of them match the local_serviceexclude_local_service
: Takes one or more Service Filter and requires that all of them do not match the local_servicetoken
: Takes one or more Match Rule and requires that any of them match the token. A missing token is an empty stringexclude_token
: Takes one or more Match Rule and requires that all of them do not match the token. A missing token is an empty stringip
: Takes one or more IP address or CIDR and requires that any of them match the ipexclude_ip
: Takes one or more IP address or CIDR and requires that all of them do not match the iprequest_matches
: Takes a map of category names and one or more Match Rule Filters that the category must satisfy. Use "*" to match any category.response_matches
: Takes a map of category names and one or more Match Rule Filters that the category must satisfy. Use "*" to match any category.downstream_matches
: same asrequest_matches
, but for streaming modeupstream_matches
: same asresponse_matches
, but for streaming moderequest_headers
: Takes a map of header names and one or more Match Rule and, for each header listed, requires that the header key exist and any of the rules match the header valueexclude_request_headers
: Takes a map of header names and one or more Match Rule and, for each header listed, requires that the header key either doesn't exist or that none of of the rules match the header valueresponse_headers
: Takes a map of header names and one or more Match Rule and, for each header listed, requires that the header key exist and any of the rules match the header valueexclude_response_headers
: Takes a map of header names and one or more Match Rule and, for each header listed, requires that the header key either doesn't exist or that none of of the rules match the header valueresponse_trailers
: Takes a map of trailer names and one or more Match Rule and, for each trailer listed, requires that the trailer key exist and any of the rules match the trailer valueexclude_response_trailers
: Takes a map of trailer names and one or more Match Rule and, for each trailer listed, requires that the trailer key either doesn't exist or that none of of the rules match the trailer valuerequest_cookie
: Takes a map of names and one or more Match Rule and, for each key listed, requires that the request cookie header contains the key and any of the rules match the header valueexclude_request_cookie
: Takes a map of names and one or more Match Rule and, for each key listed, requires that the request cookie either doesn't contain the key or that none of of the rules match the key's valueresponse_outbound
: Matches request/response pairs for which the request is inbound and the response is outboundresponse_inbound
: Matches request/response pairs for which the request is outbound and the response is inboundany
: Takes one or more Filters and requires that any of them match the request/responseall
: Takes one or more Filters and requires that all of them match the request/response
Match Rule Filter
path
: One or more json paths that the match belongs to. Can use wildcards liketest.my_ssn.*.ssn[*]
.exclude_path
: One or more json paths that the match must not belong to. Can use wildcards liketest.my_ssn.*.ssn[*]
.count
: The minimum amount of matches to qualify. Defaults to1
if not specifiedvalue
: One or more Match Rules that the matches value must matchany
: A list of Match Rule Filters where at least one should be satisfiedany
: A list of Match Rule Filters where all need to be be satisfied
Service Filter
Each service filter has exactly one of the following keys:
cluster
: Takes one or more Match Rule and requires that any of them match the cluster componentexclude_cluster
: Takes one or more Match Rule and requires that all of them do not match the cluster componentns
: Takes one or more Match Rule and requires that any of them match the namespace componentexclude_ns
: Takes one or more Match Rule and requires that all of them do not match the namespace componentsa
: Takes one or more Match Rule and requires that any of them match the service account componentexclude_sa
: Takes one or more Match Rule and requires that all of them do not match the service account componentworkload
: Takes one or more Match Rule and requires that any of them match the workload componentexclude_workload
: Takes one or more Match Rule and requires that all of them do not match the workload componentresponse_outbound
: Matches request/response pairs for which the request is inbound and the response is outboundresponse_inbound
: Matches request/response pairs for which the request is outbound and the response is inboundany
: Takes one or more Service Filters and requires that any of them match the request/responseall
: Takes one or more Service Filters and requires that all of them match the request/response
Examples
rules:
- grouping: per_inbound_service
by: service
filter:
any:
- peer_service: "cluster.local/default/cartservice"
- peer_service: "cluster.local/default/checkoutservice"
action: block
timespan_secs: 30
limit: 3000
- grouping: per_endpoint
by: ip
filter:
all:
- endpoint: "**/api/**"
- exclude_endpoint: "**/api/v1/health"
action: alert
timespan_secs: 60
limit: 750
- grouping: per_endpoint
by: ip
filter:
all:
- endpoint: "**/api/**"
- exclude_endpoint: "**/api/v1/health"
- exclude_token: exampleToken123
action: block
timespan_secs: 60
limit: 1500
- grouping: global
by: ip
timespan_secs: 10
limit: 10
filter:
peer_service: external