Skip to content

encryption: add cli command cockroach gen encryption-key#26167

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
windchan7:enc-cli
May 29, 2018
Merged

encryption: add cli command cockroach gen encryption-key#26167
craig[bot] merged 1 commit intocockroachdb:masterfrom
windchan7:enc-cli

Conversation

@windchan7
Copy link
Copy Markdown
Contributor

Added cli command cockroach gen encryption-key to generate store keys for
encryption at rest.

Encryption CLI: #19783.
Release note: None

@windchan7 windchan7 requested a review from mberhault May 29, 2018 15:34
@windchan7 windchan7 requested a review from a team as a code owner May 29, 2018 15:34
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

pkg/cli/gen.go Outdated
Short: "generate store key for encryption at rest",
Long: `Generate store key for encryption at rest.

If no size is specified through "--size=48", the size of the key will be 16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should ask for the AES size, not the file size, otherwise there's little point in having this utility.

We should also require the filename and make it an argument, not a flag value.
eg:

cockroach gen encryption-key -s 128 keys/aes-128.key

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we require user to input AES size, or use 128 by default?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

128 is a reasonable default flag value.

pkg/cli/gen.go Outdated
}

// Create the file that stores the key.
keyFile, err := os.Create(encryptionKeyPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should create this file with mode 0600 (owner read/write)

@windchan7
Copy link
Copy Markdown
Contributor Author

@mberhault Updated. But I'm a bit confused why you said this: We should ask for the AES size, not the file size, otherwise there's little point in having this utility.

@mberhault
Copy link
Copy Markdown
Contributor

The main idea behind the CLI is to make it easier for people to generate a key. A bit part of the weirdness if the extra 32 bytes needed as a key ID. So asking for the file size (as opposed to the real key size) doesn't remove that confusion.

@windchan7
Copy link
Copy Markdown
Contributor Author

Thanks for the clarification!

pkg/cli/gen.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uh. That's what os.OpenFile is for, you can open a file with a specific mode. Or dump this entire section and use ioutil.WriteFile, it does exactly what you want.

pkg/cli/gen.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a message to stdout upon success. eg: successfully created AES-128 key: keys/aes-128.key

pkg/cli/gen.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/bytes/bits/

@windchan7
Copy link
Copy Markdown
Contributor Author

Done!

Copy link
Copy Markdown
Contributor

@mberhault mberhault left a comment

Choose a reason for hiding this comment

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

LGTM

pkg/cli/gen.go Outdated
// 32 bytes are reserved for key ID.
keySize := aesSize/8 + 32
b := make([]byte, keySize)
if n, err := rand.Read(b); err != nil || n != keySize {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can skip the n != keySize, crypto/rand.Read guarantees that n == len(b) when err == nil.

Added cli command `cockroach gen encryption-key` to generate store keys for
encryption at rest.

Encryption CLI: cockroachdb#19783.
Release note: None
mberhault pushed a commit to cockroachdb/docs that referenced this pull request May 29, 2018
@mberhault mberhault mentioned this pull request May 29, 2018
29 tasks
@windchan7
Copy link
Copy Markdown
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request May 29, 2018
26143: opt: Enable additional logic tests for opt configs r=andy-kimball a=andy-kimball

Enable more logic tests (orms -> snapshot_unrelated_update).
Fix various bugs and issues that were failing tests.


26158: cli: fix `cockroach quit` r=knz a=knz

Informs/fixes #25870.
Fixes  #26144.

This patch fixes the following:

- the logic in `doShutdown()` aims to ignore errors caused by attempts
  connect to a server which is closing its gRPC channels, but was
  missing one case of such errors: during the initial check whether
  the node was running. This patch causes gRPC "closed connection"
  errors to become also ignored in that case.

- previously if there was a transient gRPC error during a hard
  shutdown whereby the shutdown could still succeed, then `cockroach
  quit` would fail no matter what. This patch makes `cockroach quit`
  retry a hard shutdown.

- the warning messages are now emitted on stderr (via `log.Warningf`)
  instead of stdout.

Release note (bug fix): fix a bug where `cockroach quit` would
erroneously fail even though the node already successfully shut down.

Release note (cli change): `cockroach quit` now emits warning message
on its standard error stream, not standard output.

26165: roachtest: enable periodic heap prof output for kv/splits/nodes=3 r=tschottdorf a=petermattis

See #26081

Release note: None

26167: encryption: add cli command `cockroach gen encryption-key` r=windchan7 a=windchan7

Added cli command `cockroach gen encryption-key` to generate store keys for
encryption at rest.

Encryption CLI: #19783.
Release note: None

Co-authored-by: Andrew Kimball <andyk@cockroachlabs.com>
Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Co-authored-by: Peter Mattis <petermattis@gmail.com>
Co-authored-by: Victor Chen <victor@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 29, 2018

Build succeeded

@craig craig bot merged commit f757482 into cockroachdb:master May 29, 2018
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.

3 participants