2022-09-05 09:06:08 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 16:03:15 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-06-21 17:59:12 +02:00
|
|
|
"context"
|
2022-11-24 10:57:58 +01:00
|
|
|
"encoding/hex"
|
2022-11-25 10:02:12 +01:00
|
|
|
"errors"
|
2022-03-22 16:03:15 +01:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
2022-05-13 13:10:27 +02:00
|
|
|
"strconv"
|
2022-04-05 09:13:09 +02:00
|
|
|
"text/tabwriter"
|
2022-06-21 17:59:12 +02:00
|
|
|
"time"
|
2022-03-22 16:03:15 +01:00
|
|
|
|
2022-09-21 13:47:57 +02:00
|
|
|
"github.com/edgelesssys/constellation/v2/bootstrapper/initproto"
|
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
|
2022-10-11 12:24:33 +02:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/clusterid"
|
2022-09-21 13:47:57 +02:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/helm"
|
2022-11-09 14:43:48 +01:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/azureshared"
|
2022-09-21 13:47:57 +02:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
2022-11-09 14:43:48 +01:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
|
2022-09-21 13:47:57 +02:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/crypto"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/grpc/dialer"
|
|
|
|
grpcRetry "github.com/edgelesssys/constellation/v2/internal/grpc/retry"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/license"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/retry"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/versions"
|
|
|
|
kms "github.com/edgelesssys/constellation/v2/kms/setup"
|
2022-04-05 09:11:45 +02:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/cobra"
|
2022-06-21 17:59:12 +02:00
|
|
|
"google.golang.org/grpc"
|
2022-03-22 16:03:15 +01:00
|
|
|
)
|
|
|
|
|
2022-06-08 08:14:28 +02:00
|
|
|
// NewInitCmd returns a new cobra.Command for the init command.
|
|
|
|
func NewInitCmd() *cobra.Command {
|
2022-03-22 16:03:15 +01:00
|
|
|
cmd := &cobra.Command{
|
2022-09-07 15:38:29 +02:00
|
|
|
Use: "init",
|
|
|
|
Short: "Initialize the Constellation cluster",
|
|
|
|
Long: "Initialize the Constellation cluster. Start your confidential Kubernetes.",
|
|
|
|
Args: cobra.ExactArgs(0),
|
|
|
|
RunE: runInitialize,
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-05-09 17:02:47 +02:00
|
|
|
cmd.Flags().String("master-secret", "", "path to base64-encoded master secret")
|
2022-09-20 10:07:55 +02:00
|
|
|
cmd.Flags().Bool("conformance", false, "enable conformance mode")
|
2022-03-22 16:03:15 +01:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// runInitialize runs the initialize command.
|
|
|
|
func runInitialize(cmd *cobra.Command, args []string) error {
|
|
|
|
fileHandler := file.NewHandler(afero.NewOsFs())
|
2022-08-09 14:04:40 +02:00
|
|
|
newDialer := func(validator *cloudcmd.Validator) *dialer.Dialer {
|
2022-08-12 15:59:45 +02:00
|
|
|
return dialer.New(nil, validator.V(cmd), &net.Dialer{})
|
2022-08-09 14:04:40 +02:00
|
|
|
}
|
2022-10-31 19:25:02 +01:00
|
|
|
|
2022-11-10 17:08:12 +01:00
|
|
|
spinner := newSpinner(cmd.ErrOrStderr())
|
2022-10-07 19:35:07 +02:00
|
|
|
defer spinner.Stop()
|
2022-09-05 18:12:46 +02:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(cmd.Context(), time.Hour)
|
|
|
|
defer cancel()
|
|
|
|
cmd.SetContext(ctx)
|
|
|
|
|
2022-10-31 19:25:02 +01:00
|
|
|
return initialize(cmd, newDialer, fileHandler, license.NewClient(), spinner)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 15:26:29 +02:00
|
|
|
// initialize initializes a Constellation.
|
2022-08-12 10:20:19 +02:00
|
|
|
func initialize(cmd *cobra.Command, newDialer func(validator *cloudcmd.Validator) *dialer.Dialer,
|
2022-10-31 19:25:02 +01:00
|
|
|
fileHandler file.Handler, quotaChecker license.QuotaChecker, spinner spinnerInterf,
|
2022-03-22 16:03:15 +01:00
|
|
|
) error {
|
2022-10-11 12:24:33 +02:00
|
|
|
flags, err := evalFlagArgs(cmd)
|
2022-04-13 15:01:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:40:49 +01:00
|
|
|
conf, err := config.New(fileHandler, flags.configPath)
|
2022-03-22 16:03:15 +01:00
|
|
|
if err != nil {
|
2022-11-15 15:40:49 +01:00
|
|
|
return displayConfigValidationErrors(cmd.ErrOrStderr(), err)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 12:24:33 +02:00
|
|
|
var idFile clusterid.File
|
|
|
|
if err := fileHandler.ReadJSON(constants.ClusterIDsFileName, &idFile); err != nil {
|
|
|
|
return fmt.Errorf("reading cluster ID file: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:40:49 +01:00
|
|
|
k8sVersion, err := versions.NewValidK8sVersion(conf.KubernetesVersion)
|
2022-09-02 14:05:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("validating kubernetes version: %w", err)
|
|
|
|
}
|
|
|
|
if versions.IsPreviewK8sVersion(k8sVersion) {
|
2022-11-10 10:27:24 +01:00
|
|
|
cmd.PrintErrf("Warning: Constellation with Kubernetes %v is still in preview. Use only for evaluation purposes.\n", k8sVersion)
|
2022-09-02 14:05:44 +02:00
|
|
|
}
|
|
|
|
|
2022-11-15 15:40:49 +01:00
|
|
|
provider := conf.GetProvider()
|
2022-08-25 14:06:29 +02:00
|
|
|
checker := license.NewChecker(quotaChecker, fileHandler)
|
2022-11-15 15:40:49 +01:00
|
|
|
if err := checker.CheckLicense(cmd.Context(), provider, conf.Provider, cmd.Printf); err != nil {
|
2022-11-10 10:27:24 +01:00
|
|
|
cmd.PrintErrf("License check failed: %v", err)
|
2022-08-16 16:06:38 +02:00
|
|
|
}
|
|
|
|
|
2022-11-15 15:40:49 +01:00
|
|
|
validator, err := cloudcmd.NewValidator(provider, conf)
|
2022-04-19 17:02:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-11-15 15:40:49 +01:00
|
|
|
serviceAccURI, err := getMarshaledServiceAccountURI(provider, conf, fileHandler)
|
2022-08-25 15:12:08 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-10-21 12:01:28 +02:00
|
|
|
masterSecret, err := readOrGenerateMasterSecret(cmd.OutOrStdout(), fileHandler, flags.masterSecretPath)
|
2022-08-12 10:20:19 +02:00
|
|
|
if err != nil {
|
2022-10-21 12:01:28 +02:00
|
|
|
return fmt.Errorf("parsing or generating master secret from file %s: %w", flags.masterSecretPath, err)
|
2022-08-12 10:20:19 +02:00
|
|
|
}
|
2022-11-24 16:39:33 +01:00
|
|
|
helmLoader := helm.NewLoader(provider, k8sVersion)
|
2022-11-18 10:05:02 +01:00
|
|
|
helmDeployments, err := helmLoader.Load(conf, flags.conformance, masterSecret.Key, masterSecret.Salt)
|
2022-08-31 13:57:59 +02:00
|
|
|
if err != nil {
|
2022-10-21 12:01:28 +02:00
|
|
|
return fmt.Errorf("loading Helm charts: %w", err)
|
2022-08-31 13:57:59 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 19:35:07 +02:00
|
|
|
spinner.Start("Initializing cluster ", false)
|
2022-06-21 17:59:12 +02:00
|
|
|
req := &initproto.InitRequest{
|
2022-08-31 13:57:59 +02:00
|
|
|
MasterSecret: masterSecret.Key,
|
|
|
|
Salt: masterSecret.Salt,
|
2022-06-21 17:59:12 +02:00
|
|
|
KmsUri: kms.ClusterKMSURI,
|
|
|
|
StorageUri: kms.NoStoreURI,
|
|
|
|
KeyEncryptionKeyId: "",
|
|
|
|
UseExistingKek: false,
|
2022-08-23 17:49:55 +02:00
|
|
|
CloudServiceAccountUri: serviceAccURI,
|
2022-11-15 15:40:49 +01:00
|
|
|
KubernetesVersion: conf.KubernetesVersion,
|
2022-11-23 10:29:36 +01:00
|
|
|
KubernetesComponents: versions.VersionConfigs[k8sVersion].KubernetesComponents.ToInitProto(),
|
2022-08-12 10:20:19 +02:00
|
|
|
HelmDeployments: helmDeployments,
|
2022-11-24 10:57:58 +01:00
|
|
|
EnforcedPcrs: conf.EnforcedPCRs(),
|
2022-11-18 10:05:02 +01:00
|
|
|
EnforceIdkeydigest: conf.EnforcesIDKeyDigest(),
|
2022-09-20 10:07:55 +02:00
|
|
|
ConformanceMode: flags.conformance,
|
2022-11-26 19:44:34 +01:00
|
|
|
InitSecret: idFile.InitSecret,
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-10-11 12:24:33 +02:00
|
|
|
resp, err := initCall(cmd.Context(), newDialer(validator), idFile.IP, req)
|
2022-10-04 19:17:05 +03:00
|
|
|
spinner.Stop()
|
2022-03-22 16:03:15 +01:00
|
|
|
if err != nil {
|
2022-11-25 10:02:12 +01:00
|
|
|
var nonRetriable *nonRetriableError
|
|
|
|
if errors.As(err, &nonRetriable) {
|
|
|
|
cmd.PrintErrln("Cluster initialization failed. This error is not recoverable.")
|
|
|
|
cmd.PrintErrln("Terminate your cluster and try again.")
|
|
|
|
}
|
2022-03-22 16:03:15 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-10-11 12:24:33 +02:00
|
|
|
idFile.CloudProvider = provider
|
|
|
|
if err := writeOutput(idFile, resp, cmd.OutOrStdout(), fileHandler); err != nil {
|
2022-07-29 10:01:10 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 17:59:12 +02:00
|
|
|
func initCall(ctx context.Context, dialer grpcDialer, ip string, req *initproto.InitRequest) (*initproto.InitResponse, error) {
|
|
|
|
doer := &initDoer{
|
|
|
|
dialer: dialer,
|
2022-06-29 15:26:29 +02:00
|
|
|
endpoint: net.JoinHostPort(ip, strconv.Itoa(constants.BootstrapperPort)),
|
2022-06-21 17:59:12 +02:00
|
|
|
req: req,
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-21 15:20:12 +02:00
|
|
|
retrier := retry.NewIntervalRetrier(doer, 30*time.Second, grpcRetry.ServiceIsUnavailable)
|
2022-06-29 14:28:37 +02:00
|
|
|
if err := retrier.Do(ctx); err != nil {
|
2022-06-21 17:59:12 +02:00
|
|
|
return nil, err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-06-21 17:59:12 +02:00
|
|
|
return doer.resp, nil
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 17:59:12 +02:00
|
|
|
type initDoer struct {
|
|
|
|
dialer grpcDialer
|
|
|
|
endpoint string
|
|
|
|
req *initproto.InitRequest
|
|
|
|
resp *initproto.InitResponse
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 17:59:12 +02:00
|
|
|
func (d *initDoer) Do(ctx context.Context) error {
|
|
|
|
conn, err := d.dialer.Dial(ctx, d.endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("dialing init server: %w", err)
|
|
|
|
}
|
2022-07-05 14:14:11 +02:00
|
|
|
defer conn.Close()
|
2022-06-21 17:59:12 +02:00
|
|
|
protoClient := initproto.NewAPIClient(conn)
|
|
|
|
resp, err := protoClient.Init(ctx, d.req)
|
2022-03-29 11:38:14 +02:00
|
|
|
if err != nil {
|
2022-11-25 10:02:12 +01:00
|
|
|
return &nonRetriableError{fmt.Errorf("init call: %w", err)}
|
2022-03-29 11:38:14 +02:00
|
|
|
}
|
2022-06-21 17:59:12 +02:00
|
|
|
d.resp = resp
|
|
|
|
return nil
|
2022-03-29 11:38:14 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 12:24:33 +02:00
|
|
|
func writeOutput(idFile clusterid.File, resp *initproto.InitResponse, wr io.Writer, fileHandler file.Handler) error {
|
2022-04-27 14:21:36 +02:00
|
|
|
fmt.Fprint(wr, "Your Constellation cluster was successfully initialized.\n\n")
|
2022-04-05 09:13:09 +02:00
|
|
|
|
2022-11-24 10:57:58 +01:00
|
|
|
ownerID := hex.EncodeToString(resp.OwnerId)
|
|
|
|
clusterID := hex.EncodeToString(resp.ClusterId)
|
2022-07-05 14:14:11 +02:00
|
|
|
|
2022-04-05 09:13:09 +02:00
|
|
|
tw := tabwriter.NewWriter(wr, 0, 0, 2, ' ', 0)
|
2022-07-26 10:58:39 +02:00
|
|
|
// writeRow(tw, "Constellation cluster's owner identifier", ownerID)
|
2022-07-27 16:10:50 +02:00
|
|
|
writeRow(tw, "Constellation cluster identifier", clusterID)
|
2022-04-06 10:36:58 +02:00
|
|
|
writeRow(tw, "Kubernetes configuration", constants.AdminConfFilename)
|
2022-04-05 09:13:09 +02:00
|
|
|
tw.Flush()
|
|
|
|
fmt.Fprintln(wr)
|
|
|
|
|
2022-06-21 17:59:12 +02:00
|
|
|
if err := fileHandler.Write(constants.AdminConfFilename, resp.Kubeconfig, file.OptNone); err != nil {
|
2022-07-29 09:52:47 +02:00
|
|
|
return fmt.Errorf("writing kubeconfig: %w", err)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-04-05 09:13:09 +02:00
|
|
|
|
2022-10-11 12:24:33 +02:00
|
|
|
idFile.OwnerID = ownerID
|
|
|
|
idFile.ClusterID = clusterID
|
|
|
|
|
2022-07-29 10:01:10 +02:00
|
|
|
if err := fileHandler.WriteJSON(constants.ClusterIDsFileName, idFile, file.OptOverwrite); err != nil {
|
2022-07-01 10:57:29 +02:00
|
|
|
return fmt.Errorf("writing Constellation id file: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-04 09:13:46 +02:00
|
|
|
fmt.Fprintln(wr, "You can now connect to your cluster by executing:")
|
2022-04-06 10:36:58 +02:00
|
|
|
fmt.Fprintf(wr, "\texport KUBECONFIG=\"$PWD/%s\"\n", constants.AdminConfFilename)
|
2022-03-22 16:03:15 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-05 09:13:09 +02:00
|
|
|
func writeRow(wr io.Writer, col1 string, col2 string) {
|
|
|
|
fmt.Fprint(wr, col1, "\t", col2, "\n")
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:03:15 +01:00
|
|
|
// evalFlagArgs gets the flag values and does preprocessing of these values like
|
|
|
|
// reading the content from file path flags and deriving other values from flag combinations.
|
2022-10-11 12:24:33 +02:00
|
|
|
func evalFlagArgs(cmd *cobra.Command) (initFlags, error) {
|
2022-03-22 16:03:15 +01:00
|
|
|
masterSecretPath, err := cmd.Flags().GetString("master-secret")
|
|
|
|
if err != nil {
|
2022-07-29 10:01:10 +02:00
|
|
|
return initFlags{}, fmt.Errorf("parsing master-secret path flag: %w", err)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-09-20 10:07:55 +02:00
|
|
|
conformance, err := cmd.Flags().GetBool("conformance")
|
|
|
|
if err != nil {
|
|
|
|
return initFlags{}, fmt.Errorf("parsing autoscale flag: %w", err)
|
|
|
|
}
|
2022-05-13 11:56:43 +02:00
|
|
|
configPath, err := cmd.Flags().GetString("config")
|
2022-04-13 15:01:02 +02:00
|
|
|
if err != nil {
|
2022-07-29 10:01:10 +02:00
|
|
|
return initFlags{}, fmt.Errorf("parsing config path flag: %w", err)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-04-13 15:01:02 +02:00
|
|
|
return initFlags{
|
2022-08-31 13:57:59 +02:00
|
|
|
configPath: configPath,
|
2022-09-20 10:07:55 +02:00
|
|
|
conformance: conformance,
|
2022-08-31 13:57:59 +02:00
|
|
|
masterSecretPath: masterSecretPath,
|
2022-03-22 16:03:15 +01:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-13 15:01:02 +02:00
|
|
|
// initFlags are the resulting values of flag preprocessing.
|
|
|
|
type initFlags struct {
|
2022-08-31 13:57:59 +02:00
|
|
|
configPath string
|
|
|
|
masterSecretPath string
|
2022-09-20 10:07:55 +02:00
|
|
|
conformance bool
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-07-29 09:52:47 +02:00
|
|
|
// masterSecret holds the master key and salt for deriving keys.
|
|
|
|
type masterSecret struct {
|
|
|
|
Key []byte `json:"key"`
|
|
|
|
Salt []byte `json:"salt"`
|
|
|
|
}
|
|
|
|
|
2022-06-09 14:10:42 +00:00
|
|
|
// readOrGenerateMasterSecret reads a base64 encoded master secret from file or generates a new 32 byte secret.
|
2022-11-10 10:27:24 +01:00
|
|
|
func readOrGenerateMasterSecret(outWriter io.Writer, fileHandler file.Handler, filename string) (masterSecret, error) {
|
2022-03-22 16:03:15 +01:00
|
|
|
if filename != "" {
|
2022-07-29 09:52:47 +02:00
|
|
|
var secret masterSecret
|
|
|
|
if err := fileHandler.ReadJSON(filename, &secret); err != nil {
|
|
|
|
return masterSecret{}, err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 09:52:47 +02:00
|
|
|
|
|
|
|
if len(secret.Key) < crypto.MasterSecretLengthMin {
|
|
|
|
return masterSecret{}, fmt.Errorf("provided master secret is smaller than the required minimum of %d Bytes", crypto.MasterSecretLengthMin)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 09:52:47 +02:00
|
|
|
if len(secret.Salt) < crypto.RNGLengthDefault {
|
|
|
|
return masterSecret{}, fmt.Errorf("provided salt is smaller than the required minimum of %d Bytes", crypto.RNGLengthDefault)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 09:52:47 +02:00
|
|
|
return secret, nil
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// No file given, generate a new secret, and save it to disk
|
2022-07-29 09:52:47 +02:00
|
|
|
key, err := crypto.GenerateRandomBytes(crypto.MasterSecretLengthDefault)
|
2022-03-22 16:03:15 +01:00
|
|
|
if err != nil {
|
2022-07-29 09:52:47 +02:00
|
|
|
return masterSecret{}, err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 09:52:47 +02:00
|
|
|
salt, err := crypto.GenerateRandomBytes(crypto.RNGLengthDefault)
|
|
|
|
if err != nil {
|
|
|
|
return masterSecret{}, err
|
|
|
|
}
|
|
|
|
secret := masterSecret{
|
|
|
|
Key: key,
|
|
|
|
Salt: salt,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := fileHandler.WriteJSON(constants.MasterSecretFilename, secret, file.OptNone); err != nil {
|
|
|
|
return masterSecret{}, err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-11-10 10:27:24 +01:00
|
|
|
fmt.Fprintf(outWriter, "Your Constellation master secret was successfully written to ./%s\n", constants.MasterSecretFilename)
|
2022-07-29 09:52:47 +02:00
|
|
|
return secret, nil
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-07-29 10:01:10 +02:00
|
|
|
func readIPFromIDFile(fileHandler file.Handler) (string, error) {
|
2022-10-11 12:24:33 +02:00
|
|
|
var idFile clusterid.File
|
2022-07-29 10:01:10 +02:00
|
|
|
if err := fileHandler.ReadJSON(constants.ClusterIDsFileName, &idFile); err != nil {
|
|
|
|
return "", err
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 10:01:10 +02:00
|
|
|
if idFile.IP == "" {
|
|
|
|
return "", fmt.Errorf("missing IP address in %q", constants.ClusterIDsFileName)
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
2022-07-29 10:01:10 +02:00
|
|
|
return idFile.IP, nil
|
2022-03-22 16:03:15 +01:00
|
|
|
}
|
|
|
|
|
2022-08-31 13:57:59 +02:00
|
|
|
func getMarshaledServiceAccountURI(provider cloudprovider.Provider, config *config.Config, fileHandler file.Handler) (string, error) {
|
2022-08-23 17:49:55 +02:00
|
|
|
switch provider {
|
|
|
|
case cloudprovider.GCP:
|
|
|
|
path := config.Provider.GCP.ServiceAccountKeyPath
|
|
|
|
|
|
|
|
var key gcpshared.ServiceAccountKey
|
|
|
|
if err := fileHandler.ReadJSON(path, &key); err != nil {
|
|
|
|
return "", fmt.Errorf("reading service account key from path %q: %w", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return key.ToCloudServiceAccountURI(), nil
|
|
|
|
|
2022-10-21 17:09:26 +02:00
|
|
|
case cloudprovider.AWS:
|
|
|
|
return "", nil // AWS does not need a service account URI
|
2022-08-23 17:49:55 +02:00
|
|
|
case cloudprovider.Azure:
|
2022-08-29 14:18:05 +02:00
|
|
|
creds := azureshared.ApplicationCredentials{
|
|
|
|
TenantID: config.Provider.Azure.TenantID,
|
|
|
|
AppClientID: config.Provider.Azure.AppClientID,
|
|
|
|
ClientSecretValue: config.Provider.Azure.ClientSecretValue,
|
|
|
|
Location: config.Provider.Azure.Location,
|
|
|
|
}
|
|
|
|
return creds.ToCloudServiceAccountURI(), nil
|
2022-08-23 17:49:55 +02:00
|
|
|
|
|
|
|
case cloudprovider.QEMU:
|
|
|
|
return "", nil // QEMU does not use service account keys
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("unsupported cloud provider %q", provider)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-21 17:59:12 +02:00
|
|
|
type grpcDialer interface {
|
|
|
|
Dial(ctx context.Context, target string) (*grpc.ClientConn, error)
|
|
|
|
}
|
2022-11-25 10:02:12 +01:00
|
|
|
|
|
|
|
type nonRetriableError struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error returns the error message.
|
|
|
|
func (e *nonRetriableError) Error() string {
|
|
|
|
return e.err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrap returns the wrapped error.
|
|
|
|
func (e *nonRetriableError) Unwrap() error {
|
|
|
|
return e.err
|
|
|
|
}
|