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

Define targetRef proto #2888

Merged
merged 17 commits into from
Sep 5, 2023
Merged

Conversation

jaellio
Copy link
Contributor

@jaellio jaellio commented Aug 8, 2023

Resolves #2885.

Part of Replacing WorkloadSelector with TargetRef for Waypoints

Adds a targetRef proto based on the policy attachment concept in Gateway API. Adds the targetRef field to AuthorizationPolicy, RequestAuthentication, Telemetry, and WasmPlugin protos.

Notable changes from design doc: (copied from this comment)

  • ProxyConfig will not have a targetRef
  • targetRef will only be valid for k8s gateways (not istio gateways) due to the complexity
  • Ambient policies will not have workload selectors in the root namespace
  • If a resource with a targetRef is applied to the root namespace it will not be applied mesh wide. Only to the resource it explicitly targets
  • No need for ReferenceGrant because of point 2; policies will be in the same ns as the workloads which will always be the same ns as the waypoints (for beta scope at least)

Remaining work:

  • Add examples to the AuthorizationPolicy, RequestAuthentication, Telemetry, and WasmPlugin protos once the control plane implementation is complete.

@istio-testing
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Aug 8, 2023
@istio-policy-bot
Copy link

😊 Welcome @jaellio! This is either your first contribution to the Istio api repo, or it's been
awhile since you've been here.

You can learn more about the Istio working groups, code of conduct, and contributing guidelines
by referring to Contributing to Istio.

Thanks for contributing!

Courtesy of your friendly welcome wagon.

@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 8, 2023
@jaellio
Copy link
Contributor Author

jaellio commented Aug 8, 2023

/test all

Copy link
Contributor

@MorrisLaw MorrisLaw left a comment

Choose a reason for hiding this comment

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

great work!

type/target_ref.proto Outdated Show resolved Hide resolved
Copy link
Contributor

@MorrisLaw MorrisLaw left a comment

Choose a reason for hiding this comment

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

Don't forget to add release notes as well.

type/target_ref.proto Outdated Show resolved Hide resolved
type/target_ref.proto Outdated Show resolved Hide resolved
Copy link
Contributor

@MorrisLaw MorrisLaw left a comment

Choose a reason for hiding this comment

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

lgtm

@jaellio jaellio marked this pull request as ready for review August 9, 2023 17:59
@jaellio jaellio requested a review from a team as a code owner August 9, 2023 17:59
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Aug 9, 2023
Copy link
Contributor

@costinm costinm left a comment

Choose a reason for hiding this comment

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

Left few comments - interesting that K8S spec doesn't seem to have a section in targetRef, but it does in parentRef in HttpRoute.

That's a pretty large problem for our policies - a gateway may have 100 hostnames and ports, having policy with targetRef=gateway implies the rules apply to all 100, and if users are not careful to add matches on hostname in the policy - bad things happen. Even if they do, it's pretty inefficient.

That could be worked around with gateway merging ( only one listener per gateway ), not sure if that got implemented.

extensions/v1alpha1/wasm.proto Outdated Show resolved Hide resolved
extensions/v1alpha1/wasm.proto Outdated Show resolved Hide resolved
networking/v1beta1/proxy_config.proto Outdated Show resolved Hide resolved
releasenotes/notes/target-ref.yaml Outdated Show resolved Hide resolved
security/v1/authorization_policy.proto Outdated Show resolved Hide resolved
security/v1/request_authentication.proto Outdated Show resolved Hide resolved
@hzxuzhonghu
Copy link
Member

  1. For targetRef = gateway or other kind of resource, how can we know which proxy should the policy apply to?

I think that will be a little hard.

  1. There could be case one CR has tragetRef to another kind of resource like gateway, but ay t0 the gateway doesnot occur yet, how do we handle that?

I think ideally we need to record the reference relationships and trigger handling after the gateway occur, but that would be expensive. Or it could also triggerc a full xds like what we do now. Not sure how this intermediate dependency compared with direct dependency.

@keithmattix
Copy link
Contributor

There could be case one CR has tragetRef to another kind of resource like gateway, but ay t0 the gateway doesnot occur yet, how do we handle that?

I wasn't fully aware that Istio APIs didn't have status until pondering this question. IMO, this is a blocker for adopting policy attachment correctly:

In terms of status, it should be reasonably easy for a user to understand that everything is working - basically, as long as the targeted object exists, and the modifications are valid, the metaresource is valid, and this should be straightforward to communicate in one or two Conditions.

