Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/#kong-community
Apache License 2.0
38.85k stars 4.77k forks source link

Problems with keys greater than 511 in declarative configuration #10219

Closed EdsonLuisVieira closed 1 year ago

EdsonLuisVieira commented 1 year ago

Is there an existing issue for this?

Kong version 3.1.1

kong 3.1.1

Current Behavior

we are upgrading Kong from 2.x to Kong 3.x, and we are facing a blocking bug :cry: We use Kong Databaseless, and with the new LMDB mechanisms from Kong 3.x, our configurations are not loading.

In the tests in declarative config file the length of a consumer's API Key is causing it (but other places may also have the same problem)

When the value has more than 511 characters Kong starts the process, but with empty configurations, also Kong reports: 2023/02/02 14:21:35 [crit] 1129#0: 8 [lua] init.lua:697: init_worker(): worker initialization error: failed to load declarative config file: MDB_BAD_VALSIZE: Unsupported size of key/DB name/data, or wrong DUPFIXED size; this node must be restarted, context: init_worker_by_lua

Expected Behavior

kong in version 3.1.1 can load declarative configuration without errors

Steps To Reproduce

  1. Using the image kong:3.1.1
  2. Load this configuration file bellow: (following the steps in the image readme)
    
    ---
    _format_version: "1.1"

consumers:

services:

routes:



### Anything else?

_No response_
chronolaw commented 1 year ago

The default max key size is 511, document of LMDB(https://lmdb.readthedocs.io/en/release/) says:

By default record keys are limited to 511 bytes in length, however this can be adjusted by rebuilding the library. The compile-time key length can be queried via [Environment.max_key_size()](https://lmdb.readthedocs.io/en/release/#lmdb.Environment.max_key_size).
carnei-ro commented 1 year ago

@chronolaw will Kong increase the default value in next versions? Or 511 is the new “hard limit” for pre-built release images?

chronolaw commented 1 year ago

We will have an internal discussion about it. Thanks for your report again.

Ticket: KAG-560.

ghost commented 1 year ago

Are there any updates? I'm willing to try to solve this problem, I just want to confirm: does it make sense to allow max key size over 512? In what scenario would a key size larger than 512 be required? @EdsonLuisVieira

I can guess some random key generation scenarios to prevent key conflicts, but I think the default key size (512) is sufficient in this scenario.

carnei-ro commented 1 year ago

@sabertobihwy In my opinion, an API Key with max of 511 chars is pretty reasonable. The only thing is: I can not upgrade Kong "as is" (without changing this secret in all my clients and reconfiguring Kong), also, it is not documented;

What also made me uncomfortable was the fact: the length of the value of the attribute key is bigger than 511 chars... so, could I not use strings bigger than 511 chars in other places, such as configs for "post function" plugin?! - The fact is I can; It only complains with API Keys.

EdsonLuisVieira commented 1 year ago

hello @sabertobihwy, in our case we are upgrading from version 2.x to 3.x and we can't make the update transparently("not counting deprecations and plugin updates"), but this kind of problem turns on a certain impediment, our main concern is that the size in the yaml is for a value but the error presents it as a key, so we are concerned that this cannot affect other values in custom plugins or definitions of routes and services.

Another point that is relevant is that the command kong config parse show the yaml as valid, so we only get the error when trying to load the new configuration in kong

hanshuebner commented 1 year ago

This will be fixed in the lmdb library: https://github.com/Kong/lua-resty-lmdb/pull/27