@@ -37,9 +37,11 @@ import (
3737 "github.com/getsops/sops/v3/hckms"
3838 "github.com/getsops/sops/v3/hcvault"
3939 "github.com/getsops/sops/v3/keys"
40+ "github.com/getsops/sops/v3/tencentkms"
4041 "github.com/getsops/sops/v3/keyservice"
4142 "github.com/getsops/sops/v3/kms"
4243 "github.com/getsops/sops/v3/logging"
44+
4345 "github.com/getsops/sops/v3/pgp"
4446 "github.com/getsops/sops/v3/stores"
4547 "github.com/getsops/sops/v3/stores/dotenv"
@@ -91,7 +93,8 @@ func main() {
9193 },
9294 }
9395 app .Name = "sops"
94- app .Usage = "sops - encrypted file editor with AWS KMS, GCP KMS, HuaweiCloud KMS, Azure Key Vault, age, and GPG support"
96+ app .Usage = "sops - encrypted file editor with AWS KMS, GCP KMS, Tencent Cloud KMS, HuaweiCloud KMS, Azure Key Vault, age, and GPG support"
97+
9598 app .ArgsUsage = "sops [options] file"
9699 app .Version = version .Version
97100 app .Authors = []cli.Author {
@@ -110,7 +113,14 @@ func main() {
110113 (You need to setup Google application default credentials. See
111114 https://developers.google.com/identity/protocols/application-default-credentials)
112115
116+ To encrypt or decrypt a document with Tencent Cloud KMS, specify the
117+ Tencent Cloud KMS key ID in the --tencent-kms flag or in the
118+ SOPS_TENCENT_KMS_IDS environment variable.
119+ (You need to setup Tencent Cloud credentials via TENCENTCLOUD_SECRET_ID,
120+ TENCENTCLOUD_SECRET_KEY, optional TENCENTCLOUD_TOKEN for STS, and TENCENTCLOUD_REGION)
121+
113122 To encrypt or decrypt a document with HuaweiCloud KMS, specify the
123+
114124 HuaweiCloud KMS key ID (format: region:key-uuid) in the --hckms flag or in the
115125 SOPS_HUAWEICLOUD_KMS_IDS environment variable.
116126 (You need to setup HuaweiCloud credentials via environment variables:
@@ -955,6 +965,7 @@ func main() {
955965 Usage : "comma separated list of Azure Key Vault URLs" ,
956966 EnvVar : "SOPS_AZURE_KEYVAULT_URLS" ,
957967 },
968+
958969 cli.StringFlag {
959970 Name : "hc-vault-transit" ,
960971 Usage : "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')" ,
@@ -970,6 +981,11 @@ func main() {
970981 Usage : "comma separated list of age recipients" ,
971982 EnvVar : "SOPS_AGE_RECIPIENTS" ,
972983 },
984+ cli.StringFlag {
985+ Name : "tencent-kms" ,
986+ Usage : "comma separated list of Tencent Cloud KMS key IDs" ,
987+ EnvVar : "SOPS_TENCENT_KMS_IDS" ,
988+ },
973989 cli.StringFlag {
974990 Name : "input-type" ,
975991 Usage : "currently json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type" ,
@@ -1306,6 +1322,7 @@ func main() {
13061322 Usage : "comma separated list of Azure Key Vault URLs" ,
13071323 EnvVar : "SOPS_AZURE_KEYVAULT_URLS" ,
13081324 },
1325+
13091326 cli.StringFlag {
13101327 Name : "hc-vault-transit" ,
13111328 Usage : "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')" ,
@@ -1321,6 +1338,11 @@ func main() {
13211338 Usage : "comma separated list of age recipients" ,
13221339 EnvVar : "SOPS_AGE_RECIPIENTS" ,
13231340 },
1341+ cli.StringFlag {
1342+ Name : "tencent-kms" ,
1343+ Usage : "comma separated list of Tencent Cloud KMS key IDs" ,
1344+ EnvVar : "SOPS_TENCENT_KMS_IDS" ,
1345+ },
13241346 cli.StringFlag {
13251347 Name : "input-type" ,
13261348 Usage : "currently json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type" ,
@@ -1704,21 +1726,22 @@ func main() {
17041726 Name : "aws-profile" ,
17051727 Usage : "The AWS profile to use for requests to AWS" ,
17061728 },
1707- cli.StringFlag {
1708- Name : "gcp-kms" ,
1709- Usage : "comma separated list of GCP KMS resource IDs" ,
1710- EnvVar : "SOPS_GCP_KMS_IDS" ,
1711- },
1712- cli.StringFlag {
1713- Name : "hckms" ,
1714- Usage : "comma separated list of HuaweiCloud KMS key IDs (format: region:key-uuid)" ,
1715- EnvVar : "SOPS_HUAWEICLOUD_KMS_IDS" ,
1716- },
1717- cli.StringFlag {
1718- Name : "azure-kv" ,
1719- Usage : "comma separated list of Azure Key Vault URLs" ,
1720- EnvVar : "SOPS_AZURE_KEYVAULT_URLS" ,
1721- },
1729+ cli.StringFlag {
1730+ Name : "gcp-kms" ,
1731+ Usage : "comma separated list of GCP KMS resource IDs" ,
1732+ EnvVar : "SOPS_GCP_KMS_IDS" ,
1733+ },
1734+ cli.StringFlag {
1735+ Name : "hckms" ,
1736+ Usage : "comma separated list of HuaweiCloud KMS key IDs (format: region:key-uuid)" ,
1737+ EnvVar : "SOPS_HUAWEICLOUD_KMS_IDS" ,
1738+ },
1739+ cli.StringFlag {
1740+ Name : "azure-kv" ,
1741+ Usage : "comma separated list of Azure Key Vault URLs" ,
1742+ EnvVar : "SOPS_AZURE_KEYVAULT_URLS" ,
1743+ },
1744+
17221745 cli.StringFlag {
17231746 Name : "hc-vault-transit" ,
17241747 Usage : "comma separated list of vault's key URI (e.g. 'https://vault.example.org:8200/v1/transit/keys/dev')" ,
@@ -1734,6 +1757,11 @@ func main() {
17341757 Usage : "comma separated list of age recipients" ,
17351758 EnvVar : "SOPS_AGE_RECIPIENTS" ,
17361759 },
1760+ cli.StringFlag {
1761+ Name : "tencent-kms" ,
1762+ Usage : "comma separated list of Tencent Cloud KMS key IDs" ,
1763+ EnvVar : "SOPS_TENCENT_KMS_IDS" ,
1764+ },
17371765 cli.BoolFlag {
17381766 Name : "in-place, i" ,
17391767 Usage : "write output back to the same file instead of stdout" ,
@@ -1810,6 +1838,14 @@ func main() {
18101838 Name : "rm-pgp" ,
18111839 Usage : "remove the provided comma-separated list of PGP fingerprints from the list of master keys on the given file" ,
18121840 },
1841+ cli.StringFlag {
1842+ Name : "add-tencent-kms" ,
1843+ Usage : "add the provided comma-separated list of Tencent Cloud KMS key IDs to the list of master keys on the given file" ,
1844+ },
1845+ cli.StringFlag {
1846+ Name : "rm-tencent-kms" ,
1847+ Usage : "remove the provided comma-separated list of Tencent Cloud KMS key IDs from the list of master keys on the given file" ,
1848+ },
18131849 cli.BoolFlag {
18141850 Name : "ignore-mac" ,
18151851 Usage : "ignore Message Authentication Code during decryption" ,
@@ -2235,7 +2271,7 @@ func getEncryptConfig(c *cli.Context, fileName string, inputStore common.Store,
22352271 }, nil
22362272}
22372273
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 ) {
2274+ func getMasterKeys (c * cli.Context , kmsEncryptionContext map [string ]* string , kmsOptionName string , pgpOptionName string , gcpKmsOptionName string , hckmsOptionName string , azureKvOptionName string , hcVaultTransitOptionName string , ageOptionName string , tencentKmsOptionName string ) ([]keys.MasterKey , error ) {
22392275 var masterKeys []keys.MasterKey
22402276 for _ , k := range kms .MasterKeysFromArnString (c .String (kmsOptionName ), kmsEncryptionContext , c .String ("aws-profile" )) {
22412277 masterKeys = append (masterKeys , k )
@@ -2274,16 +2310,19 @@ func getMasterKeys(c *cli.Context, kmsEncryptionContext map[string]*string, kmsO
22742310 for _ , k := range ageKeys {
22752311 masterKeys = append (masterKeys , k )
22762312 }
2313+ for _ , k := range tencentkms .MasterKeysFromKeyIDString (c .String (tencentKmsOptionName )) {
2314+ masterKeys = append (masterKeys , k )
2315+ }
22772316 return masterKeys , nil
22782317}
22792318
22802319func getRotateOpts (c * cli.Context , fileName string , inputStore common.Store , outputStore common.Store , svcs []keyservice.KeyServiceClient , decryptionOrder []string ) (rotateOpts , error ) {
22812320 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" )
2321+ addMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "add-kms" , "add-pgp" , "add-gcp-kms" , "add-hckms" , "add-azure-kv" , "add-hc-vault-transit" , "add-age" , "add-tencent-kms" )
22832322 if err != nil {
22842323 return rotateOpts {}, err
22852324 }
2286- rmMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "rm-kms" , "rm-pgp" , "rm-gcp-kms" , "rm-hckms" , "rm-azure-kv" , "rm-hc-vault-transit" , "rm-age" )
2325+ rmMasterKeys , err := getMasterKeys (c , kmsEncryptionContext , "rm-kms" , "rm-pgp" , "rm-gcp-kms" , "rm-hckms" , "rm-azure-kv" , "rm-hc-vault-transit" , "rm-age" , "rm-tencent-kms" )
22872326 if err != nil {
22882327 return rotateOpts {}, err
22892328 }
@@ -2433,6 +2472,7 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
24332472 var hcVaultMkKeys []keys.MasterKey
24342473 var hckmsMkKeys []keys.MasterKey
24352474 var ageMasterKeys []keys.MasterKey
2475+ var tencentkmsMkKeys []keys.MasterKey
24362476 kmsEncryptionContext := kms .ParseKMSContext (c .String ("encryption-context" ))
24372477 if c .String ("encryption-context" ) != "" && kmsEncryptionContext == nil {
24382478 return nil , common .NewExitError ("Invalid KMS encryption context format" , codes .ErrorInvalidKMSEncryptionContextFormat )
@@ -2488,7 +2528,12 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
24882528 ageMasterKeys = append (ageMasterKeys , k )
24892529 }
24902530 }
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" ) == "" {
2531+ if c .String ("tencent-kms" ) != "" {
2532+ for _ , k := range tencentkms .MasterKeysFromKeyIDString (c .String ("tencent-kms" )) {
2533+ tencentkmsMkKeys = append (tencentkmsMkKeys , k )
2534+ }
2535+ }
2536+ 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" ) == "" && c .String ("tencent-kms" ) == "" {
24922537 conf := optionalConfig
24932538 var err error
24942539 if conf == nil {
@@ -2512,6 +2557,7 @@ func keyGroups(c *cli.Context, file string, optionalConfig *config.Config) ([]so
25122557 group = append (group , pgpKeys ... )
25132558 group = append (group , hcVaultMkKeys ... )
25142559 group = append (group , ageMasterKeys ... )
2560+ group = append (group , tencentkmsMkKeys ... )
25152561 log .Debugf ("Master keys available: %+v" , group )
25162562 return []sops.KeyGroup {group }, nil
25172563}
0 commit comments