Search code examples
kongkong-plugin

Cannot enable session plugin in Kong (even after upgrading to latest)


To start I had Kong 0.14.1 installed (without docker) in ubuntu 16.04 working fine.

I tried adding the 'Session' plugin (following the plugin page's example)

curl -X POST http://localhost:8001/services/1d57a271-1a70-42ac-bb37-2e60405af347/plugins \
 --data "name=session"  \
 --data "config.storage=kong" \
 --data "config.cookie_secure=false"

But it just returned the 400 error:

{"message":"schema violation (name: plugin 'session' not enabled; add it to the 'plugins' configuration property)","name":"schema violation","fields":{"name":"plugin 'session' not enabled; add it to the 'plugins' configuration property"},"code":2}

I realized that session plugin was not included in my current version and so I attempted to upgrade to the latest (1.1.2) with these commands:

sudo dpkg -P kong-community-edition
wget -O kong-community-edition-1.1.2.trusty.all.deb https://bintray.com/kong/kong-community-edition-deb/download_file?file_path=dists/kong-community-edition-1.1.2.trusty.all.deb 
sudo dpkg -i kong-community-edition-1.1.2.*.deb   
sudo kong migrations up
sudo kong migrations finish

followed by a system restart just to be sure.

Now when i run the following i can see I'm on the latest version 1.1.2

 dpkg -l | grep kong

But I still get the same error when trying to enable the package.

I did get the following error when uninstalling kong with 'sudo dpkg -P kong-community-edition', but I'm not sure how to handle this warning, or if it is even relevant to my issue.

Removing kong-community-edition (1.1.2) ...
dpkg: warning: while removing kong-community-edition, directory '/usr/local/lib' not empty so not removed
dpkg: warning: while removing kong-community-edition, directory '/usr/local/bin' not empty so not removed
dpkg: warning: while removing kong-community-edition, directory '/usr/local/share' not empty so not removed
dpkg: warning: while removing kong-community-edition, directory '/usr/local/kong' not empty so not removed

What should I correct to allow me to enable the session plugin?

[Update]

If I add this line to the configuration file:

plugins=bundled,session

Then, I get this error when starting up:

nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:402: error loading plugin schemas: on plugin 'session': session plugin is enabled but not installed;

Solution

  • Turns out, the Kong documentation was incorrect, the session plugin is not installed by default. It needs to be installed manually.

    These are the steps I took to install the sessions plugin:

    1. Downloaded the session source code with the download button from here: https://github.com/Kong/kong-plugin-session

    2. Copied and unpacked it to the machine running my Kong instance.

    3. Followed instructions below to install with the source. I tried both the make and the pack and rock approaches. When installing from the rock I got some “/usr/local/share/lua/5.1/kong/plugins/session/*** is not tracked by this installation of LuaRocks.” warnings but didn’t seem to cause a problem: https://docs.konghq.com/1.1.x/plugin-development/distribution/?_ga=2.38394979.1991677927.1558543387-1804803425.1516137689#installing-the-plugin

    4. Updated the conf file ‘/etc/kong/kong.conf’ with the following line: plugins=bundled,session

    5. Updated the db: sudo kong migrations up

    6. Started up Kong, though it seems now I have to sudo, or else I get the following error.

    /usr/local/share/lua/5.1/kong/cmd/start.lua:61: /usr/local/share/lua/5.1/kong/cmd/start.lua:37: nginx configuration is invalid (exit code 1): nginx: [alert] could not open error log file: open() “/usr/local/kong/logs/error.log” failed (13: Permission denied) nginx: the configuration file /usr/local/kong/nginx.conf syntax is ok