If we implement status, we can report "gateway.networking.k8s.io/Gateway my-gateway does not exist" as an "Invalid" condition. From there, if the Gateway is created afterwards, there's no extra xDS push required; the policy would be taken into account when building the first push context. If the reverse happens (Gateway is created before policy) then yes a full push should probably occur.

@hzxuzhonghu
Copy link
Member

Ther could be some use case like ratelimiting, we need both targetRef and workload selector to apply the ratelimiting policy to a specific client workload.

@keithmattix
Copy link
Contributor

Ther could be some use case like ratelimiting, we need both targetRef and workload selector to apply the ratelimiting policy to a specific client workload.

I'm a bit confused; why would targetRef or workloadSelector have anything to do with the client workload? Policy attaches to the producer service, no?

@hzxuzhonghu
Copy link
Member

Ther could be some use case like ratelimiting, we need both targetRef and workload selector to apply the ratelimiting policy to a specific client workload.

I'm a bit confused; why would targetRef or workloadSelector have anything to do with the client workload? Policy attaches to the producer service, no?

The user need the limit th especific workload only. Nope, the policy can/should also work on consumer side.

@keithmattix
Copy link
Contributor

To my knowledge, Ambient only has producer waypoints/policy. Is that correct @linsun @howardjohn? That decision predates me

Comment on lines 475 to 481
// Optional. The targetRef specifies the waypoint the policy should be
// applied to. The targeted resource specified will determine which
// workloads the authorization policy applies to. The targeted resource
// must be a waypoint. The waypoint must be in the same namespace as
// the authorization policy.
//
// If not set, the policy is applied as defined by the selector.
Copy link
Member

@linsun linsun Aug 31, 2023

Choose a reason for hiding this comment

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

Should we clarify if targetRef not set, it could mean namespace scoped waypoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this might be better captured in an example.

@linsun
Copy link
Member

linsun commented Aug 31, 2023

Hi folks (cc @keithmattix @hzxuzhonghu @howardjohn etc),

Wanted to share some inconsistency between namespace scoped authz policy vs workload centric authz policy. For namespace scoped authz policy, I can continue to use the same authz policy for sidecar and ambient workloads.

For workload scoped authz policy, I would have to create a new authz policy for ambient workloads (using targetRef) along with existing authz policy for sidecar as I start to migrate sidecar to ambient.

Is my understanding correct?

If so, what do you think of supporting worload selector and targetRef (as OR relationship but allow users to declare both) and Istio can apply to it based on data plane option where workload selector is only relevant for sidecar and targetRef is only relevant for ambient waypoints?

@keithmattix
Copy link
Contributor

keithmattix commented Aug 31, 2023

@linsun AuthZ policy in particular has some nuances, specifically in the context of the layer targeted authorization policy proposal that is awaiting approval. If possible, could we move forward with these API changes and hash out the implementation details in the authorization policy PR?

That being said, I think your suggestion matches the direction that @whitneygriffith is going on her implementation

@howardjohn
Copy link
Member

howardjohn commented Aug 31, 2023 via email

@linsun
Copy link
Member

linsun commented Aug 31, 2023

Agreed, user will need to change, just trying to minimize changes for them.

@keithmattix @jaellio i am good with the PR overall. made a comment earlier: #2888 (comment)

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
ProxyConfig, and RequestAuthentication.

Need more examples.

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
comments. Added release note for targetRef.

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
use of taretRef.

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
examples.

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
complete

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
oneof to wasm plugin.

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
targeted resource

Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
extensions/v1alpha1/wasm.proto Outdated Show resolved Hide resolved
extensions/v1alpha1/wasm.proto Outdated Show resolved Hide resolved
type/v1beta1/selector.proto Outdated Show resolved Hide resolved
// multiple child resources. The PolicyTargetReference will be used instead of
// a WorkloadSelector in the RequestAuthentication, AuthorizationPolicy,
// Telemetry, and WasmPlugin CRDs to target k8s Gateway.
message PolicyTargetReference {
Copy link
Member

Choose a reason for hiding this comment

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

Can we give an example YAML referencing a Gateway? Its probably not obvious to most people

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an AuthorizationPolicy example in selector.proto. Is this where you were looking for an example?

type/v1beta1/selector.proto Outdated Show resolved Hide resolved
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
type/v1beta1/selector.proto Outdated Show resolved Hide resolved
type/v1beta1/selector.proto Outdated Show resolved Hide resolved
Signed-off-by: Jackie Elliott <jaellio@microsoft.com>
@istio-testing istio-testing merged commit 283cc40 into istio:master Sep 5, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add targetRef field to Istio CRDs that use workloadSelector