Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

guicassolato
Copy link
Contributor

@guicassolato guicassolato commented Aug 22, 2023

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)

@guicassolato guicassolato requested a review from a team as a code owner August 22, 2023 15:21
@guicassolato guicassolato self-assigned this Aug 22, 2023
@guicassolato guicassolato force-pushed the wasm-data-default-value branch from 539ff98 to 0d21000 Compare August 22, 2023 15:23
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #232 (9da6e08) into main (0adfe0c) will decrease coverage by 0.81%.
The diff coverage is 100.00%.

@@            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     
Flag Coverage Δ
integration 68.48% <ø> (-1.70%) ⬇️
unit 58.41% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
api/v1beta1 (u) ∅ <ø> (∅)
pkg/common (u) 76.99% <ø> (ø)
pkg/istio (u) 29.69% <ø> (ø)
pkg/log (u) 31.81% <ø> (ø)
pkg/reconcilers (u) 33.68% <ø> (ø)
pkg/rlptools (u) 57.63% <100.00%> (ø)
controllers (i) 68.48% <ø> (-1.70%) ⬇️
Files Changed Coverage Δ
pkg/rlptools/wasm_utils.go 62.81% <100.00%> (ø)

... and 8 files with indirect coverage changes

@@ -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("")}})
Copy link
Contributor

@eguzki eguzki Aug 22, 2023

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

Copy link
Contributor Author

@guicassolato guicassolato Aug 22, 2023

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.

Copy link
Contributor

@eguzki eguzki Aug 23, 2023

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.

Copy link
Contributor Author

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

  1. Discussed offline with @alexsnaps and @didierofrivia on 2023-07-27, and implemented by @alexsnaps on 2023-07-28.

Copy link
Contributor

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.

Copy link
Contributor Author

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
@guicassolato guicassolato force-pushed the wasm-data-default-value branch from 0d21000 to 9da6e08 Compare August 22, 2023 15:52
@guicassolato
Copy link
Contributor Author

guicassolato commented Aug 24, 2023

So, after some discussion we've decided NOT to move on with this change. The reasoning:

  1. Setting an empty string loses information; by neglecting the distinction between empty and null, we're dismissing the meaning of missing data – changing that in the future may be hard
  2. Missing a value is an exception case, therefore users should NOT design with that in mind; instead, the behaviour for such case MUST be different – e.g. define other limits for that case, using the conditions, etc
  3. Defaulting to a general RL case cannot be the solution to protect against failures (e.g. typos), but to improve the visibility instead (e.g. better logging, debugging tools, etc) – Improve traffic visibility in the data plane wasm-shim#40
  4. Consistency with Limitador - in Limitador, a limit is only enforced when the required data is complete; the same principle can apply to the wasm-shim. While the default field of the wasm config is not exposed to users, completeness in the case is controlled by the RLP controller. Let's not make "complete" something that was not set as complete by the user
  5. In the future, we can provide an option (e.g. expose the default field to users) for users to define their own desired (safe) intended behaviours when data is missing, e.g. blocking the request altogether (in contrast to sending the traffic to Limitador and let Limitador decide) – Make possible for RLP owners to define defaults when missing well-known values #238

@guicassolato guicassolato deleted the wasm-data-default-value branch August 24, 2023 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request size/small
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants