Skip to content

Commit 2bf6354

Browse files
committed
[BACKPORT 2024.1][PLAT-14805]Support adding EAR configs
Summary: Command format: `./yba ear <provider-type (aws/azure/gcp/hcv)> create -n <name> [flags]` AWS: ``` ./yba ear aws create Create an AWS encryption at rest configuration in YugabyteDB Anywhere Usage: yba ear aws create [flags] Aliases: create, add Flags: --access-key-id string AWS Access Key ID. Required for non IAM role based configurations. Can also be set using environment variable AWS_ACCESS_KEY_ID. --secret-access-key string AWS Secret Access Key. Required for non IAM role based configurations. Can also be set using environment variable AWS_SECRET_ACCESS_KEY. --region string AWS region where the customer master key is located. Can also be set using environment variable AWS_REGION --use-iam-instance-profile [Optional] Use IAM Role from the YugabyteDB Anywhere Host. EAR creation will fail on insufficient permissions on the host. (default false) --cmk-id string [Optional] Customer Master Key ID. If an identifier is not entered, a CMK ID will be auto-generated. --endpoint string [Optional] AWS KMS Endpoint. --cmk-policy-file-path string [Optional] AWS KMS Customer Master Key Policy file path. Custom policy file is not needed when Customer Master Key ID is specified. Allowed file type is json. -h, --help help for create Global Flags: -a, --apiToken string YugabyteDB Anywhere api token. --config string Config file, defaults to $HOME/.yba-cli.yaml --debug Use debug mode, same as --logLevel debug. --disable-color Disable colors in output. (default false) -H, --host string YugabyteDB Anywhere Host (default "http://localhost:9000") -l, --logLevel string Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info") -n, --name string [Optional] The name of the configuration for the action. Required for create, delete, describe, update. -o, --output string Select the desired output format. Allowed values: table, json, pretty. (default "table") --timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) --wait Wait until the task is completed, otherwise it will exit immediately. (default true) ``` Azure: ``` Create an Azure encryption at rest configuration in YugabyteDB Anywhere Usage: yba ear azure create [flags] Aliases: create, add Flags: --client-id string Azure Client ID. Can also be set using environment variable AZURE_CLIENT_ID. --tenant-id string Azure Tenant ID. Can also be set using environment variable AZURE_TENANT_ID. --client-secret string Azure Secret Access Key. Required for Non Managed Identity based configurations. Can also be set using environment variable AZURE_CLIENT_SECRET. --use-managed-identity [Optional] Use Azure Managed Identity from the YugabyteDB Anywhere Host. EAR creation will fail on insufficient permissions on the host. (default false) --vault-url string [Required] Azure Vault URL. --key-name string [Required] Azure Key Name.If master key with same name already exists then it will be used, else a new one will be created automatically. --key-algorithm string [Optional] Azure Key Algorithm. Allowed values (case sensitive): RSA (default "RSA") --key-size int [Optional] Azure Key Size. Allowed values per algorithm: RSA(Default:2048, 3072, 4096) -h, --help help for create Global Flags: -a, --apiToken string YugabyteDB Anywhere api token. --config string Config file, defaults to $HOME/.yba-cli.yaml --debug Use debug mode, same as --logLevel debug. --disable-color Disable colors in output. (default false) -H, --host string YugabyteDB Anywhere Host (default "http://localhost:9000") -l, --logLevel string Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info") -n, --name string [Optional] The name of the configuration for the action. Required for create, delete, describe, update. -o, --output string Select the desired output format. Allowed values: table, json, pretty. (default "table") --timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) --wait Wait until the task is completed, otherwise it will exit immediately. (default true) ``` GCP: ``` ./yba ear gcp create Create a GCP encryption at rest configuration in YugabyteDB Anywhere Usage: yba ear gcp create [flags] Aliases: create, add Flags: --credentials-file-path string GCP Credentials File Path. Can also be set using environment variable GOOGLE_APPLICATION_CREDENTIALS. --location string [Optional] The geographical region where the Cloud KMS resource is stored and accessed. (default "global") --key-ring-name string [Required] Name of the key ring. If key ring with same name already exists then it will be used, else a new one will be created automatically. --crypto-key-name string [Required] Name of the cryptographic key that will be used for encrypting and decrypting universe key. If crypto key with same name already exists then it will be used, else a new one will be created automatically. --protection-level string [Optional] The protection level to use for this key. Allowed values (case sensitive): SOFTWARE and HSM. (default "HSM") --endpoint string [Optional] GCP KMS Endpoint. -h, --help help for create Global Flags: -a, --apiToken string YugabyteDB Anywhere api token. --config string Config file, defaults to $HOME/.yba-cli.yaml --debug Use debug mode, same as --logLevel debug. --disable-color Disable colors in output. (default false) -H, --host string YugabyteDB Anywhere Host (default "http://localhost:9000") -l, --logLevel string Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info") -n, --name string [Optional] The name of the configuration for the action. Required for create, delete, describe, update. -o, --output string Select the desired output format. Allowed values: table, json, pretty. (default "table") --timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) --wait Wait until the task is completed, otherwise it will exit immediately. (default true) ``` HCV: ``` Create a Hashicorp Vault encryption at rest configuration in YugabyteDB Anywhere Usage: yba ear hashicorp create [flags] Aliases: create, add Flags: --vault-address string Hashicorp Vault address. Can also be set using environment variable VAULT_ADDR --role-id string [Optional] Hashicorp Vault AppRole ID. --secret-id string [Optional] Hashicorp Vault AppRole Secret ID. --auth-namespace string [Optional] Hashicorp Vault AppRole Auth Namespace. --token string [Optional] Hashicorp Vault Token. Required if AppRole credentials are not provided. Can also be set using environment variable VAULT_TOKEN --secret-engine string [Optional] Hashicorp Vault Secret Engine. Allowed values: transit. (default "transit") --key-name string [Optional] Hashicorp Vault key name. If key with same name already exists then it will be used, else a new one will be created automatically. (default "key_yugabyte") --mount-path string [Optional] Hashicorp Vault mount path. (default "transit/") -h, --help help for create Global Flags: -a, --apiToken string YugabyteDB Anywhere api token. --config string Config file, defaults to $HOME/.yba-cli.yaml --debug Use debug mode, same as --logLevel debug. --disable-color Disable colors in output. (default false) -H, --host string YugabyteDB Anywhere Host (default "http://localhost:9000") -l, --logLevel string Select the desired log level format. Allowed values: debug, info, warn, error, fatal. (default "info") -n, --name string [Optional] The name of the configuration for the action. Required for create, delete, describe, update. -o, --output string Select the desired output format. Allowed values: table, json, pretty. (default "table") --timeout duration Wait command timeout, example: 5m, 1h. (default 168h0m0s) --wait Wait until the task is completed, otherwise it will exit immediately. (default true) ``` Original commit: 38d8ae8 / D37728 Test Plan: `./yba ear hashicorp add -n dkumar-cli --token <token> --vault-address <>` `./yba ear hcv create -n dkumar-cli-approle --role-id <> --secret-id <> --vault-address <>` `./yba ear aws add -n dkumar-aws-cli --access-key-id <> --secret-access-key <> --cmk-id <>` `./yba ear aws add -n dkumar-aws-cli --access-key-id <>--secret-access-key <> --cmk-policy-file-path policy.json ` ` ./yba ear gcp add -n dkumar-cli-gcp --credentials-file-path gce.json --key-ring-name <> --crypto-key-name <>` `./yba ear azu create -n dkumar-cli-az --vault-url <> --key-name <>--client-id <> --tenant-id <> --client-secret <>` Reviewers: sneelakantan, skurapati Reviewed By: skurapati Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D37769
1 parent 9f8c943 commit 2bf6354

