2015-03-04 07:57:23 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2015-03-04 08:35:02 +00:00
|
|
|
"fmt"
|
2015-03-04 08:31:35 +00:00
|
|
|
"os"
|
2015-03-04 07:57:23 +00:00
|
|
|
"strings"
|
2015-03-04 08:31:35 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/vault/helper/password"
|
2015-03-04 07:57:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UnsealCommand is a Command that unseals the vault.
|
|
|
|
type UnsealCommand struct {
|
|
|
|
Meta
|
2015-03-14 03:17:55 +00:00
|
|
|
|
|
|
|
// Key can be used to pre-seed the key. If it is set, it will not
|
|
|
|
// be asked with the `password` helper.
|
|
|
|
Key string
|
2015-03-04 07:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *UnsealCommand) Run(args []string) int {
|
2015-03-04 16:56:10 +00:00
|
|
|
var reset bool
|
2015-03-04 07:57:23 +00:00
|
|
|
flags := c.Meta.FlagSet("unseal", FlagSetDefault)
|
2015-03-04 16:56:10 +00:00
|
|
|
flags.BoolVar(&reset, "reset", false, "")
|
2015-03-04 07:57:23 +00:00
|
|
|
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-03-13 19:58:21 +00:00
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error initializing client: %s", err))
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2015-04-13 01:39:41 +00:00
|
|
|
args = flags.Args()
|
|
|
|
|
2015-03-14 03:17:55 +00:00
|
|
|
value := c.Key
|
2015-04-13 01:39:41 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
value = args[0]
|
|
|
|
}
|
2015-03-14 03:17:55 +00:00
|
|
|
if value == "" {
|
|
|
|
fmt.Printf("Key (will be hidden): ")
|
|
|
|
value, err = password.Read(os.Stdin)
|
2015-04-06 16:34:08 +00:00
|
|
|
fmt.Printf("\n")
|
2015-03-14 03:17:55 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error attempting to ask for password. The raw error message\n"+
|
|
|
|
"is shown below, but the most common reason for this error is\n"+
|
2015-04-13 01:41:42 +00:00
|
|
|
"that you attempted to pipe a value into unseal or you're\n"+
|
|
|
|
"executing `vault unseal` from outside of a terminal.\n\n"+
|
|
|
|
"You should use `vault unseal` from a terminal for maximum\n"+
|
|
|
|
"security. If this isn't an option, the unseal key can be passed\n"+
|
|
|
|
"in using the first parameter.\n\n"+
|
2015-03-14 03:17:55 +00:00
|
|
|
"Raw error: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
2015-03-04 08:31:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 19:58:21 +00:00
|
|
|
status, err := client.Sys().Unseal(strings.TrimSpace(value))
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error attempting unseal: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(fmt.Sprintf(
|
|
|
|
"Sealed: %v\n"+
|
|
|
|
"Key Shares: %d\n"+
|
|
|
|
"Key Threshold: %d\n"+
|
|
|
|
"Unseal Progress: %d",
|
|
|
|
status.Sealed,
|
|
|
|
status.N,
|
|
|
|
status.T,
|
|
|
|
status.Progress,
|
|
|
|
))
|
2015-03-14 03:17:55 +00:00
|
|
|
|
2015-03-04 07:57:23 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *UnsealCommand) Synopsis() string {
|
|
|
|
return "Unseals the vault server"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *UnsealCommand) Help() string {
|
|
|
|
helpText := `
|
2015-04-13 01:39:41 +00:00
|
|
|
Usage: vault unseal [options] [key]
|
2015-03-04 07:57:23 +00:00
|
|
|
|
|
|
|
Unseal the vault by entering a portion of the master key. Once all
|
|
|
|
portions are entered, the Vault will be unsealed.
|
|
|
|
|
|
|
|
Every Vault server initially starts as sealed. It cannot perform any
|
|
|
|
operation except unsealing until it is sealed. Secrets cannot be accessed
|
|
|
|
in any way until the vault is unsealed. This command allows you to enter
|
|
|
|
a portion of the master key to unseal the vault.
|
|
|
|
|
2015-04-13 01:39:41 +00:00
|
|
|
The unseal key can be specified via the command line, but this is
|
|
|
|
not recommended. The key may then live in your terminal history. This
|
|
|
|
only exists to assist in scripting.
|
|
|
|
|
2015-03-04 07:57:23 +00:00
|
|
|
General Options:
|
|
|
|
|
2015-04-28 16:15:38 +00:00
|
|
|
-address=addr The address of the Vault server.
|
2015-03-04 07:57:23 +00:00
|
|
|
|
|
|
|
-ca-cert=path Path to a PEM encoded CA cert file to use to
|
|
|
|
verify the Vault server SSL certificate.
|
|
|
|
|
|
|
|
-ca-path=path Path to a directory of PEM encoded CA cert files
|
|
|
|
to verify the Vault server SSL certificate. If both
|
|
|
|
-ca-cert and -ca-path are specified, -ca-path is used.
|
|
|
|
|
|
|
|
-insecure Do not verify TLS certificate. This is highly
|
|
|
|
not recommended. This is especially not recommended
|
|
|
|
for unsealing a vault.
|
|
|
|
|
2015-03-04 16:56:10 +00:00
|
|
|
Unseal Options:
|
|
|
|
|
|
|
|
-reset Reset the unsealing process by throwing away
|
|
|
|
prior keys in process to unseal the vault.
|
|
|
|
|
2015-03-04 07:57:23 +00:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|