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

Config revamp #110

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Config revamp #110

wants to merge 8 commits into from

Conversation

adam-cattermole
Copy link
Member

@adam-cattermole adam-cattermole commented Oct 15, 2024

Changes

This is moving towards a configuration based on the suggestion in #108.

Currently this is looking as follows:

services:
  auth-service:
    type: auth
    endpoint: auth-cluster
    failureMode: deny
    timeout: 10ms
  ratelimit-service:
    type: ratelimit
    endpoint: ratelimit-cluster
    failureMode: deny
actionSets:
  - name: rlp-ns-A/rlp-name-A
    routeRuleConditions:
      hostnames: [ "*.toystore.com" ]
      matches:
      - selector: request.url_path
        operator: startswith
        value: /get
      - selector: request.host
        operator: eq
        value: test.toystore.com
      - selector: request.method
        operator: eq
        value: GET
    actions:
    - service: ratelimit-service
      scope: rlp-ns-A/rlp-name-A
      conditions: []
      data:
      - selector:
          selector: request.headers.My-Custom-Header
      - static:
          key: admin
          value: "1"

I've separated all of the changes by commit to try make it easier to read the changes.

The primary change to non-config types is that we now have actions.conditions so we can conditionally perform an action - example provided in the envoy configuration that only calls the rate limiting service when user_id == 'alice':

make build && make local-setup

Port-forward envoy and watch the logs for all services:

kubectl port-forward --namespace default deployment/envoy 8000:8000
kubectl logs -f deployment/envoy
kubectl logs -f deployment/authorino
kubectl logs -f deployment/limitador

Test unauthenticated does not get rate limited:

curl -H "Host: test.b.multi.com" http://127.0.0.1:8000/get -i
# HTTP/1.1 401 Unauthorized

Bob is not rate limited (note no calls to limitador in logs):

while :; do curl --write-out '%{http_code}\n' --silent --output /dev/null -H "Authorization: APIKEY IAMBOB" -H "Host: test.b.multi.com" http://127.0.0.1:8000/get | grep -E --color "\b(429)\b|$"; sleep 1; done

Alice has 5 requests per 10 seconds:

while :; do curl --write-out '%{http_code}\n' --silent --output /dev/null -H "Authorization: APIKEY IAMALICE" -H "Host: test.b.multi.com" http://127.0.0.1:8000/get | grep -E --color "\b(429)\b|$"; sleep 1; done

Outstanding

  • Tests for conditional actions
  • Retrieve the scope from action.data (won't do)

For a future PR:

  • Convert routeRuleConditions.matches and action.conditions from PatternExpression to CEL
  • "Merge" subsequent actions of the same type to only make a single call for ratelimit

guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 15, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 15, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 15, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 16, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
Copy link
Contributor

@eguzki eguzki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

@eguzki
Copy link
Contributor

eguzki commented Oct 16, 2024

Verification steps working

@adam-cattermole
Copy link
Member Author

Latest commit removes action.scope and this information is retrieved from the data section now

@adam-cattermole adam-cattermole marked this pull request as ready for review October 16, 2024 12:52
@adam-cattermole
Copy link
Member Author

I'm still writing tests for conditional actions, and realise that we need a coordinated merge of this so potentially this should be reviewed/merged to a feature branch

@eguzki
Copy link
Contributor

eguzki commented Oct 16, 2024

Latest commit removes action.scope and this information is retrieved from the data section now

From data? This is unexpected. From a static data item with a key name (by convention) domain?

What if there are many, which one has preference?

@adam-cattermole
Copy link
Member Author

adam-cattermole commented Oct 16, 2024

From data? This is unexpected. From a static data item with a key name (by convention) domain?

I'm not tied to this change, and I can drop the commit. But I was working toward what we agreed in #108 where the data required to build the message was defined in the data of the action

- routeRuleConditions:
    hostnames:
    - "*.foo.com"
    - "users.bar.com"
    matches:
    - request.method == "GET"
    - request.path.startsWith('/bar')
  actions:
  - conditions:
    - "!['127.0.0.1', '192.168.1.1'].contains(source.ip)"
    action:
      service: limitador
      data:
        ip: source.ip
        magic_RL_name: "'1'"
  - conditions: []
    action:
      service: authorino
      data:
        authCfg: "'someIdentifier'"

@adam-cattermole
Copy link
Member Author

I've dropped that commit fwiw. I tend to agree that right now the purpose of the data and scope is different and the way (we currently) process the data items means we need some custom logic to process a specific keyed data item, which doesn't seem right

@guicassolato
Copy link

Latest commit removes action.scope and this information is retrieved from the data section now

From data? This is unexpected. From a static data item with a key name (by convention) domain?

I agree with @eguzki. I don't like this change.

Whether as domain or as authCfg, in both cases this is a required piece of data and in both cases it has the meaning of “scope”. Inside of data, it feels out of place IMO. Unlike the rest of what goes there, scope is not as much "user-defined" data.

The way it was before, we could technically have an action without any data, which makes sense to me since we have default data that comes from the type of action (service) anyway. In fact, auth is an example of action that typically would involve zero user-defined data. And I could speculate with meaning to that for ratelimit as well (e.g. letting Limitador knows about request without activating any limit).

Anyway, I honestly liked more how it was before. Thanks for ditching the commit!

@adam-cattermole
Copy link
Member Author

Thanks both for the constructive feedback, will continue on tests for conditional actions

guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 16, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 16, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
guicassolato added a commit to Kuadrant/kuadrant-operator that referenced this pull request Oct 18, 2024
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Rename conditions to matches - hoist all_of

Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

3 participants