diff --git a/cmd/admin_k9s.go b/cmd/admin_k9s.go index 07c94ac8..00dabdf3 100644 --- a/cmd/admin_k9s.go +++ b/cmd/admin_k9s.go @@ -38,6 +38,23 @@ func launchK9s(args []string) { for _, variable := range vars { os.Setenv(variable.Key, variable.Value) + + // Generate temporary file + ENV for GCP auth + // https://serverfault.com/questions/848580/how-to-use-google-application-credentials-with-gcloud-on-a-server + if variable.Key == "GOOGLE_CREDENTIALS" { + googleCredentialsFile, err := os.CreateTemp("", "sample") + if err != nil { + log.Error("Can't create google credentials file : " + err.Error()) + } + defer os.Remove(googleCredentialsFile.Name()) + + _, err = googleCredentialsFile.WriteString(variable.Value) + if err != nil { + log.Error("Can't create google credentials file : " + err.Error()) + } + + os.Setenv("CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE", googleCredentialsFile.Name()) + } } utils.GenerateExportEnvVarsScript(vars, args[0]) diff --git a/pkg/vault.go b/pkg/vault.go index a11ae263..18b76f25 100644 --- a/pkg/vault.go +++ b/pkg/vault.go @@ -2,6 +2,7 @@ package pkg import ( b64 "encoding/base64" + "encoding/json" "os" "github.com/hashicorp/vault/api" @@ -52,6 +53,13 @@ func GetVarsByClusterId(clusterID string) []utils.Var { vaultVars = append(vaultVars, utils.Var{Key: "AWS_DEFAULT_REGION", Value: value.(string)}) case "AWS_SECRET_ACCESS_KEY", "aws_secret_access_key": vaultVars = append(vaultVars, utils.Var{Key: "AWS_SECRET_ACCESS_KEY", Value: value.(string)}) + case "GOOGLE_CREDENTIALS", "google_credentials": + jsonStr, err := json.Marshal(value) + if err != nil { + log.Error("Can't convert to json GOOGLE_CREDENTIALS") + return []utils.Var{} + } + vaultVars = append(vaultVars, utils.Var{Key: "GOOGLE_CREDENTIALS", Value: string(jsonStr)}) case "kubeconfig_b64", "KUBECONFIG_b64": decodedValue, encErr := b64.StdEncoding.DecodeString(value.(string)) if encErr != nil {