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

question: How to get client IP and custom headers in Lua filter #13457

Closed
nic-chen opened this issue Oct 9, 2020 · 8 comments · Fixed by #13536
Closed

question: How to get client IP and custom headers in Lua filter #13457

nic-chen opened this issue Oct 9, 2020 · 8 comments · Fixed by #13536
Labels
area/lua enhancement Feature requests. Not bugs or questions.

Comments

@nic-chen
Copy link
Contributor

nic-chen commented Oct 9, 2020

I am developing a framework that support Apache APISIX plugins run directly in Envoy Lua filter without modify Envoy. #13307

But in the process, I found that some header values, such as client IP and custom headers, cannot be get in Lua filter.

I think client IP and custom headers should be very commonly used.

I might misreading/misunderstanding, but I don't know how to get them, please remind me, thank you !

@nic-chen nic-chen added the triage Issue requires triage label Oct 9, 2020
@dio
Copy link
Member

dio commented Oct 9, 2020

I found that some header values, such as client IP and custom headers, cannot be get in Lua filter.

Sorry, do you mean you have this information available on headers but it was not there when you tried to access it?

FWIW, I think the information is available here:

/**
* @return the downstream remote address. Note that this will never be nullptr. This may be
* equivalent to downstreamDirectRemoteAddress, unless the remote address is inferred from a
* proxy proto, x-forwarded-for, etc.
*/
virtual const Network::Address::InstanceConstSharedPtr& downstreamRemoteAddress() const PURE;
However, yes currently we have the StreamInfo wrapper but not all information is accessible from Lua script.

@dio dio added enhancement Feature requests. Not bugs or questions. area/lua and removed triage Issue requires triage labels Oct 9, 2020
@nic-chen
Copy link
Contributor Author

Sorry, do you mean you have this information available on headers but it was not there when you tried to access it?

I reconfirmed that the custom headers are available by handle:headers(), sorry about that.

However, yes currently we have the StreamInfo wrapper but not all information is accessible from Lua script.

It seems that only protocol, dynamicMetadata and downstreamSslConnection are exposed.
Would We export downstreamRemoteAddress to Lua filter ? 😃

@dio
Copy link
Member

dio commented Oct 10, 2020

@nic-chen sure. I think this is a good exercise for a new contributor. Do you want to try? I can try to help with providing guidance and review. Here is a complete (well, it's still missing docs) patch to expose downstream local address: https://github.com/envoyproxy/envoy/compare/master...dio:lua-streaminfo-addresss?expand=1, you can then add more getters to StreamInfoWrapper as you wish 🙂.

@nic-chen
Copy link
Contributor Author

@nic-chen sure. I think this is a good exercise for a new contributor. Do you want to try? I can try to help with providing guidance and review. Here is a complete (well, it's still missing docs) patch to expose downstream local address: https://github.com/envoyproxy/envoy/compare/master...dio:lua-streaminfo-addresss?expand=1.

Wow, so nice you are!

I have always used JAVA, PHP, GO, Lua, JavaScript to work, and have never used C++.

But I would like to try it out and learn, hoping to contribute more in the future.

@nic-chen
Copy link
Contributor Author

@nic-chen sure. I think this is a good exercise for a new contributor. Do you want to try? I can try to help with providing guidance and review. Here is a complete (well, it's still missing docs) patch to expose downstream local address: https://github.com/envoyproxy/envoy/compare/master...dio:lua-streaminfo-addresss?expand=1, you can then add more getters to StreamInfoWrapper as you wish 🙂.

Do you mind if I push directly to your repo? Or should I submit the code on my repo? Then create a pr.
Thanks !

@dio
Copy link
Member

dio commented Oct 10, 2020

@nic-chen I think I prefer for you to work on your own repo. Please note that the patch that I have exposes downstream local address, which probably not what you want. You can of course expose more, since the pattern will be the same (the remote ones: downstreamRemoteAddress(), downstreamDirectRemoteAddress(), etc).

Have you successfully built envoy on your local? Please let me know if you have any issues.

You can follow the official docs https://github.com/envoyproxy/envoy/blob/8a1d44422ba9ffa303c89b109b57e8889655b53a/bazel/README.md#building-envoy-with-bazel on building it, or the short one here (if you're on Linux (Debian-based) and want to use clang): https://gist.github.com/dio/9a7c826a2dbf004a81112db0d167d209.

@nic-chen
Copy link
Contributor Author

@dio
OK. Thanks so much.

I will try to build and make some test.

It may take some time. There should be issues in this process that need your help, if so, I will ping you here. : )

@nic-chen
Copy link
Contributor Author

@dio

I works on macOS, so took some time to build..

I think i could submit a pr today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lua enhancement Feature requests. Not bugs or questions.
Projects
None yet
2 participants