2019-09-04 19:40:54 +00:00
|
|
|
// Copyright © 2019, Oracle and/or its affiliates.
|
|
|
|
package seal
|
|
|
|
|
|
|
|
import (
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
2020-01-11 01:39:52 +00:00
|
|
|
"github.com/hashicorp/go-kms-wrapping/wrappers/ocikms"
|
2019-09-04 19:40:54 +00:00
|
|
|
"github.com/hashicorp/vault/command/server"
|
|
|
|
"github.com/hashicorp/vault/vault"
|
2020-01-11 01:39:52 +00:00
|
|
|
"github.com/hashicorp/vault/vault/seal"
|
2019-09-04 19:40:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func configureOCIKMSSeal(configSeal *server.Seal, infoKeys *[]string, info *map[string]string, logger log.Logger, inseal vault.Seal) (vault.Seal, error) {
|
2020-01-11 01:39:52 +00:00
|
|
|
kms := ocikms.NewWrapper(nil)
|
2019-09-04 19:40:54 +00:00
|
|
|
kmsInfo, err := kms.SetConfig(configSeal.Config)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("error on setting up config for OCI KMS", "error", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-11 01:39:52 +00:00
|
|
|
autoseal := vault.NewAutoSeal(&seal.Access{
|
|
|
|
Wrapper: kms,
|
|
|
|
})
|
2019-09-04 19:40:54 +00:00
|
|
|
if kmsInfo != nil {
|
|
|
|
*infoKeys = append(*infoKeys, "Seal Type", "OCI KMS KeyID")
|
|
|
|
(*info)["Seal Type"] = configSeal.Type
|
2020-01-11 01:39:52 +00:00
|
|
|
(*info)["OCI KMS KeyID"] = kmsInfo[ocikms.KMSConfigKeyID]
|
|
|
|
(*info)["OCI KMS Crypto Endpoint"] = kmsInfo[ocikms.KMSConfigCryptoEndpoint]
|
|
|
|
(*info)["OCI KMS Management Endpoint"] = kmsInfo[ocikms.KMSConfigManagementEndpoint]
|
|
|
|
(*info)["OCI KMS Principal Type"] = kmsInfo["principal_type"]
|
2019-09-04 19:40:54 +00:00
|
|
|
}
|
|
|
|
return autoseal, nil
|
|
|
|
}
|