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(proxy/pdk) add support for X-Forwarded-Prefix #5620

Merged
merged 1 commit into from
Mar 11, 2020

Conversation

bungle
Copy link
Member

@bungle bungle commented Feb 27, 2020

Summary

Kong currently adds these headers to upstream request:

X-Forwarded-For
X-Forwarded-Port
X-Forwarded-Proto
X-Forwarded-Host
X-Real-IP

@erikgb mentioned that he would like to have X-Forwarded-Prefix
added on #5602.

This PR adds that, and additionally introduces a new PDK function:

local path = kong.request.get_forwarded_path()

Issues Resolved

Close #5602

@bungle
Copy link
Member Author

bungle commented Feb 27, 2020

The first thing I notice, is that quite a few formatting fixes have been included in this commit. I tend to prefer to have refactoring, including formatting, separated from changes. Would you consider to split the source code changes in two commits? Doing that, it will also be easier to review the PR - when the changes related to this new feature is separated from the re-formatting. Any potential merge/rebase conflict also tends to be easier to resolve (correctly) doing so....

You are right, but Github also has ignore whitespace when reviewing:
https://github.com/Kong/kong/pull/5620/files?utf8=%E2%9C%93&diff=split&w=1

kong/pdk/request.lua Show resolved Hide resolved
kong/runloop/handler.lua Show resolved Hide resolved
@erikgb
Copy link

erikgb commented Mar 5, 2020

Anything more I can do to get this merged? I have reviewed the code, and I think it looks good. @kikito has requested changes, but I am not sure what changes are actually required.

### Summary

Kong currently adds these headers to upstream request:
```
X-Forwarded-For
X-Forwarded-Port
X-Forwarded-Proto
X-Forwarded-Host
X-Real-IP
```

@erikgb mentioned that he would like to have `X-Forwarded-Prefix`
added on #5602.

This PR adds that, and additionally introduces a new PDK function:
```lua
local path = kong.request.get_forwarded_path()
```

### Issues Resolved

Close #5602
@bungle bungle merged commit 8773aab into next Mar 11, 2020
@bungle bungle deleted the feat/x-forwarded-prefix branch March 11, 2020 17:21
@hishamhm hishamhm added this to the 2.1.0 milestone Mar 12, 2020
bungle added a commit that referenced this pull request Aug 7, 2020
### Summary

The PR #5620 implemented `X-Forwarded-Prefix` wrong. The implementation
looks more like proprietary `X-Forwarded-Path`. This commit changes that
accordingly. Next commit in this PR will re-introduce X-Forwarded-Prefix
correctly.

I decided to keep the current behavior as it is already used in some code
with PDK `kong.request.get_forwarded_path` (e.g. if the plugin needs to get
the original request path, the one that is perhaps rewritten by Kong or a
proxy before Kong, perhaps Kong as well).
bungle added a commit that referenced this pull request Aug 7, 2020
…warded_prefix

### Summary

The PR #5620 implemented `X-Forwarded-Prefix` wrong as reported in these:
- #6190
- Kong/kubernetes-ingress-controller#784
- #6132

And also by some other sources.

This commit re-implements `X-Forwarded-Prefix`:

1. Is there trusted `X-Forwarded-Prefix` header in request? If yes, then set
   that as the `X-Forwarded-Prefix` (note: at this point we don't support
   multi-value `X-Forwarded-Prefix` headers, e.g. appending. We don't support
   multi-value in `X-Forwarded-Host/-Port/-Proto` either.
2. Has Kong router stripped the prefix of the request URI before proxying, if
   yes, then set `X-Forwarded-Prefix` to match the stripped prefix.
3. If 1 or 2 didn't set the header, set it to `/`.

### Issues Resolved

Fix #6190
Fix Kong/kubernetes-ingress-controller#784
Fix #6132
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

Successfully merging this pull request may close these issues.

5 participants