Community Plugin: This plugin is developed, tested, and maintained by a third-party contributor.
You can use the Kong Path Allow plugin on a Service, Route, or Consumer with paths. The plugin will check if the path is in the path allow list, and if not, return a 403.
Install
Luarocks
luarocks install kong-path-allow
Source Code
$ git clone https://github.com/seifchen/kong-path-allow.git
$ cd /path/to/kong/plugins/kong-path-allow
$ luarocks make *.rockspec
See the README in the plugin source repository for more usage examples.
Maintainers
seifchen
Configuration Reference
This plugin is compatible with DB-less mode.
Example plugin configuration
Enable on a service
Enable on a route
Enable on a consumer
Enable globally
The following examples provide some typical configurations for enabling
the kong-path-allow
plugin on a
service.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/services/SERVICE_NAME|SERVICE_ID/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes"
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-path-allow-example
config:
allow_paths:
- /api/services
- /api/routes
plugin: kong-path-allow
Next, apply the KongPlugin resource to a
service by annotating the
service as follows:
apiVersion: v1
kind: Service
metadata:
name: SERVICE_NAME|SERVICE_ID
labels:
app: SERVICE_NAME|SERVICE_ID
annotations:
konghq.com/plugins: kong-path-allow-example
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: SERVICE_NAME|SERVICE_ID
selector:
app: SERVICE_NAME|SERVICE_ID
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
Add this section to your declarative configuration file:
plugins:
- name: kong-path-allow
service: SERVICE_NAME|SERVICE_ID
config:
allow_paths:
- /api/services
- /api/routes
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
The following examples provide some typical configurations for enabling
the kong-path-allow
plugin on a
route.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/routes/ROUTE_NAME|ROUTE_ID/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes"
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-path-allow-example
config:
allow_paths:
- /api/services
- /api/routes
plugin: kong-path-allow
Then, apply it to an ingress (route or routes)
by annotating the ingress as follows:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ROUTE_NAME|ROUTE_ID
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: kong-path-allow-example
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
service:
name: echo
port:
number: 80
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
Add this section to your declarative configuration file:
plugins:
- name: kong-path-allow
route: ROUTE_NAME
config:
allow_paths:
- /api/services
- /api/routes
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration
will target.
The following examples provide some typical configurations for enabling
the kong-path-allow
plugin on a
consumer.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/consumers/CONSUMER_NAME|CONSUMER_ID/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes"
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
You can combine consumer.id
, service.id
, or route.id
in the same request, to further narrow the scope of the plugin.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-path-allow-example
config:
allow_paths:
- /api/services
- /api/routes
plugin: kong-path-allow
Then, apply it to a consumer by
annotating the KongConsumer resource as follows:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: CONSUMER_NAME|CONSUMER_ID
annotations:
konghq.com/plugins: kong-path-allow-example
kubernetes.io/ingress.class: kong
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
Add this section to your declarative configuration file:
plugins:
- name: kong-path-allow
consumer: CONSUMER_NAME|CONSUMER_ID
config:
allow_paths:
- /api/services
- /api/routes
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
A plugin which is not associated to any service, route, or consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
The following examples provide some typical configurations for enabling
the kong-path-allow
plugin globally.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/plugins/ \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes"
Create a KongClusterPlugin
resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-kong-path-allow>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
allow_paths:
- /api/services
- /api/routes
plugin: kong-path-allow
Add a plugins
entry in the declarative
configuration file:
plugins:
- name: kong-path-allow
config:
allow_paths:
- /api/services
- /api/routes
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter |
Description |
name
required
Type: string |
The name of the plugin, in this case kong-path-allow . |
service.name or service.id
Type: string |
The name or ID of the service the plugin targets.
Set one of these parameters if adding the plugin to a service through the top-level /plugins endpoint.
Not required if using /services/SERVICE_NAME|SERVICE_ID/plugins . |
route.name or route.id
Type: string |
The name or ID of the route the plugin targets.
Set one of these parameters if adding the plugin to a route through the top-level /plugins endpoint.
Not required if using /routes/ROUTE_NAME|ROUTE_ID/plugins . |
consumer.name or consumer.id
Type: string |
The name or ID of the consumer the plugin targets.
Set one of these parameters if adding the plugin to a consumer through the top-level /plugins endpoint.
Not required if using /consumers/CONSUMER_NAME|CONSUMER_ID/plugins . |
enabled
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.allow_paths
required
Default value: []
|
An allowed path. Any request path that does not match one of the paths in this list will be forbidden and return a 403 error code.
|
config.regex
required
Default value: true
|
A boolean value that specifies whether the plugin uses regex for path matching. If true , the plugin will use ngx.re.match to match the request_path and allow_paths values. If false , it will strictly judge whether the two paths are equal.
|