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

Restrict policies to non-duplicate routes #2318

Merged
merged 5 commits into from
Aug 7, 2024

Conversation

sjberman
Copy link
Contributor

@sjberman sjberman commented Jul 31, 2024

Problem: Some NGINX directives are not applied or enforced when configured in an internal location. This occurs when redirecting or rewriting a request from an external location to an internal location.

Solution: Only accept a policy if the Route it targets is the only Route that matches the hostname, port, and path combination. If other Routes overlap, the policy will be rejected.

This allows us to apply policy configuration to the external location instead of the internal locations. We would limit the policies we accept rather than limiting which Routes we accept.

This is possible because, with the policy restriction, a policy cannot be applied to a Route that shares an external location with another Route.

However, for the otel module, we still require some internal location directives to be specified, so the policy generator has been refactored to account for this.

Finally, revert named locations back to internal locations. As part of this process, we've learned that named locations do not behave as expected.

Testing: Manual verification that policies work with matching conditions, as well as Condition is set properly when overlapping routes exist in relation to a policy.

Closes #2308

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Fix an issue that prevented ClientSettingsPolicies and ObservabilityPolicies from working when attached to an HTTPRoute where matching conditions were defined.

@github-actions github-actions bot added the bug Something isn't working label Jul 31, 2024
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 99.69970% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.07%. Comparing base (bafc4f7) to head (a269f71).

Files Patch % Lines
internal/mode/static/manager.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2318      +/-   ##
==========================================
+ Coverage   87.77%   88.07%   +0.29%     
==========================================
  Files          96       97       +1     
  Lines        6847     6993     +146     
  Branches       50       50              
==========================================
+ Hits         6010     6159     +149     
+ Misses        780      777       -3     
  Partials       57       57              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sjberman sjberman force-pushed the fix/policy-restriction branch 2 times, most recently from 273d0ab to 34b6db7 Compare August 1, 2024 17:16
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 1, 2024
@sjberman sjberman force-pushed the fix/policy-restriction branch from 34b6db7 to dece2b5 Compare August 1, 2024 17:58
@sjberman sjberman marked this pull request as ready for review August 1, 2024 18:11
@sjberman sjberman requested review from a team as code owners August 1, 2024 18:11
Copy link
Contributor

@ADubhlaoich ADubhlaoich left a comment

Choose a reason for hiding this comment

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

Doc changes LGTM. Always nice to see a notice removed because a feature has been added!

Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

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

🚀 🚀

internal/mode/static/nginx/config/http/config.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/policies.go Show resolved Hide resolved
internal/mode/static/state/graph/policies.go Show resolved Hide resolved
@sjberman sjberman force-pushed the fix/policy-restriction branch from dece2b5 to cb06d8a Compare August 5, 2024 17:43
@sjberman sjberman requested a review from kate-osborn August 5, 2024 20:01
Copy link
Contributor

@bjee19 bjee19 left a comment

Choose a reason for hiding this comment

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

Submitting this for now, about halfway through reviewing.

sjberman and others added 4 commits August 7, 2024 09:55
Problem: Some NGINX directives are not applied or enforced when configured in an internal location. This occurs when redirecting or rewriting a request from an external location to an internal location.

Solution: Only accept a policy if the Route it targets is the only Route that matches the hostname, port, and path combination. If other Routes overlap, the policy will be rejected.

This allows us to apply policy configuration to the external location instead of the internal locations. We would limit the policies we accept rather than limiting which Routes we accept.

This is possible because, with the policy restriction, a policy cannot be applied to a Route that shares an external location with another Route.

However, for the otel module, we still require some internal location directives to be specified, so the policy generator has been refactored to account for this.

Finally, revert named locations back to internal locations. As part of this process, we've learned that named locations do not behave as expected.

Co-authored-by: Kate Osborn <[email protected]>
@sjberman sjberman force-pushed the fix/policy-restriction branch from 8509c3b to 8fdf3a4 Compare August 7, 2024 15:55
Copy link
Contributor

@bjee19 bjee19 left a comment

Choose a reason for hiding this comment

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

🚀

@sjberman sjberman enabled auto-merge (squash) August 7, 2024 18:39
@sjberman sjberman merged commit 2cb44de into nginxinc:main Aug 7, 2024
37 checks passed
@sjberman sjberman deleted the fix/policy-restriction branch August 7, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation release-notes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Inconsistent application of NGINX directives in internal location blocks
4 participants