Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help request: custom plugin failed to load plugin [demo] err: module 'apisix.plugins.demo' not found: #11835

Open
bmbper opened this issue Dec 16, 2024 · 1 comment
Labels
bug Something isn't working plugin

Comments

@bmbper
Copy link

bmbper commented Dec 16, 2024

Description

  1. config file: config.yaml
deployment:
  role: traditional
  role_traditional:
    config_provider: etcd
  admin:
    admin_key:
      - name: admin
        key: edd1c9f034335f136f87ad84b625c8f1  # using fixed API token has security risk, please update it when you deploy to production environment
        role: admin
apisix:
  extra_lua_path: /usr/local/apisix/custom/?.lua
  log_level: debug
plugins:
  - demo
  1. plugin file /usr/local/apisix/custom/apisix/plugins/demo.lua
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements.  See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License.  You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local core     = require("apisix.core")
local consumer_mod = require("apisix.consumer")
local plugin_name = "demo"


local schema = {
    type = "object",
    properties = {
        header = {
            type = "string",
            default = "apikey",
        },
        query = {
            type = "string",
            default = "apikey",
        },
        hide_credentials = {
            type = "boolean",
            default = false,
        }
    },
}

local consumer_schema = {
    type = "object",
    properties = {
        key = { type = "string" },
    },
    encrypt_fields = {"key"},
    required = {"key"},
}


local _M = {
    version = 0.1,
    priority = 2500,
    type = 'auth',
    name = plugin_name,
    schema = schema,
    consumer_schema = consumer_schema,
}


function _M.check_schema(conf, schema_type)
    if schema_type == core.schema.TYPE_CONSUMER then
        return core.schema.check(consumer_schema, conf)
    else
        return core.schema.check(schema, conf)
    end
end


function _M.rewrite(conf, ctx)
    local from_header = true
    local key = core.request.header(ctx, conf.header)

    if not key then
        local uri_args = core.request.get_uri_args(ctx) or {}
        key = uri_args[conf.query]
        from_header = false
    end

    if not key then
        return 401, {message = "Missing API key found in request"}
    end

    local consumer_conf = consumer_mod.plugin(plugin_name)
    if not consumer_conf then
        return 401, {message = "Missing related consumer"}
    end

    local consumers = consumer_mod.consumers_kv(plugin_name, consumer_conf, "key")
    local consumer = consumers[key]
    if not consumer then
        return 401, {message = "Invalid API key in request"}
    end
    core.log.info("consumer: ", core.json.delay_encode(consumer))

    if conf.hide_credentials then
        if from_header then
            core.request.set_header(ctx, conf.header, nil)
        else
            local args = core.request.get_uri_args(ctx)
            args[conf.query] = nil
            core.request.set_uri_args(ctx, args)
        end
    end

    consumer_mod.attach_consumer(ctx, consumer, consumer_conf)
    core.log.info("hit key-auth rewrite")
end


return _M

  1. when i run apisix start, i got an error in error.log
2024/12/16 17:05:52 [error] 152181#152181: *22207 [lua] plugin.lua:138: load_plugin(): failed to load plugin [demo] err: module 'apisix.plugins.demo' not found:
	no field package.preload['apisix.plugins.demo']
	no file '/usr/local/apisix/custom/\apisix/plugins/demo.lua'
	no file '/usr/local/apisix//deps/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/apisix//deps/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/apisix/apisix/plugins/demo.lua'
	no file '/usr/local/apisix/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo.ljbc'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo/init.ljbc'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo.ljbc'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo/init.ljbc'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo/init.lua'
	no file './apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/apisix/apisix/plugins/demo.lua'
	no file './apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo.ljbc'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo/init.ljbc'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo.ljbc'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo/init.ljbc'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo/init.lua'
	no file './apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo.lua'
	no file '/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/demo/init.lua'
	no file '/usr/local/apisix//deps/lib64/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/apisix//deps/lib/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/openresty/site/lualib/apisix/plugins/demo.so'
	no file '/usr/local/openresty/lualib/apisix/plugins/demo.so'
	no file './apisix/plugins/demo.so'
	no file '/usr/local/lib/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './apisix/plugins/demo.so'
	no file '/usr/local/lib/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/apisix/plugins/demo.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/usr/local/apisix//deps/lib64/lua/5.1/apisix.so'
	no file '/usr/local/apisix//deps/lib/lua/5.1/apisix.so'
	no file '/usr/local/openresty/site/lualib/apisix.so'
	no file '/usr/local/openresty/lualib/apisix.so'
	no file './apisix.so'
	no file '/usr/local/lib/lua/5.1/apisix.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/apisix.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './apisix.so'
	no file '/usr/local/lib/lua/5.1/apisix.so'
	no file '/usr/local/openresty/luajit/lib/lua/5.1/apisix

Environment

  • APISIX version (run apisix version): 3.9.1

  • Operating system (run uname -a): Linux worker4 3.10.0-1160.el7.x86_64 change: added doc of how to load plugin. #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.25.3.1

  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): 3.5.17

  • APISIX Dashboard version, if relevant: not use

  • Plugin runner version, for issues related to plugin runners:

  • LuaRocks version, for installation issues (run luarocks --version): not found

