Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Annotations: Use dedicated regular expression for proxy-cookie-domain. - #14536

Merged
k8s-ci-robot merged 7 commits into
kubernetes:mainfrom
mhbahmani:main
Feb 9, 2026
Merged

k8s-ci-robot merged 7 commits into
kubernetes:mainfrom
mhbahmani:main

Conversation

@mhbahmani

@mhbahmani mhbahmani commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Now, proxy-cookie-domain accepts values like "example.com" (only one domain) which brokes nginx and blocks nginx reloading. This would lead to ingress not getting reloaded and configurations doesn't get applied.

This PR tightens validation for the proxy-cookie-domain annotation so it only allows:

  • off
  • two space-separated tokens (e.g. domain and replacement) using alphanumeric characters

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

I did not find a related issue.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/docs needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 8, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @mhbahmani!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 8, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @mhbahmani. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 8, 2026

@Gacko Gacko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your change currently breaks existing tests, please check why this is the case (ideally without changing those tests, as we otherwise risk a regression).

@mhbahmani

Copy link
Copy Markdown
Contributor Author

Your change currently breaks existing tests, please check why this is the case (ideally without changing those tests, as we otherwise risk a regression).

It's fixed now.
It worth mentioning that the regex i'm using is still far from ideal. Values like "example.com: example.org" are being accepted. Do you think it's better to write a more comprehensive regex for this annotation (and similar ones)?
One of the things i have in mind is to allow multiple whites spaces between the domains.

I would be happy to get your opinion and improve the validations if it worth it.

// This combination can also be used on fields that may contain characters like / (as ns/name)
BasicCharsRegex = regexp.MustCompile("^[/" + alphaNumericChars + "]*$")
// CookieDomainRegex validates proxy cookie domain: either "off" or two space-separated tokens (e.g. domain replacement)
CookieDomainRegex = regexp.MustCompile("^(off|[/" + alphaNumericChars + "]+\\s[" + alphaNumericChars + "]+)$")

@Gacko Gacko Feb 8, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a regular expression specific to a single annotation, while the other regular expressions are more generic. So please place this one close to the actual annotation instead.

Also please consider the documentation of this directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_domain.

There it states you could even use a regular expression as a value. But yes, overall it should be either off or domain replacement and I don't think NGINX really cares about the amount of whitespaces, so I'd be rather safe than sorry and allow multiple of them.

What makes me wonder: alphaNumericChars does not contain whitespaces. I assume this only works because of the removeSpace parameter in parser.ValidateRegex, right?

@mhbahmani mhbahmani Feb 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since I was using alphaNumericChars, I defined CookieDomainRegex here. Your'e right, I move it to somewhere near the usage.

Yes this config accepts regex values in nginx, but currently ingress doesn't support regex values. Using regex fails the validation here:

if EnableAnnotationValidation && annotationValue != "" {
if err := validateFunc(annotationValue); err != nil {
klog.Warningf("validation error on ingress %s/%s: annotation %s contains invalid value %s", ing.GetNamespace(), ing.GetName(), name, annotationValue)
return "", ing_errors.NewValidationError(annotationFullName)

And silently sets off here:
config.CookieDomain, err = parser.GetStringAnnotation(proxyCookieDomainAnnotation, ing, a.annotationConfig.Annotations)
if err != nil {
config.CookieDomain = defBackend.ProxyCookieDomain
}

As this behaivour (not rejecting the ingress crd and setting a default value in nginx config) is being used in multiple scenarios, it seems that it's a design desicion and I don't know if it's a good idea to change it here, even though as an ingress user I prefer to get rejected at CRD apply step :) (At least for simple cases this. For more complicated scenarios like snippets it faces some challenges that maybe they are out of the scope of ingress) and I would happy to work on this.

And yes, it works in current version because of removeSpace being set to true.

The main reason that I made this PR is for supporting cases where a value for proxy_cookie_domain is not valid to nginx and leads to breaking the nginx, but it passes the ingress validation. But if you think It should prevent the ingress being applied, I can work on it and come up with some more resilient and comprehensive changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, no, all good. I just wanted to make sure your change is not restricting anyone. But since any other value other than these allowed by your regular expression would either have been rejected or broke NGINX configuration before, it's fine. 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. Thanks.

Just to clarify, do you see incompatibilities like these with nginx, or the permissiveness in Ingress validation on ingress CRDs, as an area for improvement? Or do these fallbacks to default values tend to be the way they are by design? I think instead of falling back to default values, Ingress could reject or show a warning when applying such configurations.
Just want to know if it's worth putting time into or not :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's worth it. This project is going to get retired end of month, so I'd rather not introduce such a change in behavior anymore.

@Gacko Gacko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still please move the new regular expression to where it's being used and maybe consider allowing multiple whitespaces (if NGINX would also tolerate that) including a test case. Everything else looks fine!

@Gacko

Gacko commented Feb 9, 2026

Copy link
Copy Markdown
Member

/retitle Annotations: Use dedicated regular expression for proxy-cookie-domain.
/triage accepted
/kind bug
/priority backlog
/hold

@k8s-ci-robot k8s-ci-robot changed the title Use proper regex for proxy-cookie-domain annotation validation Annotations: Use dedicated regular expression for proxy-cookie-domain. Feb 9, 2026
@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority labels Feb 9, 2026

@Gacko Gacko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/unhold
/lgtm

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 9, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Gacko, mhbahmani

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 9, 2026
@Gacko

Gacko commented Feb 9, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 9, 2026
@k8s-ci-robot
k8s-ci-robot merged commit ded3b60 into kubernetes:main Feb 9, 2026
19 checks passed
@Gacko

Gacko commented Feb 9, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.14

@Gacko

Gacko commented Feb 9, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.13

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@Gacko: new pull request created: #14550

Details

In response to this:

/cherry-pick release-1.14

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@Gacko: new pull request created: #14551

Details

In response to this:

/cherry-pick release-1.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/docs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants