Bootstrap FreeKB - Kong Community Edition (KongCE) - create acl Plugin using REST API
Kong Community Edition (KongCE) - create acl Plugin using REST API


The curl POST command can be used to configure a plugin. A plugin can be associated with a service or a route, thus this assumes you have already created the service or route that you want to associate the plugin with.


On the Kong server

If Kong is running on docker, refer to Kong - Docker container command line for the steps on how to issue commands in the Kong Docker container. Assuming you are using the default kong.conf file, the Kong Admin API will listen on port 8001.

If issuing this command on the Kong server, this command will configure the acl plugin for example-service.

curl -X POST "http://localhost:8001/services/example-service/plugins" --data "name=acl" --data "config.whitelist=example-group" --data "config.hide_groups_header=true"

 

This command will configure the acl plugin for example-route.

curl -X POST "http://localhost:8001/routes/example-route/plugins" --data "name=acl" --data "config.whitelist=example-group" --data "config.hide_groups_header=true"

 


From a remote server

If issuing this command from a remote server, this command will configure the acl plugin for example-service.

curl -X POST "http://hostname:8000/admin-api/services/example-service/plugins" --data "name=acl" --data "config.whitelist=example-group" --data "config.hide_groups_header=true"

 

This command will configure the acl plugin for example-route.

curl -X POST "http://hostname:8000/admin-api/routes/example-route/plugins" --data "name=acl" --data "config.whitelist=example-group" --data "config.hide_groups_header=true"

 


Validation

If the plugin was successfully configured, something like this should be displayed. Additionally, the cURL command can be used to ensure the plugin exists.

{
 "created_at":1585020145,
 "config":{
           "hide_groups_header":true,
           "blacklist":null,
           "whitelist":["example-group"]},
           "id":"62d77992-e3f2-458c-a3a7-38150504c7d9",
           "service":{"id":"1a653c60-0d39-4838-a6ed-d47314b1c05e"},
           "enabled":true,
           "protocols":["grpc","grpcs","http","https"],
           "name":"acl",
           "consumer":null,
           "route":null,
           "tags":null
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 70d99a in the box below so that we can be sure you are a human.