2018-09-18 03:03:00 +00:00
|
|
|
package seal
|
|
|
|
|
|
|
|
import (
|
2018-10-19 21:43:57 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/vault/command/server"
|
|
|
|
"github.com/hashicorp/vault/vault"
|
2018-10-29 13:30:24 +00:00
|
|
|
"github.com/hashicorp/vault/vault/seal"
|
2018-09-18 03:03:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ConfigureSeal func(*server.Config, *[]string, *map[string]string, log.Logger, vault.Seal) (vault.Seal, error) = configureSeal
|
|
|
|
)
|
|
|
|
|
2018-10-29 13:30:24 +00:00
|
|
|
func configureSeal(config *server.Config, infoKeys *[]string, info *map[string]string, logger log.Logger, inseal vault.Seal) (outseal vault.Seal, err error) {
|
2018-10-19 21:43:57 +00:00
|
|
|
if config.Seal != nil || os.Getenv("VAULT_SEAL_TYPE") != "" {
|
|
|
|
if config.Seal == nil {
|
|
|
|
config.Seal = &server.Seal{
|
|
|
|
Type: os.Getenv("VAULT_SEAL_TYPE"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch config.Seal.Type {
|
2018-10-29 13:30:24 +00:00
|
|
|
case seal.AliCloudKMS:
|
2018-10-19 21:43:57 +00:00
|
|
|
return configureAliCloudKMSSeal(config, infoKeys, info, logger, inseal)
|
|
|
|
|
2018-10-29 13:30:24 +00:00
|
|
|
case seal.AWSKMS:
|
2018-10-19 21:43:57 +00:00
|
|
|
return configureAWSKMSSeal(config, infoKeys, info, logger, inseal)
|
|
|
|
|
2018-10-29 13:30:24 +00:00
|
|
|
case seal.GCPCKMS:
|
2018-10-19 21:43:57 +00:00
|
|
|
return configureGCPCKMSSeal(config, infoKeys, info, logger, inseal)
|
|
|
|
|
2018-10-29 13:30:24 +00:00
|
|
|
case seal.AzureKeyVault:
|
2018-10-19 21:43:57 +00:00
|
|
|
return configureAzureKeyVaultSeal(config, infoKeys, info, logger, inseal)
|
|
|
|
|
2018-10-29 13:30:24 +00:00
|
|
|
case seal.PKCS11:
|
2018-10-19 21:43:57 +00:00
|
|
|
return nil, fmt.Errorf("Seal type 'pkcs11' requires the Vault Enterprise HSM binary")
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Unknown seal type %q", config.Seal.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
return inseal, nil
|
|
|
|
}
|