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

VAULT-19278 Static secret caching docs #23621

Merged
merged 16 commits into from
Nov 2, 2023
Merged

Conversation

VioletHynes
Copy link
Contributor

@VioletHynes VioletHynes commented Oct 11, 2023

The docs for the static secret caching feature!

As part of this PR, I corrected some capitalization of Agent and Proxy that seems to have been adjusted from the following PR: #21426. Proxy and Agent should be capitalized, just like Vault.

The feature isn't fully implemented yet (at time of raising this docs PR), but I had an opportune time to write these, and I can include an update to the docs if anything small needs to be updated, but I doubt anything major will change at this point.

@VioletHynes VioletHynes requested a review from a team as a code owner October 11, 2023 18:55
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Oct 11, 2023
@VioletHynes VioletHynes added this to the 1.16.0-rc1 milestone Oct 11, 2023
@github-actions
Copy link

Build Results:
All builds succeeded! ✅

@github-actions
Copy link

CI Results:
All Go tests succeeded! ✅

Copy link
Contributor

@kubawi kubawi left a comment

Choose a reason for hiding this comment

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

Hey, I've found two unfinished sentences that made it to the PR, so leaving a request changes, but other than these the docs look good. Thanks for taking the time to fix capitalisation in so many places, our docs will look slicker now.

Copy link
Contributor

@kubawi kubawi left a comment

Choose a reason for hiding this comment

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

LGTM!


Vault Agent's API Proxy functionality allows you to use Vault Agent's API as a proxy
for Vault's API.

~> Note: This functionality will be deprecated in a future release. Please
switch to using [Vault Proxy](/vault/docs/agent-and-proxy/proxy) for API proxying purposes, instead.

~> Note: Unlike Vault Agent, [Vault Proxy](/vault/docs/agent-and-proxy/proxy) supports
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't Vault Agent support static secret caching? This statement is misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't support static secret caching through it's API proxy -- while templating it does output templates to files, which acts like a cache in case of downtime but, the cache subsystem of Agent doesn't support it, nor does the API proxy.

I'll try and reword this so it's clearer! Thanks!


Vault Agent's API Proxy functionality allows you to use Vault Agent's API as a proxy
for Vault's API.

~> Note: This functionality will be deprecated in a future release. Please
switch to using [Vault Proxy](/vault/docs/agent-and-proxy/proxy) for API proxying purposes, instead.

~> Note: Unlike Vault Agent, [Vault Proxy](/vault/docs/agent-and-proxy/proxy) supports
[the caching of static secrets](/vault/docs/agent-and-proxy/proxy/caching/static-secret-caching)
(KVv1 and KVv2) through its API proxy, requiring less requests to be forwarded to Vault itself. We recommend
Copy link
Contributor

Choose a reason for hiding this comment

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

(KVv1 and KVv2) through its API proxy, requiring less requests to be forwarded to Vault itself. We recommend

should be

(KVv1 and KVv2) through its API proxy, requiring fewer requests to be forwarded to Vault itself. We recommend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! I always get less/fewer mixed up :P

Copy link
Contributor

@schavis schavis left a comment

Choose a reason for hiding this comment

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

I still need to review the new static secret doc, will try to get that done later this afternoon

# Vault agent caching
# Vault Agent caching

~> Note: Unlike Vault Agent, [Vault Proxy](/vault/docs/agent-and-proxy/proxy) supports
Copy link
Contributor

Choose a reason for hiding this comment

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

If we think this note will be useful in other places in the future, I would recommend making it into a partial so it's easier to maintain the language going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're planning on deprecating the API proxy aspect of Agent in the future, so (and perhaps this is optimistic), we'll hopefully be able to remove this when we do. To put it another way, though, we won't be adding any new functionality or pages to Agent's API proxy functionality

Comment on lines 42 to 45
Vault Proxy can be configured to cache KVv1 and KVv2 secrets as well as dynamic secrets described
above. This means that, when enabled, subsequent requests to the same KV secret made via Proxy will
only result in a single request made to Vault. Proxy will keep a single cache entry of the secret in its
cache, and will only provide the cached response to requests made with tokens that can access the secret.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Vault Proxy can be configured to cache KVv1 and KVv2 secrets as well as dynamic secrets described
above. This means that, when enabled, subsequent requests to the same KV secret made via Proxy will
only result in a single request made to Vault. Proxy will keep a single cache entry of the secret in its
cache, and will only provide the cached response to requests made with tokens that can access the secret.
You can configure Vault Proxy to cache dynamic secrets and static, KVv1 and KVv2
secrets. When you enable caching for static secrets. Proxy keeps a cached entry
of the secret but only provides the cached response to requests made with tokens
that can access the secret. As a result, multiple requests to Vault Proxy for
the same KV secret only require a single, initial request made to Vault.

Style correction: write in active voice, speak directly to the reader, avoid "this" as a pronoun

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I slightly reworded the last sentence to hopefully be clearer:
initial request made to Vault
->
initial request to be forwarded to Vault

To hopefully make it clear that Proxy does the forwarding for you, and the client doesn't need to send the request to Vault itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave this un-resolved to give you a chance to review the updated wording -- let me know if you disagree and I can change it back :)

