Skip to content

Allow selecting nodes by CIDR policy#27464

Merged
nathanjsweet merged 5 commits intomainfrom
ft/main/cidr-policy-nodes
Sep 15, 2023
Merged

Allow selecting nodes by CIDR policy#27464
nathanjsweet merged 5 commits intomainfrom
ft/main/cidr-policy-nodes

Conversation

@squeed
Copy link
Copy Markdown
Contributor

@squeed squeed commented Aug 11, 2023

This PR adds a new option, policy-cidr-selects-nodes, which means that cluster nodes can be selected by CIDR network policies. Normally nodes are only accessible via remote-node entity selectors.

How it works:
We already have the notion of an "identity scope" -- if the top 8 bits of the 32-bit identity are 0, we assume the ID is global. If the top bits are 0x01, then the ID is a local CIDR identity. This PR declares the scope 0x02 to be for node identities.

A separate identity scope is needed because the datapath needs to be able to quickly determine if a given identity corresponds to a remote node. Previously, all nodes had reserved identities 4 or 7. By using a separate identity scope, a fast bit comparison can be done without any additional map lookups.

So, most of this PR consists of refactoring commits to prepare for scoped local identity allocators. Then, a few commits at the end enable the behavior, switching nodes to the new identity scope and attaching cidr: labels to the local-node identity.


Fixes: #20550

@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 Aug 11, 2023
@squeed squeed force-pushed the ft/main/cidr-policy-nodes branch from ca47340 to 49b3622 Compare August 15, 2023 16:47
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Aug 16, 2023

CI is not interesting because this is all behind a feature flag. I'll add a do-not-merge commit that changes the default.

@squeed squeed force-pushed the ft/main/cidr-policy-nodes branch from 49b3622 to 0133006 Compare August 16, 2023 14:20
@maintainer-s-little-helper

This comment was marked as outdated.

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Aug 16, 2023
@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Aug 16, 2023

Test failures are all uninteresting; mostly checkpatch related issues (which is intentional) and one test that needs to be updated to handle node identities being enabled by default. Nice!

@nathanjsweet nathanjsweet force-pushed the ft/main/cidr-policy-nodes branch from 0133006 to d5bddb3 Compare September 1, 2023 16:09
@maintainer-s-little-helper

This comment was marked as outdated.

@nathanjsweet nathanjsweet force-pushed the ft/main/cidr-policy-nodes branch from d5bddb3 to 6084a1d Compare September 1, 2023 23:24
@maintainer-s-little-helper

This comment was marked as outdated.

@maintainer-s-little-helper

This comment was marked as outdated.

@squeed
Copy link
Copy Markdown
Contributor Author

squeed commented Sep 6, 2023

All remaining functional tasks are done. This PR is ready for full review. Un-marking as draft.

Note: there is still a do-not-merge commit which forces the feature-flag on. This will be removed before merging. We're working on adding integration tests; these may be added in a follow-up commit, as they will require cilium-cli support.

@squeed squeed marked this pull request as ready for review September 6, 2023 10:26
@squeed squeed requested review from a team as code owners September 6, 2023 10:27
nathanjsweet and others added 2 commits September 14, 2023 10:15
- identity: Properly Assign Host Identity to IPs

  When the option "PolicyCIDRSelectsNodes" is set to true then
  we need to make sure to label all host IPs with their CIDR labels
  as well so that they are selectable.

  When nodemanager adds or updates the local host it is on, the
  IP addresses associated with it are added as labels to the host identity
  before it is initialized for the IPCache entry.

- policy: Unit Tests For Cluster Entity CIDR Selection

  When cluster entities are CIDR selectable via the
  PolicyCIDRMatchMode option, then test for these
  entities being selectable in a policy via a CIDR
  rule.

Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
This adds the ability to enable this NetworkPolicy feature wherein nodes
are selectable by CIDR selectors. Ordinarily this is not allowed.

This commit just wires up the option.

Signed-off-by: Casey Callendrello <cdc@isovalent.com>
@nathanjsweet nathanjsweet force-pushed the ft/main/cidr-policy-nodes branch from 6ff0870 to cd8d773 Compare September 14, 2023 15:16
@nathanjsweet
Copy link
Copy Markdown
Member

/test

@christarazi christarazi added kind/feature This introduces new functionality. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. labels Sep 14, 2023
Copy link
Copy Markdown
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.

LGTM now as there no outstanding concerns. Please go through the remaining unresolved conversations, as I still see 7 as reported by the GH UI.

@nathanjsweet nathanjsweet requested a review from gandro September 14, 2023 18:32
@nathanjsweet
Copy link
Copy Markdown
Member

@gandro I added you to the reviewers to review the "helm" parts. Thanks 🙏 .

@nathanjsweet nathanjsweet merged commit a213d45 into main Sep 15, 2023
@nathanjsweet nathanjsweet deleted the ft/main/cidr-policy-nodes branch September 15, 2023 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects/v1.13 This issue affects v1.13 branch affects/v1.14 This issue affects v1.14 branch backport/author The backport will be carried out by the author of the PR. kind/feature This introduces new functionality. release-note/major This PR introduces major new functionality to Cilium. 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.

Kubernetes network policy for api-server