Skip to content

add requestHeaderModifier fail #2225

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

Closed
Eason-Liu opened this issue Jul 11, 2024 · 3 comments
Closed

add requestHeaderModifier fail #2225

Eason-Liu opened this issue Jul 11, 2024 · 3 comments

Comments

@Eason-Liu
Copy link

Describe the bug
I have configured httproute.spec.rules.filters.requestHeaderModifier.add.name and httproute.spec.rules.filters.requestHeaderModifier.add.value in httproute. The values are X-Real-IP and remote_addr, respectively. httproute.spec.rules.filters.type is RequestHeaderModifier. However, in the nginx-gateway Pod, remote_addr is recognized as proxy_set_header X-Real-IP "${x_real_ip_header_var}remote_addr"; how can I configure it to recognize as proxy_set_header X-Real-IP "$remote_addr"? I have tried configuring httproute.spec.rules.filters.requestHeaderModifier.add.value as $remote_addr, but it causes all proxy_set_header commands in the nginx-gateway to not be recognized. How can I resolve this issue?

@kate-osborn
Copy link
Contributor

Hi @Eason-Liu, we don't support setting nginx variables like $remote_addr in requestHeaderModifier filter, or any of the HeaderModifiers.

If you describe the HTTPRoute where you defined this requestHeaderModifier you should see an error like:

All rules are invalid: spec.rules[0].filters[0].RequestHeaderModifier.add: Invalid value: v1.HTTPHeader{Name:"X-Real-IP", Value:"$remote_addr"}: a valid value must have all '"' escaped and must not contain any '$' or end with an unescaped '\' (e.g. 'my-header-value',  or 'example/12345==', regex used for validation is '([^"$\\]|\\[^$])*')

Can I ask what you are trying to achieve? Are you trying to preserve the client's IP address? Would this planned feature help: #1406?

@Eason-Liu
Copy link
Author

Yes, I want to retain the client's real IP address for log analysis.

@kate-osborn
Copy link
Contributor

Yes, I want to retain the client's real IP address for log analysis.

@Eason-Liu thanks for the response. #1406 will add this feature and is planned for the next release.

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

No branches or pull requests

2 participants