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

Update the text about duplicate priority values #229

Merged
merged 1 commit into from
May 31, 2024

Conversation

danwinship
Copy link
Contributor

Clarify the limits of the undefined behavior when two policies have the same priority.

Fixes #216

/cc @astoycos @tssurya @npinaeva @fasaxc @nathanjsweet @aojea

@k8s-ci-robot
Copy link
Contributor

@danwinship: GitHub didn't allow me to request PR reviews from the following users: fasaxc, nathanjsweet.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Clarify the limits of the undefined behavior when two policies have the same priority.

Fixes #216

/cc @astoycos @tssurya @npinaeva @fasaxc @nathanjsweet @aojea

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 14, 2024
Copy link

netlify bot commented May 14, 2024

Deploy Preview for kubernetes-sigs-network-policy-api ready!

Name Link
🔨 Latest commit 8be8ff5
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-network-policy-api/deploys/6644fcc51ef4bb0008f5f59d
😎 Deploy Preview https://deploy-preview-229--kubernetes-sigs-network-policy-api.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 14, 2024
// The behavior is undefined if two ANP objects have same priority.
// Every AdminNetworkPolicy should have a unique priority value. If multiple
// policies have the same priority, and match the same connection, then it is
// implementation-defined which policy's rules get applied to it.
Copy link
Member

Choose a reason for hiding this comment

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

maybe replace "implementation-defined" with "the policies will be applied in some order"? implementation-defined feels like implementations must tell you an order, but I think the point is to not rely on any specific order here

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 said "implementation-defined" because I wanted to make it clear that different implementations might do different things. I also didn't want to say anything that could be read as implying that the result will be predictable...

Updated... what do you think of the new text?

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 14, 2024
Comment on lines 63 to 66
// Every AdminNetworkPolicy should have a unique priority value; if two (or more)
// policies with the same priority could both match a connection, then there is no
// way for the user to reliably determine which of the policies will actually be
// applied to it.
Copy link
Contributor

Choose a reason for hiding this comment

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

looks nicer now than saying implementation defined..

Suggested change
// Every AdminNetworkPolicy should have a unique priority value; if two (or more)
// policies with the same priority could both match a connection, then there is no
// way for the user to reliably determine which of the policies will actually be
// applied to it.
// Every AdminNetworkPolicy should have a unique priority value; if two (or more)
// policies have the same priority and both have rules that match the same connection at the same index (rules have precedence based on ordering), then there is no
// way for the user to reliably determine which of the policies will actually be
// applied to the connection. If both policies match different non-overlapping connections
// then both policies are expected to work correctly

something like that? I wanted to make sure we highlight the fact that both ANPs are expected to be created and applied correctly at least for the non overlapping case.. don't want to overengineer this but if I have ANP1 at prio3 whose rule0 matches connectionA and ANP2 at prio3 whose rule1 matches connectionA for sure its guaranteed ANP1 wins, so I guess its a combo of prio+precedence when we speak about two ANPs?

Copy link
Member

Choose a reason for hiding this comment

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

if I have ANP1 at prio3 whose rule0 matches connectionA and ANP2 at prio3 whose rule1 matches connectionA for sure its guaranteed ANP1 wins

Wait Is it? I don't think we can count on ANP internal rule ordering when there's conflicting priorities, i.e ordering rule0 vs rule1 across two different ANPs doesn't make much sense to me 🤔 . In this ^^ case based on what Dan has written I would think the rules do overlap (regardless of rule index) and expect that only one of the ANPs takes effect (which one is up to the implementation).

But I'm happy to be told otherwise :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we have ever said how internal precedence works across multiple policies https://github.com/kubernetes-sigs/network-policy-api/blob/main/apis/v1alpha1/adminnetworkpolicy_types.go#L80-L82, so I think we should also add a note there for policies with the same priority, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if I have ANP1 at prio3 whose rule0 matches connectionA and ANP2 at prio3 whose rule1 matches connectionA for sure its guaranteed ANP1 wins

No, that's an allowed implementation, but it's not guaranteed.

eg, assuming "ANP1" and "ANP2" are the actual object names, then in the calico-esque "the ANPs get sorted alphabetically" interpretation, then rule1 in ANP1 has precedence over rule0 in ANP2.

And in the "denies beat allows" example, it depends on the actual rules: if ANP1 rule0 is Allow and ANP2 rule1 is Deny, then the result is Deny.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about: "if two (or more) policies with the same priority could both match a connection, then the implementation can apply any of the matching policies to the connection, and there is no way for the user to reliably determine which one it will choose" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

if I have ANP1 at prio3 whose rule0 matches connectionA and ANP2 at prio3 whose rule1 matches connectionA for sure its guaranteed ANP1 wins

No, that's an allowed implementation, but it's not guaranteed.

eg, assuming "ANP1" and "ANP2" are the actual object names, then in the calico-esque "the ANPs get sorted alphabetically" interpretation, then rule1 in ANP1 has precedence over rule0 in ANP2.

And in the "denies beat allows" example, it depends on the actual rules: if ANP1 rule0 is Allow and ANP2 rule1 is Deny, then the result is Deny.

ah I see your point; withdrawing that statement then.

Copy link
Contributor

Choose a reason for hiding this comment

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

how about: "if two (or more) policies with the same priority could both match a connection, then the implementation can apply any of the matching policies to the connection, and there is no way for the user to reliably determine which one it will choose" ?

yes this works, lgtm

@astoycos
Copy link
Member

astoycos commented May 14, 2024

Only thing I might do is consider adding the #216 link to the comment? I know it's not great to embed issues there but if folks are confused the issue conversation could help clear things up.

@nathanjsweet
Copy link

LGTM

Copy link
Contributor

@tssurya tssurya left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship, tssurya

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit fcd330d into kubernetes-sigs:main May 31, 2024
10 checks passed
@danwinship danwinship deleted the priority-conflict branch May 31, 2024 19:26
@danwinship danwinship mentioned this pull request Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

having two ANPs with the same priority must be well-defined
6 participants