-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default dynamic wasm rule data to empty string #232
Conversation
539ff98
to
0d21000
Compare
Codecov Report
@@ Coverage Diff @@
## main #232 +/- ##
==========================================
- Coverage 64.01% 63.21% -0.81%
==========================================
Files 33 33
Lines 3224 3224
==========================================
- Hits 2064 2038 -26
- Misses 990 1009 +19
- Partials 170 177 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -245,7 +245,7 @@ func dataFromLimt(limitIdentifier string, limit *kuadrantv1beta2.Limit) (data [] | |||
data = append(data, wasm.DataItem{Static: &wasm.StaticSpec{Key: limitIdentifier, Value: "1"}}) | |||
|
|||
for _, counter := range limit.Counters { | |||
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: counter}}) | |||
data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: counter, Default: common.Ptr("")}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I set as counter request.headers.My-Custom-Header-01
? All the requests not having that header will contribute to a single (limitador's internal hit) counter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requests that do not have that header are treated as requests that have that header with an empty value, therefore sharing the same counter.
If what you want is to trigger or not trigger a limit based on the presence or absence of a header, use a condition instead; not a counter qualifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, what you say is correct, but I do not fully agree on this UX: if you set a counter based on a header, add a condition on the header existence.
For me, adding a counter implicitly tells I only want to rate limit traffic that is qualified by the counter.
Let's see what @didierofrivia and @alexsnaps have to say about this
Let's say we have this RLP
apiVersion: kuadrant.io/v2beta1
kind: RateLimitPolicy
metadata: {}
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: <HTTPROUTE-NAME>
limits:
some-name:
routeSelectors:
matches:
- path:
type: PathPrefix
value: "/toys"
rates:
- limit: 50
duration: 1
unit: minute
counters:
- auth.identity.username
What would you expect from this RLP? rate limiting traffic authenticated (hence, the auth.identify.username
exists in the metadata) is expected. So far so good. What about traffic not authenticated (hence, the auth.identify.username
does not exist in the metadata)?? With this PR approved, the traffic which is not authenticated will be rate limited because the username es ""
. Without the changes of this PR, if the request is not authenticated, rate limiting will not be triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eguzki, coincidently, this was exactly the example that made us1 want to default to an empty string in the wasm-shim (what Kuadrant/wasm-shim#39 wants to revert now).
Footnotes
-
Discussed offline with @alexsnaps and @didierofrivia on 2023-07-27, and implemented by @alexsnaps on 2023-07-28. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kuadrant/wasm-shim#39 does not revert entirely that commit. Only reverts the behavior when the descriptor is not found in the module generating RLS descriptors. For the conditions, Kuadrant/wasm-shim#39 keeps the changes to allow operators to be meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kuadrant/wasm-shim#39 does not revert entirely that commit.
I understand that. But, most importantly, I also understand that setting the default value to ""
, so some RL is enforced, is one approach. In itself, it is nor better, nor worse than setting no default at all. If most people prefers the contrary of what's proposed here, I'm good with that too obviously.
… prevent selectors that fail to select a value to invalidate the limit
0d21000
to
9da6e08
Compare
So, after some discussion we've decided NOT to move on with this change. The reasoning:
|
Sets the empty string as the default value for the counter qualifiers ("wasm data items") in the wasm config, to prevent the selectors that fail to select a value to invalidate the limit.
Ref.: Kuadrant/wasm-shim#39 (comment)