Skip to content

Conversation

squeed
Copy link
Contributor

@squeed squeed commented Jun 3, 2024

In order to determine applicable identities to which a policy applies, we need to evaluate label selectors. Given that we already have an efficient mechanism for caching label selectors (the SelectorCache), we should use that for subject endpoints as well.

This refactors the PolicyRepository to use the SelectorCache when determining subject identities. It removes yet another static cache of matched identities and a corresponding event bus. It also saves memory in the case of reused selectors, which is common.

An important consideration is that any new identities must be in the SelectorCache before that endpoint is regenerated, or else it will not get the correct set of policies. Indeed this is safe, because identity allocation updates the SelectorCache synchronously, and endpoints must have their security identity allocated before they can use it.

@squeed squeed requested review from a team as code owners June 3, 2024 11:51
@squeed squeed requested review from derailed, aditighag and ldelossa June 3, 2024 11:51
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jun 3, 2024
@github-actions github-actions bot added the sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. label Jun 3, 2024
@squeed squeed requested a review from christarazi June 3, 2024 11:51
@squeed squeed added the release-note/misc This PR makes changes that have no direct user impact. label Jun 3, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jun 3, 2024
@squeed
Copy link
Contributor Author

squeed commented Jun 3, 2024

/test

Copy link
Member

@christarazi christarazi left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, a nice simplification. Just one question below.

I noticed a few legitimate CI failures:

@squeed squeed force-pushed the policyrepo-selectorcache branch from 2c07bc0 to d582284 Compare June 4, 2024 16:15
@squeed
Copy link
Contributor Author

squeed commented Jun 4, 2024

/test

@christarazi
Copy link
Member

https://github.com/cilium/cilium/actions/runs/9370599204/job/25797962137#step:13:179 seems like a relevant failure. Host firewall tests failed again, so seems unlikely to be a flake 🤔

@squeed
Copy link
Contributor Author

squeed commented Jun 5, 2024

Fixed up the integration tests; some of them had incomplete scaffolding now that the SelectorCache is used in a few more places. No logic issues.

@squeed squeed force-pushed the policyrepo-selectorcache branch from e02e801 to 5b17c49 Compare June 5, 2024 08:10
@squeed
Copy link
Contributor Author

squeed commented Jun 5, 2024

/test

@squeed
Copy link
Contributor Author

squeed commented Jun 5, 2024

Host firewall tests do seem to be broken; marking as DNM while I debug

@squeed squeed added the dont-merge/needs-cleanup This PR requires additional development work before merging. label Jun 6, 2024
squeed added 2 commits June 7, 2024 14:28
While computing the delta on an ID allocation, the SelectorCache
incorretly handled the case where a label change caused an identity to
no longer be selected by a selectior.

The only identity that should have mutable labels is the local host, so
this is not actually a visible bug. In preparation for using the
SelectorCache to determine policy targets, however, it is now necessary.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
In order to determine applicable identities to which a policy applies, we
need to evaluate label selectors. Given that we already have an
efficient mechanism for caching label selectors (the SelectorCache), we
should use that for subject endpoints as well.

This refactors the PolicyRepository to use the SelectorCache when
determining subject identities. It removes yet another static cache of
matched identities and a corresponding event bus. It also saves memory
in the case of reused selectors, which is common.

An important consideration is that any new identities must be in the
selectorcache *before* that endpoint is regenerated, or else it will not
get the correct set of policies. Indeed this is safe, because identity
allocation updates the SelectorCache synchronously, and endpoints must
have their security identity allocated before they can use it.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
@squeed squeed force-pushed the policyrepo-selectorcache branch from 5b17c49 to 4068646 Compare June 7, 2024 12:28
@squeed
Copy link
Contributor Author

squeed commented Jun 7, 2024

/ci-ginkgo

@squeed squeed removed the dont-merge/needs-cleanup This PR requires additional development work before merging. label Jun 7, 2024
@squeed
Copy link
Contributor Author

squeed commented Jun 7, 2024

There, fixed a HostFirewall case I hadn't handled correctly. Thanks, CI!

@squeed
Copy link
Contributor Author

squeed commented Jun 7, 2024

/test

Copy link
Contributor

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@squeed Nice work!

@squeed
Copy link
Contributor Author

squeed commented Jun 10, 2024

CI is green. @aditighag / @ldelossa could you give this a review, please?

@aditighag
Copy link
Member

CI is green. @aditighag / @ldelossa could you give this a review, please?

Hi @squeed I don't have full context, and it's perhaps best reviewed by someone else. I'll remove my review assignment. Sorry for the late response.

@aditighag aditighag removed their request for review June 11, 2024 20:01
Copy link
Contributor

@ldelossa ldelossa 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 have the full context but reviewed the changes. The code looks reasonable to me 👍

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 12, 2024
@dylandreimerink
Copy link
Member

Our bot is a bit confused, we still require an approval from @cilium/endpoint, it will auto merge once that is in

@squeed squeed requested a review from christarazi June 12, 2024 16:00
@dylandreimerink dylandreimerink added this pull request to the merge queue Jun 12, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 12, 2024
Merged via the queue into cilium:main with commit 2e2c6c5 Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants