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

feat(conf): inject nginx directives into kong's proxy location block #11623

Merged
merged 2 commits into from
Nov 13, 2023

Conversation

vvicaretti
Copy link
Contributor

@vvicaretti vvicaretti commented Sep 20, 2023

Summary

The injection of Nginx directives is currently supported in the http and server contexts, but not in the location context.

To inject Nginx directives into the location context, it is required to create and maintain a custom Nginx template, as detailed in this document.

The goal is to enable injection of Nginx location directives into the Kong Gateway’s proxy block, following the same pattern used for http and server contexts, without the need of a custom Nginx template.

This would streamline the process and maintain consistency across different Kong Gateway’s proxy contexts.

Checklist

  • The Pull Request has tests
  • A changelog file has been added to CHANGELOG/unreleased/kong or adding skip-changelog label on PR if unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Full changelog

  • Add nginx_location_*. The new prefix allows for the dynamic injection of Nginx directives into the / location block within Kong's proxy server {} block.

Issue reference

Fix #[issue number]

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@vvicaretti vvicaretti marked this pull request as ready for review September 20, 2023 12:38
@vvicaretti vvicaretti force-pushed the feat/inject-nginx-directives-location branch from 20b3033 to 350b432 Compare September 20, 2023 12:40
@vvicaretti vvicaretti marked this pull request as draft September 20, 2023 13:31
@vvicaretti vvicaretti force-pushed the feat/inject-nginx-directives-location branch 2 times, most recently from 7b9ebe5 to 80b6fd7 Compare September 20, 2023 19:10
@vvicaretti vvicaretti marked this pull request as ready for review September 20, 2023 19:11
@vvicaretti
Copy link
Contributor Author

vvicaretti commented Sep 21, 2023

@bungle since these are internal locations, I figured there is less need for end users to inject Nginx directives there.
Do you think it should be possible to modify them as well?

To expand a bit on the specific use case:

An application sets an X-Accel-Redirect header to instruct Nginx where to fetch static assets. This job is delegated to the Nginx-based Edge layer.
In an architecture where Kong sits in between the Edge layer and the application, it is required to instruct Kong to ignore and pass along the X-Accel-Redirect header.
The common pattern to do so would be to add the following directives under the relevant location block:

proxy_ignore_headers X-Accel-Redirect;
proxy_pass_header X-Accel-Redirect;

That's currently not possible, unless we use a custom template which makes upgrades tricky

@team-eng-enablement team-eng-enablement added the author/community PRs from the open-source community (not Kong Inc) label Sep 22, 2023
@kikito kikito requested a review from gszr September 26, 2023 17:13
@bungle
Copy link
Member

bungle commented Oct 23, 2023

since these are internal locations, I figured there is less need for end users to inject Nginx directives there

Those internal locations get used if you for example:

  1. turn route.request_buffering=on
  2. turn route.response_buffering=on
  3. call kong.service.request.enable_buffering()
  4. implement :response phase on an enabled plugin
  5. proxy grpc traffic

So while they are internal, I feel we need to think wether we want the same directives replicated on each, or have their own injections.

@vvicaretti
Copy link
Contributor Author

So while they are internal, I feel we need to think wether we want the same directives replicated on each, or have their own injections.

I believe it is up to the maintainers to decide what's the best way forward.
I would be happy to update the PR accordingly.

@jschmid1 jschmid1 force-pushed the feat/inject-nginx-directives-location branch from 8318c1f to 7e17d1f Compare November 13, 2023 08:22
Copy link
Contributor

@jschmid1 jschmid1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the nice contribution @vvicaretti. We had a look at this and this should be fine. I started the tests to see if anything breaks 👍🏼

`nginx_location_*`: the new prefix allows for the dynamic
injection of Nginx directives into the `/` location block within
Kong's Proxy server block.
@vvicaretti vvicaretti force-pushed the feat/inject-nginx-directives-location branch from 7e17d1f to d1e177b Compare November 13, 2023 10:02
@vvicaretti
Copy link
Contributor Author

I have pushed this commit d1e177b to include a changelog file (the test was failing). I am afraid tests will have to be triggered one more time :)

@bungle bungle merged commit b1b5f94 into Kong:master Nov 13, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author/community PRs from the open-source community (not Kong Inc) core/configuration core/templates size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants