-
Notifications
You must be signed in to change notification settings - Fork 860
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
Followup: Adding Hashicorp Vault KMS #623
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a8bc111
feat: initial adding of vualt transit backend to sops
gitirabassi 7004d5c
feat(docs): added docs in README.md and in command help
gitirabassi 37d68f1
fix(vault): addressed typos and fixes from autrilla
gitirabassi b5a8928
fix(test): typo while rebasing
gitirabassi 9256361
fix typos and imporve error messages for vault kms
ldue 5350855
rename package from vault to hcvault
ldue b68f1f2
refactor vault keysource url validation
ldue adf1b23
add negative test cases for vault keysource
ldue 086b91f
add hc vault transit config option via objects
ldue d6885b3
remove vault_example.yml
ldue 3372156
streamline key name to snake case
ldue 201f661
rename `BackendPath` to `EnginePath` for hc vault
ldue 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
target | ||
Cargo.lock | ||
vendor/ | ||
coverage.txt | ||
profile.out |
This file contains 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |||||
"go.mozilla.org/sops/v3/cmd/sops/subcommand/updatekeys" | ||||||
"go.mozilla.org/sops/v3/config" | ||||||
"go.mozilla.org/sops/v3/gcpkms" | ||||||
"go.mozilla.org/sops/v3/hcvault" | ||||||
"go.mozilla.org/sops/v3/keys" | ||||||
"go.mozilla.org/sops/v3/keyservice" | ||||||
"go.mozilla.org/sops/v3/kms" | ||||||
|
@@ -78,6 +79,14 @@ func main() { | |||||
(you need to setup google application default credentials. See | ||||||
https://developers.google.com/identity/protocols/application-default-credentials) | ||||||
|
||||||
|
||||||
To encrypt or decrypt a document with HashiCorp Vault's Transit Secret Engine, specify the | ||||||
Vault key URI name in the --hc-vault-transit flag or in the SOPS_VAULT_URIS (eg. https://vault.example.org:8200/v1/transit/keys/dev | ||||||
where 'https://vault.example.org:8200' is the vault server, 'transit' the enginePath, and 'dev' is the name of the key ) | ||||||
environment variable. | ||||||
(you need to enable the Transit Secrets Engine in Vault. See | ||||||
https://www.vaultproject.io/docs/secrets/transit/index.html) | ||||||
|
||||||
To encrypt or decrypt a document with Azure Key Vault, specify the | ||||||
Azure Key Vault key URL in the --azure-kv flag or in the SOPS_AZURE_KEYVAULT_URL | ||||||
environment variable. | ||||||
|
@@ -91,11 +100,11 @@ func main() { | |||||
To use multiple KMS or PGP keys, separate them by commas. For example: | ||||||
$ sops -p "10F2...0A, 85D...B3F21" file.yaml | ||||||
|
||||||
The -p, -k, --gcp-kms and --azure-kv flags are only used to encrypt new documents. Editing | ||||||
The -p, -k, --gcp-kms, --hc-vault-transit and --azure-kv flags are only used to encrypt new documents. Editing | ||||||
or decrypting existing documents can be done with "sops file" or | ||||||
"sops -d file" respectively. The KMS and PGP keys listed in the encrypted | ||||||
documents are used then. To manage master keys in existing documents, use | ||||||
the "add-{kms,pgp,gcp-kms,azure-kv}" and "rm-{kms,pgp,gcp-kms,azure-kv}" flags. | ||||||
the "add-{kms,pgp,gcp-kms,azure-kv,hc-vault-transit}" and "rm-{kms,pgp,gcp-kms,azure-kv,hc-vault-transit}" flags. | ||||||
|
||||||
To use a different GPG binary than the one in your PATH, set SOPS_GPG_EXEC. | ||||||
To use a GPG key server other than gpg.mozilla.org, set SOPS_GPG_KEYSERVER. | ||||||
|
@@ -224,7 +233,7 @@ func main() { | |||||
}, | ||||||
cli.BoolFlag{ | ||||||
Name: "recursive", | ||||||
Usage: "If the source path is a directory, publish all its content recursively", | ||||||
Usage: "If the source path is a directory, publish all its content recursively", | ||||||
}, | ||||||
cli.BoolFlag{ | ||||||
Name: "verbose", | ||||||
|
@@ -351,6 +360,10 @@ func main() { | |||||
Name: "azure-kv", | ||||||
Usage: "the Azure Key Vault key URL the new group should contain. Can be specified more than once", | ||||||
}, | ||||||
cli.StringSliceFlag{ | ||||||
Name: "hc-vault", | ||||||
Usage: "the full vault path to the key used to encrypt/decrypt. Make you choose and configure a key with encrption/decryption enabled (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev'). Can be specified more than once", | ||||||
}, | ||||||
cli.BoolFlag{ | ||||||
Name: "in-place, i", | ||||||
Usage: "write output back to the same file instead of stdout", | ||||||
|
@@ -368,6 +381,7 @@ func main() { | |||||
pgpFps := c.StringSlice("pgp") | ||||||
kmsArns := c.StringSlice("kms") | ||||||
gcpKmses := c.StringSlice("gcp-kms") | ||||||
vaultURIs := c.StringSlice("hc-vault") | ||||||
azkvs := c.StringSlice("azure-kv") | ||||||
var group sops.KeyGroup | ||||||
for _, fp := range pgpFps { | ||||||
|
@@ -379,6 +393,14 @@ func main() { | |||||
for _, kms := range gcpKmses { | ||||||
group = append(group, gcpkms.NewMasterKeyFromResourceID(kms)) | ||||||
} | ||||||
for _, uri := range vaultURIs { | ||||||
k, err := hcvault.NewMasterKeyFromURI(uri) | ||||||
if err != nil { | ||||||
log.WithError(err).Error("Failed to add key") | ||||||
continue | ||||||
} | ||||||
group = append(group, k) | ||||||
} | ||||||
for _, url := range azkvs { | ||||||
k, err := azkv.NewMasterKeyFromURL(url) | ||||||
if err != nil { | ||||||
|
@@ -501,6 +523,11 @@ func main() { | |||||
Usage: "comma separated list of Azure Key Vault URLs", | ||||||
EnvVar: "SOPS_AZURE_KEYVAULT_URLS", | ||||||
}, | ||||||
cli.StringFlag{ | ||||||
Name: "hc-vault--transit", | ||||||
Usage: "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')", | ||||||
EnvVar: "SOPS_VAULT_URIS", | ||||||
}, | ||||||
cli.StringFlag{ | ||||||
Name: "pgp, p", | ||||||
Usage: "comma separated list of PGP fingerprints", | ||||||
|
@@ -550,6 +577,14 @@ func main() { | |||||
Name: "rm-kms", | ||||||
Usage: "remove the provided comma-separated list of KMS ARNs from the list of master keys on the given file", | ||||||
}, | ||||||
cli.StringFlag{ | ||||||
Name: "add-hc-vault-transit", | ||||||
Usage: "add the provided comma-separated list of Vault's URI key to the list of master keys on the given file ( eg. https://vault.example.org:8200/v1/transit/keys/dev)", | ||||||
}, | ||||||
cli.StringFlag{ | ||||||
Name: "rm-hc-vault-transit", | ||||||
Usage: "remove the provided comma-separated list of Vault's URI key from the list of master keys on the given file ( eg. https://vault.example.org:8200/v1/transit/keys/dev)", | ||||||
}, | ||||||
cli.StringFlag{ | ||||||
Name: "add-pgp", | ||||||
Usage: "add the provided comma-separated list of PGP fingerprints to the list of master keys on the given file", | ||||||
|
@@ -615,8 +650,8 @@ func main() { | |||||
return toExitError(err) | ||||||
} | ||||||
if _, err := os.Stat(fileName); os.IsNotExist(err) { | ||||||
if c.String("add-kms") != "" || c.String("add-pgp") != "" || c.String("add-gcp-kms") != "" || c.String("add-azure-kv") != "" || | ||||||
c.String("rm-kms") != "" || c.String("rm-pgp") != "" || c.String("rm-gcp-kms") != "" || c.String("rm-azure-kv") != "" { | ||||||
if c.String("add-kms") != "" || c.String("add-pgp") != "" || c.String("add-gcp-kms") != "" || c.String("add-hc-vault-transit") != "" || c.String("add-azure-kv") != "" || | ||||||
c.String("rm-kms") != "" || c.String("rm-pgp") != "" || c.String("rm-gcp-kms") != "" || c.String("rm-hc-vault-transit") != "" || c.String("rm-azure-kv") != "" { | ||||||
return common.NewExitError("Error: cannot add or remove keys on non-existent files, use `--kms` and `--pgp` instead.", codes.CannotChangeKeysFromNonExistentFile) | ||||||
} | ||||||
if c.Bool("encrypt") || c.Bool("decrypt") || c.Bool("rotate") { | ||||||
|
@@ -729,6 +764,13 @@ func main() { | |||||
for _, k := range azureKeys { | ||||||
addMasterKeys = append(addMasterKeys, k) | ||||||
} | ||||||
hcVaultKeys, err := hcvault.NewMasterKeysFromURIs(c.String("add-hc-vault-transit")) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
for _, k := range hcVaultKeys { | ||||||
addMasterKeys = append(addMasterKeys, k) | ||||||
} | ||||||
|
||||||
var rmMasterKeys []keys.MasterKey | ||||||
for _, k := range kms.MasterKeysFromArnString(c.String("rm-kms"), kmsEncryptionContext, c.String("aws-profile")) { | ||||||
|
@@ -747,6 +789,14 @@ func main() { | |||||
for _, k := range azureKeys { | ||||||
rmMasterKeys = append(rmMasterKeys, k) | ||||||
} | ||||||
hcVaultKeys, err = hcvault.NewMasterKeysFromURIs(c.String("rm-hc-vault-transit")) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
for _, k := range hcVaultKeys { | ||||||
rmMasterKeys = append(rmMasterKeys, k) | ||||||
} | ||||||
|
||||||
output, err = rotate(rotateOpts{ | ||||||
OutputStore: outputStore, | ||||||
InputStore: inputStore, | ||||||
|
@@ -938,6 +988,7 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) { | |||||
var pgpKeys []keys.MasterKey | ||||||
var cloudKmsKeys []keys.MasterKey | ||||||
var azkvKeys []keys.MasterKey | ||||||
var hcVaultMkKeys []keys.MasterKey | ||||||
kmsEncryptionContext := kms.ParseKMSContext(c.String("encryption-context")) | ||||||
if c.String("encryption-context") != "" && kmsEncryptionContext == nil { | ||||||
return nil, common.NewExitError("Invalid KMS encryption context format", codes.ErrorInvalidKMSEncryptionContextFormat) | ||||||
|
@@ -961,12 +1012,21 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) { | |||||
azkvKeys = append(azkvKeys, k) | ||||||
} | ||||||
} | ||||||
if c.String("hc-vault-transit") != "" { | ||||||
hcVaultKeys, err := hcvault.NewMasterKeysFromURIs(c.String("vault")) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
for _, k := range hcVaultKeys { | ||||||
hcVaultMkKeys = append(hcVaultMkKeys, k) | ||||||
} | ||||||
} | ||||||
if c.String("pgp") != "" { | ||||||
for _, k := range pgp.MasterKeysFromFingerprintString(c.String("pgp")) { | ||||||
pgpKeys = append(pgpKeys, k) | ||||||
} | ||||||
} | ||||||
if c.String("kms") == "" && c.String("pgp") == "" && c.String("gcp-kms") == "" && c.String("azure-kv") == "" { | ||||||
if c.String("kms") == "" && c.String("pgp") == "" && c.String("gcp-kms") == "" && c.String("azure-kv") == "" && c.String("vault") == "" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
conf, err := loadConfig(c, file, kmsEncryptionContext) | ||||||
// config file might just not be supplied, without any error | ||||||
if conf == nil { | ||||||
|
@@ -983,6 +1043,8 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) { | |||||
group = append(group, cloudKmsKeys...) | ||||||
group = append(group, azkvKeys...) | ||||||
group = append(group, pgpKeys...) | ||||||
group = append(group, hcVaultMkKeys...) | ||||||
log.Infof("Master keys available: %+v", group) | ||||||
return []sops.KeyGroup{group}, nil | ||||||
} | ||||||
|
||||||
|
This file contains 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.
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.