Skip to content

add huaweicloud kms as the seal wrapper#8590

Closed
zengchen1024 wants to merge 2 commits into
hashicorp:mainfrom
zengchen1024:huaweicloud
Closed

add huaweicloud kms as the seal wrapper#8590
zengchen1024 wants to merge 2 commits into
hashicorp:mainfrom
zengchen1024:huaweicloud

Conversation

@zengchen1024
Copy link
Copy Markdown

No description provided.

@zengchen1024 zengchen1024 force-pushed the huaweicloud branch 2 times, most recently from d17bacc to 88c0a2e Compare March 19, 2020 11:41
@jefferai jefferai changed the title add huaweicloud kms as the seal wrapper [DO NOT MERGE] add huaweicloud kms as the seal wrapper Mar 19, 2020
@jefferai
Copy link
Copy Markdown
Member

Please do not merge until the configutil branch is merged and this is updated to the new paradigm.

@zengchen1024
Copy link
Copy Markdown
Author

@jefferai Is configutil branch merged? Thanks!!!

@jefferai
Copy link
Copy Markdown
Member

Not yet. See #8362 to track.

@pbernal
Copy link
Copy Markdown
Contributor

pbernal commented Jun 12, 2020

@zengchen1024 - FYI, Jeff's configutil branch was merged

@zengchen1024
Copy link
Copy Markdown
Author

@pbernal thanks

@zengchen1024
Copy link
Copy Markdown
Author

@jefferai Could you take a look at this pr? Thanks!!!

@zengchen1024 zengchen1024 changed the title [DO NOT MERGE] add huaweicloud kms as the seal wrapper add huaweicloud kms as the seal wrapper Jun 16, 2020
@zengchen1024
Copy link
Copy Markdown
Author

@jefferai Could you take a look at this pr? Thanks!!!

@niuzhenguo
Copy link
Copy Markdown

@jefferai Can you please have a look at this when you got time, thanks!

@antonin-a
Copy link
Copy Markdown

Hello , we would like to use this one as Vault users. Is there any progress ?

@zengchen1024
Copy link
Copy Markdown
Author

@antonin-a I think it just needs rebase

@osaluden
Copy link
Copy Markdown

osaluden commented Feb 1, 2021

Hi there, do you have any news regarding this feature? Actually we really do need this, thanks a lot for your kind help.

@zengchen1024
Copy link
Copy Markdown
Author

@osaluden I will try

@heatherezell
Copy link
Copy Markdown
Contributor

Hi folks! I wanted to give a quick update. We haven't forgotten about this PR, and we're discussing internally within the engineering team about the support this PR needs and other work that may need to occur with it. I'll be sure to check in again on it, and please feel free to reach out in the future if you haven't heard from me in a while. Thanks for your patience!

@heatherezell
Copy link
Copy Markdown
Contributor

Hello! Due to our lack of ability to test this change, we would prefer not to be the maintainers for this. However, you can please feel free to fork the project and implement it for yourself as needed. Thanks for understanding!

@jefferai
Copy link
Copy Markdown
Member

Just a note -- the upstream go-kms-wrapper lib is undergoing large changes to allow wrappers to be built as plugins. Once that happens, if Vault is updated to support these plugins, you'll be able to provide them as plugin binaries without having to fork Vault. So there's a way forward, depending on Vault's overall roadmap.

@heatherezell
Copy link
Copy Markdown
Contributor

Thanks, @jefferai! Appreciate the info. :)

@osaluden
Copy link
Copy Markdown

Thank you for your feedback, dealing with the plugin way is indeed a good choice :)

@atefhaloui
Copy link
Copy Markdown

Hi,
I've just added the huaweicloud and it's perfectly working. This is my patch against v1.12.2:

