-
Notifications
You must be signed in to change notification settings - Fork 2
jepsen: run the existing suites against an encrypted cluster (§8.4) #1232
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
Open
bootjp
wants to merge
2
commits into
main
Choose a base branch
from
design/jepsen-encrypted-cluster
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Command jepsen-encryption-setup produces a KEK-wrapped DEK for the Jepsen | ||
| // harness, which needs one to call `elastickv-admin encryption bootstrap`. | ||
| // | ||
| // This is TEST HARNESS TOOLING, not an operator tool. It exists because | ||
| // bootstrap takes the wrapped DEK bytes as an argument -- an operator gets them | ||
| // from their KMS -- and the Jepsen harness has only a local KEK file. Keeping it | ||
| // here rather than adding an `elastickv-admin` subcommand avoids putting DEK | ||
| // generation into operator-facing tooling, where handling raw key material | ||
| // needs its own design and review. | ||
| // | ||
| // The plaintext DEK never leaves this process: it is generated, wrapped under | ||
| // the KEK, and only the wrapped form is printed. The wrapped DEK is safe to pass | ||
| // on a command line, which is the whole point of the envelope scheme. | ||
| package main | ||
|
|
||
| import ( | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/bootjp/elastickv/internal/encryption" | ||
| "github.com/bootjp/elastickv/internal/encryption/kek" | ||
| "github.com/cockroachdb/errors" | ||
| ) | ||
|
|
||
| func main() { | ||
| if err := run(os.Args[1:], os.Stdout); err != nil { | ||
| fmt.Fprintf(os.Stderr, "jepsen-encryption-setup: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func run(args []string, out *os.File) error { | ||
| fs := flag.NewFlagSet("jepsen-encryption-setup", flag.ContinueOnError) | ||
| kekFile := fs.String("kek-file", "", "path to the §5.1 KEK file (32 raw bytes, owner-only mode)") | ||
| if err := fs.Parse(args); err != nil { | ||
| if errors.Is(err, flag.ErrHelp) { | ||
| return nil | ||
| } | ||
| return errors.Wrap(err, "parse flags") | ||
| } | ||
| if *kekFile == "" { | ||
| return errors.New("--kek-file is required") | ||
| } | ||
| wrapped, err := wrapFreshDEK(*kekFile) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if _, err := fmt.Fprintln(out, wrapped); err != nil { | ||
| return errors.Wrap(err, "write wrapped dek") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // wrapFreshDEK generates one AES-256 DEK and returns its base64 wrapped form. | ||
| func wrapFreshDEK(kekFile string) (string, error) { | ||
| wrapper, err := kek.NewFileWrapper(kekFile) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "open kek file") | ||
| } | ||
| dek := make([]byte, encryption.KeySize) | ||
| if _, err := rand.Read(dek); err != nil { | ||
| return "", errors.Wrap(err, "generate dek") | ||
| } | ||
| wrapped, err := wrapper.Wrap(dek) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "wrap dek") | ||
| } | ||
| return base64.StdEncoding.EncodeToString(wrapped), nil | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/bootjp/elastickv/internal/encryption" | ||
| "github.com/bootjp/elastickv/internal/encryption/kek" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func writeTestKEK(t *testing.T) string { | ||
| t.Helper() | ||
|
|
||
| path := filepath.Join(t.TempDir(), "kek") | ||
| kekBytes := make([]byte, encryption.KeySize) | ||
| for i := range kekBytes { | ||
| kekBytes[i] = byte(i + 1) | ||
| } | ||
| require.NoError(t, os.WriteFile(path, kekBytes, 0o600)) | ||
| return path | ||
| } | ||
|
|
||
| // The wrapped DEK must round-trip through the same wrapper the server uses, or | ||
| // bootstrap would be handed bytes the node cannot unwrap -- and the Jepsen suite | ||
| // would fail at bootstrap instead of running encrypted. | ||
| func TestWrapFreshDEKProducesAnUnwrappableDEK(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| path := writeTestKEK(t) | ||
| encoded, err := wrapFreshDEK(path) | ||
| require.NoError(t, err) | ||
|
|
||
| raw, err := base64.StdEncoding.DecodeString(encoded) | ||
| require.NoError(t, err) | ||
|
|
||
| wrapper, err := kek.NewFileWrapper(path) | ||
| require.NoError(t, err) | ||
| dek, err := wrapper.Unwrap(raw) | ||
| require.NoError(t, err) | ||
| require.Len(t, dek, encryption.KeySize, | ||
| "bootstrap rejects a DEK that is not AES-256") | ||
| } | ||
|
|
||
| // Two invocations must not produce the same DEK: the harness calls this once for | ||
| // the storage DEK and once for the raft DEK, and bootstrap requires them to | ||
| // differ. | ||
| func TestWrapFreshDEKGeneratesADistinctDEKEachCall(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| path := writeTestKEK(t) | ||
| wrapper, err := kek.NewFileWrapper(path) | ||
| require.NoError(t, err) | ||
|
|
||
| seen := make(map[string]struct{}, 8) | ||
| for range 8 { | ||
| encoded, err := wrapFreshDEK(path) | ||
| require.NoError(t, err) | ||
| raw, err := base64.StdEncoding.DecodeString(encoded) | ||
| require.NoError(t, err) | ||
| dek, err := wrapper.Unwrap(raw) | ||
| require.NoError(t, err) | ||
| _, dup := seen[string(dek)] | ||
| require.False(t, dup, "each call must generate a fresh DEK") | ||
| seen[string(dek)] = struct{}{} | ||
| } | ||
| } | ||
|
|
||
| func TestRunRequiresAKEKFile(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| require.Error(t, run(nil, os.Stdout)) | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Because this option is added to
common-cli-opts, the S3, SQS, DynamoDB-types, DynamoDB-multi-table, and Redis-zset entrypoints all accept--encryption; however, their test constructors omit:encryptionwhen buildingekdb/db(a repo-wide search shows onlyredis_workload.cljanddynamodb_workload.cljpropagate it). Those commands therefore silently launch an unencrypted cluster despite the CLI promise. Either propagate the option through every workload using the common options or reject/remove it from unsupported entrypoints.Useful? React with 👍 / 👎.