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

engineccl: Support JWKS for encryption-at-rest keys and hook up v2 #119913

Merged
merged 4 commits into from Mar 11, 2024

Conversation

bdarnell
Copy link
Member

@bdarnell bdarnell commented Mar 5, 2024

The JWKS format for key files is now supported in addition to the legacy format (which was just raw key bytes). Keys in JWKS format can request the faster V2 encryption implementation, supporting graceful rotation into the new implementation.

Fixes #119767

@bdarnell bdarnell requested review from a team as code owners March 5, 2024 09:17
@bdarnell bdarnell requested a review from jbowens March 5, 2024 09:17
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This command is related to enterprise functionality, so I'm moving it to CCL
before expanding it.

Epic: None
Release note: None
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 5 files at r1, 4 of 4 files at r3, 7 of 7 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @bdarnell and @jbowens)


-- commits line 22 at r3:
[nit] left over


pkg/ccl/cliccl/gen.go line 60 at r4 (raw file):

		case 256:
			et = enginepbccl.EncryptionType_AES_256_CTR_V2
		}

default: return error?


pkg/ccl/storageccl/engineccl/pebble_key_manager.go line 183 at r4 (raw file):

			key.Info.EncryptionType = enginepbccl.EncryptionType_AES256_CTR
		default:
			return nil, errors.Wrapf(jwkErr, "could not parse store key. Key length %d is not valid for old-style key", keyLength)

[nit] If there is a bug when generating a JWK key (or it becomes corrupted for whatever reason), we will get this error. It would be nice to also show the jwkErr in the message.


pkg/ccl/storageccl/engineccl/enginepbccl/key_registry.go line 11 at r4 (raw file):

package enginepbccl

import fmt "fmt"

[nit] the fmt is unnecessary


pkg/ccl/storageccl/engineccl/enginepbccl/key_registry.go line 17 at r4 (raw file):

	switch e {
	case EncryptionType_AES128_CTR:
		return "cockroach-aes-128-ctr-v1", nil

[nit] it's unfortunate (error prone) that we have multiple instances of these string constants. Consider defining them only once in a [...]string{EncryptionType_AES128_CTR: "cockroach-aes-128-ctr-v1", ..} or adding a roundtripping test.

We could also make use of e.String() which is already defined (e.g. return "COCKROACH_" + e.String()).

Copy link
Member Author

@bdarnell bdarnell left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jbowens and @RaduBerinde)


-- commits line 22 at r3:

Previously, RaduBerinde wrote…

[nit] left over

Fixed


pkg/ccl/cliccl/gen.go line 60 at r4 (raw file):

Previously, RaduBerinde wrote…

default: return error?

Sure. It's redundant since we also checked at the top of the function, but it doesn't hurt.


pkg/ccl/storageccl/engineccl/pebble_key_manager.go line 183 at r4 (raw file):

Previously, RaduBerinde wrote…

[nit] If there is a bug when generating a JWK key (or it becomes corrupted for whatever reason), we will get this error. It would be nice to also show the jwkErr in the message.

jwkErr is there as the wrapped error, which I think is the right way to model this in our errors library (I also considered CombineErrors with both jwkErr and a new fmt.Errorf for the old-style key case).

With a small tweak here's what it looks like:

Received unexpected error:
                                could not parse store key. Key length 17 is not valid for old-style key. Parse error for new-style key: failed to unmarshal JWK set: error reading token: EOF

pkg/ccl/storageccl/engineccl/enginepbccl/key_registry.go line 11 at r4 (raw file):

Previously, RaduBerinde wrote…

[nit] the fmt is unnecessary

Weird, I wonder why goimports did that.


pkg/ccl/storageccl/engineccl/enginepbccl/key_registry.go line 17 at r4 (raw file):

Previously, RaduBerinde wrote…

[nit] it's unfortunate (error prone) that we have multiple instances of these string constants. Consider defining them only once in a [...]string{EncryptionType_AES128_CTR: "cockroach-aes-128-ctr-v1", ..} or adding a roundtripping test.

We could also make use of e.String() which is already defined (e.g. return "COCKROACH_" + e.String()).

Meh, I feel better about our ability to manually keep two short lists in sync than to write something clever to avoid the duplication.

Fixes: cockroachdb#119767
Release note (enterprise change): `cockroach gen encryption-key` now
accepts a `--version=2` parameter. Version 2 keys activate a new
encryption implementation with improved performance. This is
expected to become the default in CockroachDB 24.2.
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r6, 6 of 7 files at r7, 1 of 1 files at r8, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jbowens)


pkg/ccl/storageccl/engineccl/pebble_key_manager.go line 183 at r4 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

jwkErr is there as the wrapped error, which I think is the right way to model this in our errors library (I also considered CombineErrors with both jwkErr and a new fmt.Errorf for the old-style key case).

With a small tweak here's what it looks like:

Received unexpected error:
                                could not parse store key. Key length 17 is not valid for old-style key. Parse error for new-style key: failed to unmarshal JWK set: error reading token: EOF

Looks great!

@bdarnell
Copy link
Member Author

bors r=RaduBerinde

@craig
Copy link
Contributor

craig bot commented Mar 11, 2024

Build succeeded:

@craig craig bot merged commit 2e7ab27 into cockroachdb:master Mar 11, 2024
18 checks passed
@bdarnell bdarnell deleted the ear-jwks branch March 11, 2024 08:08
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.

engineccl: Support JWKS format for encryption-at-rest keys
3 participants