Skip to content

Commit caf8e82

Browse files
authored
feat(policy): add HTTPLocalRateLimitPolicy (#13231)
This adds the HTTPLocalRateLimitPolicy CRD, which is indexed by the policy controller and exposed by the inbound API. - 81ebc08: HTTPLocalRateLimitPolicy CRD and related changes - 01afd23: policy controller central changes - b098925: rust tests updates and additions - 2f45597: golden files updates. ## Testing In a cluster with linkerd and emojivoto injected, deploy these resources: ```yaml apiVersion: policy.linkerd.io/v1beta3 kind: Server metadata: namespace: emojivoto name: web-http spec: # permissive policy, so we don't require setting up authz accessPolicy: all-unauthenticated podSelector: matchLabels: app: web-svc port: http proxyProtocol: HTTP/1 ``` ```yaml apiVersion: policy.linkerd.io/v1alpha1 kind: HTTPLocalRateLimitPolicy metadata: namespace: emojivoto name: web-rl spec: targetRef: group: policy.linkerd.io kind: Server name: web-http total: requestsPerSecond: 100 identity: requestsPerSecond: 20 overrides: - requestsPerSecond: 10 clientRefs: - kind: ServiceAccount namespace: emojivoto name: default ``` ```console $ kubectl -n emojivoto get httplocalratelimitpolicies.policy.linkerd.io NAME TARGET_KIND TARGET_NAME TOTAL_RPS IDENTITY_RPS web-rl Server web-http 100 20 ``` Then see how the RL policy is exposed at the inbound API under the protocol section, with `linkerd dg policy -n emojivoto po/web-85f6fb8564-jp67d 8080`: ```yaml ... protocol: Kind: Http1: local_rate_limit: identity: requestsPerSecond: 20 metadata: Kind: Resource: group: policy.linkerd.io kind: httplocalratelimitpolicy name: web-rl overrides: - clients: identities: - name: default.emojivoto.serviceaccount.identity.linkerd.cluster.local limit: requestsPerSecond: 10 total: requestsPerSecond: 100 ... ```
1 parent 5cbe45c commit caf8e82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1301
-36
lines changed

charts/linkerd-control-plane/templates/destination-rbac.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ webhooks:
180180
apiVersions: ["*"]
181181
resources:
182182
- authorizationpolicies
183+
- httplocalratelimitpolicies
183184
- httproutes
184185
- networkauthentications
185186
- meshtlsauthentications
@@ -224,6 +225,7 @@ rules:
224225
- policy.linkerd.io
225226
resources:
226227
- authorizationpolicies
228+
- httplocalratelimitpolicies
227229
- httproutes
228230
- meshtlsauthentications
229231
- networkauthentications
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: httplocalratelimitpolicies.policy.linkerd.io
6+
annotations:
7+
{{ include "partials.annotations.created-by" . }}
8+
labels:
9+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
10+
linkerd.io/control-plane-ns: {{.Release.Namespace}}
11+
spec:
12+
group: policy.linkerd.io
13+
names:
14+
kind: HTTPLocalRateLimitPolicy
15+
listKind: HTTPLocalRateLimitPolicyList
16+
plural: httplocalratelimitpolicies
17+
singular: httplocalratelimitpolicy
18+
shortNames: []
19+
scope: Namespaced
20+
versions:
21+
- name: v1alpha1
22+
served: true
23+
storage: true
24+
subresources:
25+
status: {}
26+
schema:
27+
openAPIV3Schema:
28+
type: object
29+
required: [spec]
30+
properties:
31+
spec:
32+
type: object
33+
required: [targetRef]
34+
properties:
35+
targetRef:
36+
description: >-
37+
TargetRef references a resource to which the rate limit
38+
policy applies. Only Server is allowed.
39+
type: object
40+
required: [kind, name]
41+
properties:
42+
group:
43+
description: >-
44+
Group is the group of the referent. When empty, the
45+
Kubernetes core API group is inferred.
46+
maxLength: 253
47+
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
48+
type: string
49+
kind:
50+
description: Kind is the kind of the referent.
51+
maxLength: 63
52+
minLength: 1
53+
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
54+
type: string
55+
name:
56+
description: Name is the name of the referent.
57+
maxLength: 253
58+
minLength: 1
59+
type: string
60+
total:
61+
description: >-
62+
Overall rate-limit, which all traffic coming to this
63+
target should abide.
64+
If unset no overall limit is applied.
65+
type: object
66+
required: [requestsPerSecond]
67+
properties:
68+
requestsPerSecond:
69+
format: int64
70+
type: integer
71+
identity:
72+
description: >-
73+
Fairness for individual identities; each separate client,
74+
grouped by identity, will have this rate-limit. The
75+
requestsPerSecond value should be less than or equal to the
76+
total requestsPerSecond (if set).
77+
type: object
78+
required: [requestsPerSecond]
79+
properties:
80+
requestsPerSecond:
81+
format: int64
82+
type: integer
83+
overrides:
84+
description: >-
85+
Overrides for traffic from a specific client. The
86+
requestsPerSecond value should be less than or equal to the
87+
total requestsPerSecond (if set).
88+
type: array
89+
items:
90+
type: object
91+
required: [requestsPerSecond, clientRefs]
92+
properties:
93+
requestsPerSecond:
94+
format: int64
95+
type: integer
96+
clientRefs:
97+
type: array
98+
items:
99+
type: object
100+
required: [kind, name]
101+
properties:
102+
group:
103+
description: >-
104+
Group is the group of the referent. When empty, the
105+
Kubernetes core API group is inferred.
106+
maxLength: 253
107+
pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
108+
type: string
109+
kind:
110+
description: Kind is the kind of the referent.
111+
maxLength: 63
112+
minLength: 1
113+
pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$
114+
type: string
115+
namespace:
116+
description: >-
117+
Namespace is the namespace of the referent.
118+
When unspecified (or empty string), this refers to the
119+
local namespace of the Policy.
120+
maxLength: 63
121+
minLength: 1
122+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
123+
type: string
124+
name:
125+
description: Name is the name of the referent.
126+
maxLength: 253
127+
minLength: 1
128+
type: string
129+
additionalPrinterColumns:
130+
- name: Target_kind
131+
description: The resource kind to which the rate-limit applies
132+
type: string
133+
jsonPath: .spec.targetRef.kind
134+
- name: Target_name
135+
type: string
136+
description: The resource name to which the rate-limit applies
137+
jsonPath: .spec.targetRef.name
138+
- name: Total_RPS
139+
description: The overall rate-limit
140+
type: integer
141+
format: int32
142+
jsonPath: .spec.total.requestsPerSecond
143+
- name: Identity_RPS
144+
description: The rate-limit per identity
145+
type: integer
146+
format: int32
147+
jsonPath: .spec.identity.requestsPerSecond

cli/cmd/install.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var (
5151
TemplatesCrdFiles = []string{
5252
"templates/policy/authorization-policy.yaml",
5353
"templates/policy/egress-network.yaml",
54+
"templates/policy/http-local-ratelimit-policy.yaml",
5455
"templates/policy/httproute.yaml",
5556
"templates/policy/meshtls-authentication.yaml",
5657
"templates/policy/network-authentication.yaml",

cli/cmd/testdata/install_controlplane_tracing_output.golden

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_crds.golden

+147
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_custom_domain.golden

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)