@dosubot dosubot bot added bug Something isn't working plugin labels Dec 16, 2024
@mikyll
Copy link
Contributor

mikyll commented Dec 16, 2024

Try setting the following in your config.yaml:

apisix:
  extra_lua_path: /usr/local/apisix/custom/apisix/plugins/?.lua

Also beware that the values you set in config.yaml override the default ones. In your example this snippet:

plugins:
  - demo

Means that APISIX won't load all the other default plugins 👀

Not sure if that's what you want, but typically you would have something like this (see config.yaml.example):

plugins:                           # plugin list (sorted by priority)
  - real-ip                        # priority: 23000
  - ai                             # priority: 22900
  - client-control                 # priority: 22000
  - proxy-control                  # priority: 21990
  - request-id                     # priority: 12015
  - zipkin                         # priority: 12011
  #- skywalking                    # priority: 12010
  #- opentelemetry                 # priority: 12009
  - ext-plugin-pre-req             # priority: 12000
  - fault-injection                # priority: 11000
  - mocking                        # priority: 10900
  - serverless-pre-function        # priority: 10000
  #- batch-requests                # priority: 4010
  - cors                           # priority: 4000
  - ip-restriction                 # priority: 3000
  - ua-restriction                 # priority: 2999
  - referer-restriction            # priority: 2990
  - csrf                           # priority: 2980
  - uri-blocker                    # priority: 2900
  - request-validation             # priority: 2800
  - chaitin-waf                    # priority: 2700
  - multi-auth                     # priority: 2600
  - openid-connect                 # priority: 2599
  - cas-auth                       # priority: 2597
  - authz-casbin                   # priority: 2560
  - authz-casdoor                  # priority: 2559
  - wolf-rbac                      # priority: 2555
  - ldap-auth                      # priority: 2540
  - hmac-auth                      # priority: 2530
  - basic-auth                     # priority: 2520
  - jwt-auth                       # priority: 2510
  - jwe-decrypt                    # priority: 2509
  - key-auth                       # priority: 2500

  # Your custom plugin
  - demo                           # priority: 2500

  - consumer-restriction           # priority: 2400
  - attach-consumer-label          # priority: 2399
  - forward-auth                   # priority: 2002
  - opa                            # priority: 2001
  - authz-keycloak                 # priority: 2000
  #- error-log-logger              # priority: 1091
  - proxy-cache                    # priority: 1085
  - body-transformer               # priority: 1080
  - ai-prompt-template             # priority: 1071
  - ai-prompt-decorator            # priority: 1070
  - ai-rag                         # priority: 1060
  - ai-content-moderation          # priority: 1040 TODO: compare priority with other ai plugins
  - proxy-mirror                   # priority: 1010
  - proxy-rewrite                  # priority: 1008
  - workflow                       # priority: 1006
  - api-breaker                    # priority: 1005
  - limit-conn                     # priority: 1003
  - limit-count                    # priority: 1002
  - limit-req                      # priority: 1001
  #- node-status                   # priority: 1000
  - ai-proxy                       # priority: 999
  #- brotli                        # priority: 996
  - gzip                           # priority: 995
  - server-info                    # priority: 990
  - traffic-split                  # priority: 966
  - redirect                       # priority: 900
  - response-rewrite               # priority: 899
  - degraphql                      # priority: 509
  - kafka-proxy                    # priority: 508
  #- dubbo-proxy                   # priority: 507
  - grpc-transcode                 # priority: 506
  - grpc-web                       # priority: 505
  - http-dubbo                     # priority: 504
  - public-api                     # priority: 501
  - prometheus                     # priority: 500
  - datadog                        # priority: 495
  - loki-logger                    # priority: 414
  - elasticsearch-logger           # priority: 413
  - echo                           # priority: 412
  - loggly                         # priority: 411
  - http-logger                    # priority: 410
  - splunk-hec-logging             # priority: 409
  - skywalking-logger              # priority: 408
  - google-cloud-logging           # priority: 407
  - sls-logger                     # priority: 406
  - tcp-logger                     # priority: 405
  - kafka-logger                   # priority: 403
  - rocketmq-logger                # priority: 402
  - syslog                         # priority: 401
  - udp-logger                     # priority: 400
  - file-logger                    # priority: 399
  - clickhouse-logger              # priority: 398
  - tencent-cloud-cls              # priority: 397
  - inspect                        # priority: 200
  #- log-rotate                    # priority: 100
  # <- recommend to use priority (0, 100) for your custom plugins
  - example-plugin                 # priority: 0
  #- gm                            # priority: -43
  #- ocsp-stapling                 # priority: -44
  - aws-lambda                     # priority: -1899
  - azure-functions                # priority: -1900
  - openwhisk                      # priority: -1901
  - openfunction                   # priority: -1902
  - serverless-post-function       # priority: -2000
  - ext-plugin-post-req            # priority: -3000
  - ext-plugin-post-resp           # priority: -4000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants