-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Metadata insertion plugin #1962
Conversation
Here's some metadata plugin that allows kong to modify Headers and Querystring based on two source of metadata, the persistent ones in database / redis and the ones in the transitory store. Transitory store could allow other plugins to prepare metadata on the fly when kong receive a Request. (View Tieske suggestion here #550) One of the test cover the use case by feeding the transitory store with fixtures. I've added a debug.lua library for my POC, I should probably remove it if the pull request ever gets approved. Also I believe my request_headers_factory and request_querystring_factory could be use in the request-transformer plugin, so it might be wise to move in /kong/tools or something like that ? Comments are welcome, i've never done Lua / OpenResty before. Full changelog Implement metadata-insertion plugin Issues resolved Fix #550
@thibaultcha Sorry for the lost of comment history, I was struggling with rebase so I created a new branch Ref: #1961 |
So from #1961:
The rest of the comment history does not apply anymore. |
… working all the time. The actual index order might change depending on generated unique id for the consumer_id field.
So let's get back to business now that my PR git history looks ok @thibaultcha Can you tell me more about what other approach is possible ? Thx ! |
I believe having it as a plugin offers flexibility. And allowing other plugins to be able to also feed the ngx.ctx.transitory_store seems a great value for people who don't want persistent metadata but instead doing some parsing over the actual request or any other scenarios possible. @Tieske seemed to have some idea in mind regarding this. |
I am most of all reluctant to adding more plugins before implementing the plugins development API, which, among other things, could implement such helpers around the |
I see ! Seems like a legit meditation. I'm just trying to figure out the future here, because I might be forced to find another metadata solution if it takes months to implement, we all have commitments to deliver hehe Let me know ! |
Hi, We shall not accept community plugins in the core anymore. Feel free to publish this plugin on your own following the distributing your plugin guide. You are also encouraged to advertise it on the mailing list, and we will soon provide a "community plugins" section on getkong.org/plugins/ on which you will be able to document it. In the future, we plan to take out of this core repository all of the plugins we currently have as well. Thank you! |
The main drawback here is the maintenance overhead such "alien" plugins add to the Kong team. To answer your questions @JnMik:
Probably some time this year.
Yes, very!
For maintaining a given plugin with the upcoming changes, one might have to move a bit of logic here or there until we declare it stable (thinking when we will add new "contexts/hooks" like In terms of the Public Lua API (things like A bigger concern might be the DAO and the model. We will very likely change them quite a lot to improve and make Kong more flexible. This might mean that Consumers metadata will end up in the core model anyways 😉 |
Not sure anymore if this is worth distributing my own custom plugin or wait for the consumers metadata to be in the core model. It tooks 4 months receiving a follow up here, I feel it could take years before the metadata shows up in the core model lol I'll think about it. |
We have a lot on our plate. (referring to why the model is yet to be rewritten) We had uncertainties and decisions to make before coming back to the currently proposed plugins. |
I personally think it is worth it, since there is no support for such a feature in Kong itself yet, and as you highlighted, there might not be for a little while, still, and I know some users would be interested. Up to you! |
@JnMik Did you abandon the project? Can't believe we still don't have it and it's been 2 years |
Summary
We want to be able to add metadata on our customers.
These metadata could be forwarded to upstream APIs when request pass through Kong.
Our most basic use case : We proxy multiple 3-party APIs and want our customers to have one single API key. Their 3-party API key would be hidden in their metadata, and passed along with the request.
Apply metadata-insertion plugin on an API endpoint
The metadata-insertion plugin can be added on an API with a configuration like this (it looks like request-transformer plugin):
Placeholder replacement order
The %placeholder% for metadata will be resolved based on three data source (cassandra, redis, transitory store)
What is the transitory store ?
Transitory store allows other plugins to prepare metadata on the fly when kong receive a request.
(View Tieske suggestion here #550)
One of the test cover the use case by feeding the transitory store with fixtures.
Plugin flow
To add metadata in database, POST request can be done on /consumers/:username_or_id/metadata/
Finish Cassandra DAO #1 First the plugin verify if the request is done by an authenticated consumer. If not, the plugin force an HTTP_UNAUTHORIZED response to indicate that Metadata is necessary on that api endpoint. (We do not want the upstream API to receive incomplete request).
How to distribute (release process) Kong? #2 Then the plugin loads the persistent metadata of that user in memory (Redis if already in memory, fallback on cassandra).
/bin/kong global script #3 Then the transitory store is loaded as well in memory, replacing persistent metadata if same key already exist.
Polishing the controllers + more integration tests #4 Finally %placeholer% are replaced, so the metadata are added to target Headers & Querystring.
Debug tool
I've added a debug.lua library for my POC, I understand that I should probably remove it if the pull request ever gets approved.
Headers & Querystring factory
Also I believe my request_headers_factory and request_querystring_factory could be used in the request-transformer plugin.
Full changelog
Implement metadata-insertion plugin
Comments are welcome, i've never done Lua / OpenResty before.
Issues resolved
Fix #550
Edit: Changed my summary to explain the big picture of how the plugin works.