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

use other dependencies in custom plugin, show xxx module not found:No LuaRocks module found for xxx #6728

Open
1 task done
miniboxhaha opened this issue Nov 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@miniboxhaha
Copy link

miniboxhaha commented Nov 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

my custom plugin depend on other lua module. i follow KIC custom plugin to Deploy.
when request arrive to kong, log show third party xxx module not found:No LuaRocks module found for xxx.
then i see kong custom plugin guide, i think maybe i should install module use a initContainer with luarocks install before kong is running.
or maybe should copy *.lua files in /usr/local/share/lua/5.3/ to container /usr/local/share/lua/5.1
i tryed exec /bin/bash to kong container, then luarocks install modulename, and said do not have permissions to write, suggest to use --local agrs
then i use luarocks install modulename --local, it says /home/kong/.luarocks/lib/luarocks/rocks-5.1 does not exist and your user does not have write permissions in /home
here is my value.yaml

deployment:
  test:
    enabled: false

controller:
  proxy:
    nameOverride: "{{ .Release.Name }}-gateway-proxy"

  # enabled: true
  enabled: false

  deployment:
    kong:
      enabled: false

  ingressController:
    enabled: true
    image:
      repository: registry.cluster.local:30443/kong/kubernetes-ingress-controller
      tag: "3.3.1"

    gatewayDiscovery:
      enabled: true
      generateAdminApiService: true

  podAnnotations:
    kuma.io/gateway: enabled
    # This port must match your Kong admin API port. 8444 is the default.
    # If you set gateway.admin.tls.containerPort, change these annotations
    # to use that value.
    traffic.kuma.io/exclude-outbound-ports: "8444"
    traffic.sidecar.istio.io/excludeOutboundPorts: "8444"

gateway:
  replicaCount: 1
  plugins:
    configMaps:
    - name: my-kong-plugin-header
      pluginName: my-header
    - name: my-kong-plugin-jwt-auth
      pluginName: my-jwt-auth
  proxy:
    type: NodePort
    http:
      nodePort: 32000
  manager:
    type: NodePort
    http:
      nodePort: 32100
  admin:
    enabled: true
    http:
      enabled: true
      nodePort: 32080
      servicePort: 32080
      containerPort: 32080
  enabled: true
  image:
    repository: registry.cluster.local:30443/kong
    tag: "3.7"
  dblessConfig:
    config: |
      _format_version: "3.0"
      _transform: true

      services:
      - name: my-first-service
        protocol: http
        port: 3000
        host: my-first-upstreams
        path: /test_header
        routes:
        - name: my-first-route
          plugins:
          - name: my-jwt-auth
            config: 
                header_value: haha
          paths:
            - /test_app/test_header
      upstreams: 
      - name: my-first-upstreams
        algorithm: consistent-hashing
        hash_on: ip
        targets:
        - target: test-app-service.ha:3000
  deployment:
    kong:
      enabled: true

  

  ingressController:
    enabled: false

  env:
    role: traditional
    database: "off"

here is my plugin

-- handler.lua
local MyJwtAuth = {}
MyJwtAuth.PRIORITY = 1000
MyJwtAuth.VERSION = "1.0.0"
function MyJwtAuth:header_filter(conf)
  -- do custom logic here
  local jwt = require "luajwtjitsi"
  local key = "example_key"
  local payload = {
    iss = "12345678",
    nbf = os.time(),
    exp = os.time() + 3600,
    role = "admin"
  }
  local alg = "HS256"   -- (default)
  local token, err = jwt.encode(payload, key, alg)
  local decoded, err = jwt.verify(token, alg, key)
  kong.response.set_header("myheader", decoded["role"])
end

return MyJwtAuth

-- schema.lua
return {
    name = "myjwtauth",
    fields = {
        {
            config = {
                type = "record",
                fields = {
                    { header_value = { type = "string", default = "roar", }, },
                },
            },
        },
    }
}


Expected Behavior

No response

Steps To Reproduce

No response

Kong Ingress Controller version

No response

Kubernetes version

No response

Anything else?

No response

@miniboxhaha miniboxhaha added the bug Something isn't working label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant