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

Custom plugin clashing with a Kong plugin #14144

Closed
1 task done
rodolfobrunner opened this issue Jan 13, 2025 · 4 comments
Closed
1 task done

Custom plugin clashing with a Kong plugin #14144

rodolfobrunner opened this issue Jan 13, 2025 · 4 comments

Comments

@rodolfobrunner
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

3.9.0

Current Behavior

We have a custom plugin developed in-house called "redirect" that we have been using for mock responses when a configured header is present.

When Kong introduced the official Redirect plugin, it caused a conflict with our custom plugin. Specifically, the introduction of the official plugin resulted in the loss of partial configuration for our plugin. Consequently, all requests began being redirected to our mock server, regardless of whether the configured header was present.

When attempting to reconfigure our custom plugin using deck, we encountered the following error:

Error: 1 errors occurred:
	while processing event: Update plugin redirect (global) failed: HTTP status 400 (message: "3 schema violations (config.location: required field missing; config.mock_header: unknown field; config.proxy_host: unknown field)")

Expected Behavior

It seems reasonable to expect that Kong should fail the migration process when such a conflict arises, providing an opportunity to fix the problem before rolling out the new version. We are open to start prefixing our custom plugin names to avoid clashes, but I believe we won't be alone with this problem.

Steps To Reproduce

No response

Anything else?

No response

@ProBrian
Copy link
Contributor

Hi @rodolfobrunner , could you give the configuration schema of your custom plugin? Also the reproduce steps would be helpful, like:

  1. previous version works well with custom plugin(what's your deployment topology?)
  2. upgrade to 3.9(how did you do the migration, kong migrations cmd?)
  3. run kong after upgrade then see error(did you enable the kong official redirect plugin?)

Thanks.

@rodolfobrunner
Copy link
Author

rodolfobrunner commented Jan 16, 2025

Hello @ProBrian

local typedefs = require "kong.db.schema.typedefs"
local PLUGIN_NAME = "forward"

-- schema properties https://docs.konghq.com/gateway/latest/plugin-development/configuration/
-- schema typedefs https://github.com/Kong/kong/blob/master/kong/db/schema/typedefs.lua

local schema = {
  name = PLUGIN_NAME,
  fields = {
    -- the 'fields' array is the top-level entry with fields defined by Kong
    { consumer = typedefs.no_consumer }, -- this plugin cannot be configured on a consumer (typical for auth plugins)
    { protocols = typedefs.protocols_http },
    {
      config = {
        -- The 'config' record is the custom part of the plugin schema
        type = "record",
        fields = {
          { disabled = { type = "boolean", required = true, default = false, } },
          { mock_header = { type = "string", required = true, default = "mock-response" }},
          { proxy_host = { type = "string", required = true }},
        }
      },
    },
  },
}

return schema

this was our deck output after the we detected the problem, this was our attempt to reconfigure the our plugin with a matching name :


updating plugin redirect (global)  {
   "config": {
     "keep_incoming_path": false,
     "status_code": 301
+    "location": null
+    "mock_header": "Mock-Response"
+    "proxy_host": "XXXXXXXXXXXX"
   },
   "enabled": true,
   "id": "2768b6e6-54b2-4278-a099-7ae17bbaee58",
   "name": "redirect",
   "protocols": [
     "grpc",
     "grpcs",
     "http",
     "https"
   ],
   "tags": [
     "global"
   ]
 }

Summary:
  Created: 0
  Updated: 0
  Deleted: 0
Error: 1 errors occurred:
	while processing event: Update plugin redirect (global) failed: HTTP status 400 (message: "3 schema violations (config.location: required field missing; config.mock_header: unknown field; config.proxy_host: unknown field)")

About your questions:

  1. Traditional Deployment
  2. We are using kong-2.22.0 chart. We used perUpgrade as described here. The actual flags are: init: false, preUpgrade: true, postUpgrade: true
  3. We did not enable Kong official redirect plugin. Not willingly, but was turned on and that was part of the problem.

@ProBrian
Copy link
Contributor

ProBrian commented Jan 20, 2025

Hi @rodolfobrunner,
Seems the kong migrations doesn't perfectly handle such upgrading case, we will take time to do more enhancement.
For now, Here's the workaround that you can have a try, to make your custom plugin works:

  1. rename your custom plugin. e.g. "redirect" to "redirect-custom".
  2. make sure your plugin code folder is correctly renamed an mounted.
  3. using deck to sync config change, I think your attempt on deck sync is basically correct except that you didn't change the service binding plugin's name to the new name:
    `
    updating plugin redirect (global) {
    "config": {
    "keep_incoming_path": false,
    "status_code": 301
  • "location": null
  • "mock_header": "Mock-Response"
  • "proxy_host": "XXXXXXXXXXXX"
    },
    ...
    "id": "2768b6e6-54b2-4278-a099-7ae17bbaee58",
    "name": "redirect-custom",
    ...
    }

Make sure the plugin name also changed to new name redirect-custom in kong.yml, then use deck to try again. Then the service will target to your custom plugin, not the built in redirect plugin.

@ProBrian
Copy link
Contributor

close this one, since we have a workaround and will handle the migrations enhancement with other task in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants