Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Get govulncheck
# Pinned because govulncheck's Go floor moves ahead of the toolchain
# this workflow derives from kms/go.mod: v1.8.0 requires Go 1.26.
run: go install golang.org/x/vuln/cmd/govulncheck@v1.7.0
run: go install golang.org/x/vuln/cmd/govulncheck@latest
shell: bash
- name: Run govulncheck
env:
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.25.0
go 1.26

use (
./kes
Expand Down
2 changes: 1 addition & 1 deletion kes/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/minio/kms-go/kes

go 1.25
go 1.26

require (
aead.dev/mem v0.2.0
Expand Down
30 changes: 30 additions & 0 deletions kms/client-examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,36 @@ func ExampleClient_CreateEnclave() {
}
}

// ExampleClient_ImportKeyRing shows how to import a key with all of its
// versions in a single request.
func ExampleClient_ImportKeyRing() {
key, err := mtls.ParsePrivateKey("k1:d7cY_5k8HbBGkZpoy2hGmvkxg83QDBXsA_nFXDfTk2E")
if err != nil {
log.Fatalf("Failed to parse KMS API key: %v", err)
}

client, err := kms.NewClient(&kms.Config{
Endpoints: []string{
"127.0.0.1:7373",
},
APIKey: key,
})
if err != nil {
log.Fatalf("Failed to create KMS client: %v", err)
}

request := &kms.ImportKeyRingRequest{
Name: "my-key",
Versions: []kms.ImportKeyVersion{
{Version: 1, Type: kms.AES256, Key: make([]byte, 32)},
{Version: 2, Type: kms.AES256, Key: make([]byte, 32)},
},
}
if err = client.ImportKeyRing(context.TODO(), "minio-tenant-foo", request); err != nil {
log.Fatalf("Failed to import key ring '%s': %v", request.Name, err)
}
}

// ExampleClient_DeleteEnclave shows how to delete an existing enclave.
func ExampleClient_DeleteEnclave() {
key, err := mtls.ParsePrivateKey("k1:d7cY_5k8HbBGkZpoy2hGmvkxg83QDBXsA_nFXDfTk2E")
Expand Down
28 changes: 28 additions & 0 deletions kms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,34 @@ func (c *Client) ImportKey(ctx context.Context, enclave string, req *ImportKeyRe
return resp.Body.Close()
}

// ImportKeyRing imports an existing key ring, i.e. a key with all of its
// versions, with the name req.Name into the given enclave in a single
// request. Imported keys are marked by the KMS server to distinguish them
// from keys that never left the KMS boundary.
//
// It returns ErrEnclaveNotFound if no such enclave exists and ErrKeyExists
// if such a key already exists wrapped in a HostError.
//
// The returned error is of type *HostError.
func (c *Client) ImportKeyRing(ctx context.Context, enclave string, req *ImportKeyRingRequest) error {
p := pool.Get(128 + 64*len(req.Versions))
defer pool.Put(p)

body, err := cmds.Encode((*p)[:0], cmds.KeyImportRing, req)
if err != nil {
return err
}

resp, err := c.Send(ctx, &Request{
Enclave: enclave,
Body: body,
})
if err != nil {
return err
}
return resp.Body.Close()
}

// KeyStatus returns status information about one or multiple keys
// within the enclave. Without any requests, KeyStatus returns an
// empty slice and no error.
Expand Down
12 changes: 9 additions & 3 deletions kms/cmds/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
KeyList Command = 208
KeyListVersions Command = 209
KeyMAC Command = 210
KeyImportRing Command = 211

PolicyCreate Command = 301
PolicyDelete Command = 302
Expand Down Expand Up @@ -123,9 +124,10 @@ var isWrite = map[Command]struct{}{ // Commands that change state on a KMS serve
EnclaveCreate: {},
EnclaveDelete: {},

KeyCreate: {},
KeyDelete: {},
KeyImport: {},
KeyCreate: {},
KeyDelete: {},
KeyImport: {},
KeyImportRing: {},

PolicyCreate: {},
PolicyDelete: {},
Expand Down Expand Up @@ -164,6 +166,8 @@ var cmdTexts = map[Command]string{

KeyCreate: "KEY:CREATE",
KeyDelete: "KEY:DELETE",
KeyImport: "KEY:IMPORT",
KeyImportRing: "KEY:IMPORTRING",
KeyStatus: "KEY:STATUS",
KeyEncrypt: "KEY:ENCRYPT",
KeyDecrypt: "KEY:DECRYPT",
Expand Down Expand Up @@ -200,6 +204,8 @@ var textCmds = map[string]Command{

"KEY:CREATE": KeyCreate,
"KEY:DELETE": KeyDelete,
"KEY:IMPORT": KeyImport,
"KEY:IMPORTRING": KeyImportRing,
"KEY:STATUS": KeyStatus,
"KEY:ENCRYPT": KeyEncrypt,
"KEY:DECRYPT": KeyDecrypt,
Expand Down
6 changes: 4 additions & 2 deletions kms/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module github.com/minio/kms-go/kms

go 1.25
go 1.26

toolchain go1.26.9

require (
aead.dev/mem v0.2.0
aead.dev/mtls v0.4.0
google.golang.org/protobuf v1.36.11
google.golang.org/protobuf v1.36.12
)

tool google.golang.org/protobuf/cmd/protoc-gen-go
4 changes: 2 additions & 2 deletions kms/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ aead.dev/mtls v0.4.0 h1:s+nuIKH0ZZIZ1RsfOjYVx0q2OcfKFKS3UaJGngrTLFY=
aead.dev/mtls v0.4.0/go.mod h1:ZuSTM2+kagQsjaWoHn7yTU36MAaEaH/5Aq5XR4uYMk4=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
118 changes: 38 additions & 80 deletions kms/protobuf/log.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading