Skip to content

Annotations: Quote auth proxy headers. #13371

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

Merged
merged 1 commit into from
Aug 4, 2025

Conversation

jkroepke
Copy link
Contributor

What this PR does / why we need it:

Validate the values inside a config map linked by the auth-proxy-set-headers annotation.

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

How Has This Been Tested?

Locally, manually.

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 do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 12, 2025
@k8s-ci-robot k8s-ci-robot requested a review from Gacko May 12, 2025 20:31
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label May 12, 2025
@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. needs-priority labels May 12, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @jkroepke. 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.

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 the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 12, 2025
@jkroepke jkroepke marked this pull request as ready for review May 12, 2025 20:32
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 12, 2025
@k8s-ci-robot k8s-ci-robot requested a review from strongjz May 12, 2025 20:32
Copy link

netlify bot commented May 12, 2025

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 41b04f2
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/68225ab65ddc8c000847c8da

Copy link

netlify bot commented May 12, 2025

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 5b9be69
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-ingress-nginx/deploys/6890ad91ad323f0008574b98

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 24, 2025
Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

/triage accepted
/kind bug
/priority backlog
/hold

If you're concerned about code injection, I'd rather quote the value here as we already did here. Annotation validation is optional and can be turned off. Also your regular expression might break existing deployments, which then leads to people turning off annotation validation.

@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 Jul 24, 2025
@jkroepke jkroepke closed this Aug 2, 2025
@jkroepke jkroepke force-pushed the authorization-value branch from f48a0e8 to 15ee736 Compare August 2, 2025 15:06
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 2, 2025
@jkroepke jkroepke reopened this Aug 2, 2025
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 2, 2025
@jkroepke jkroepke force-pushed the authorization-value branch from ecb7737 to 748cf6c Compare August 2, 2025 15:38
@jkroepke jkroepke requested a review from Gacko August 2, 2025 15:38
@jkroepke
Copy link
Contributor Author

jkroepke commented Aug 2, 2025

Hi @Gacko

thanks for your review. Please take a look. I may ask if using gos sprintf %q has any downsides compared to strconv.Quote and %v.

@jkroepke jkroepke force-pushed the authorization-value branch from 748cf6c to 1ee9740 Compare August 2, 2025 16:28
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 2, 2025
@jkroepke jkroepke force-pushed the authorization-value branch from 1ee9740 to 7ab707e Compare August 2, 2025 18:48
@@ -619,8 +619,13 @@ func buildAuthProxySetHeaders(headers map[string]string) []string {
}

for name, value := range headers {
res = append(res, fmt.Sprintf("proxy_set_header '%v' '%v';", name, value))
if strings.ContainsAny(name, "\n\r") || strings.ContainsAny(value, "\n\r") {
Copy link
Member

Choose a reason for hiding this comment

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

I think newlines ain't an issue as long as they are quoted.

Copy link
Member

Choose a reason for hiding this comment

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

Also because this would be a breaking change and I'd like to back-port this to the release branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I know, header fields over multiple lines are deprecated in RFC 7230 and in this context (auth proxy set headers), there is known situation where a new line is used as for an request header.

However, if you wish, I can remove this restriction.

Copy link
Member

Choose a reason for hiding this comment

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

I'm less worried about the newline in the header being sent to the auth backend. What we should fix here is the possibility of injecting code in the NGINX configuration.

@Gacko
Copy link
Member

Gacko commented Aug 4, 2025

Hi @Gacko

thanks for your review. Please take a look. I may ask if using gos sprintf %q has any downsides compared to strconv.Quote and %v.

I don't think there is much of a difference in the result and it's mostly about how you're using them - as in: You don't need to use Sprintf and a format string and can just use stringconv.Quote if you just need a string to be quoted without additional formatting. In this particular case it might be better to use %q.

The only real difference I see is, that stringconv.Quote really only accepts strings, so is a little more type safe.

Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

/retitle Annotations: Quote auth proxy headers.
/triage accepted
/kind bug
/priority backlog

@k8s-ci-robot k8s-ci-robot changed the title fix(auth-proxy-set-headers): Validate authorization header values Annotations: Quote auth proxy headers. Aug 4, 2025
@Gacko Gacko force-pushed the authorization-value branch from 7ab707e to 5b9be69 Compare August 4, 2025 12:54
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 4, 2025
Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 4, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

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 Aug 4, 2025
@Gacko
Copy link
Member

Gacko commented Aug 4, 2025

I implemented the suggested changes, so we can still have this in the next patch release. As stated above, I removed the filtering for \n and \r since could potentially affect user deployments and therefore be a breaking change we could not back-port to the release branches.

@Gacko Gacko removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 4, 2025
@k8s-ci-robot k8s-ci-robot merged commit 3d90678 into kubernetes:main Aug 4, 2025
27 checks passed
@Gacko
Copy link
Member

Gacko commented Aug 4, 2025

/cherry-pick release-1.13

@Gacko
Copy link
Member

Gacko commented Aug 4, 2025

/cherry-pick release-1.12

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #13708

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.

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #13709

In response to this:

/cherry-pick release-1.12

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/S Denotes a PR that changes 10-29 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