Comment on lines 63 to 66
If a token requests a KV secret, we store in the cache that this token has the capability to access a secret.
Therefore, subsequent requests by the same token will be able to access this secret from the cache. For a second
token to access the same secret, it must first complete a successful `GET` to the secret before its permission
to access the secret is cached, and its subsequent requests can be served from the cache instead of Vault itself.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If a token requests a KV secret, we store in the cache that this token has the capability to access a secret.
Therefore, subsequent requests by the same token will be able to access this secret from the cache. For a second
token to access the same secret, it must first complete a successful `GET` to the secret before its permission
to access the secret is cached, and its subsequent requests can be served from the cache instead of Vault itself.
Similarly, when a token requests access to a KV secret, it must complete a
success `GET` request. If the request is successful, Proxy caches the fact that
the token was successful in addition to the result. Subsequent requests by the
same token can then access this secret from the cache instead of Vault.

Style correction: write in active voice, avoid repetitive statements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reads a little confusingly to me, since the token is cached as part of the client making the request, i.e. two requests are not required and it might sound like tokens are not part of client requests somehow? I think your version is still better, and I've updated it, but I wonder if we can still make it clearer

Comment on lines 73 to 80
Vault Proxy will also intermittently check the permissions of tokens that can access cache entries. This interval
defaults to once every five minutes, but is configurable by the `static_secret_token_capability_refresh_interval` configuration.
Every interval, Proxy will perform a call to [`sys/capabilies-self`](/vault/api-docs/system/capabilities-self) on
each token's behalf to validate that it still has previously-demonstrated capabilities to read secrets from the cache.
If there is a difference, and a permission (or the token itself) has been revoked, then the cache will be updated,
and it will no longer be to able access those paths from the cache. Note that the `static_secret_token_capability_refresh_interval`
configuration can be seen as the maximum period after which permission to read a KV secret can be revoked that a
token will retain access.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Vault Proxy will also intermittently check the permissions of tokens that can access cache entries. This interval
defaults to once every five minutes, but is configurable by the `static_secret_token_capability_refresh_interval` configuration.
Every interval, Proxy will perform a call to [`sys/capabilies-self`](/vault/api-docs/system/capabilities-self) on
each token's behalf to validate that it still has previously-demonstrated capabilities to read secrets from the cache.
If there is a difference, and a permission (or the token itself) has been revoked, then the cache will be updated,
and it will no longer be to able access those paths from the cache. Note that the `static_secret_token_capability_refresh_interval`
configuration can be seen as the maximum period after which permission to read a KV secret can be revoked that a
token will retain access.
Vault Proxy also checks and refreshes the access permissions of known tokens
according to the window set with `static_secret_token_capability_refresh_interval`.
By default, the refresh interval is five minutes.
Every interval, Proxy calls [`sys/capabilies-self`](/vault/api-docs/system/capabilities-self) on
behalf of every token in the cache to confirm the token still has permission to
access the cached secret. If the result from Vault indicates that permission (or
the token itself) was revoked, Proxy updates the cache entry so that the affected
token can no longer access the relevant paths from the cache. The refresh interval
is essentially the maximum period after which permission to read a KV secret is
fully revoked for the relevant token.
For token refresh to work, any token that will access the cache also needs
`update` permission for [`sys/capabilies-self`](/vault/api-docs/system/capabilities-self).
Having `update` permission for the token lets Proxy test capabilities for the
token against multiple paths with a single request instead of testing for a `403`
response for each path explicitly.
<Warning title="Refresh with API proxy may affect multiple clients">
If API proxy is configured to use auto-authentication for tokens, **all**
requests that pass through Vault Proxy use the same token. As result, Proxy
makes a single request to Vault every refresh interval, no matter how many
secrets are currently cached.
</Warning>

Style correction: write in active voice, 1 idea per sentence. Also folds in content from earlier in the doc

Copy link
Contributor Author

@VioletHynes VioletHynes Oct 20, 2023

Choose a reason for hiding this comment

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

This was mostly great, but I updated the end for clarity as it was slightly inaccurate (or, at least, could be read in an inaccurate way). I'll leave this unresolved just in case you wanted to re-review.

@schavis
Copy link
Contributor

schavis commented Oct 19, 2023

Apologies for the delay, I pulled into a few things that distracted me for a bit. Let me know if you have any questions about the suggestions.

the Proxy depends on features that do not exist in older Vault server
versions. Whenever possible, we release newer functionality as opt-in
and provide graceful degradation when connecting to an older Vault
server instance. But the new functionality may be required In cases
Copy link
Contributor

Choose a reason for hiding this comment

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

Server

the Proxy depends on features that do not exist in older Vault server
versions. Whenever possible, we release newer functionality as opt-in
and provide graceful degradation when connecting to an older Vault
server instance. But the new functionality may be required In cases
Copy link
Contributor

Choose a reason for hiding this comment

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

"may be required in"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Updated

@VioletHynes VioletHynes merged commit 1c9090b into main Nov 2, 2023
@VioletHynes VioletHynes deleted the docs/violethynes/VAULT-19278 branch November 2, 2023 20:01
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.

4 participants