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

New Mutable Authorized Entry Cache #4451

Merged
merged 4 commits into from
Oct 4, 2023

Conversation

azdagron
Copy link
Member

Introduces a new mutable authorized entry cache. This cache can by dynamically updated with changes to entries and agent selectors.

There is a commit on here go move to go1.21 which can be removed once #4450 is merged.

This cache is not wired up to anything. It is intended to be the caching layer that is built via the entry+agent events polled via the database that @faisal-memon is working on.

@azdagron azdagron force-pushed the authorizedentrycache-new branch from 5c7820c to f9dca51 Compare August 19, 2023 03:54
@azdagron
Copy link
Member Author

Thinking a little more about agent expiry, there won't be an event to know when an agent expires. Needs a little more work there.

@evan2645
Copy link
Member

Done in concert with #4411

pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
@azdagron azdagron mentioned this pull request Sep 15, 2023
7 tasks
@azdagron azdagron force-pushed the authorizedentrycache-new branch from edd7a57 to 850c927 Compare September 23, 2023 18:23
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Andrew Harding <azdagron@gmail.com>
@azdagron azdagron force-pushed the authorizedentrycache-new branch from 850c927 to 029b6a8 Compare September 23, 2023 18:29
@azdagron azdagron marked this pull request as ready for review September 23, 2023 18:29
@azdagron azdagron changed the title WIP: New Mutable Authorized Entry Cache New Mutable Authorized Entry Cache Sep 23, 2023
@azdagron
Copy link
Member Author

@faisal-memon, the cache has now been updated with the capability of having expired agent information pruned from the cache by an outside caller. The "hydrator" glue should call this function on some cadence (maybe hourly? or at the same rate it prunes events?).

pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
}
}

func (c *Cache) stats() cacheStats {
Copy link
Member

Choose a reason for hiding this comment

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

If this function is only used by tests, maybe can be moved to cache_test.go?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't feel super strongly, but my preference would be to keep all of the methods of Cache in the same file. Let me know if you feel more strongly than me and I'll move it :)

pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
pkg/server/authorizedentries/cache.go Outdated Show resolved Hide resolved
Comment on lines +113 to +114
c.agentsByID.ReplaceOrInsert(agent)
c.agentsByExpiresAt.ReplaceOrInsert(agent)
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: looks like it is always done by couple (replace or Delete) in all cache objects that are related.
I wonder if we must have a function that call both.. func (c xxxx) updateAgent(agent) { c.agentsByID.ReplaceOrInsert(agent) \n c.agentsByExpiresAt.ReplaceOrInsert}

but at the same time it feels as an overkill.. because those are called in the function that basically takes care of updating/deleting records...
what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, also feels like overkill to me. I'd rather keep it for now.

return true
})

for _, record := range entryRecordsToDelete {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we found the entryID as an entry that means it will no be an alias right?
so we can avoid next iteration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. Will short-circuit.

Comment on lines +266 to +268
func spiffeIDFromProto(id *types.SPIFFEID) string {
return fmt.Sprintf("spiffe://%s%s", id.TrustDomain, id.Path)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

no a comment for this PR, but it makes me think that we must have parsers like this on in a helper function.
same for isNodeAlias

AliasesBySelector: 2, // one for each selector
}, cache.stats())

cache.RemoveEntry(entry1.Id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

may we add a test case that when removing an invalid entryID nothing change?

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, done.

Comment on lines +268 to +269
expiresAt := now.Add(time.Hour * time.Duration(1+len(a.agents)))
a.agents[node] = agentInfo{
Copy link
Collaborator

Choose a reason for hiding this comment

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

is not it preventing to test cases where we have 2 agents with the same time? may we test that scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

Restructured the test to test this.

case a.EntryID > b.EntryID:
return false
default:
return a.ParentID < b.ParentID
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe I'm missing something, but this means that we have 2 entries with the same EntryID? so technically we may never get into this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, you are right. I'll clean this up.

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.

LGTM!, but need to resolve DCO

@azdagron azdagron force-pushed the authorizedentrycache-new branch from be21b22 to 463f446 Compare October 4, 2023 15:15
@azdagron
Copy link
Member Author

azdagron commented Oct 4, 2023

Ugg, i really need to add my commit hook back.... thanks :)

@azdagron azdagron merged commit 420db05 into spiffe:main Oct 4, 2023
@azdagron azdagron deleted the authorizedentrycache-new branch October 4, 2023 21:24
faisal-memon pushed a commit to faisal-memon/spire that referenced this pull request Oct 9, 2023
Signed-off-by: Andrew Harding <azdagron@gmail.com>
Signed-off-by: Faisal Memon <fymemon@yahoo.com>
@amartinezfayo amartinezfayo modified the milestones: 1.8.1, 1.8.2, 1.8.3 Oct 11, 2023
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.

4 participants