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

NACL BOX master key support #569

Closed
wants to merge 2 commits into from
Closed

NACL BOX master key support #569

wants to merge 2 commits into from

Conversation

jvehent
Copy link
Contributor

@jvehent jvehent commented Nov 9, 2019

This is work in progress and not yet functional.

The goal is to provide a new type of master key using the NaCl Box protocol that uses local private keys. It's meant to provide an alternative to PGP for those who want to encrypt files locally, without relying on hosted KMS.

I added a new cmdline tool called makenaclboxkey that generates a keypair under $HOME/.sops/naclbox/.

Most of the logic is in place, but I need to finish the integration with the store. Data key encryption works, but nonce and ephemeralpubkey aren't captured in the file metadata.

Early review/feedback much appreciated.

@jvehent jvehent added enhancement priority/low Low priority issues labels Nov 9, 2019
@jvehent jvehent requested review from ajvb and autrilla November 9, 2019 15:46
@jvehent jvehent self-assigned this Nov 9, 2019
Copy link
Contributor

@ajvb ajvb left a comment

Choose a reason for hiding this comment

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

I like this idea and it looks good to me at this point (didn't do a full "code review" at this point). My main concern is that I don't think we should ship two binaries. Subcommands work great and the functionality of makenaclboxkey imo does not call to be a separate binary.

PublicKey, PrivateKey string
}

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have this as a subcommand under the sops binary? Could be sops naclbox-gen or similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, but I'd prefer to keep the longer makenaclboxkey name.

if err != nil {
panic(err)
}
os.MkdirAll(os.Getenv("HOME")+"/.sops/naclbox", 0750)
Copy link
Contributor

Choose a reason for hiding this comment

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

We will need to make sure this is compliant with Windows before we ship.

@jvehent
Copy link
Contributor Author

jvehent commented Nov 11, 2019

I wasn't sure if you wanted this in a subcommand, so thanks for that piece of information.
I also want to implement private key wrapping with a passphrase entered via pinentry before shipping this. Cleartext private keys are bad.

Copy link
Contributor

@autrilla autrilla left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I don't know how to best handle the encrypted private key on disk. Pinentry is okay, but is this something sops should handle? Could we tell people "make sure your home directory is properly encrypted" instead? My concern is that we're never going to be able to implement the authentication mechanisms people are going to want for decryption. E.g. can I use my fingerprint sensor?

PublicKey, PrivateKey string
}

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, but I'd prefer to keep the longer makenaclboxkey name.

// When used in Sops, we don't care much about the sender keypair, but it is
// required for the protocol to work, so we issue an ephemeral keypair instead
// and store its pubkey alongside the encrypted data key, so it can later
// be decrypted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this say "so it can later be reencrypted"? Unless I'm misunderstanding, you're generating a key pair and throwing away the priv key (since it's not going to decrypt anything), and we need to keep it so we can reencrypt the data key in the future if needed without generating a completely new keypair.

// $HOME/.sops/naclbox/<sha256(pubkey)>.key
// where <sha256(pubkey)> is the sha256 hash of the raw public key
h := sha256.Sum256(key.pub[:])
path := fmt.Sprintf("%s/.sops/naclbox/%x.key", os.Getenv("HOME"), h[:])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd split this into several functions to make it a bit easier to understand. There seems to be a few steps going on, e.g. loading the keys, validating them (base64 decoding and such), and actually decrypting

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add an environment variable that allows to relocate they key to a different directory than $HOME.

@jvehent
Copy link
Contributor Author

jvehent commented Nov 12, 2019

@autrilla Quick question about the protobuf of keyservice: I noticed it hasn't been updated in a while, and when I added the new key type and regenerated the pb.go file, it changed it dramatically. In particular, Awsprofile was gone. This seems to break tests in CI
keyservice/server_test.go:60:5: unknown field 'AwsProfile' in struct literal of type KmsKey (but does have Awsprofile)

Do you know what's going on there? Was it manually updated at some point?

@autrilla
Copy link
Contributor

@jvehent I think it's kind of the opposite? Looks like the generated Go code was checked in, but the updated proto definition was not. 4 is the tag previously used for that field, and it's the one you're adding in this PR, so we're good on that side. If you make the name:

-string awsprofile = 4;
+string aws_profile = 4;

It'll also go back to the old generated code name, which I think we should keep.

@Mic92
Copy link
Contributor

Mic92 commented Jul 3, 2020

Hopefully this will create a lot less headaches than gnupg's over-complicated design.

@jimmycuadra jimmycuadra mentioned this pull request Jul 4, 2020
@jvehent
Copy link
Contributor Author

jvehent commented Aug 17, 2020

deprecated in favor of age

@jvehent jvehent closed this Aug 17, 2020
@ajvb ajvb deleted the naclbox branch April 8, 2021 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement priority/low Low priority issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants