Rate limit by Principal metadatav3.16+
Rate limit by Principal, with the limit and rate limiting key both driven by CEL expressions reading the Principal’s metadata.
Prerequisites
- Authentication configured with Kong Identity Principal support
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
config:
identifier: principal
custom_key: unknown-partner
limit:
- 10
window_size:
- 60
expressions:
custom_key: principal.metadata.partner_id
limit:
- principal.metadata.rate_limitMake the following request:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane.
See the Konnect Control Planes Config API reference to learn about region-specific URLs and personal access tokens.
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
service: serviceName|Id
config:
identifier: principal
custom_key: unknown-partner
limit:
- 10
window_size:
- 60
expressions:
custom_key: principal.metadata.partner_id
limit:
- principal.metadata.rate_limitMake sure to replace the following placeholders with your own values:
serviceName|Id: Theidornameof the service the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
serviceName|Id: Theidornameof the service the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
serviceId: Theidof the service the plugin configuration will target.
See the Konnect Control Planes Config API reference to learn about region-specific URLs and personal access tokens.
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
route: routeName|Id
config:
identifier: principal
custom_key: unknown-partner
limit:
- 10
window_size:
- 60
expressions:
custom_key: principal.metadata.partner_id
limit:
- principal.metadata.rate_limitMake sure to replace the following placeholders with your own values:
routeName|Id: Theidornameof the route the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
routeName|Id: Theidornameof the route the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
routeId: Theidof the route the plugin configuration will target.
See the Konnect Control Planes Config API reference to learn about region-specific URLs and personal access tokens.
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
consumer: consumerName|Id
config:
identifier: principal
custom_key: unknown-partner
limit:
- 10
window_size:
- 60
expressions:
custom_key: principal.metadata.partner_id
limit:
- principal.metadata.rate_limitMake sure to replace the following placeholders with your own values:
consumerName|Id: Theidornameof the consumer the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/consumers/{consumerName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
consumerName|Id: Theidornameof the consumer the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/{consumerId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
consumerId: Theidof the consumer the plugin configuration will target.
See the Konnect Control Planes Config API reference to learn about region-specific URLs and personal access tokens.
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: rate-limiting-advanced
consumer_group: consumerGroupName|Id
config:
identifier: principal
custom_key: unknown-partner
limit:
- 10
window_size:
- 60
expressions:
custom_key: principal.metadata.partner_id
limit:
- principal.metadata.rate_limitMake sure to replace the following placeholders with your own values:
consumerGroupName|Id: Theidornameof the consumer group the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/consumer_groups/{consumerGroupName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
consumerGroupName|Id: Theidornameof the consumer group the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumer_groups/{consumerGroupId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "rate-limiting-advanced",
"config": {
"identifier": "principal",
"custom_key": "unknown-partner",
"limit": [
10
],
"window_size": [
60
]
},
"expressions": {
"custom_key": "principal.metadata.partner_id",
"limit": [
"principal.metadata.rate_limit"
]
}
}
'Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
consumerGroupId: Theidof the consumer group the plugin configuration will target.
See the Konnect Control Planes Config API reference to learn about region-specific URLs and personal access tokens.