mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-12 17:47:02 +02:00
* Add ability to migrate autoseal to autoseal This adds the ability to migrate from shamir to autoseal, autoseal to shamir, or autoseal to autoseal, by allowing multiple seal stanzas. A disabled stanza will be used as the config being migrated from; this can also be used to provide an unwrap seal on ent over multiple unseals. A new test is added to ensure that autoseal to autoseal works as expected. * Fix test * Provide default shamir info if not given in config * Linting feedback * Remove context var that isn't used * Don't run auto unseal watcher when in migration, and move SetCores to SetSealsForMigration func * Slight logic cleanup * Fix test build and fix bug * Updates * remove GetRecoveryKey function
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package seal
|
|
|
|
import (
|
|
"github.com/hashicorp/errwrap"
|
|
log "github.com/hashicorp/go-hclog"
|
|
"github.com/hashicorp/vault/command/server"
|
|
"github.com/hashicorp/vault/logical"
|
|
"github.com/hashicorp/vault/vault"
|
|
"github.com/hashicorp/vault/vault/seal/alicloudkms"
|
|
)
|
|
|
|
func configureAliCloudKMSSeal(configSeal *server.Seal, infoKeys *[]string, info *map[string]string, logger log.Logger, inseal vault.Seal) (vault.Seal, error) {
|
|
kms := alicloudkms.NewSeal(logger)
|
|
kmsInfo, err := kms.SetConfig(configSeal.Config)
|
|
if err != nil {
|
|
// If the error is any other than logical.KeyNotFoundError, return the error
|
|
if !errwrap.ContainsType(err, new(logical.KeyNotFoundError)) {
|
|
return nil, err
|
|
}
|
|
}
|
|
autoseal := vault.NewAutoSeal(kms)
|
|
if kmsInfo != nil {
|
|
*infoKeys = append(*infoKeys, "Seal Type", "AliCloud KMS Region", "AliCloud KMS KeyID")
|
|
(*info)["Seal Type"] = configSeal.Type
|
|
(*info)["AliCloud KMS Region"] = kmsInfo["region"]
|
|
(*info)["AliCloud KMS KeyID"] = kmsInfo["kms_key_id"]
|
|
if domain, ok := kmsInfo["domain"]; ok {
|
|
*infoKeys = append(*infoKeys, "AliCloud KMS Domain")
|
|
(*info)["AliCloud KMS Domain"] = domain
|
|
}
|
|
}
|
|
return autoseal, nil
|
|
}
|