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

Add support for dynamic metadata in OPA policies #479

Merged

Conversation

tjons
Copy link
Collaborator

@tjons tjons commented Nov 6, 2023

This PR resolves open-policy-agent/opa#6209 by adding a special dynamic_metadata keyword to the OPA envoy plugin API. When an evaluated policy returns an object with the dynamic_metadata keyword, it will be written to the DynamicMetadata field of the returned CheckResponse. This allows users to emit data from OPA policies that can be consumed elsewhere in the envoy filterchain to enable richer and more dynamic auth scenarios.

@tjons tjons force-pushed the 6209-dynamic-metadata branch from 9591afd to 4e7102a Compare November 6, 2023 16:54
@srenatus
Copy link
Collaborator

srenatus commented Nov 6, 2023

The code looks good! We'll need some docs for that, though, or this fine feature might go unnoticed. Would you be up to raising a companion PR against the OPA docs? 😃

@tjons
Copy link
Collaborator Author

tjons commented Nov 6, 2023

@srenatus yes, was going to ask about that. I'm adding some additional tests too to response_test.go. I noticed a lot of the tests in the internal_test.go file are testing the same features in multiple places... is there sufficient coverage in this PR or should I test dynamic metadata in some of the other areas?

@tjons
Copy link
Collaborator Author

tjons commented Nov 6, 2023

@srenatus see open-policy-agent/opa#6389 for docs PR. I don't think there's a lot of detail needed here but let me know if you think there should be more added.

Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

The changes look good. I had just one small comment. Also having test coverage for the boolean policy decision scenario would be good. Then please squash your commits and we can get this in. Thanks @tjons!

switch decision := result.Decision.(type) {
case bool:
if decision {
return nil, fmt.Errorf("dynamic metadata undefined for simple 'allow'")
Copy link
Member

Choose a reason for hiding this comment

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

What about dynamic metadata undefined for simple 'allow' -> dynamic metadata undefined for boolean decision

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!

@tjons tjons force-pushed the 6209-dynamic-metadata branch from 777fd1d to a3e71fe Compare November 6, 2023 23:03
@tjons
Copy link
Collaborator Author

tjons commented Nov 6, 2023

updated, squashed and pushed @ashutosh-narkar! looking forward to getting this in :)

@tjons tjons requested a review from ashutosh-narkar November 6, 2023 23:04
Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @tjons!

@ashutosh-narkar
Copy link
Member

@tjons can you please fix the commit message body? There are multiple sign-offs in there. This is a good reference to author commit messages.

Signed-off-by: tjons <tyler.schade@solo.io>
@tjons tjons force-pushed the 6209-dynamic-metadata branch from a3e71fe to 41f3797 Compare November 6, 2023 23:22
@tjons
Copy link
Collaborator Author

tjons commented Nov 6, 2023

@ashutosh-narkar done!

@tjons tjons requested a review from ashutosh-narkar November 6, 2023 23:22
@ashutosh-narkar ashutosh-narkar merged commit de4182f into open-policy-agent:main Nov 6, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for dynamic metadata
3 participants