From 0d00f3a55bdf2c6665ecfd7f0fb8b68e74241815 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 13 Jun 2022 21:06:13 +0100 Subject: [PATCH] kms: initialize after cli parsing (#15076) KMS depends on the --certs-dir flag. Ensure KMS is initialized after loading the flag. --- cmd/common-main.go | 7 ++++++- cmd/gateway-main.go | 3 +++ cmd/server-main.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 47dce73d5..e0f1f1e06 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -784,17 +784,22 @@ func handleCommonEnvVars() { } globalActiveCred = cred } +} +// Initialize KMS global variable after valiadating and loading the configuration. +// It depends on KMS env variables and global cli flags. +func handleKMSConfig() { switch { case env.IsSet(config.EnvKMSSecretKey) && env.IsSet(config.EnvKESEndpoint): logger.Fatal(errors.New("ambigious KMS configuration"), fmt.Sprintf("The environment contains %q as well as %q", config.EnvKMSSecretKey, config.EnvKESEndpoint)) } if env.IsSet(config.EnvKMSSecretKey) { - GlobalKMS, err = kms.Parse(env.Get(config.EnvKMSSecretKey, "")) + KMS, err := kms.Parse(env.Get(config.EnvKMSSecretKey, "")) if err != nil { logger.Fatal(err, "Unable to parse the KMS secret key inherited from the shell environment") } + GlobalKMS = KMS } if env.IsSet(config.EnvKESEndpoint) { var endpoints []string diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 9e38c35a7..f4c9a2af9 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -212,6 +212,9 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Handle gateway specific env gatewayHandleEnvVars() + // Initialize KMS configuration + handleKMSConfig() + // Set system resources to maximum. setMaxResources() diff --git a/cmd/server-main.go b/cmd/server-main.go index 47a3f07ad..e88f021de 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -435,6 +435,9 @@ func serverMain(ctx *cli.Context) { // Handle all server command args. serverHandleCmdArgs(ctx) + // Initialize KMS configuration + handleKMSConfig() + // Set node name, only set for distributed setup. globalConsoleSys.SetNodeName(globalLocalNodeName)