diff --git a/go.mod b/go.mod
index 91b6f9b96b..6cdc218848 100644
--- a/go.mod
+++ b/go.mod
@@ -72,6 +72,7 @@ require (
        github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2 v2.0.1
        github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.1
        github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.1
+       github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.0
        github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.0
        github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.1
        github.com/hashicorp/go-memdb v1.3.3
@@ -324,6 +325,7 @@ require (
        github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 // indirect
        github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
        github.com/huandu/xstrings v1.3.2 // indirect
+       github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba // indirect
        github.com/imdario/mergo v0.3.13 // indirect
        github.com/jackc/chunkreader/v2 v2.0.1 // indirect
        github.com/jackc/pgconn v1.11.0 // indirect
diff --git a/go.sum b/go.sum
index 0b119fd3ea..53f160fdf8 100644
--- a/go.sum
+++ b/go.sum
@@ -984,6 +984,8 @@ github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.1 h1:6joKpqC
 github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.1/go.mod h1:sDmsWR/W2LqwU217o32RzdHMb/FywGLF72PVIhpZ3hE=
 github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.1 h1:+paf/3ompzaXe07BdxkV1vTnqvhwtmZPE4yQnMPTThI=
 github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.1/go.mod h1:YRtkersQ2N3iHlPDG5B3xBQtBsNZ3bjmlCwnrl26jVE=
+github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.0 h1:VUJDNM4Y6glGLm/LmaYuQSctuCCenQP1QjuEpFZNbk8=
+github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.0/go.mod h1:8BmhljC25aLYilAe9Md1Sr6ocu/ViY1bgUO1DrQzhP0=
 github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.0 h1:FnWV2E0NLj+yYdhToUQjU81ayCMgURiL2WbJ0V7u/XY=
 github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.0/go.mod h1:17twrc0lM8IpfGqIv69WQvwgDiu3nRwWlk5YfCSQduY=
 github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.1 h1:72zlIBTJd2pvYmINqotpvcI4ZXLxhRq2cVPTuqv0xqY=
@@ -1156,6 +1158,8 @@ github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87/go.mod h1:CtWFDAQg
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
 github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
+github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba h1:KFikP/B8lypq9FTWlxm366g0hVsnLBIV6EwAS4SQcKw=
+github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
diff --git a/internalshared/configutil/kms.go b/internalshared/configutil/kms.go
index 78da77662b..51e9937270 100644
--- a/internalshared/configutil/kms.go
+++ b/internalshared/configutil/kms.go
@@ -15,6 +15,7 @@ import (
        "github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2"
+       "github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2"
        "github.com/hashicorp/go-multierror"
@@ -193,6 +194,9 @@ func configureWrapper(configKMS *KMS, infoKeys *[]string, info *map[string]strin
        case wrapping.WrapperTypePkcs11:
                return nil, fmt.Errorf("KMS type 'pkcs11' requires the Vault Enterprise HSM binary")

+       case wrapping.WrapperTypeHuaweiCloudKms:
+               wrapper, kmsInfo, err = GetHuaweiCloudKMSFunc(configKMS, opts...)
+
        default:
                return nil, fmt.Errorf("Unknown KMS type %q", configKMS.Type)
        }
@@ -342,6 +346,29 @@ var GetTransitKMSFunc = func(kms *KMS, opts ...wrapping.Option) (wrapping.Wrappe
        return wrapper, info, nil
 }

+var GetHuaweiCloudKMSFunc = func(kms *KMS, opts ...wrapping.Option) (wrapping.Wrapper, map[string]string, error) {
+       wrapper := huaweicloudkms.NewWrapper()
+       wrapperInfo, err := wrapper.SetConfig(context.Background(), wrapping.WithConfigMap(kms.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, nil, err
+               }
+       }
+       info := make(map[string]string)
+       if wrapperInfo != nil {
+               info["HuaweiCloud KMS Region"] = wrapperInfo.Metadata["region"]
+               info["HuaweiCloud KMS Project"] = wrapperInfo.Metadata["project"]
+               info["HuaweiCloud KMS Access Key"] = wrapperInfo.Metadata["access_key"]
+               info["HuaweiCloud KMS Secret Key"] = wrapperInfo.Metadata["secret_key"]
+               info["HuaweiCloud KMS KeyID"] = wrapperInfo.Metadata["kms_key_id"]
+               if endpoint, ok := wrapperInfo.Metadata["identity_endpoint"]; ok {
+                       info["HuaweiCloud KMS Identity Endpoint"] = endpoint
+               }
+       }
+       return wrapper, info, nil
+}
+
 func createSecureRandomReader(conf *SharedConfig, wrapper wrapping.Wrapper) (io.Reader, error) {
        return rand.Reader, nil
 }

And associated doc:

diff --git a/website/content/docs/configuration/seal/huaweicloudkms.mdx b/website/content/docs/configuration/seal/huaweicloudkms.mdx
new file mode 100644
index 0000000..42ce637
--- /dev/null
+++ b/website/content/docs/configuration/seal/huaweicloudkms.mdx
@@ -0,0 +1,95 @@
+---
+layout: docs
+page_title: HuaweiCloud KMS - Seals - Configuration
+description: |-
+  The HuaweiCloud KMS seal configures Vault to use HuaweiCloud KMS as the seal wrapping
+  mechanism.
+---
+
+# `huaweicloudkms` Seal
+
+-> **Note:** The Seal Wrap functionality is enabled by default. For this reason, the KMS service must be available throughout Vault's runtime and not just during the unseal process. Refer to the [Seal Wrap](/docs/enterprise/sealwrap) documenation for more information.
+
+The HuaweiCloud KMS seal configures Vault to use HuaweiCloud KMS as the seal wrapping mechanism.
+The HuaweiCloud KMS seal is activated by one of the following:
+
+- The presence of a `seal "huaweicloudkms"` block in Vault's configuration file
+- The presence of the environment variable `VAULT_SEAL_TYPE` set to `huaweicloudkms`. If
+  enabling via environment variable, all other required values specific to HuaweiCloud
+  KMS (i.e. `VAULT_HUAWEICLOUDKMS_SEAL_KEY_ID`) must be also supplied, as well as all
+  other HuaweiCloud-related environment variables that lends to successful
+  authentication (i.e. `HUAWEICLOUD_ACCESS_KEY`, etc.).
+
+## `huaweicloudkms` Example
+
+This example shows configuring HuaweiCloud KMS seal through the Vault configuration file
+by providing all the required values:
+
+```hcl
+seal "huaweicloudkms" {
+  region            = "eu-west-0"
+  project           = "eu-west-0"
+  access_key        = "0wNEpMNlzy7szvbi"
+  secret_key        = "PumkTg9jdmau1cXxYacgE736PJj4cA"
+  kms_key_id        = "18c35a6f-4e0a-4a1b-a9fa-7dfab1d4fa73"
+  identity_endpoint = "https://iam.eu-west-0.prod-cloud-ocb.orange-business.com/v3"
+}
+```
+
+## `huaweicloudkms` Parameters
+
+These parameters apply to the `seal` stanza in the Vault configuration file:
+
+- `region` `(string: <required> "cn-north-1")`: The HuaweiCloud region where the encryption key
+lives. May also be specified by the `HUAWEICLOUD_REGION`
+environment variable.
+
+- `project` `(string: <required> "cn-north-1")`: The HuaweiCloud project where the encryption key
+lives. May also be specified by the `HUAWEICLOUD_PROJECT`
+environment variable.
+
+- `access_key` `(string: <required>)`: The HuaweiCloud access key ID to use. May also be
+specified by the `HUAWEICLOUD_ACCESS_KEY` environment variable.
+
+- `secret_key` `(string: <required>)`: The HuaweiCloud secret access key to use. May
+also be specified by the `HUAWEICLOUD_SECRET_KEY` environment variable.
+
+- `kms_key_id` `(string: <required>)`: The HuaweiCloud KMS key ID to use for encryption
+and decryption. May also be specified by the `VAULT_HUAWEICLOUDKMS_SEAL_KEY_ID`
+environment variable.
+
+- `identity_endpoint` `(string: "")`: The KMS API endpoint to be used to make HuaweiCloud KMS
+  requests. May also be specified by the `HUAWEICLOUD_IDENTITY_ENDPOINT` environment
+  variable. This is useful, for example, when connecting to KMS over a [VPC
+  Endpoint](https://docs.aws.amazon.com/kms/latest/developerguide/kms-vpc-endpoint.html).
+  If not set, Vault will use the default API endpoint for your region.
+
+Refer to the [Seal Migration](/docs/concepts/seal#seal-migration) documentation for more information about the seal migration process.
+
+## Authentication
+
+Authentication-related values must be provided, either as environment
+variables or as configuration parameters.
+
+~> **Note:** Although the configuration file allows you to pass in
+`HUAWEICLOUD_ACCESS_KEY` and `HUAWEICLOUD_SECRET_KEY` as part of the seal's parameters, it
+is _strongly_ recommended to set these values via environment variables.
+
+```text
+HuaweiCloud authentication values:
+* `HUAWEICLOUD_REGION`
+* `HUAWEICLOUD_PROJECT`
+* `HUAWEICLOUD_ACCESS_KEY`
+* `HUAWEICLOUD_SECRET_KEY`
+```
+
+## `huaweicloudkms` Environment Variables
+
+Alternatively, the HuaweiCloud KMS seal can be activated by providing the following
+environment variables:
+
+```text
+Vault Seal specific values:
+* `VAULT_SEAL_TYPE`
+* `VAULT_HUAWEICLOUDKMS_SEAL_KEY_ID`
+```

Cheers

@Matthiator
Copy link
Copy Markdown

hello, what is the status here? Is there a way to accept the pull request or the path from @atefhaloui ?

@atefhaloui
Copy link
Copy Markdown

Hi,
This is the same patch for v1.15.2:

diff --git a/go.mod b/go.mod
index 0fe069045e..17b5514e3b 100644
--- a/go.mod
+++ b/go.mod
@@ -84,12 +84,13 @@ require (
        github.com/hashicorp/go-gcp-common v0.8.0
        github.com/hashicorp/go-hclog v1.5.0
        github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0
-       github.com/hashicorp/go-kms-wrapping/v2 v2.0.13
+       github.com/hashicorp/go-kms-wrapping/v2 v2.0.14
        github.com/hashicorp/go-kms-wrapping/wrappers/aead/v2 v2.0.7-1
        github.com/hashicorp/go-kms-wrapping/wrappers/alicloudkms/v2 v2.0.1
        github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2 v2.0.7
        github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.8
        github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.8
+       github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.1
        github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.7
        github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.8
        github.com/hashicorp/go-memdb v1.3.4
@@ -212,14 +213,14 @@ require (
        go.uber.org/atomic v1.11.0
        go.uber.org/goleak v1.2.1
        golang.org/x/crypto v0.14.0
-       golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
+       golang.org/x/exp v0.0.0-20231006140011-7918f672742d
        golang.org/x/net v0.17.0
        golang.org/x/oauth2 v0.11.0
-       golang.org/x/sync v0.3.0
+       golang.org/x/sync v0.4.0
        golang.org/x/sys v0.13.0
        golang.org/x/term v0.13.0
        golang.org/x/text v0.13.0
-       golang.org/x/tools v0.10.0
+       golang.org/x/tools v0.14.0
        google.golang.org/api v0.138.0
        google.golang.org/grpc v1.58.3
        google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
@@ -397,6 +398,7 @@ require (
        github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 // indirect
        github.com/hashicorp/yamux v0.1.1 // indirect
        github.com/huandu/xstrings v1.4.0 // indirect
+       github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba // indirect
        github.com/imdario/mergo v0.3.15 // indirect
        github.com/jackc/chunkreader/v2 v2.0.1 // indirect
        github.com/jackc/pgconn v1.14.0 // indirect
@@ -510,7 +512,7 @@ require (
        go.uber.org/multierr v1.7.0 // indirect
        go.uber.org/zap v1.19.1 // indirect
        golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
-       golang.org/x/mod v0.12.0 // indirect
+       golang.org/x/mod v0.13.0 // indirect
        golang.org/x/time v0.3.0 // indirect
        golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
        google.golang.org/appengine v1.6.7 // indirect
diff --git a/go.sum b/go.sum
index cfc6fa44a4..b4b86768fd 100644
--- a/go.sum
+++ b/go.sum
@@ -1982,8 +1982,8 @@ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
 github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0 h1:pSjQfW3vPtrOTcasTUKgCTQT7OGPPTTMVRrOfU6FJD8=
 github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0/go.mod h1:xvb32K2keAc+R8DSFG2IwDcydK9DBQE+fGA5fsw6hSk=
 github.com/hashicorp/go-kms-wrapping/v2 v2.0.8/go.mod h1:qTCjxGig/kjuj3hk1z8pOUrzbse/GxB1tGfbrq8tGJg=
-github.com/hashicorp/go-kms-wrapping/v2 v2.0.13 h1:29PE6fIDYcg2gQJIaQ8a8XtuW/jI3tQMwB95LsAY5GM=
-github.com/hashicorp/go-kms-wrapping/v2 v2.0.13/go.mod h1:NtMaPhqSlfQ72XWDD2g80o8HI8RKkowIB8/WZHMyPY4=
+github.com/hashicorp/go-kms-wrapping/v2 v2.0.14 h1:1ZuhfnZgRnLK8S0KovJkoTCRIQId5pv3sDR7pG5VQBw=
+github.com/hashicorp/go-kms-wrapping/v2 v2.0.14/go.mod h1:0dWtzl2ilqKpavgM3id/kFK9L3tjo6fS4OhbVPSYpnQ=
 github.com/hashicorp/go-kms-wrapping/wrappers/aead/v2 v2.0.7-1 h1:ZV26VJYcITBom0QqYSUOIj4HOHCVPEFjLqjxyXV/AbA=
 github.com/hashicorp/go-kms-wrapping/wrappers/aead/v2 v2.0.7-1/go.mod h1:b99cDSA+OzcyRoBZroSf174/ss/e6gUuS45wue9ZQfc=
 github.com/hashicorp/go-kms-wrapping/wrappers/alicloudkms/v2 v2.0.1 h1:ydUCtmr8f9F+mHZ1iCsvzqFTXqNVpewX3s9zcYipMKI=
@@ -1994,6 +1994,8 @@ github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.8 h1:CtccMhY
 github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.8/go.mod h1:hOe8opjBp3RtxEwfIXLVW0gFDTPHnmopkGiUWPuCPiM=
 github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.8 h1:16I8OqBEuxZIowwn3jiLvhlx+z+ia4dJc9stvz0yUBU=
 github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.8/go.mod h1:6QUMo5BrXAtbzSuZilqmx0A4px2u6PeFK7vfp2WIzeM=
+github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.1 h1:4C4MGXRn27u4Qgq+7JKei2G5WFVVaVlAckHkcTSHxV8=
+github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2 v2.0.1/go.mod h1:QxZ5cnaKlyPbBOHKNzLzXqlON/Vq41ar03ryyS4ddpY=
 github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.7 h1:KeG3QGrbxbr2qAqCJdf3NR4ijAYwdcWLTmwSbR0yusM=
 github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.7/go.mod h1:rXxYzjjGw4HltEwxPp9zYSRIo6R+rBf1MSPk01bvodc=
 github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.8 h1:uvdmC28xaqklqRQ3HWvq9HP4jX7Vy4M5JrJqAxfo5ig=
@@ -2192,6 +2194,8 @@ github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
 github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
 github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
 github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
+github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba h1:KFikP/B8lypq9FTWlxm366g0hVsnLBIV6EwAS4SQcKw=
+github.com/huaweicloud/golangsdk v0.0.0-20210831081626-d823fe11ceba/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
 github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -3304,8 +3308,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
 golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
 golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
 golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
-golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
-golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
+golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
+golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
 golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=
 golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
 golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
@@ -3353,8 +3357,8 @@ golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
-golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
-golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
+golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -3507,8 +3511,9 @@ golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
 golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
+golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
+golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
 golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -3829,8 +3834,8 @@ golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k=
 golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
 golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
-golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
-golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
+golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
+golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
 golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/internalshared/configutil/kms.go b/internalshared/configutil/kms.go
index aa09d42cb6..0232fff177 100644
--- a/internalshared/configutil/kms.go
+++ b/internalshared/configutil/kms.go
@@ -22,6 +22,7 @@ import (
        "github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2"
+       "github.com/hashicorp/go-kms-wrapping/wrappers/huaweicloudkms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2"
        "github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2"
        "github.com/hashicorp/go-multierror"
@@ -260,6 +261,9 @@ func configureWrapper(configKMS *KMS, infoKeys *[]string, info *map[string]strin
        case wrapping.WrapperTypePkcs11:
                return nil, fmt.Errorf("KMS type 'pkcs11' requires the Vault Enterprise HSM binary")

+       case wrapping.WrapperTypeHuaweiCloudKms:
+               wrapper, kmsInfo, err = GetHuaweiCloudKMSFunc(configKMS, opts...)
+
        default:
                return nil, fmt.Errorf("Unknown KMS type %q", configKMS.Type)
        }
@@ -419,6 +423,29 @@ var GetTransitKMSFunc = func(kms *KMS, opts ...wrapping.Option) (wrapping.Wrappe
        return wrapper, info, nil
 }

+var GetHuaweiCloudKMSFunc = func(kms *KMS, opts ...wrapping.Option) (wrapping.Wrapper, map[string]string, error) {
+       wrapper := huaweicloudkms.NewWrapper()
+       wrapperInfo, err := wrapper.SetConfig(context.Background(), append(opts, wrapping.WithDisallowEnvVars(true), wrapping.WithConfigMap(kms.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, nil, err
+               }
+       }
+       info := make(map[string]string)
+       if wrapperInfo != nil {
+               info["HuaweiCloud KMS Region"] = wrapperInfo.Metadata["region"]
+               info["HuaweiCloud KMS Project"] = wrapperInfo.Metadata["project"]
+               info["HuaweiCloud KMS Access Key"] = wrapperInfo.Metadata["access_key"]
+               info["HuaweiCloud KMS Secret Key"] = wrapperInfo.Metadata["secret_key"]
+               info["HuaweiCloud KMS KeyID"] = wrapperInfo.Metadata["kms_key_id"]
+               if endpoint, ok := wrapperInfo.Metadata["identity_endpoint"]; ok {
+                       info["HuaweiCloud KMS Identity Endpoint"] = endpoint
+               }
+       }
+       return wrapper, info, nil
+}
+
 func createSecureRandomReader(_ *SharedConfig, _ []*EntropySourcerInfo, _ hclog.Logger) (io.Reader, error) {
        return rand.Reader, nil
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.