-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add HTTP PATCH support to KV #12687
Merged
Add HTTP PATCH support to KV #12687
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…hodSucceeds to specify -method flag
pmmukh
approved these changes
Oct 8, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one question, but lgtm!
ncabatoff
approved these changes
Oct 12, 2021
This was referenced Nov 16, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces support for HTTP
PATCH
into Vault. The ACL layer has been modified to include apatch
capability. Despite the fact that a patch operation could be interpreted as a type of update, the update capability will continue to function as it does today.A
PatchOperation
has been added to the existinglogical.Operation
set. Vault'slogical
request handling will map HTTPPATCH
requests to aPatchOperation
. Currently, Vault will only support JSON merge patch requests which must have aContent-Type
header with a MIME type ofapplication/merge-patch+json
. If an incorrect MIME type has been provided, Vault will respond with415 Unsupported Media Type
.PATCH
requests must be made to existing resources. A404 Not Found
response will be returned to the requester in the case that alogical.Request
handler returns anil
response without an error.To ensure consistent handling of JSON merge patch requests, a global
framework.HandlePatchOperation
function has been provided which accepts request data, the existing resource data, and a preprocessor func (framework.PatchPreprocessorFunc
). The preprocessor is used to ensure the shape of the request data matches the shape of the resource data. Theframework.HandlePatchOperation
function uses a library called json-patch in order to perform the patch operation. The library expects that both the patch document and the existing resource are provided as marshaled JSON in the form of byte arrays. The patch abstraction will be responsible for the following:framework.FieldData
a usingGetOk
method so that unexpected fields are ignored and data types are handled properlyA
JSONMergePatch
function will be added to the Logical API in the Vault Go client. It will set the Content-Type header value to application/merge-patch+json.The existing
vault kv patch
command performs a read, local update, and update in order to achieve a patch operation. The command has been modified to initially attempt an HTTPPATCH
using theJSONMergePatch
function with a fallback to current behavior in the case of a 403 response. The-cas
and-method
flags have also been added to the command.The
-method
flag supports the values ofpatch
andrw
. Thepatch
method will explicitly run the HTTPPATCH
logic. Therw
method will run the existing read-then-write flow.The -cas flag will be used for the check-and-set version if provided for HTTP
PATCH
. The-cas
flag will be ignored for the read-then-write flow. Instead, theversion
value from the secret returned by the read will specify the cas field used in the subsequent write.Documentation PR: #12689
Fixes #1468
Fixes #7437
Fixes #12330