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

Add patch support #49

Merged
merged 23 commits into from Oct 13, 2021
Merged

Add patch support #49

merged 23 commits into from Oct 13, 2021

Conversation

ccapurso
Copy link
Contributor

@ccapurso ccapurso commented Sep 30, 2021

Overview

Providing supplemental data or performing a partial update to a KV secret entry currently requires a GET request, local update, and PUT request. This process has both security and data integrity implications. Requiring a user to fetch a KV secret’s data in full when attempting to perform a partial update necessitates the read ACL capability for a given endpoint. One might want to allow a user or system to update secret entries but not read them.

Vault PR #12687 introduces support for HTTP PATCH requests, specifically JSON merge patch requests, along with a new patch ACL capability. The new logical operation to handle backend requests is called PatchOperation.

Design of Change

A PatchOperation handler was added to the data path (/<mount>/data/:path). Like the CreateOperation handler, it uses check-and-set and is specified as the cas field within the options map. The cas validation logic was abstracted so that both the CreateOperation and PatchOperation handlers could perform consistent checks.

A PATCH request must be performed on an existing resource. If a key metadata entry exists without data, a 404 is returned with the version (which should be 0), created_time, deletion_time, and destroyed fields. This response payload is consistent for the same scenario in the ReadOperation handler. If no key metadata or data entry exists for the path requested, the PatchOperation short circuits and will ultimately bubble up to a 404 within Vault's response handling logic.

The JSON merge patch abstraction within Vault (framework.HandlePatchOperation) accepts an optional preprocessor function. This is due to the inconsistency between what API endpoints accept as input and what is ultimately stored. In the case of KV's data endpoint, only the map under the data key needs to be stored. The preprocessor function simply pulls that out as the data to use in the JSON merge patch operation with the existing []byte data read from storage for the current version of the secret.

The logic to cleanup old versions has been abstracted so that is performed consistently between the CreateOperation and PatchOperation handlers.

A successful response will include the version, created_time, deletion_time, and destroyed fields for the newly created version of the secret entry.

Related Issues/Pull Requests

@ccapurso ccapurso requested a review from a team September 30, 2021 18:44
path_data.go Outdated Show resolved Hide resolved
path_data.go Outdated Show resolved Hide resolved
path_data.go Outdated Show resolved Hide resolved
@ccapurso ccapurso marked this pull request as ready for review October 4, 2021 16:08
Copy link

@ncabatoff ncabatoff left a comment

Choose a reason for hiding this comment

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

Haven't yet got to the tests but the changes overall look good. And thanks for the wonderful PR description and comments!

go.mod Outdated Show resolved Hide resolved
path_data.go Outdated Show resolved Hide resolved
path_data.go Show resolved Hide resolved
path_data.go Show resolved Hide resolved
@ccapurso ccapurso merged commit eec8a1c into master Oct 13, 2021
@ccapurso ccapurso deleted the add-patch-support branch October 13, 2021 15:45
@ccapurso ccapurso mentioned this pull request Feb 3, 2022
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.

None yet

4 participants