forked from siderolabs/talos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add KMS assisted encryption key handler
Talos now supports new type of encryption keys which rely on Sealing/Unsealing randomly generated bytes with a KMS server: ``` systemDiskEncryption: ephemeral: keys: - kms: endpoint: https://1.2.3.4:443 slot: 0 ``` gRPC API definitions and a simple reference implementation of the KMS server can be found in this [repository](https://github.com/siderolabs/kms-client/blob/main/cmd/kms-server/main.go). Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
- Loading branch information
Showing
62 changed files
with
1,220 additions
and
362 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package mgmt | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
"github.com/siderolabs/kms-client/api/kms" | ||
"github.com/siderolabs/kms-client/pkg/server" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/sync/errgroup" | ||
"google.golang.org/grpc" | ||
|
||
grpclog "github.com/siderolabs/talos/pkg/grpc/middleware/log" | ||
) | ||
|
||
var kmsLaunchCmdFlags struct { | ||
addr string | ||
key []byte | ||
} | ||
|
||
// kmsLaunchCmd represents the kms-launch command. | ||
var kmsLaunchCmd = &cobra.Command{ | ||
Use: "kms-launch", | ||
Short: "Internal command used by QEMU provisioner", | ||
Long: ``, | ||
Args: cobra.NoArgs, | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if kmsLaunchCmdFlags.key == nil { | ||
return fmt.Errorf("no key provided to the KMS server") | ||
} | ||
|
||
srv := server.NewServer(func(_ context.Context, nodeUUID string) ([]byte, error) { | ||
return kmsLaunchCmdFlags.key, nil | ||
}) | ||
|
||
lis, err := net.Listen("tcp", kmsLaunchCmdFlags.addr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("starting KMS server on %s", kmsLaunchCmdFlags.addr) | ||
|
||
logMiddleware := grpclog.NewMiddleware(log.New(log.Writer(), "", log.Flags())) | ||
|
||
s := grpc.NewServer( | ||
grpc.UnaryInterceptor(logMiddleware.UnaryInterceptor()), | ||
grpc.StreamInterceptor(logMiddleware.StreamInterceptor()), | ||
) | ||
kms.RegisterKMSServiceServer(s, srv) | ||
|
||
eg, ctx := errgroup.WithContext(cmd.Context()) | ||
|
||
eg.Go(func() error { | ||
err := s.Serve(lis) | ||
if errors.Is(err, context.Canceled) { | ||
return nil | ||
} | ||
|
||
return err | ||
}) | ||
|
||
eg.Go(func() error { | ||
<-ctx.Done() | ||
|
||
s.Stop() | ||
|
||
return nil | ||
}) | ||
|
||
return s.Serve(lis) | ||
}, | ||
} | ||
|
||
func init() { | ||
kmsLaunchCmd.Flags().StringVar(&kmsLaunchCmdFlags.addr, "kms-addr", "localhost", "KMS listen address (IP or host)") | ||
kmsLaunchCmd.Flags().BytesBase64Var(&kmsLaunchCmdFlags.key, "kms-key", nil, "KMS key to use") | ||
addCommand(kmsLaunchCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.