@@ -44,6 +44,7 @@ import (
4444 "github.com/getsops/sops/v3/stores"
4545 "github.com/getsops/sops/v3/stores/dotenv"
4646 "github.com/getsops/sops/v3/stores/json"
47+ "github.com/getsops/sops/v3/tcloudkms"
4748 "github.com/getsops/sops/v3/version"
4849)
4950
@@ -91,13 +92,13 @@ func main() {
9192 },
9293 }
9394 app .Name = "sops"
94- app .Usage = "sops - encrypted file editor with AWS KMS, GCP KMS, HuaweiCloud KMS, Azure Key Vault, age, and GPG support"
95+ app .Usage = "sops - encrypted file editor with AWS KMS, GCP KMS, HuaweiCloud KMS, T Cloud Public KMS, Azure Key Vault, age, and GPG support"
9596 app .ArgsUsage = "sops [options] file"
9697 app .Version = version .Version
9798 app .Authors = []cli.Author {
9899 {Name : "CNCF Maintainers" },
99100 }
100- app .UsageText = `sops is an editor of encrypted files that supports AWS KMS, GCP, HuaweiCloud KMS, AZKV,
101+ app .UsageText = `sops is an editor of encrypted files that supports AWS KMS, GCP, HuaweiCloud KMS, T Cloud Public KMS, AZKV,
101102 PGP, and Age
102103
103104 To encrypt or decrypt a document with AWS KMS, specify the KMS ARN
@@ -117,6 +118,12 @@ func main() {
117118 HUAWEICLOUD_SDK_AK, HUAWEICLOUD_SDK_SK, HUAWEICLOUD_SDK_PROJECT_ID, or
118119 use credentials file at ~/.huaweicloud/credentials)
119120
121+ To encrypt or decrypt a document with T Cloud Public KMS, specify the
122+ T Cloud Public KMS key ID (format: key-uuid) in the --tcloudkms flag or in the
123+ OS_KMS_IDS environment variable.
124+ (You need to setup T Cloud Public credentials via environment variables:
125+ OS_ACCESS_KEY, OS_SECRET_KEY, OS_AUTH_URL)
126+
120127 To encrypt or decrypt a document with HashiCorp Vault's Transit Secret
121128 Engine, specify the Vault key URI name in the --hc-vault-transit flag
122129 or in the SOPS_VAULT_URIS environment variable (for example
@@ -180,7 +187,8 @@ func main() {
180187 fmt .Fprint (c .App .Writer , GenZshCompletion (app .Name ))
181188 return nil
182189 },
183- }},
190+ },
191+ },
184192 },
185193 {
186194 Name : "exec-env" ,
@@ -582,6 +590,10 @@ func main() {
582590 Name : "hckms" ,
583591 Usage : "the HuaweiCloud KMS key ID (format: region:key-uuid) the new group should contain. Can be specified more than once" ,
584592 },
593+ cli.StringSliceFlag {
594+ Name : "tcloudkms" ,
595+ Usage : "the T Cloud Public KMS key ID (format: key-uuid) the new group should contain. Can be specified more than once" ,
596+ },
585597 cli.StringSliceFlag {
586598 Name : "azure-kv" ,
587599 Usage : "the Azure Key Vault key URL the new group should contain. Can be specified more than once" ,
@@ -950,6 +962,11 @@ func main() {
950962 Usage : "comma separated list of HuaweiCloud KMS key IDs (format: region:key-uuid)" ,
951963 EnvVar : "SOPS_HUAWEICLOUD_KMS_IDS" ,
952964 },
965+ cli.StringFlag {
966+ Name : "tcloudkms" ,
967+ Usage : "comma separated list of T Cloud Public KMS key IDs (format: key-uuid)" ,
968+ EnvVar : "SOPS_TCLOUD_KMS_IDS" ,
969+ },
953970 cli.StringFlag {
954971 Name : "azure-kv" ,
955972 Usage : "comma separated list of Azure Key Vault URLs" ,
@@ -1068,7 +1085,6 @@ func main() {
10681085 KeyServices : svcs ,
10691086 encryptConfig : encConfig ,
10701087 })
1071-
10721088 if err != nil {
10731089 return toExitError (err )
10741090 }
@@ -1143,6 +1159,14 @@ func main() {
11431159 Name : "rm-hckms" ,
11441160 Usage : "remove the provided comma-separated list of HuaweiCloud KMS key IDs (format: region:key-uuid) from the list of master keys on the given file" ,
11451161 },
1162+ cli.StringFlag {
1163+ Name : "add-tcloudkms" ,
1164+ Usage : "add the provided comma-separated list of T Cloud Public KMS key IDs (format: key-uuid) to the list of master keys on the given file" ,
1165+ },
1166+ cli.StringFlag {
1167+ Name : "rm-tcloudkms" ,
1168+ Usage : "remove the provided comma-separated list of T Cloud Public KMS key IDs (format: key-uuid) from the list of master keys on the given file" ,
1169+ },
11461170 cli.StringFlag {
11471171 Name : "add-azure-kv" ,
11481172 Usage : "add the provided comma-separated list of Azure Key Vault key URLs to the list of master keys on the given file" ,
@@ -1209,8 +1233,8 @@ func main() {
12091233 return toExitError (err )
12101234 }
12111235 if _ , err := os .Stat (fileName ); os .IsNotExist (err ) {
1212- if c .String ("add-kms" ) != "" || c .String ("add-pgp" ) != "" || c .String ("add-gcp-kms" ) != "" || c .String ("add-hckms" ) != "" || c .String ("add-hc-vault-transit" ) != "" || c .String ("add-azure-kv" ) != "" || c .String ("add-age" ) != "" ||
1213- c .String ("rm-kms" ) != "" || c .String ("rm-pgp" ) != "" || c .String ("rm-gcp-kms" ) != "" || c .String ("rm-hckms" ) != "" || c .String ("rm-hc-vault-transit" ) != "" || c .String ("rm-azure-kv" ) != "" || c .String ("rm-age" ) != "" {
1236+ if c .String ("add-kms" ) != "" || c .String ("add-pgp" ) != "" || c .String ("add-gcp-kms" ) != "" || c .String ("add-hckms" ) != "" || c .String ("add-tcloudkms" ) != "" || c . String ( "add- hc-vault-transit" ) != "" || c .String ("add-azure-kv" ) != "" || c .String ("add-age" ) != "" ||
1237+ c .String ("rm-kms" ) != "" || c .String ("rm-pgp" ) != "" || c .String ("rm-gcp-kms" ) != "" || c .String ("rm-hckms" ) != "" || c .String ("rm-tcloudkms" ) != "" || c . String ( "rm- hc-vault-transit" ) != "" || c .String ("rm-azure-kv" ) != "" || c .String ("rm-age" ) != "" {
12141238 return common .NewExitError (fmt .Sprintf ("Error: cannot add or remove keys on non-existent file %q, use the `edit` subcommand instead." , fileName ), codes .CannotChangeKeysFromNonExistentFile )
12151239 }
12161240 }
@@ -1301,6 +1325,11 @@ func main() {
13011325 Usage : "comma separated list of HuaweiCloud KMS key IDs (format: region:key-uuid)" ,
13021326 EnvVar : "SOPS_HUAWEICLOUD_KMS_IDS" ,
13031327 },
1328+ cli.StringFlag {
1329+ Name : "tcloudkms" ,
1330+ Usage : "comma separated list of T Cloud Public KMS key IDs (format: key-uuid)" ,
1331+ EnvVar : "SOPS_TCLOUD_KMS_IDS" ,
1332+ },
13041333 cli.StringFlag {
13051334 Name : "azure-kv" ,
13061335 Usage : "comma separated list of Azure Key Vault URLs" ,
@@ -1714,6 +1743,11 @@ func main() {
17141743 Usage : "comma separated list of HuaweiCloud KMS key IDs (format: region:key-uuid)" ,
17151744 EnvVar : "SOPS_HUAWEICLOUD_KMS_IDS" ,
17161745 },
1746+ cli.StringFlag {
1747+ Name : "tcloudkms" ,
1748+ Usage : "comma separated list of T Cloud Public KMS key IDs (format: key-uuid)" ,
1749+ EnvVar : "SOPS_TCLOUD_KMS_IDS" ,
1750+ },
17171751 cli.StringFlag {
17181752 Name : "azure-kv" ,
17191753 Usage : "comma separated list of Azure Key Vault URLs" ,
@@ -1770,6 +1804,14 @@ func main() {
17701804 Name : "rm-hckms" ,
17711805 Usage : "remove the provided comma-separated list of HuaweiCloud KMS key IDs (format: region:key-uuid) from the list of master keys on the given file" ,
17721806 },
1807+ cli.StringFlag {
1808+ Name : "add-tcloudkms" ,
1809+ Usage : "add the provided comma-separated list of T Cloud Public KMS key IDs (format: key-uuid) to the list of master keys on the given file" ,
1810+ },
1811+ cli.StringFlag {
1812+ Name : "rm-tcloudkms" ,
1813+ Usage : "remove the provided comma-separated list of T Cloud Public KMS key IDs (format: key-uuid) from the list of master keys on the given file" ,
1814+ },
17731815 cli.StringFlag {
17741816 Name : "add-azure-kv" ,
17751817 Usage : "add the provided comma-separated list of Azure Key Vault key URLs to the list of master keys on the given file" ,
@@ -1904,8 +1946,8 @@ func main() {
19041946 return toExitError (err )
19051947 }
19061948 if _ , err := os .Stat (fileName ); os .IsNotExist (err ) {
1907- if c .String ("add-kms" ) != "" || c .String ("add-pgp" ) != "" || c .String ("add-gcp-kms" ) != "" || c .String ("add-hckms" ) != "" || c .String ("add-hc-vault-transit" ) != "" || c .String ("add-azure-kv" ) != "" || c .String ("add-age" ) != "" ||
1908- c .String ("rm-kms" ) != "" || c .String ("rm-pgp" ) != "" || c .String ("rm-gcp-kms" ) != "" || c .String ("rm-hckms" ) != "" || c .String ("rm-hc-vault-transit" ) != "" || c .String ("rm-azure-kv" ) != "" || c .String ("rm-age" ) != "" {
1949+ if c .String ("add-kms" ) != "" || c .String ("add-pgp" ) != "" || c .String ("add-gcp-kms" ) != "" || c .String ("add-hckms" ) != "" || c .String ("add-tcloudkms" ) != "" || c . String ( "add- hc-vault-transit" ) != "" || c .String ("add-azure-kv" ) != "" || c .String ("add-age" ) != "" ||
1950+ c .String ("rm-kms" ) != "" || c .String ("rm-pgp" ) != "" || c .String ("rm-gcp-kms" ) != "" || c .String ("rm-hckms" ) != "" || c .String ("rm-tcloudkms" ) != "" || c . String ( "rm- hc-vault-transit" ) != "" || c .String ("rm-azure-kv" ) != "" || c .String ("rm-age" ) != "" {
19091951 return common .NewExitError (fmt .Sprintf ("Error: cannot add or remove keys on non-existent file %q, use `--kms` and `--pgp` instead." , fileName ), codes .CannotChangeKeysFromNonExistentFile )
19101952 }
19111953 if isEncryptMode || isDecryptMode || isRotateMode {
@@ -2235,7 +2277,7 @@ func getEncryptConfig(c *cli.Context, fileName string, inputStore common.Store,
22352277 }, nil
22362278}
22372279
2238- func getMasterKeys (c * cli.Context , kmsEncryptionContext map [string ]* string , kmsOptionName string , pgpOptionName string , gcpKmsOptionName string , hckmsOptionName string , azureKvOptionName string , hcVaultTransitOptionName string , ageOptionName string ) ([]keys.MasterKey , error ) {
2280+ func getMasterKeys (c * cli.Context , kmsEncryptionContext map [string ]* string , kmsOptionName string , pgpOptionName string , gcpKmsOptionName string , hckmsOptionName string , tcloudkmsOptionName string , azureKvOptionName string , hcVaultTransitOptionName string , ageOptionName string ) ([]keys.MasterKey , error ) {
22392281 var masterKeys []keys.MasterKey
22402282 for _ , k := range kms .MasterKeysFromArnString (c .String (kmsOptionName ), kmsEncryptionContext , c .String ("aws-profile" )) {
22412283 masterKeys = append (masterKeys , k )
@@ -2253,6 +2295,13 @@ func getMasterKeys(c *cli.Context, kmsEncryptionContext map[string]*string, kmsO
22532295 for _ , k := range hckmsKeys {
22542296 masterKeys = append (masterKeys , k )
22552297 }
2298+ tcloudkmsKeys , err := tcloudkms .NewMasterKeysFromKeyIDString (c .String (tcloudkmsOptionName ))
2299+ if err != nil {
2300+ return nil , err
2301+ }
2302+ for _ , k := range tcloudkmsKeys {
2303+ masterKeys = append (masterKeys , k )
2304+ }
22562305 azureKeys , err := azkv .MasterKeysFromURLs (c .String (azureKvOptionName ))
22572306 if err != nil {
22582307 return nil , err
@@ -2279,11 +2328,11 @@ func getMasterKeys(c *cli.Context, kmsEncryptionContext map[string]*string, kmsO
22792328
22802329func getRotateOpts (c * cli.Context , fileName string , inputStore common.Store , outputStore common.Store , svcs []keyservice.KeyServiceClient , decryptionOrder []string ) (rotateOpts , error ) {
22812330 kmsEncryptionContext := kms .ParseKMSContext (c .String ("encryption-context" ))
2282- addMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "add-kms" , "add-pgp" , "add-gcp-kms" , "add-hckms" , "add-azure-kv" , "add-hc-vault-transit" , "add-age" )
2331+ addMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "add-kms" , "add-pgp" , "add-gcp-kms" , "add-hckms" , "add-tcloudkms" , "add- azure-kv" , "add-hc-vault-transit" , "add-age" )
22832332 if err != nil {
22842333 return rotateOpts {}, err
22852334 }
2286- rmMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "rm-kms" , "rm-pgp" , "rm-gcp-kms" , "rm-hckms" , "rm-azure-kv" , "rm-hc-vault-transit" , "rm-age" )
2335+ rmMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "rm-kms" , "rm-pgp" , "rm-gcp-kms" , "rm-hckms" , "rm-tcloudkms" , "rm- azure-kv" , "rm-hc-vault-transit" , "rm-age" )
22872336 if err != nil {
22882337 return rotateOpts {}, err
22892338 }
@@ -2432,6 +2481,7 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
24322481 var azkvKeys []keys.MasterKey
24332482 var hcVaultMkKeys []keys.MasterKey
24342483 var hckmsMkKeys []keys.MasterKey
2484+ var tcloudkmsMkKeys []keys.MasterKey
24352485 var ageMasterKeys []keys.MasterKey
24362486 kmsEncryptionContext := kms .ParseKMSContext (c .String ("encryption-context" ))
24372487 if c .String ("encryption-context" ) != "" && kmsEncryptionContext == nil {
@@ -2456,6 +2506,15 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
24562506 hckmsMkKeys = append (hckmsMkKeys , k )
24572507 }
24582508 }
2509+ if c .String ("tcloudkms" ) != "" {
2510+ tcloudkmsKeys , err := tcloudkms .NewMasterKeysFromKeyIDString (c .String ("tcloudkms" ))
2511+ if err != nil {
2512+ return nil , err
2513+ }
2514+ for _ , k := range tcloudkmsKeys {
2515+ tcloudkmsMkKeys = append (tcloudkmsMkKeys , k )
2516+ }
2517+ }
24592518 if c .String ("azure-kv" ) != "" {
24602519 azureKeys , err := azkv .MasterKeysFromURLs (c .String ("azure-kv" ))
24612520 if err != nil {
@@ -2488,7 +2547,7 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
24882547 ageMasterKeys = append (ageMasterKeys , k )
24892548 }
24902549 }
2491- if c .String ("kms" ) == "" && c .String ("pgp" ) == "" && c .String ("gcp-kms" ) == "" && c .String ("hckms" ) == "" && c .String ("azure-kv" ) == "" && c .String ("hc-vault-transit" ) == "" && c .String ("age" ) == "" {
2550+ if c .String ("kms" ) == "" && c .String ("pgp" ) == "" && c .String ("gcp-kms" ) == "" && c .String ("hckms" ) == "" && c .String ("tcloudkms" ) == "" && c . String ( " azure-kv" ) == "" && c .String ("hc-vault-transit" ) == "" && c .String ("age" ) == "" {
24922551 conf := optionalConfig
24932552 var err error
24942553 if conf == nil {
@@ -2508,6 +2567,7 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
25082567 group = append (group , kmsKeys ... )
25092568 group = append (group , cloudKmsKeys ... )
25102569 group = append (group , hckmsMkKeys ... )
2570+ group = append (group , tcloudkmsMkKeys ... )
25112571 group = append (group , azkvKeys ... )
25122572 group = append (group , pgpKeys ... )
25132573 group = append (group , hcVaultMkKeys ... )
0 commit comments