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

opa: pass URL query parameters to OPA policy evaluation #3207

Merged
merged 6 commits into from
Sep 12, 2024

Conversation

mefarazath
Copy link
Contributor

@mefarazath mefarazath commented Aug 26, 2024

Improve the envoy request adapting logic to include query parameters sent in the request.

This would allow the policy evaluation opaAuthorizeRequest* and opaServeResponse* filters to make use of query parameters/values in the policy.

@mefarazath mefarazath force-pushed the pass-query-params-to-opa branch 2 times, most recently from 734e183 to 166fd5b Compare August 26, 2024 13:14
@mefarazath mefarazath marked this pull request as ready for review August 26, 2024 13:15
@mefarazath mefarazath closed this Aug 26, 2024
@mefarazath mefarazath reopened this Aug 26, 2024
@mefarazath mefarazath changed the title opa: pass URL query parameters to OPA policy evalution opa: pass URL query parameters to OPA policy evaluation Aug 26, 2024
Improve the envoy request adapting logic to include query parameters sent in the request.
This would allow the policy evaluationin opaAuthorizeRequest* and opaServeResponse* filters to make use of query parameters/values in the policy.

Signed-off-by: Farasath Ahamed <[email protected]>
@szuecs szuecs added the bugfix Bug fixes and patches label Aug 26, 2024
@szuecs
Copy link
Member

szuecs commented Aug 26, 2024

👍

@mefarazath
Copy link
Contributor Author

mefarazath commented Aug 27, 2024

@szuecs I added a few more test cases based on review comments (which removed your previous 👍🏻 rightly so with new changes in)
Please take a look approve if everything looks fine.

(Update: there a few comments to address.)

- Use escaped path + raw query string to build the path set in envoy request
- Add test cases to cover few additional special cases (empty query string, space in path)

Signed-off-by: Farasath Ahamed <[email protected]>
@szuecs
Copy link
Member

szuecs commented Sep 6, 2024

2 small things.
Can you resolve comments that are "fixed"? Thanks

@mjungsbluth
Copy link
Collaborator

👍

Comment on lines +15 to +17
if err := validateURLForInvalidUTF8(req.URL); err != nil {
return nil, fmt.Errorf("invalid url: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this check?

Copy link
Contributor Author

@mefarazath mefarazath Sep 12, 2024

Choose a reason for hiding this comment

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

This was done as a part of reducing errors in decision logs in OPA when the http path contained invalid UTF-8 characters. I have extended this check to query params in this PR and moved the check a bit above.
(Introduced in https://github.com/zalando/skipper/pull/3086/files#diff-dee220a324e25f9867826168abe29e559c7291d044fe87d44165c3ef28384c5cR38)

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean decision logs in Skipper or in OPA?

Copy link
Contributor Author

@mefarazath mefarazath Sep 12, 2024

Choose a reason for hiding this comment

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

Sorry I should have been precise. I meant the errors in decision logs in OPA.

Copy link
Member

Choose a reason for hiding this comment

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

So do we want to save a roundtrip here by pre-validating URL?
Can this be done on OPA side, e.g. can it decide to reject request if URL is not valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So do we want to save a roundtrip here by pre-validating URL? Can this be done on OPA side, e.g. can it decide to reject request if URL is not valid?

To be honest, saving the round trip was just a side benefit.

Our main concern was that requests with invalid URLs were failing before even reaching the policy logic (due to parse errors in OPA), but they still generated decision log entries marked as errors. This was creating a lot of noise in some of the application policies, especially when there were frequent malicious requests happening every day. We were worried that this noise could cause the teams to overlook or ignore real policy errors that actually need attention.

@AlexanderYastrebov
Copy link
Member

👍

@MustafaSaber MustafaSaber merged commit 7cb3dc2 into zalando:master Sep 12, 2024
10 checks passed
Pushpalanka pushed a commit that referenced this pull request Oct 11, 2024
Improve the envoy request adapting logic to include query parameters sent in the request.
This would allow the policy evaluationin opaAuthorizeRequest* and opaServeResponse* filters to make use of query parameters/values in the policy.

- Add test cases to cover multi valued query params and trailing ? in URL path

- Change the logic to build path with query params
  - Use escaped path + raw query string to build the path set in envoy request
  - Add test cases to cover few additional special cases (empty query string, space in path)

- Use req.URL.RequestURI() to set the path with query params

Signed-off-by: Farasath Ahamed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Bug fixes and patches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants