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

SyncAuthorizedEntries RPC implementation #4648

Merged
merged 8 commits into from
Dec 14, 2023

Conversation

azdagron
Copy link
Member

@azdagron azdagron commented Nov 9, 2023

Implements the SyncAuthorizedEntries RPC, which allows agent's to only sync down changes instead of the entire set of entries.

Note that the RPC only switches into revision diff based syncing of entries when the number of authorized entries is more than the entry page size (currently 500). This means that many deployments won't notice a change.

The server-side implementation is always on and available. Agent's only use the RPC if the "use_sync_authorized_entries" feature flag is enabled in the experimental configuration.

Fixes: #3496

Implements the SyncAuthorizedEntries RPC, which allows agent's to only
sync down changes instead of the entire set of entries.

The server-side implementation is always on and available. Agent's only
use the RPC if the "use_sync_authorized_entries" feature flag is enabled
in the experimental configuration.

Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Copy link
Collaborator

@MarcosDY MarcosDY left a comment

Choose a reason for hiding this comment

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

Looks great!!! some minor comments

pkg/agent/client/client.go Outdated Show resolved Hide resolved
pkg/agent/client/client.go Outdated Show resolved Hide resolved
pkg/agent/client/client.go Outdated Show resolved Hide resolved
pkg/agent/client/client.go Show resolved Hide resolved
telemetry.Selectors: serverEntry.Selectors,
telemetry.Error: err.Error(),
}).Warn("Received malformed entry from SPIRE server")
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmm, if it failed to parse (that is unexpected) entry will be removed from cache, like when entry was removed,
is this something you expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I imagine if the agent does not fully understand the entry, then it's dangerous to continue serving the entry. It might have changed in significant, security sensitive ways.

pkg/server/api/entry/v1/service.go Outdated Show resolved Hide resolved
resp.Entries = append(resp.Entries, entriesToSearch[i])
}
entriesToSearch = entriesToSearch[i:]
if len(entriesToSearch) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens if there are some IDs left, to be returned, but we get out of entries? may we log that?
and in case entry not found, nothing is either, and slice is "recalculated" with [0:] that is doing nothing, but may we avoid that?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, the re-slicing to [0:] in this corner case seems ok since it is a valid operation and I think any code added to try and prevent it happening hurts readability....

I'm not sure about logging either. This endpoint is intended for agents and a well-behaving agent won't make a request with IDs that it didn't observe in the initial response. The code is robust against that happening but in practice it would be strange for that to happen.... how strongly do you feel about the logging? I am happy to add it if you are very worried.

More: false,
},
},
// Request nothing
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a test case where you have 3 items, but in the middle one is not found?
that will reasult in a single page of 2
and what happens if the 3rd is not found? (I suspect it will be page with 2 + another page with nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Added test cases.

if totalEntries < 0 || totalEntries > maxEntries {
t.Skip()
}
if staleEntries < 0 || staleEntries > totalEntries {
Copy link
Collaborator

Choose a reason for hiding this comment

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

based in boundaries, it is not possible to happen, but just in case, can you add logs or error? to prevent to have invalid tests? (same for both skip)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fuzzing will very much produce combinations that hit these conditions.

test/spiretest/logs.go Show resolved Hide resolved
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
@azdagron
Copy link
Member Author

I think I've addressed all your comments, @MarcosDY. I also converted the feature flag to an experimental flag. Please let me know if I've missed something!

@MarcosDY MarcosDY added this to the 1.8.7 milestone Dec 14, 2023
@MarcosDY MarcosDY merged commit f8dc824 into spiffe:main Dec 14, 2023
32 checks passed
rushi47 pushed a commit to rushi47/spire that referenced this pull request Apr 11, 2024
* SyncAuthorizedEntries RPC implementation

Implements the SyncAuthorizedEntries RPC, which allows agent's to only
sync down changes instead of the entire set of entries.

The server-side implementation is always on and available. Agent's only
use the RPC if the "use_sync_authorized_entries" feature flag is enabled
in the experimental configuration.

Signed-off-by: Andrew Harding <azdagron@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Introduce SyncAuthorizedEntries RPC
2 participants