Skip to content

Conversation

jrajahalme
Copy link
Member

@jrajahalme jrajahalme commented Oct 4, 2024

Clean up code not that selector cache is transactional, please review by commit:

  • policy: Rename ForEach...WithBroaderID/NarrowerID
  • policy: Remove redundant code left over from CIDR checks
  • policy: cleanups with transactional selector cache
  • policy: Skip checking for deny entries when there are none
  • policy: Remove DatapathKey helpers
  • policy: Clean-up trie iteration helpers
  • policy: Remove dead mapstate_test code

@jrajahalme jrajahalme added kind/cleanup This includes no functional changes. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. labels Oct 4, 2024
@jrajahalme jrajahalme requested a review from a team as a code owner October 4, 2024 12:11
@jrajahalme jrajahalme requested a review from derailed October 4, 2024 12:11
@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 Oct 4, 2024
@jrajahalme jrajahalme added the release-note/misc This PR makes changes that have no direct user impact. label Oct 4, 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 Oct 4, 2024
@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from bc59679 to f075830 Compare October 4, 2024 12:39
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme requested review from nathanjsweet and removed request for derailed October 4, 2024 14:30
@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from f075830 to 5ee18a4 Compare October 4, 2024 16:08
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from 078d781 to ea3b3a2 Compare October 7, 2024 08:42
@jrajahalme jrajahalme requested a review from a team as a code owner October 7, 2024 08:42
@jrajahalme
Copy link
Member Author

Rebased to bypass a broken unit test.

Copy link
Member

@nathanjsweet nathanjsweet left a comment

Choose a reason for hiding this comment

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

One nit or clarification.

@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from ea3b3a2 to 8ecf721 Compare October 8, 2024 18:39
@jrajahalme
Copy link
Member Author

Rebased to resolve merge conflict.

@jrajahalme jrajahalme closed this Oct 8, 2024
@jrajahalme
Copy link
Member Author

jrajahalme commented Oct 8, 2024

GitHub claimed merge conflict with pkg/policy/mapstate.go when there is none. Let's see if reopening the PR gets rid of that.

Turns out my main branch was not updated as expected.

@jrajahalme jrajahalme reopened this Oct 8, 2024
@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from 8ecf721 to ea76835 Compare October 8, 2024 19:13
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme added the dont-merge/blocked Another PR must be merged before this one. label Oct 8, 2024
@jrajahalme
Copy link
Member Author

To be rebased when #35150 merges.

Only the wildcard ANY key can have a "broader ID" than a key with a specific
identity. Likewise only a specific (non-ANY) ID can be a narrower ID.

Clarify this by renaming 'ForEachNarrowerKeyWithBroaderID' as
'ForEachAnyKeyWithNarrowerPortProto' and
'ForEachBroaderKeyWithNarrowerID' as 'ForEachBroaderKeyWithSpecificID'
and moving the check for ANY identity in the new key to the caller.

This change reserves the broader/narrower verbiage to L4 protocol and
port parts of a Key.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
'ForEachNarrowerOrEqualKey(newKey, ...)' only iterates keys with narrower
or equal IDs (as well as proto/ports). A key is narrower or equal if
'newKey.Identity' is '0' (ANY), or if the iterated key's identity is the
same as the newKey's.

'ForEachBroaderOrEqualKey(newKey, ...) only iterates keys with broader of
equal IDs (as well as proto/ports). A key is broader or equal if iterated
key's identity is '0' (ANY), or if the iterated key's identity is the
same as the newKey's.

Given the above the first condition in the removed code blocks is always
true and the code can be simplified accordingly.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Simplify code and clean up comments. No functional changes.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Do not check for deny entries when there are none. In general this is of
marginal benefit, but may allow for unifying the insertion code in
future, removing the "features" flags, as deny related code can be
consistently skipped if there are no deny rules.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Since the removal of CIDR indices and introduction of the transactional
selector cache, there is no difference between the
ForEachBroaderOrEqualDatapathKey and ForEachBroaderOrEqualKey, or
ForEachNarrowerOrEqualDatapathKey and ForEachNarrowerOrEqualKey,
respectively. Remove the "DatapathKey" versions.

No functional changes.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Introduce new trie iteration helpers:
- forSpecificIDs calls 'f' for each non-ANY ID in 'idSet'
- forIDs calls 'f' for each ID in 'idSet'
- forID calls 'f' if 'k.Identity' exists in 'idSet'

Use the above to reduce code duplication and replace use of 'forDescendantIDs' with code like:

    if key.Identity == 0 {
        return msm.forSpecificIDs(k, idSet, f)
    }

No functional changes.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
With transactional selector cache the action `insertBasDeny` is no longer
needed, since the deny entry for the B's identities are already added as
part of A, as in this case A is a deny entry and it includes all the IDs
of B.

Fixes: cilium#34205
Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
It is possible a new entry is not merged if, for example, the new entry
is an allow entry and a deny entry with the same key already exists. When
this happens the skipped entry should not be recorded as a dependency.

To facilitate the above 'addKeyWithChanges()' now returns 'true' if the
entry was added or merged, or 'false' if the entry was skipped.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Allow entries with an default auth type should "inherit" the explicit
auth type of the most specific covering key. Currently we use
'IsSuperSetOf()' to figure out if a key is a covering key to another. We
used to consider keys with the wildcard identity to be less specific than
the keys with a specific identity, regardless of the protocol and
destination port fields. This seems wrong; consider the following example
with three keys/entries:

n ID/proto/port	auth type
3. 43/TCP/80    default auth type
2. */TCP/*      explicit type 2
1. 43/*/*       explicit type 1

Both keys 3 & 2 are covering keys for key 1. The current 'IsSuperSetOf()'
considers 3 to be more specific than 2. Neither of 3 or 2 is a covering
key for each other, so there is some space for interpretation in which of
them should be considered more specific. We have recently changed the
datapath to always consider a key with a more specific
protocol/destination port to be considered the more specific one, and
when they are the same, then consider the key with a specified identity
to be more specific than the key with a wildcard identity. Similarly, for
explicit auth propagation we should consider key 2 to be more specific
covering key for the key 1, as it has more specific L4 (protocol/port)
than key 3.

When inserting key 3, we failed to record key 2 as possibly more specific
key to key 3. 'authPreferredInsert()' is adjusted to note wildcard
identity keys with an explicit auth type as possibly more specific
covering keys than the key being added, so that the auth type of the
entry 3 is not propagated to entry 1.

An existing unit test is modified to reflect this example.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
@jrajahalme jrajahalme force-pushed the policy-mapstate-cleanups branch from ea76835 to b1c427e Compare October 8, 2024 21:42
@jrajahalme jrajahalme removed the dont-merge/blocked Another PR must be merged before this one. label Oct 8, 2024
@jrajahalme
Copy link
Member Author

Rebased after #35150 merged.

@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme enabled auto-merge October 8, 2024 21:44
@jrajahalme jrajahalme added this pull request to the merge queue Oct 9, 2024
@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 Oct 9, 2024
Merged via the queue into cilium:main with commit b62c84e Oct 9, 2024
63 checks passed
@jrajahalme jrajahalme deleted the policy-mapstate-cleanups branch October 9, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup This includes no functional changes. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. 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.

2 participants