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 not compatible with DB-less mode.
Enable the plugin on a service
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a service by
making the following request:
curl -X POST http://{HOST}:8001/services/{SERVICE}/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes" \
--data "config.regex=true"
SERVICE
is 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
regex: true
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}
labels:
app: {SERVICE}
annotations:
konghq.com/plugins: <kong-path-allow-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: {SERVICE}
selector:
app: {SERVICE}
{SERVICE}
is 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
.
For example, configure this plugin on a service by
adding this section to your declarative configuration file:
plugins:
- name: kong-path-allow
service: {SERVICE}
config:
allow_paths:
- /api/services
- /api/routes
regex: true
SERVICE
is the id
or name
of the service that this plugin
configuration will target.
Enable the plugin on a route
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a route with:
$ curl -X POST http://{HOST}:8001/routes/{ROUTE}/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes" \
--data "config.regex=true"
ROUTE
is 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
regex: true
plugin: kong-path-allow
Then, apply it to an ingress (Route or Routes)
by annotating the ingress as follows:
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: {ROUTE}
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <kong-path-allow-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
ROUTE
is 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
.
For example, configure this plugin on a route by
adding this section to your declarative configuration file:
plugins:
- name: kong-path-allow
route: <route>
config:
allow_paths:
- /api/services
- /api/routes
regex: true
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
Enabling the plugin on a consumer
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a consumer with:
$ curl -X POST http://{HOST}:8001/consumers/{CONSUMER}/plugins \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes" \
--data "config.regex=true"
CONSUMER
is the id
or username
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
regex: true
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}
annotations:
konghq.com/plugins: <kong-path-allow-example>
kubernetes.io/ingress.class: kong
CONSUMER
is the id
or username
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
.
For example, configure this plugin on a consumer by
adding this section to your declarative configuration file:
plugins:
- name: kong-path-allow
consumer: {CONSUMER}
config:
allow_paths:
- /api/services
- /api/routes
regex: true
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
Enable the plugin globally
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.
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin globally with:
$ curl -X POST http://{HOST}:8001/plugins/ \
--data "name=kong-path-allow" \
--data "config.allow_paths=/api/services" \
--data "config.allow_paths=/api/routes" \
--data "config.regex=true"
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
regex: true
plugin: kong-path-allow
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
plugins:
- name: kong-path-allow
config:
allow_paths:
- /api/services
- /api/routes
regex: true
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.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
consumer.id
Type: string |
The ID of the Consumer the plugin targets. |
enabled
required
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.
|