ingress-nginx: Wrong validation for permanent-redirect and temporal-redirect annotation values

Hi everyone,

I think in this file there is a wrong validator for the values of permanent-redirect and temporal-redirect annotation used.

Reasoning: It should be possible to use variables like “$request_uri” for redirecting to the same path as in the original request for example, but this is blocked by the validation because the $ is not allowed. If I use a configuration-snippet with the following content, it works fine:

return 301 https://wheelscompany.com/$request_uri;

So for me it looks like if URLWithNginxVariableRegex should be the correct Regex to be used at this point.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 38
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Same problem here after upgrading from helm chart 4.11.4 to 4.12.0 http://nginx.ingress.kubernetes.io/permanent-redirect: https://www.domain.com/$redirect_uri

👍 This is blocking upgrade for us, with multiple high CVSS scores.

We also hit this in Prod yesterday with 4.12.2.

confirm the same issue with $redirect_uri on 4.12.1

Just hit this issue today when I started debugging why my redirect (which I was pretty sure worked) doesn’t work anymore.

I can confirm it’s problem with v1.12. Rolling back to Helm Chart 4.11.4 (which is latest chart before 1.12, and installs 1.11.4) resolved issue.

Just to add on, auth-sign in validation appears broken when updating from v1.11.3 to v1.12.0 as well:

W0128 09:25:51.467367       7 validators.go:237] validation error on ingress foo/bar: annotation auth-signin contains invalid value https://auth.example.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri

EDIT: Looking a bit deeper, auth-signin already uses URLWithNginxVariableRegex, so this error this is likely due to the URL encoded characters in the address. This is working on v1.11.3, so not sure what has changed since that release, however potentially not related to this issue.

@lindhe No, those issues are older and what the OP (and us) are trying was working just fine with Helm version 4.11.3 (as @MiGrandjean said as well).

@Vierlip We just installed 4.12.2 and the issue is still there. We will be reverting to a 4.11 version until we hear back from the team.

This is grave; having “invalid” values causes the annot to be ignored.

The Ingress though is still processed, without the annotation.

In cases of annots like nginx.ingress.kubernetes.io/auth-url et al, this will leave your previously-fine Ingress now fully unprotected.

Please make the whole Ingress fail if any annotations fail validation.

Have you tried setting:

controller:
  enableAnnotationValidations: false

ATTENTION tthis does not validate the annotaation anymore and let’s sth like $redirect_uri in there through, but it could potentially brake your nginx configuration being reloaded

Relference: https://github.com/kubernetes/ingress-nginx/releases/tag/controller-v1.12.1

Unfortunately, to fix https://github.com/advisories/GHSA-mgvx-rpfc-9mpv it was necessary to disable the validation of the generated NGINX configuration during the validation of Ingress resources.

The resulting NGINX configuration is still checked before the actual loading, so that there are no failures of the underlying NGINX. However, invalid Ingress resources can lead to the NGINX configuration no longer being able to be updated.

To reduce such situations as far as possible, we therefore recommend enabling annotation validation and disabling snippet annotations. In case of doubt, such states can be determined from the logs of the Ingress NGINX Controller. Watch out for a line of dashes followed by “Error:” telling you what went wrong.