How Kuma chooses the right policy to apply
E.g., there might be a catch-all policy that sets the baseline for your organization
Additionally, there might be a more focused use case-specific policy, e.g.
type: TrafficLog
mesh: default
name: web-to-backend-policy
sources:
- match:
kuma.io/service: web
cloud: aws
region: us
destinations:
- match:
kuma.io/service: backend
conf:
backend: splunk
What does Kuma
do when it encounters multiple matching policies ?
The answer depends on policy type:
- since
TrafficPermission
represents a grant of access given to a particular clientservice
,Kuma
conceptually “aggregates” all such grants by applying ALLTrafficPermission
policies that match a connection betweensources
anddestinations
Dataplane
s - for other policy types -
TrafficRoute
,TrafficLog
,HealthCheck
- conceptual “aggregation” would be too complex for users to always keep in mind; that is whyKuma
chooses and applies only “the most specific” matching policy in that case
Going back to 2 TrafficLog
policies described above:
- for connections between
web
andDataplanes
Kuma
will choose and applyweb-to-backend-policy
policy as “the most specific” in that case - for connections between all other dataplanes
Kuma
will choose and applycatch-all-policy
policy as “the most specific” in that case
“The most specific” policy is defined according to the following rules:
-
E.g.,
web-to-backend-policy
policy matches a connection between 2Dataplane
s by 4 tags (3 tags onsources
and 1 tag ondestinations
), whilecatch-all-policy
matches only by 2 tags (1 tag onsources
and 1 tag ondestinations
) a policy that matches by the exact tag value is more specific than policy that matches by a
'*'
(wildcard) tag valueE.g.,
web-to-backend-policy
policy matchessources
bykuma.io/service: web
, whilecatch-all-policy
matches bykuma.io/service: *
if 2 policies match a connection between 2
Dataplane
s by the same number of tags, and the total number of matches by the exact tag value is the same for both policies, and the total number of matches by a'*'
(wildcard) tag value is the same for both policies, then a “more specific” policy is the one whoose name comes first when ordered alphabetically
E.g.,
-
sources:
- match:
kuma.io/service: '*'
cloud: aws
region: us
destinations:
- match:
is “more specific” than
match by the exact tag value
sources:
- match:
kuma.io/service: web
destinations:
- match:
kuma.io/service: backend
is “more specific” than a match by a
'*'
(wildcard)sources:
- match:
destinations:
- match:
kuma.io/service: '*'
match with a greater total number of matches by the exact tag value
is “more specific” than
sources:
- match:
kuma.io/service: web
version: '*'
destinations:
- match:
kuma.io/service: backend
when 2 matches are otherwise “equally specific”
name: policy-1
sources:
- match:
kuma.io/service: web
version: v1
destinations:
- match: