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

Cache trusted cert values, invalidating when anything changes #25421

Merged
merged 6 commits into from
Feb 15, 2024

Conversation

sgmiller
Copy link
Collaborator

Previously, trusted certs were loaded and parsed on every login call. This
is both slow, and means a copy of the trusted certs is in memory per login.
For highly concurrent use this raises Vault's memory usage unnecessarily.

@sgmiller sgmiller requested a review from a team as a code owner February 14, 2024 18:49
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Feb 14, 2024
Copy link

github-actions bot commented Feb 14, 2024

CI Results:
All Go tests succeeded! ✅

Copy link

github-actions bot commented Feb 14, 2024

Build Results:
All builds succeeded! ✅

@sgmiller sgmiller added this to the 1.16.0-rc1 milestone Feb 14, 2024
@sgmiller sgmiller marked this pull request as draft February 15, 2024 15:54
@sgmiller
Copy link
Collaborator Author

sgmiller commented Feb 15, 2024

Converting to draft to add cache sizing and unit tests, docs

@sgmiller sgmiller marked this pull request as ready for review February 15, 2024 16:37
Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

👍

@@ -646,6 +657,13 @@ func (b *backend) loadTrustedCerts(ctx context.Context, storage logical.Storage,
conf.QueryAllServers = conf.QueryAllServers || entry.OcspQueryAllServers
}
}

b.trustedCache.Add(certName, &trusted{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Should this only happen if !b.trustedCacheDisabled

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely, otherwise we're just wasting memory.

Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

Good catch on the atomic bool, completely missed that

@sgmiller sgmiller enabled auto-merge (squash) February 15, 2024 21:32
@sgmiller sgmiller merged commit 734afbe into main Feb 15, 2024
84 checks passed
@sgmiller sgmiller deleted the sgm/vault-23962/cert-cache-trusted branch February 15, 2024 21:48
sgmiller added a commit that referenced this pull request Feb 15, 2024
* Cache trusted cert values, invalidating when anything changes

* rename to something more indicative

* defer

* changelog

* Use an LRU cache rather than a static map so we can't use too much memory.  Add docs, unit tests

* Don't add to cache if disabled.  But this races if just a bool, so make the disabled an atomic
sgmiller added a commit that referenced this pull request Feb 15, 2024
* Cache trusted cert values, invalidating when anything changes

* rename to something more indicative

* defer

* changelog

* Use an LRU cache rather than a static map so we can't use too much memory.  Add docs, unit tests

* Don't add to cache if disabled.  But this races if just a bool, so make the disabled an atomic
sgmiller added a commit that referenced this pull request Feb 20, 2024
#25464)

* Cache trusted cert values, invalidating when anything changes

* rename to something more indicative

* defer

* changelog

* Use an LRU cache rather than a static map so we can't use too much memory.  Add docs, unit tests

* Don't add to cache if disabled.  But this races if just a bool, so make the disabled an atomic
sgmiller added a commit that referenced this pull request Feb 20, 2024
#25465)

* Cache trusted cert values, invalidating when anything changes

* rename to something more indicative

* defer

* changelog

* Use an LRU cache rather than a static map so we can't use too much memory.  Add docs, unit tests

* Don't add to cache if disabled.  But this races if just a bool, so make the disabled an atomic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants