Skip to content

Conversation

@tjons
Copy link
Collaborator

@tjons tjons commented Jun 15, 2025

Resolves #710

I'm debatable if we should actually merge the functionality change here. We currently send the full check request to the interpreter for policy evaluation. However, a user recently expressed the desire to be able to validate SPIFFE principal identities via the plugin. The plugin technically supports this today, but it's a) not clearly documented and b) requires a significant amount of understanding of both how the plugin and Envoy work.

This PR adds a new input variable, source_principal that extracts the source peer principal and makes it available as a top level input for use in policy evaluation. I didn't even realize that we do indeed send the entire proto until I had completed the work, which is probably a good indicator that the UX here can be improved, since I'm pretty deep in the plugin.

I'm open to thoughts about whether this should, or shouldn't, be added. If we decide not to surface it as a top-level input variable, I can remove that part and keep the authorization test, as I think that at least has some value for others looking through the codebase.

@tjons tjons force-pushed the tjons/710-checkrequest-spiffe branch from a61257d to 43ca3ed Compare June 16, 2025 00:46
Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

Regarding a) not clearly documented: what's the discoverability of the new attribute? Do we need to also update documentation/examples? If so, would it be more complicated to simply describe how to retrieve the principal from where it's available today?

That said, I don't see a reason for not making it easier for policy authors by surfacing a new input attribute, even if it introduces some redundancy. This is the case for some of the other top-level input attributes, right?

@tjons
Copy link
Collaborator Author

tjons commented Jun 23, 2025

@johanfylling thanks for your feedback! I'm glad you see some value here, I've spent some time thinking about it and I'm more convinced of my own work now too :)

That said, I don't see a reason for not making it easier for policy authors by surfacing a new input attribute, even if it introduces some redundancy. This is the case for some of the other top-level input attributes, right?

somewhat, but we transform all of them in one way or another, like the parsed body and parsed path variables: https://github.com/open-policy-agent/opa-envoy-plugin/blob/main/envoyauth/request.go#L74. I think this would be the first fully aliased input, but I think it's probably a significant improvement to usability and discoverability, and I'm thinking that it might be worth thinking about adding more of these to provide a gentler input API for new users in the future.

@tjons tjons force-pushed the tjons/710-checkrequest-spiffe branch from 43ca3ed to 1e9672b Compare June 23, 2025 01:57
@tjons tjons requested a review from johanfylling June 23, 2025 01:57
@remeric
Copy link

remeric commented Jun 25, 2025

Thanks everyone for working on this and all your input, this will be really helpful!

I did want to follow up again and see if the destination principal would also be possible to send as well. There was a little conversation on the original Istio ticket but wasn’t sure if it was ever decided if that was possible or should be done.

Thanks!

@johanfylling
Copy link
Contributor

@tjons, what's the status on this PR? Are you waiting for further input from me? Have you given further thought on my comments regarding also supporting ext_authz_v2.CheckRequest and to default input.source_principal to undefined?

@tjons tjons mentioned this pull request Jun 30, 2025
@tjons tjons force-pushed the tjons/710-checkrequest-spiffe branch from 1e9672b to 05b73c3 Compare June 30, 2025 13:33
@tjons
Copy link
Collaborator Author

tjons commented Jun 30, 2025

@johanfylling thanks for the ping! I think this is ready for a review, I've added support for the v2 API and converted the input.source_principal variable to an ast.Value

@tjons
Copy link
Collaborator Author

tjons commented Jun 30, 2025

Thanks everyone for working on this and all your input, this will be really helpful!

I did want to follow up again and see if the destination principal would also be possible to send as well. There was a little conversation on the original Istio ticket but wasn’t sure if it was ever decided if that was possible or should be done.

Thanks!

Hey @remeric, I'll take a look at that. We may not promote it to a top-level input variable, but it is available today (if sent) with input.request.attributes.destination.principal. I'll be adding some examples once this is all done, including the Istio side, so we'll be sure to better document this in the future.

johanfylling
johanfylling previously approved these changes Jun 30, 2025
Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

Thank you 😃 👍

Just a pair of nits, but no blockers.

@tjons tjons force-pushed the tjons/710-checkrequest-spiffe branch from 05b73c3 to c6e7151 Compare June 30, 2025 17:45
@tjons tjons requested a review from johanfylling June 30, 2025 17:47
@tjons
Copy link
Collaborator Author

tjons commented Jun 30, 2025

@johanfylling nits addressed! I think we're good to go here

@tjons tjons enabled auto-merge (squash) June 30, 2025 17:47
@tjons tjons force-pushed the tjons/710-checkrequest-spiffe branch from c6e7151 to b19f166 Compare July 1, 2025 12:26
Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

Looks great 👍
Thank you!

@tjons tjons merged commit 6d9eccc into open-policy-agent:main Jul 1, 2025
8 checks passed
@ashutosh-narkar
Copy link
Member

Thanks everyone for working on this and all your input, this will be really helpful!
I did want to follow up again and see if the destination principal would also be possible to send as well. There was a little conversation on the original Istio ticket but wasn’t sure if it was ever decided if that was possible or should be done.
Thanks!

Hey @remeric, I'll take a look at that. We may not promote it to a top-level input variable, but it is available today (if sent) with input.request.attributes.destination.principal. I'll be adding some examples once this is all done, including the Istio side, so we'll be sure to better document this in the future.

Thanks for working on this @tjons! When do you think we can have some examples to try out? In the meantime, if you could provide some pointers or examples around how destination.principal can be extracted that would be really helpful. Thanks!

@tjons
Copy link
Collaborator Author

tjons commented Jul 10, 2025

@ashutosh-narkar I'll try to find some time this week, been a bit busy the last few days. The whole v3.CheckRequest is sent as input.request, so simply referencing input.request.attributes.destination.principal should be enough to access it, if and only if it's there. This depends on the stage in the Envoy filter chain that the extauthz filter is applied - if it's before destination is determined, it won't be set, but if it's applied after endpoint selection (painting with a broad brush here), it should be present.

@ashutosh-narkar
Copy link
Member

Thanks for your response @tjons!

cc @remeric

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.

Allow the full envoy checkrequest to be used as input data

5 participants