29 files changed

+1285
-70
lines changed

managed/yba-cli/NOTICE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ The following subcomponents are used:
4848
## github.com/aws/aws-sdk-go
4949

5050
* Name: github.com/aws/aws-sdk-go
51-
* Version: v1.45.24
52-
* License: [Apache-2.0](https://github.com/aws/aws-sdk-go/blob/v1.45.24/LICENSE.txt)
51+
* Version: v1.55.5
52+
* License: [Apache-2.0](https://github.com/aws/aws-sdk-go/blob/v1.55.5/LICENSE.txt)
5353

5454

5555
## github.com/aws/aws-sdk-go/internal/sync/singleflight

managed/yba-cli/cmd/ear/aws/aws_ear.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var AWSEARCmd = &cobra.Command{
2525
func init() {
2626
AWSEARCmd.Flags().SortFlags = false
2727

28-
// AWSEARCmd.AddCommand(createAWSEARCmd)
28+
AWSEARCmd.AddCommand(createAWSEARCmd)
2929
// AWSEARCmd.AddCommand(updateAWSEARCmd)
3030
AWSEARCmd.AddCommand(listAWSEARCmd)
3131
AWSEARCmd.AddCommand(describeAWSEARCmd)
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* Copyright (c) YugaByte, Inc.
3+
*/
4+
5+
package aws
6+
7+
import (
8+
"fmt"
9+
"strings"
10+
11+
"github.com/sirupsen/logrus"
12+
"github.com/spf13/cobra"
13+
"github.com/yugabyte/yugabyte-db/managed/yba-cli/cmd/ear/earutil"
14+
"github.com/yugabyte/yugabyte-db/managed/yba-cli/cmd/util"
15+
ybaAuthClient "github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/client"
16+
"github.com/yugabyte/yugabyte-db/managed/yba-cli/internal/formatter"
17+
)
18+
19+
// createAWSEARCmd represents the ear command
20+
var createAWSEARCmd = &cobra.Command{
21+
Use: "create",
22+
Aliases: []string{"add"},
23+
Short: "Create a YugabyteDB Anywhere AWS encryption at rest configuration",
24+
Long: "Create an AWS encryption at rest configuration in YugabyteDB Anywhere",
25+
PreRun: func(cmd *cobra.Command, args []string) {
26+
configNameFlag, err := cmd.Flags().GetString("name")
27+
if err != nil {
28+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
29+
}
30+
if len(strings.TrimSpace(configNameFlag)) == 0 {
31+
cmd.Help()
32+
logrus.Fatalln(
33+
formatter.Colorize(
34+
"No encryption at rest config name found to create\n",
35+
formatter.RedColor))
36+
}
37+
isIAM, err := cmd.Flags().GetBool("use-iam-instance-profile")
38+
if err != nil {
39+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
40+
}
41+
42+
accessKeyID, err := cmd.Flags().GetString("access-key-id")
43+
if err != nil {
44+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
45+
}
46+
if isIAM && len(accessKeyID) > 0 {
47+
cmd.Help()
48+
logrus.Fatalln(
49+
formatter.Colorize("Cannot set both credentials and use-iam-instance-profile"+
50+
"\n", formatter.RedColor))
51+
}
52+
},
53+
Run: func(cmd *cobra.Command, args []string) {
54+
authAPI := ybaAuthClient.NewAuthAPIClientAndCustomer()
55+
56+
requestBody := make(map[string]interface{})
57+
58+
configName, err := cmd.Flags().GetString("name")
59+
if err != nil {
60+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
61+
}
62+
requestBody["name"] = configName
63+
64+
isIAM, err := cmd.Flags().GetBool("use-iam-instance-profile")
65+
if err != nil {
66+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
67+
}
68+
if !isIAM {
69+
accessKeyID, err := cmd.Flags().GetString("access-key-id")
70+
if err != nil {
71+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
72+
}
73+
secretAccessKey, err := cmd.Flags().GetString("secret-access-key")
74+
if err != nil {
75+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
76+
}
77+
if len(accessKeyID) == 0 && len(secretAccessKey) == 0 {
78+
awsCreds, err := util.AwsCredentialsFromEnv()
79+
if err != nil {
80+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
81+
}
82+
accessKeyID = awsCreds.AccessKeyID
83+
secretAccessKey = awsCreds.SecretAccessKey
84+
}
85+
requestBody[util.AWSAccessKeyEnv] = accessKeyID
86+
requestBody[util.AWSSecretAccessKeyEnv] = secretAccessKey
87+
}
88+
89+
region, err := cmd.Flags().GetString("region")
90+
if err != nil {
91+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
92+
}
93+
if len(strings.TrimSpace(region)) == 0 {
94+
region, err = util.AWSRegionFromEnv()
95+
if err != nil {
96+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
97+
}
98+
}
99+
requestBody[util.AWSRegionEnv] = region
100+
101+
endpoint, err := cmd.Flags().GetString("endpoint")
102+
if err != nil {
103+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
104+
}
105+
if len(strings.TrimSpace(endpoint)) != 0 {
106+
requestBody[util.AWSEndpointEnv] = endpoint
107+
}
108+
109+
cmkID, err := cmd.Flags().GetString("cmk-id")
110+
if err != nil {
111+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
112+
}
113+
if len(strings.TrimSpace(cmkID)) != 0 {
114+
requestBody[util.AWSCMKIDField] = cmkID
115+
} else {
116+
cmkPolicyFile, err := cmd.Flags().GetString("cmk-policy-file-path")
117+
if err != nil {
118+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
119+
}
120+
if len(strings.TrimSpace(cmkPolicyFile)) != 0 {
121+
cmkPolicy, err := util.ReadFileToString(cmkPolicyFile)
122+
if err != nil {
123+
logrus.Fatalf(formatter.Colorize(err.Error()+"\n", formatter.RedColor))
124+
}
125+
requestBody[util.AWSCMKPolicyField] = cmkPolicy
126+
}
127+
}
128+
129+
rCreate, response, err := authAPI.CreateKMSConfig(util.AWSEARType).
130+
KMSConfig(requestBody).Execute()
131+
if err != nil {
132+
errMessage := util.ErrorFromHTTPResponse(response, err, "EAR: AWS", "Create")
133+
logrus.Fatalf(formatter.Colorize(errMessage.Error()+"\n", formatter.RedColor))
134+
}
135+
136+
configUUID := rCreate.GetResourceUUID()
137+
taskUUID := rCreate.GetTaskUUID()
138+
139+
earutil.WaitForCreateEARTask(authAPI,
140+
configName, configUUID, util.AWSEARType, taskUUID)
141+
142+
},
143+
}
144+
145+
func init() {
146+
createAWSEARCmd.Flags().SortFlags = false
147+
148+
createAWSEARCmd.Flags().String("access-key-id", "",
149+
fmt.Sprintf("AWS Access Key ID. %s "+
150+
"Can also be set using environment variable %s.",
151+
formatter.Colorize("Required for non IAM role based configurations.",
152+
formatter.GreenColor),
153+
util.AWSAccessKeyEnv))
154+
createAWSEARCmd.Flags().String("secret-access-key", "",
155+
fmt.Sprintf("AWS Secret Access Key. %s "+
156+
"Can also be set using environment variable %s.",
157+
formatter.Colorize("Required for non IAM role based configurations.",
158+
formatter.GreenColor),
159+
util.AWSSecretAccessKeyEnv))
160+
createAWSEARCmd.MarkFlagsRequiredTogether("access-key-id", "secret-access-key")
161+
createAWSEARCmd.Flags().String("region", "",
162+
fmt.Sprintf("AWS region where the customer master key is located. "+
163+
"Can also be set using environment variable %s",
164+
util.AWSRegionEnv))
165+
createAWSEARCmd.Flags().Bool("use-iam-instance-profile", false,
166+
"[Optional] Use IAM Role from the YugabyteDB Anywhere Host. EAR "+
167+
"creation will fail on insufficient permissions on the host. (default false)")
168+
169+
createAWSEARCmd.Flags().String("cmk-id", "",
170+
"[Optional] Customer Master Key ID. "+
171+
"If an identifier is not entered, a CMK ID will be auto-generated.")
172+
createAWSEARCmd.Flags().String("endpoint", "",
173+
"[Optional] AWS KMS Endpoint.")
174+
createAWSEARCmd.Flags().String("cmk-policy-file-path", "",
175+
"[Optional] AWS KMS Customer Master Key Policy file path. "+
176+
"Custom policy file is not needed when Customer Master Key ID is specified. "+
177+
"Allowed file type is json.")
178+
}

managed/yba-cli/cmd/ear/azu/azu_ear.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var AzureEARCmd = &cobra.Command{
2626
func init() {
2727
AzureEARCmd.Flags().SortFlags = false
2828

29-
// AzureEARCmd.AddCommand(createAzureEARCmd)
29+
AzureEARCmd.AddCommand(createAzureEARCmd)
3030
// AzureEARCmd.AddCommand(updateAzureEARCmd)
3131
AzureEARCmd.AddCommand(listAzureEARCmd)
3232
AzureEARCmd.AddCommand(describeAzureEARCmd)

0 commit comments

Comments
 (0)