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

Transit BYOK export capabilities #20736

Merged
merged 8 commits into from May 30, 2023
Merged

Transit BYOK export capabilities #20736

merged 8 commits into from May 30, 2023

Conversation

cipherboy
Copy link
Contributor

@cipherboy cipherboy commented May 24, 2023

This still needs tests, but this adds the bulk of the work to support BYOK exporting of keys, now that #17934 has landed.

In particular, the combination of the two features allows an operator to securely establish key material between two separate Transit installations. This potentially allows one cluster to be used as a source cluster (encrypting a large amount of data) and a second cluster to decrypt this data later. This might be useful in hybrid or site-specific deployments of Vault for instance.


I want to make additional changes to bump_version before release, and wanted a way of testing export + import of keys easily, plus wanted to enable this particular use case.

In the future, it might be nice to move UnwrapKey into the shared namespace as well, now that tink is added as a formal dependency.


TODO in this PR:

  • Sanity check test for all key types.
  • Documentation

@cipherboy cipherboy added this to the 1.14 milestone May 24, 2023
@cipherboy cipherboy force-pushed the cipherboy-transit-byok branch 2 times, most recently from 3808ad2 to ad64780 Compare May 24, 2023 16:18
@cipherboy cipherboy added the backport/1.14.x Backport changes to `release/1.14.x` label May 26, 2023
This allows one keysutil to wrap another key, assuming that key has an
type matching one of keysutil's allowed KeyTypes. This allows completing
the BYOK import loop with Transit, allowing imported wrapping keys to
export (wrap) other keys in transit, without having them leave in
plaintext.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Still respecting exportable, we allow encrypted-only export of transit
keys to another cluster using the BYOK semantics.

In particular, this allows an operator to securely establish key
material between two separate Transit installations. This potentially
allows one cluster to be used as a source cluster (encrypting a large
amount of data) and a second cluster to decrypt this data later. This
might be useful in hybrid or site-specific deployments of Vault for
instance.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Also updates to a newer version while we're here.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Copy link
Contributor

@kitography kitography left a comment

Choose a reason for hiding this comment

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

Some nits, but this looks great.

website/content/api-docs/secret/transit.mdx Outdated Show resolved Hide resolved
@@ -41,6 +42,8 @@ import (
"github.com/hashicorp/vault/sdk/helper/jsonutil"
"github.com/hashicorp/vault/sdk/helper/kdf"
"github.com/hashicorp/vault/sdk/logical"

"github.com/google/tink/go/kwp/subtle"
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a nice way to get forward secrecy, that's really cool

Copy link
Contributor

Choose a reason for hiding this comment

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

tink isn't listed within the SDK's go.mod, which is technically should be if we are using it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it?

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 think 812395c would've done so, but I might be wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about that, I see you added them within this PR. Somehow they merged in my head.


// validationFunc verifies the ciphertext, signature or hmac based on the
// set 'feature'
validationFunc := func(keyName string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason this isn't a function external to this call?

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 think it uses variables from above and this follows the existing pattern of tests above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Er, and by above, I mean path_backup_test.go lol :-D

builtin/logical/transit/path_byok.go Show resolved Hide resolved
return nil, fmt.Errorf("no such source key for export")
}
if !b.System().CachingDisabled() {
srcP.Lock(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a potential deadlock here, but I don't think there is much we can do about it and I don't think it's realistic people would call this with inverted params in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, agreed. In general, I think it'd be hard to do inverted semantics unless you were using non-Transit BYOK importing. Given dest is a Transit key, it lacks a private counterpart, and so cannot be exported...

Maybe we delay this !b.System().CachingDisabled() check and first check that the src key has private counterparts, but I don't think that'll help the default case...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah and if caching is enabled disabled the lock is acquired within the b.GetPolicy so we are still hosed.

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.

LGTM, might want to get @schultz-is to have a look through as well.

Co-authored-by: Matt Schultz <975680+schultz-is@users.noreply.github.com>
Copy link
Contributor

@schultz-is schultz-is left a comment

Choose a reason for hiding this comment

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

lgtm!

@cipherboy cipherboy enabled auto-merge (squash) May 30, 2023 21:20
@cipherboy cipherboy merged commit 63ccb60 into main May 30, 2023
92 of 93 checks passed
@cipherboy cipherboy deleted the cipherboy-transit-byok branch May 30, 2023 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.14.x Backport changes to `release/1.14.x` enhancement secret/transit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants