kong icon indicating copy to clipboard operation
kong copied to clipboard

Error "error loading plugin schemas: on plugin <my-plugin>: <my-plugin> plugin is enabled but not installed" with Python plugin for kong

Open AlleMartins opened this issue 1 year ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Kong version ($ kong version)

Kong 3.6

Current Behavior

Using kong version 3.6, I am encountering when running the kong image "error loading plugin schemas: on plugin : plugin is enabled but not installed". The plugin is implemented with Python 3.12.3, I am using the python plugin present in this link as a plugin: https://github.com/Kong/kong-plugin-py-geocode/tree/main/kong-py-plugins. My docker-compose.yml is as follows: version: '3.9' x-kong-config: &kong-env KONG_DATABASE: ${KONG_DATABASE:-postgres} KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong} KONG_PG_HOST: db KONG_PG_USER: ${KONG_PG_USER:-kong} KONG_PG_PASSWORD_FILE: /run/secrets/kong_postgres_password

volumes: kong_data: {} kong_prefix_vol: driver_opts: type: tmpfs device: tmpfs kong_tmp_vol: driver_opts: type: tmpfs device: tmpfs

networks: kong-net: external: false

services: kong-migrations: image: "${KONG_DOCKER_TAG:-kong:latest}" command: kong migrations bootstrap profiles: [ "database" ] depends_on: - db environment: <<: *kong-env secrets: - kong_postgres_password networks: - kong-net restart: on-failure

kong-migrations-up: image: "${KONG_DOCKER_TAG:-kong:latest}" command: kong migrations up && kong migrations finish profiles: [ "database" ] depends_on: - db environment: <<: *kong-env secrets: - kong_postgres_password networks: - kong-net restart: on-failure

kong: build: context: . dockerfile: Dockerfile.kong #image: "${KONG_DOCKER_TAG:-kong:latest}" user: "${KONG_USER:-kong}" environment: <<: *kong-env KONG_ADMIN_ACCESS_LOG: /dev/stdout KONG_ADMIN_ERROR_LOG: /dev/stderr KONG_PROXY_LISTEN: "${KONG_PROXY_LISTEN:-0.0.0.0:8000}" KONG_ADMIN_LISTEN: "${KONG_ADMIN_LISTEN:-0.0.0.0:8001}" KONG_ADMIN_GUI_LISTEN: "${KONG_ADMIN_GUI_LISTEN:-0.0.0.0:8002}" KONG_PROXY_ACCESS_LOG: /dev/stdout KONG_PROXY_ERROR_LOG: /dev/stderr KONG_PREFIX: ${KONG_PREFIX:-/var/run/kong} KONG_DECLARATIVE_CONFIG: "/opt/kong/kong.yaml" KONG_LOG_LEVEL: "info" KONG_PLUGINS: "bundled, my_plugin, python_plugin" #KONG_CUSTOM_PLUGINS: python_plugin KONG_PLUGINSERVER_NAMES: python_plugin KONG_PLUGINSERVER_PY_START_CMD: >- /usr/local/bin/kong-python-pluginserver --plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin --dump KONG_PLUGINSERVER_PY_QUERY_CMD: >- /usr/local/bin/kong-python-pluginserver --plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin --dump secrets: - kong_postgres_password networks: - kong-net ports: # The following two environment variables default to an insecure value (0.0.0.0) # according to the CIS Security test. - "${KONG_INBOUND_PROXY_LISTEN:-0.0.0.0}:8000:8000/tcp" - "${KONG_INBOUND_SSL_PROXY_LISTEN:-0.0.0.0}:8443:8443/tcp" # Making them mandatory but undefined, like so would be backwards-breaking: # - "${KONG_INBOUND_PROXY_LISTEN?Missing inbound proxy host}:8000:8000/tcp" # - "${KONG_INBOUND_SSL_PROXY_LISTEN?Missing inbound proxy ssl host}:8443:8443/tcp" # Alternative is deactivating check 5.13 in the security bench, if we consider Kong's own config to be enough security here

  - "127.0.0.1:8001:8001/tcp"
  - "127.0.0.1:8444:8444/tcp"
  - "127.0.0.1:8002:8002/tcp"
healthcheck:
  test: [ "CMD", "kong", "health" ]
  interval: 10s
  timeout: 10s
  retries: 10
restart: on-failure:5
read_only: true
volumes:
  - kong_prefix_vol:${KONG_PREFIX:-/var/run/kong}
  - kong_tmp_vol:/tmp
  - ./config:/opt/kong
security_opt:
  - no-new-privileges

db: image: postgres:9.5 profiles: [ "database" ] environment: POSTGRES_DB: ${KONG_PG_DATABASE:-kong} POSTGRES_USER: ${KONG_PG_USER:-kong} POSTGRES_PASSWORD_FILE: /run/secrets/kong_postgres_password secrets: - kong_postgres_password healthcheck: test: [ "CMD", "pg_isready", "-d", "${KONG_PG_DATABASE:-kong}", "-U", "${KONG_PG_USER:-kong}" ] interval: 30s timeout: 30s retries: 3 restart: on-failure stdin_open: true tty: true networks: - kong-net volumes: - kong_data:/var/lib/postgresql/data

secrets: kong_postgres_password: file: ./POSTGRES_PASSWORD

and my dockerfile.kong is as follows:
FROM kong:3.6

USER root

