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

Output full secret path in certain kv commands #14301

Merged
merged 10 commits into from
Mar 8, 2022
Merged

Conversation

digivava
Copy link
Collaborator

This PR is meant to mitigate some of the confusion for new Vault users, who often struggle with the discrepancy between the shortened path used by the CLI (secret/foo) and the real secret path (secret/data/foo). This bites people when they've only worked with the CLI but then need to write a policy or make a logical call with our Go and Ruby client libraries.

With this change, vault kv get, vault kv put, vault kv patch, and vault kv metadata get will all output another top-level section when run in table output mode. I did not add this to the kv commands that produce just a simple success message, and I did not add it to kv rollback as it seemed irrelevant given the use case.

Examples:

Creating a new secret:

$ vault kv put secret/my-secret foo=bar
==== Secret Path ====
secret/data/my-secret

======= Metadata =======
Key                Value
---                -----
created_time       2022-02-28T17:29:34.110676Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

Reading a secret:

$ vault kv get secret/my-secret
==== Secret Path ====
secret/data/my-secret

======= Metadata =======
Key                Value
---                -----
created_time       2022-02-28T17:29:34.110676Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

=== Data ===
Key    Value
---    -----
foo    bar

For kv metadata get, the same logic is used, but the header is slightly different:

$ vault kv metadata get secret/my-secret
===== Metadata Path =====
secret/metadata/my-secret

========== Metadata ==========
Key                     Value
---                     -----
cas_required            false
created_time            2022-02-28T17:29:34.110676Z
current_version         1
custom_metadata         <nil>
delete_version_after    0s
max_versions            0
oldest_version          0
updated_time            2022-02-28T17:29:34.110676Z

====== Version 1 ======
Key              Value
---              -----
created_time     2022-02-28T17:29:34.110676Z
deletion_time    n/a
destroyed        false

While "Data Path" may seem more internally accurate and matching with "Metadata Path", I chose to go with "Secret Path" for the main use case (regular kv commands) because I want totally new users who are not familiar with the /data /metadata subcategories to immediately intuit that this is the "real path" to their secret.

@digivava digivava requested a review from a team February 28, 2022 17:39
@vercel vercel bot temporarily deployed to Preview – vault February 28, 2022 17:42 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook February 28, 2022 17:42 Inactive
@vercel vercel bot temporarily deployed to Preview – vault February 28, 2022 17:54 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook February 28, 2022 17:54 Inactive
Copy link
Contributor

@averche averche left a comment

Choose a reason for hiding this comment

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

Small nit comments, otherwise LGTM 👍

command/kv_helpers.go Outdated Show resolved Hide resolved
command/kv_metadata_get.go Outdated Show resolved Hide resolved
command/kv_patch.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 3, 2022 17:13 Inactive
@vercel vercel bot temporarily deployed to Preview – vault March 3, 2022 17:13 Inactive
Copy link
Contributor

@VinnyHC VinnyHC left a comment

Choose a reason for hiding this comment

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

This is a great addition that doesn't seem to muddy things up too much! Do you think there's an easy way to add some tests?

command/kv_put.go Outdated Show resolved Hide resolved
@AnPucel
Copy link
Contributor

AnPucel commented Mar 3, 2022

This is great! So, we decided against adding the Metadata path when returning the secret path due to difficulty?

@digivava
Copy link
Collaborator Author

digivava commented Mar 3, 2022

This is great! So, we decided against adding the Metadata path when returning the secret path due to difficulty?

Yeah, I wasn't able to think of a way to get the metadata path at this point in the code, without breaking for paths that have words like "data" in the actual secret name or mount name.

@vercel vercel bot temporarily deployed to Preview – vault March 3, 2022 18:04 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 3, 2022 18:04 Inactive
@vercel vercel bot temporarily deployed to Preview – vault March 3, 2022 23:14 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 3, 2022 23:14 Inactive
@vercel vercel bot temporarily deployed to Preview – vault March 4, 2022 01:48 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 4, 2022 01:48 Inactive
@vercel vercel bot temporarily deployed to Preview – vault March 7, 2022 19:25 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 7, 2022 19:25 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 8, 2022 16:27 Inactive
@vercel vercel bot temporarily deployed to Preview – vault March 8, 2022 16:27 Inactive
@digivava digivava merged commit 191868d into main Mar 8, 2022
@digivava digivava deleted the digivava/output-full-path branch March 8, 2022 21:17
digivava added a commit that referenced this pull request Mar 10, 2022
* Full secret path in table output of get and put

* Add path output to KV patch and metadata get

* Add changelog

* Don't print secret path for kv-v1

* Make more readable

* Switch around logic to not swallow error

* Add test for secret path

* Fix metadata test

* Add unit test for padequalsigns

* Remove wonky kv get tests
digivava added a commit that referenced this pull request Mar 11, 2022
* Output full secret path in certain kv commands (#14301)

* Full secret path in table output of get and put

* Add path output to KV patch and metadata get

* Add changelog

* Don't print secret path for kv-v1

* Make more readable

* Switch around logic to not swallow error

* Add test for secret path

* Fix metadata test

* Add unit test for padequalsigns

* Remove wonky kv get tests

* Remove unneeded comments (#14423)
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