Custom plugin enabled but not installed

Hi,

Is this the proper way to add JS plugins?
I am running into a “plugin is enabled but not installed” issue when attempting to install custom Javascript plugins to my Kong API (Traditional set up) running on docker.

Plugin creation:

  1. Write plugins in JavaScript
  2. Use Plugins With Containers
  3. Build docker container and start kong inside of it so I can see the error logs, folder structures, etc.

When I run my container I get this:

$ kong start --v
2024/07/10 18:09:26 [verbose] Kong: 3.7.0
2024/07/10 18:09:26 [verbose] reading config file at /etc/kong/kong.conf
2024/07/10 18:09:26 [verbose] prefix in use: /usr/local/kong
2024/07/10 18:09:26 [verbose] preparing nginx prefix directory at /usr/local/kong
2024/07/10 18:09:26 [verbose] SSL enabled on admin_gui, no custom certificate set: using default certificates
2024/07/10 18:09:26 [verbose] generating admin_gui SSL certificate (/usr/local/kong/ssl/admin-gui-kong-default.crt) and key (/usr/local/kong/ssl/admin-gui-kong-default.key) for listener
2024/07/10 18:09:26 [verbose] generating admin_gui SSL certificate (/usr/local/kong/ssl/admin-gui-kong-default-ecdsa.crt) and key (/usr/local/kong/ssl/admin-gui-kong-default-ecdsa.key) for listener
2024/07/10 18:09:26 [verbose] generating trusted certs combined file in /usr/local/kong/.ca_combined
2024/07/10 18:09:26 [verbose] generating ffdhe2048 DH parameters
2024/07/10 18:09:26 [verbose] retrieving cache schema state...
2024/07/10 18:09:26 [verbose] schema state retrieved
2024/07/10 18:09:26 [verbose] could not start Kong, stopping services
2024/07/10 17:28:57 [verbose] stopped services
Error: 
/usr/local/share/lua/5.1/kong/cmd/start.lua:110: /usr/local/share/lua/5.1/kong/cmd/start.lua:99: nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/kong/nginx.conf:7
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:707: error loading plugin schemas: on plugin 'kongPlugin': kongPlugin plugin is enabled but not installed;
no plugin found; on plugin 'helloWorld': helloWorld plugin is enabled but not installed;
no plugin found
stack traceback:
        [C]: in function 'assert'
        /usr/local/share/lua/5.1/kong/init.lua:707: in function 'init'
        init_by_lua(nginx-kong.conf:41):3: in main chunk

stack traceback:
        [C]: in function 'error'
        /usr/local/share/lua/5.1/kong/cmd/start.lua:110: in function 'cmd_exec'
        /usr/local/share/lua/5.1/kong/cmd/init.lua:31: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:31>
        [C]: in function 'xpcall'
        /usr/local/share/lua/5.1/kong/cmd/init.lua:31: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:15>
        (command line -e):7: in function 'inline_gen'
        init_worker_by_lua(nginx.conf:130):44: in function <init_worker_by_lua(nginx.conf:130):43>
        [C]: in function 'xpcall'
        init_worker_by_lua(nginx.conf:130):52: in function <init_worker_by_lua(nginx.conf:130):50>

This is what my Dockerfile looks like:

FROM kong:3.7.0
USER root

# Install dependencies
RUN apt-get update && apt-get install -y nodejs npm
RUN npm install -g kong-pdk

# Copy config files, plugins, and install
COPY kong.yaml /usr/local/kong/declarative/kong.yaml
COPY kong.conf /etc/kong/kong.conf
COPY helloWorld.js kongPlugin.js package.json /usr/local/kong/js-plugins/
WORKDIR /usr/local/kong/js-plugins
RUN npm install

# Reset back to default user
USER kong
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 8000 8443 8001 8444
CMD ["kong", "docker-start"]

and kong.conf file where I specify the two additional plugins:

database = off
declarative_config = /usr/local/kong/declarative/kong.yaml

# Enable JavaScript plugins
plugins = bundled,helloWorld,kongPlugin

# Plugin server configuration
pluginserver_names = js
pluginserver_js_start_cmd = /usr/local/bin/kong-js-pluginserver -v --plugins-directory /usr/local/kong/js-plugins
pluginserver_js_query_cmd = /usr/local/bin/kong-js-pluginserver --plugins-directory /usr/local/kong/js-plugins --dump-all-plugins
pluginserver_js_socket = /usr/local/kong/js_pluginserver.sock

# Proxy and Admin API listen addresses
proxy_listen = 0.0.0.0:8000
admin_listen = 0.0.0.0:8001

I have verified that the JS files and package.json files are copied over to their respective directories inside docker as well as verified that npm installs node_modules for them. Am I missing something?

Hi,

Using JS plugins with Kong is a bit complicated task. The better option is to use Lua because it is better and faster than another backend language. Javascript plugin documentation is not very clear, I have started a PR to include some examples:

On the above question, the JS plugin server creates a “js_pluginserver.sock”, so if more than one plugin is running, you may need to define a different name with a “–sock-name” option.

/usr/local/bin/kong-js-pluginserver -v --plugins-directory /usr/local/kong/ts-plugins --sock-name ts_pluginserver.sock

Let me know if you have any issues.

1 Like