Skip to content

Conversation

jrajahalme
Copy link
Member

@jrajahalme jrajahalme commented Oct 12, 2024

Fixes due to redirects being now created before mapstate is computed:

  • Remove listener from MapStateEntry, was only needed to generate proxyID for proxy port retrieval. Now proxy port is already available before MapStateEntries are created, so the listener name is no longer needed
  • Remove placeholder 'unrealizedRedirectPort', which was only needed when new redirects were created after mapstate had already been computed

Fixes: #35350

Save the old entry value when overridden by deny. MapStateEntry merge logic was simplified by only calling merge() if both entries are allows or denies. Now the caller overrides an allow with deny by overwriting it, but that branch missed the storing of the old value.

Fixes: #34437

Keep policy MapState internals private to the policy package. Replace the MapState interface with a limited set of accessor functions on EndpointPolicy. This way the endpoint does need direct access to the MapState map with the policy package internal bookkeeping.

Do not update the realized policy from the endpoint package when applying map changes to bpf policy maps. This is possible since the realized policy is either the same as the desired policy (when applying incremental changes) or the pending desired policy from which the changes are being applied is going to replace the old realized policy when the endpoint regeneration succeeds. If the endpoint regeneration fails, we also need to have the prior realized policy intact as the "last known good policy" which can be restored against a fresh dump of the policy map.

This also fixes the problem where MapStateEntries inserted from the endpoint package were missing the internal bookkeeping, like "owners", "derivedFromRules", etc.

Simplify denyPreferredInsertWithChanges by updating mapstate directly when iterating and simplify insertion of dependent keys with helpers and by using normal if/else structure.

Removal of the Listener field together with structural changes to keep mapstate internals private speed up BenchmarkRegenerateCIDRDenyPolicyRules by ~17% (~25% less memory used with ~12% less allocations)

@jrajahalme jrajahalme added sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. release-note/misc This PR makes changes that have no direct user impact. labels Oct 12, 2024
@jrajahalme jrajahalme requested review from a team as code owners October 12, 2024 21:18
@jrajahalme jrajahalme marked this pull request as draft October 12, 2024 21:18
@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from da8a2d0 to 8f9502b Compare October 13, 2024 06:28
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch 2 times, most recently from 1709143 to 6294adb Compare October 13, 2024 14:18
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 6294adb to 1b514f7 Compare October 15, 2024 17:31
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 1b514f7 to 09bb775 Compare October 19, 2024 13:27
@jrajahalme jrajahalme marked this pull request as ready for review October 19, 2024 13:27
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 09bb775 to 5647101 Compare October 20, 2024 20:56
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 5647101 to eba9149 Compare October 20, 2024 21:06
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from eba9149 to 5d89f34 Compare October 20, 2024 21:50
@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch 2 times, most recently from 1294849 to 8a6745a Compare October 22, 2024 14:01
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 8a6745a to 0d59c86 Compare October 25, 2024 18:35
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 0d59c86 to 5cdafec Compare October 26, 2024 16:18
@jrajahalme jrajahalme changed the title Policy unexport mapstate internals endpoint/policy: Keep internals separate Oct 26, 2024
@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from 9daa380 to d2fc3be Compare October 30, 2024 15:30
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme requested a review from squeed October 30, 2024 17:04
Redirects are now created before EndpointPolicy, so all redirects already
exist when processing incremental changes for the EndpointPolicy. Hence
'unrealizedRedirectPort' symbol is no longer needed.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Now that proxy redirects are created before mapstate entries, we no
longer need the listener name in the MapStateEntry.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Old value must be saved also when overriding an allow entry with a deny.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Change key tests to validate full MapStateEntries by changing from Equals
to DeepEquals.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Remove extraneous printing and Use t.Logf() instead of fmt.Printf().

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Do not export DerivedFromRules member so that we can change the
implementation later. Remove from tests where it's value was ignored
anyway, and add actual validation for them in the endpoint integration
tests. Note that these were ignored there as well before, so there are
some missing labels, now in comments. To be fixed in forthcoming commits.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Prepare for hiding internals of MapStateEntry by making ChangeState.Old
private.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Remove the following actions in
TestMapState_denyPreferredInsertWithSubnets test left unnecessary since
the introduction of the transactional selector cache:

- insertAWithBProto
- insertAasB
- insertBWithAProto
- insertBWithAProtoAsDeny

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
… entry

Remove unused 'incremental' attribute from policy map updates.

Store the actual delete entry value rather than the missing empty value
in reported mapstate diffs.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Skip updating the realized mapstate when updating bpf policy map, as:

1. Usually the realized mapstate is the same as desired mapstate so there is
   nothing to update

2. The realized mapstate is ephemeral dump from the datapath, there is no
   point updating it.

3. When a new policy has been computed, the new desired mapstate will
   replace the old realized mapstate anyway after the successful policy
   update. If policy update fails use a full policy map dump for restoring
   to the last known good policy.

   Not updating the realized policy also keeps the old realized policy as
   "the last known good" policy that we can restore to when policy update
   fails.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
We generally want to add new policy map entries to avoid transient
drops. Since policy map size is limited, it is possible that adds fail
due to hitting the size limit. In that case it is possible that more
space would be available if any entries are deleted, so it makes sense to
retry after key deletion.

Note that since we no longer update the realized map on successful map
updates, we need to do the full map diff again.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Define mapStateEntry to hold the internal bookkeeping and contain
MapStateEntry without them. This way the containters used for internal
bookkeeping are not exposed to other packages.

Remove the MapState interface that was ill-defined due to mixing &
matching exported and non-exported methods. Within the policy package use
'*mapState' directly, and export the needed functions via
'EndpointPolicy'.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
When an existing entry is updated without changing its IsDeny flag the
update can be done on the 'entries' map without delete from the other
map, or without sanity checking the key.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Upon reflecting on the iterators used when deleting covered entries, or
adding new ones due to precedence, it is safe to add them directly, as
the iterators hold enough state for it to be safe to delete entries on
descendants, and add entries to existing trie nodes.

Simplify insertion of dependent keys with new helpers.

Simplify the structure of 'denyPreferredInsertWithChanges' by not
returning early on the end of the deny block.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
@jrajahalme jrajahalme force-pushed the policy-unexport-mapstate-internals branch from d2fc3be to 2a8d66a Compare October 30, 2024 18:42
@jrajahalme
Copy link
Member Author

Rebased in hopes some CI fixes have been merged to main in the meanwhile...

@jrajahalme
Copy link
Member Author

/test

@squeed
Copy link
Contributor

squeed commented Oct 30, 2024

really really nice. I'm making sure I grok the changes, but these look good to me.

@jrajahalme jrajahalme requested a review from squeed October 31, 2024 09:51
@jrajahalme jrajahalme added this pull request to the merge queue Oct 31, 2024
Merged via the queue into cilium:main with commit 4acea77 Oct 31, 2024
66 checks passed
@jrajahalme jrajahalme deleted the policy-unexport-mapstate-internals branch October 31, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is a bug in the Cilium logic. release-blocker/1.17 This issue will prevent the release of the next version of Cilium. 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