This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix httproute authorization annotation feature * new demo: updating the ratelimitpolicy targetref * small doc fixes * demo: authenticated rate limit * fix doc rate limit authenticated
- Loading branch information
Showing
4 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
## Authenticated rate limiting | ||
|
||
This demo shows how to configure rate limiting after authentication stage and rate limit configuration | ||
is per API key basis. | ||
|
||
### Steps | ||
|
||
Create local cluster and deploy kuadrant | ||
|
||
``` | ||
make local-setup | ||
``` | ||
|
||
Deploy toystore example deployment | ||
|
||
``` | ||
kubectl apply -f examples/toystore/toystore.yaml | ||
``` | ||
|
||
Create `toystore` HTTPRoute to configure routing to the toystore service | ||
|
||
```yaml | ||
kubectl apply -f - <<EOF | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
kind: HTTPRoute | ||
metadata: | ||
name: toystore | ||
labels: | ||
app: toystore | ||
spec: | ||
parentRefs: | ||
- name: kuadrant-gwapi-gateway | ||
namespace: kuadrant-system | ||
hostnames: ["*.toystore.com"] | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: "/toy" | ||
method: GET | ||
backendRefs: | ||
- name: toystore | ||
port: 80 | ||
|
||
EOF | ||
``` | ||
|
||
Check `toystore` HTTPRoute works | ||
|
||
``` | ||
curl -v -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
Annotate HTTPRoute with Kuadrant auth provider to create AuthorizationPolicy | ||
|
||
``` | ||
kubectl annotate httproute/toystore kuadrant.io/auth-provider=kuadrant-authorization | ||
``` | ||
|
||
Create Authorino's AuthConfig and API key secrets | ||
|
||
```yaml | ||
kubectl apply -f -<<EOF | ||
apiVersion: authorino.kuadrant.io/v1beta1 | ||
kind: AuthConfig | ||
metadata: | ||
name: simple-api-protection | ||
spec: | ||
hosts: | ||
- api.toystore.com | ||
identity: | ||
- name: friends | ||
apiKey: | ||
labelSelectors: | ||
api: toystore | ||
credentials: | ||
in: authorization_header | ||
keySelector: APIKEY | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: key-a | ||
labels: | ||
authorino.kuadrant.io/managed-by: authorino | ||
api: toystore | ||
stringData: | ||
api_key: KEY-A | ||
type: Opaque | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: key-b | ||
labels: | ||
authorino.kuadrant.io/managed-by: authorino | ||
api: toystore | ||
stringData: | ||
api_key: KEY-B | ||
type: Opaque | ||
EOF | ||
``` | ||
Check `toystore` HTTPRoute requires API key | ||
|
||
``` | ||
curl -v -H 'Authorization: APIKEY KEY-A' -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
Add rate limit policy to protect per API key basis | ||
|
||
|
||
```yaml | ||
kubectl apply -f -<<EOF | ||
--- | ||
apiVersion: apim.kuadrant.io/v1alpha1 | ||
kind: RateLimitPolicy | ||
metadata: | ||
name: toystore | ||
spec: | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
name: toystore | ||
rateLimits: | ||
- stage: POSTAUTH | ||
actions: | ||
- request_headers: | ||
descriptor_key: key | ||
header_name: "Authorization" | ||
skip_if_absent: true | ||
domain: toystore-app | ||
limits: | ||
- conditions: [] | ||
max_value: 2 | ||
namespace: toystore-app | ||
seconds: 30 | ||
variables: ["key"] | ||
EOF | ||
``` | ||
|
||
Check the authenticated rate limit policy works: 2 requests every 30 secs. | ||
|
||
``` | ||
curl -v -H 'Authorization: APIKEY KEY-A' -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
``` | ||
curl -v -H 'Authorization: APIKEY KEY-B' -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
## Updating the RateLimitPolicy `targetRef` attribute | ||
|
||
This demo shows how the kuadrant's controller applies the rate limit policy to the new HTTPRoute | ||
object and cleans up rate limit configuration to the HTTPRoute object no longer referenced by the policy. | ||
|
||
### Steps | ||
|
||
Create local cluster and deploy kuadrant | ||
|
||
``` | ||
make local-setup | ||
``` | ||
|
||
Deploy toystore example deployment | ||
|
||
``` | ||
kubectl apply -f examples/toystore/toystore.yaml | ||
``` | ||
|
||
Create `toystore` HTTPRoute to configure routing to the toystore service | ||
|
||
```yaml | ||
kubectl apply -f - <<EOF | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
kind: HTTPRoute | ||
metadata: | ||
name: toystore | ||
labels: | ||
app: toystore | ||
spec: | ||
parentRefs: | ||
- name: kuadrant-gwapi-gateway | ||
namespace: kuadrant-system | ||
hostnames: ["*.toystore.com"] | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: "/toy" | ||
method: GET | ||
backendRefs: | ||
- name: toystore | ||
port: 80 | ||
|
||
EOF | ||
``` | ||
|
||
Check `toystore` HTTPRoute works | ||
|
||
``` | ||
curl -v -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
![](https://i.imgur.com/ykv86hV.png) | ||
|
||
Rate limit `toystore` HTTPRoute | ||
|
||
```yaml | ||
kubectl apply -f - <<EOF | ||
--- | ||
apiVersion: apim.kuadrant.io/v1alpha1 | ||
kind: RateLimitPolicy | ||
metadata: | ||
name: toystore | ||
spec: | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
name: toystore | ||
rateLimits: | ||
- stage: PREAUTH | ||
actions: | ||
- generic_key: | ||
descriptor_key: vhaction | ||
descriptor_value: "yes" | ||
domain: toystore-app | ||
limits: | ||
- conditions: ["vhaction == yes"] | ||
max_value: 2 | ||
namespace: toystore-app | ||
seconds: 5 | ||
variables: [] | ||
EOF | ||
``` | ||
|
||
Check the rate limit policy works: 2 requests every 5 secs. | ||
|
||
``` | ||
curl -v -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
Add a second HTTPRoute: `carstore` | ||
|
||
![](https://i.imgur.com/ruabBi3.png) | ||
|
||
```yaml | ||
kubectl apply -f - <<EOF | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
kind: HTTPRoute | ||
metadata: | ||
name: carstore | ||
labels: | ||
app: carstore | ||
spec: | ||
parentRefs: | ||
- name: kuadrant-gwapi-gateway | ||
namespace: kuadrant-system | ||
hostnames: ["api.carstore.com"] | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: "/car" | ||
method: GET | ||
backendRefs: | ||
- name: toystore | ||
port: 80 | ||
EOF | ||
``` | ||
|
||
Check `carstore` HTTPRoute works | ||
|
||
``` | ||
curl -v -H 'Host: api.carstore.com' http://localhost:9080/car | ||
``` | ||
|
||
Update RLP `targetRef` to the new HTTPRoute `carstore` | ||
|
||
![](https://i.imgur.com/eu30Mry.png) | ||
|
||
``` | ||
k edit ratelimitpolicy toystore | ||
``` | ||
|
||
Check `toystore` HTTPRoute is no longer rate limited | ||
|
||
``` | ||
curl -v -H 'Host: api.toystore.com' http://localhost:9080/toy | ||
``` | ||
|
||
Check `carstore` HTTPRoute is rate limited | ||
|
||
``` | ||
curl -v -H 'Host: api.carstore.com' http://localhost:9080/car | ||
``` | ||
|
||
Remove the rate limit policy | ||
|
||
``` | ||
k delete ratelimitpolicy toystore | ||
``` | ||
|
||
Check `toystore` and `carstore` HTTPRoutes are no longer rate limited |