RUN apt-get update &&
apt-get install -y python3 python3-pip python3-dev libffi-dev gcc g++ make &&
PYTHONWARNINGS=ignore pip3 install kong-pdk geopy

COPY ./kong-python-pdk /opt/kong-python-pdk

COPY --chown=kong --chmod=555 ./kong-python-pdk/kong-pluginserver.py /usr/local/bin/kong-python-pluginserver

COPY custom_plugins/python_plugin /usr/local/share/lua/5.1/kong/plugins/python_plugin

COPY custom_plugins/my_plugin /usr/local/share/lua/5.1/kong/plugins/my_plugin

RUN chown -R kong:kong /usr/local/share/lua/5.1/kong/plugins/my_plugin

RUN chown -R kong:kong /usr/local/share/lua/5.1/kong/plugins/python_plugin

USER kong

ENV KONG_PLUGINS="bundled, my_plugin, python_plugin"

EXPOSE 8000 8443 8001 8444

CMD ["kong", "docker-start"]

the name of my embedded server is python_plugin, and to run everything I run the shell command: set KONG_DATABASE=postgres && docker-compose --profile database up --build
but when the command is executed, the previously mentioned error returns. Leaving aside my first plugin written in lua (working), my directory tree is as follows: /usr/local/ ├── bin/ │ └── kong-python-pluginserver # Script per avviare il server del plugin └── share/ └── lua/ └── 5.1/ └── kong/ └── plugins/ ├── python_plugin/ # Directory per il plugin Python │ └── prova_plugin.py # Codice del plugin Python └── my_plugin/ # Directory per altri plugin Lua personalizzati └── handler.lua and schema.lua # Codice del plugin Lua

finally, my kong.yaml is as follows: _format_version: "2.1" _transform: true What do I need to change? From the documentation provided, it appears that kong cannot find my python code, but although everything seems fine, it still doesn't work (https://support.konghq.com/support/s/article/plugin-is-enabled- but-not-installed)

Expected Behavior

No response

Steps To Reproduce

  1. download the images for docker: https://github.com/Kong/kong?tab=readme-ov-file
  2. modify the docker-compose.yml and create in the same directory dockerfile.kong
  3. add in the same directory as docker-compose.yml e dockerfile.kong kong-python-pdk (present in this link: https://github.com/Kong/kong-plugin-py-geocode/tree/main/kong-py-plugins )
  4. modify the tree of directory like me docker-compose-1 docker-compose-2 docker-compose-3 dockerfile-cong

Anything else?

No response

AlleMartins avatar May 28 '24 14:05 AlleMartins

The plugin server is just an instance that runs your python. In your config it is python_plugin but also config'd a server named py. Two fixes are

KONG_PLUGINSERVER_NAMES: py
KONG_PLUGINSERVER_PY_START_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump
KONG_PLUGINSERVER_PY_QUERY_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump

or

KONG_PLUGINSERVER_NAMES: python_plugin
KONG_PLUGINSERVER_PYTHON_PLUGIN_START_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump
KONG_PLUGINSERVER_PYTHON_PLUGIN_QUERY_CMD: >-
/usr/local/bin/kong-python-pluginserver
--plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin
--dump

Kong will get the plugin name when the pluginserver starts.

Smuggla avatar May 29 '24 18:05 Smuggla

After applying your change, therefore changing the name of the embedded server, with py, I get this error: "[error] init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/ process.lua:145: Not a plugin info table: kong-1 | /usr/local/bin/kong-python-pluginserver --plugins-directory /usr/local/share/lua/5.1/kong/plugins/python_plugin --dump" I will now attach the important codes of the project, and the logs error (the unspecified settings are like the previous ones said, in the previous commit) docker-compose-1 docker-compose-2 DockerFile-conf info_error plugin-python plugin-python2

AlleMartins avatar May 30 '24 09:05 AlleMartins

I also add on-board information which may be relevant: my version of kong is the community version, not the enterprise version, I also looked at this link, because it dealt with a similar problem but with the Go programming language: https://support. konghq.com/support/s/article/Golang-custom-plugin-throwing-not-a-plugin-info-table-and-error-loading-plugin-schemas-no-plugin-found, also I changed the name of the my python plugin from "prova_plugin.py" to "python_plugin.py"

AlleMartins avatar May 30 '24 09:05 AlleMartins

Use --dump-all-plugins instead of --dump if you are using embedded plugin server (i.e. not dedicated server).

fffonion avatar May 30 '24 10:05 fffonion

After I apply your change, this "info" appears, the image continues to run, but if I try to access the website (I created a small server with Flask) it doesn't work, so I assume it's an error. The image continues to work, in fact if I do: curl -i GET http://localhost:8001/plugins/enabled it is present, and if I try to activate it it works too error log

AlleMartins avatar May 30 '24 10:05 AlleMartins

Please ensure you have py-pdk correctly installed. pip3 install kong-pdk in case it's not installed.

StarlightIbuki avatar Jun 18 '24 07:06 StarlightIbuki

This issue is marked as stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Jul 03 '24 01:07 github-actions[bot]

Dear contributor,

We are automatically closing this issue because it has not seen any activity for three weeks. We're sorry that your issue could not be resolved. If any new information comes up that could help resolving it, please feel free to reopen it.

Your contribution is greatly appreciated!

Please have a look our pledge to the community for more information.

Sincerely, Your Kong Gateway team

github-actions[bot] avatar Jul 10 '24 01:07 github-actions[bot]