libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 01/01: Fix inadvertent regression introduced in v3.3.0 which would break EC2 driver for some reasons because the driver would incorrectly try to use signature version 2 where it should use version 4.
Date Fri, 22 Jan 2021 15:59:15 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch ec2_regression_signature_version_fix
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit 7ddb35a3a1a7d010a43d1dd84668566cb60ef503
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Fri Jan 22 16:57:39 2021 +0100

    Fix inadvertent regression introduced in v3.3.0 which would break EC2
    driver for some reasons because the driver would incorrectly try to
    use signature version 2 where it should use version 4.
    
    Also add support for overriding which signature version is used by
    passing "signature_version" argument to the driver constructor.
    
    Original issue reported by @olegrtecno (#1545).
---
 contrib/scrape-ec2-sizes.py                        |  2 +-
 libcloud/compute/constants/ec2_instance_types.py   |  8 +--
 .../constants/ec2_region_details_complete.py       | 53 +++++++++++++++++-
 .../constants/ec2_region_details_partial.py        | 62 ++++++++++++++--------
 libcloud/compute/drivers/ec2.py                    | 14 +++--
 libcloud/test/compute/test_ec2.py                  | 27 ++++++++++
 6 files changed, 136 insertions(+), 30 deletions(-)

diff --git a/contrib/scrape-ec2-sizes.py b/contrib/scrape-ec2-sizes.py
index 3470a2b..9d38dd5 100755
--- a/contrib/scrape-ec2-sizes.py
+++ b/contrib/scrape-ec2-sizes.py
@@ -374,7 +374,7 @@ def dump():
 
     # 3. Write file with partial region details (everything except instance_types attribute)
     regions_partial = {}
-    keys_to_keep = ["api_name", "country", "id", "endpoint"]
+    keys_to_keep = ["api_name", "country", "id", "endpoint", "signature_version"]
 
     for region_name, region_details in regions.items():
         regions_partial[region_name] = {}
diff --git a/libcloud/compute/constants/ec2_instance_types.py b/libcloud/compute/constants/ec2_instance_types.py
index f6f9e89..3f8efd8 100644
--- a/libcloud/compute/constants/ec2_instance_types.py
+++ b/libcloud/compute/constants/ec2_instance_types.py
@@ -7861,7 +7861,6 @@ INSTANCE_TYPES = {
             "enhancedNetworkingSupported": "Yes",
             "instanceFamily": "Memory optimized",
             "instanceType": "r5b.12xlarge",
-            "instancesku": "7P2YNCQ6H3U2X5QF",
             "intelAvx2Available": "No",
             "intelAvxAvailable": "Yes",
             "intelTurboAvailable": "No",
@@ -7919,7 +7918,7 @@ INSTANCE_TYPES = {
             "enhancedNetworkingSupported": "Yes",
             "instanceFamily": "Memory optimized",
             "instanceType": "r5b.24xlarge",
-            "instancesku": "4EU892NQBG6BUNYX",
+            "instancesku": "ACQGXR86YVD63UND",
             "intelAvx2Available": "No",
             "intelAvxAvailable": "Yes",
             "intelTurboAvailable": "No",
@@ -8034,7 +8033,7 @@ INSTANCE_TYPES = {
             "enhancedNetworkingSupported": "Yes",
             "instanceFamily": "Memory optimized",
             "instanceType": "r5b.large",
-            "instancesku": "FRZJP32T9SK4EF2X",
+            "instancesku": "ZKY4MDE2M5KFXBKB",
             "intelAvx2Available": "No",
             "intelAvxAvailable": "Yes",
             "intelTurboAvailable": "No",
@@ -9889,7 +9888,7 @@ INSTANCE_TYPES = {
             "enhancedNetworkingSupported": "No",
             "instanceFamily": "General purpose",
             "instanceType": "t4g.2xlarge",
-            "instancesku": "5GRYRXZ4H2TXBSTD",
+            "instancesku": "W6EAUTAAWGZMSKZH",
             "intelAvx2Available": "No",
             "intelAvxAvailable": "No",
             "intelTurboAvailable": "No",
@@ -9975,6 +9974,7 @@ INSTANCE_TYPES = {
             "enhancedNetworkingSupported": "No",
             "instanceFamily": "General purpose",
             "instanceType": "t4g.micro",
+            "instancesku": "S2M8BS97FGPUHMN7",
             "intelAvx2Available": "No",
             "intelAvxAvailable": "No",
             "intelTurboAvailable": "No",
diff --git a/libcloud/compute/constants/ec2_region_details_complete.py b/libcloud/compute/constants/ec2_region_details_complete.py
index 7874b1b..d237df6 100644
--- a/libcloud/compute/constants/ec2_region_details_complete.py
+++ b/libcloud/compute/constants/ec2_region_details_complete.py
@@ -641,7 +641,15 @@ REGION_DETAILS = {
             "t3.micro",
             "t3.nano",
             "t3.small",
-            "t3.xlarge"
+            "t3.xlarge",
+            "x1.16xlarge",
+            "x1.32xlarge",
+            "x1e.16xlarge",
+            "x1e.2xlarge",
+            "x1e.32xlarge",
+            "x1e.4xlarge",
+            "x1e.8xlarge",
+            "x1e.xlarge"
         ],
         "signature_version": "4"
     },
@@ -1157,6 +1165,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "x1.16xlarge",
             "x1.32xlarge",
             "x1e.16xlarge",
@@ -1420,6 +1435,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "x1.16xlarge",
             "x1.32xlarge",
             "x1e.16xlarge",
@@ -1632,6 +1654,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "x1.16xlarge",
             "x1.32xlarge",
             "x1e.16xlarge",
@@ -2301,6 +2330,7 @@ REGION_DETAILS = {
             "p3.2xlarge",
             "p3.8xlarge",
             "p3dn.24xlarge",
+            "p4d.24xlarge",
             "r3.2xlarge",
             "r3.4xlarge",
             "r3.8xlarge",
@@ -2618,6 +2648,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "x1.16xlarge",
             "x1.32xlarge",
             "z1d.12xlarge",
@@ -3008,6 +3045,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "x1.16xlarge",
             "x1.32xlarge",
             "x1e.16xlarge",
@@ -3944,6 +3988,13 @@ REGION_DETAILS = {
             "t3a.nano",
             "t3a.small",
             "t3a.xlarge",
+            "t4g.2xlarge",
+            "t4g.large",
+            "t4g.medium",
+            "t4g.micro",
+            "t4g.nano",
+            "t4g.small",
+            "t4g.xlarge",
             "z1d.12xlarge",
             "z1d.2xlarge",
             "z1d.3xlarge",
diff --git a/libcloud/compute/constants/ec2_region_details_partial.py b/libcloud/compute/constants/ec2_region_details_partial.py
index 5a1fae7..745fb26 100644
--- a/libcloud/compute/constants/ec2_region_details_partial.py
+++ b/libcloud/compute/constants/ec2_region_details_partial.py
@@ -19,120 +19,140 @@ REGION_DETAILS = {
         "api_name": "ec2_ap_northeast",
         "country": "Japan",
         "endpoint": "ec2.ap-northeast-1.amazonaws.com",
-        "id": "ap-northeast-1"
+        "id": "ap-northeast-1",
+        "signature_version": "2"
     },
     "ap-northeast-2": {
         "api_name": "ec2_ap_northeast",
         "country": "South Korea",
         "endpoint": "ec2.ap-northeast-2.amazonaws.com",
-        "id": "ap-northeast-2"
+        "id": "ap-northeast-2",
+        "signature_version": "4"
     },
     "ap-northeast-3": {
         "api_name": "ec2_ap_northeast",
         "country": "Japan",
         "endpoint": "ec2.ap-northeast-3.amazonaws.com",
-        "id": "ap-northeast-3"
+        "id": "ap-northeast-3",
+        "signature_version": "4"
     },
     "ap-south-1": {
         "api_name": "ec2_ap_south_1",
         "country": "India",
         "endpoint": "ec2.ap-south-1.amazonaws.com",
-        "id": "ap-south-1"
+        "id": "ap-south-1",
+        "signature_version": "4"
     },
     "ap-southeast-1": {
         "api_name": "ec2_ap_southeast",
         "country": "Singapore",
         "endpoint": "ec2.ap-southeast-1.amazonaws.com",
-        "id": "ap-southeast-1"
+        "id": "ap-southeast-1",
+        "signature_version": "2"
     },
     "ap-southeast-2": {
         "api_name": "ec2_ap_southeast_2",
         "country": "Australia",
         "endpoint": "ec2.ap-southeast-2.amazonaws.com",
-        "id": "ap-southeast-2"
+        "id": "ap-southeast-2",
+        "signature_version": "2"
     },
     "ca-central-1": {
         "api_name": "ec2_ca_central_1",
         "country": "Canada",
         "endpoint": "ec2.ca-central-1.amazonaws.com",
-        "id": "ca-central-1"
+        "id": "ca-central-1",
+        "signature_version": "4"
     },
     "cn-north-1": {
         "api_name": "ec2_cn_north",
         "country": "China",
         "endpoint": "ec2.cn-north-1.amazonaws.com.cn",
-        "id": "cn-north-1"
+        "id": "cn-north-1",
+        "signature_version": "4"
     },
     "cn-northwest-1": {
         "api_name": "ec2_cn_northwest",
         "country": "China",
         "endpoint": "ec2.cn-northwest-1.amazonaws.com.cn",
-        "id": "cn-northwest-1"
+        "id": "cn-northwest-1",
+        "signature_version": "4"
     },
     "eu-central-1": {
         "api_name": "ec2_eu_central",
         "country": "Frankfurt",
         "endpoint": "ec2.eu-central-1.amazonaws.com",
-        "id": "eu-central-1"
+        "id": "eu-central-1",
+        "signature_version": "4"
     },
     "eu-north-1": {
         "api_name": "ec2_eu_north_stockholm",
         "country": "Stockholm",
         "endpoint": "ec2.eu-north-1.amazonaws.com",
-        "id": "eu-north-1"
+        "id": "eu-north-1",
+        "signature_version": "4"
     },
     "eu-west-1": {
         "api_name": "ec2_eu_west",
         "country": "Ireland",
         "endpoint": "ec2.eu-west-1.amazonaws.com",
-        "id": "eu-west-1"
+        "id": "eu-west-1",
+        "signature_version": "2"
     },
     "eu-west-2": {
         "api_name": "ec2_eu_west_london",
         "country": "United Kingdom",
         "endpoint": "ec2.eu-west-2.amazonaws.com",
-        "id": "eu-west-2"
+        "id": "eu-west-2",
+        "signature_version": "4"
     },
     "eu-west-3": {
         "api_name": "ec2_eu_west_paris",
         "country": "France",
         "endpoint": "ec2.eu-west-3.amazonaws.com",
-        "id": "eu-west-3"
+        "id": "eu-west-3",
+        "signature_version": "4"
     },
     "sa-east-1": {
         "api_name": "ec2_sa_east",
         "country": "Brazil",
         "endpoint": "ec2.sa-east-1.amazonaws.com",
-        "id": "sa-east-1"
+        "id": "sa-east-1",
+        "signature_version": "2"
     },
     "us-east-1": {
         "api_name": "ec2_us_east",
         "country": "USA",
         "endpoint": "ec2.us-east-1.amazonaws.com",
-        "id": "us-east-1"
+        "id": "us-east-1",
+        "signature_version": "2"
     },
     "us-east-2": {
         "api_name": "ec2_us_east_ohio",
         "country": "USA",
         "endpoint": "ec2.us-east-2.amazonaws.com",
-        "id": "us-east-2"
+        "id": "us-east-2",
+        "signature_version": "4"
     },
     "us-gov-west-1": {
         "api_name": "ec2_us_govwest",
         "country": "US",
         "endpoint": "ec2.us-gov-west-1.amazonaws.com",
-        "id": "us-gov-west-1"
+        "id": "us-gov-west-1",
+        "signature_version": "2"
     },
     "us-west-1": {
         "api_name": "ec2_us_west",
         "country": "USA",
         "endpoint": "ec2.us-west-1.amazonaws.com",
-        "id": "us-west-1"
+        "id": "us-west-1",
+        "signature_version": "2"
     },
     "us-west-2": {
         "api_name": "ec2_us_west_oregon",
         "country": "US",
         "endpoint": "ec2.us-west-2.amazonaws.com",
-        "id": "us-west-2"
+        "id": "us-west-2",
+        "signature_version": "2"
     }
-}
\ No newline at end of file
+}
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 5eb6a21..0c5f2fc 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -5788,7 +5788,7 @@ class EC2NodeDriver(BaseEC2NodeDriver):
     }
 
     def __init__(self, key, secret=None, secure=True, host=None, port=None,
-                 region='us-east-1', token=None, **kwargs):
+                 region='us-east-1', token=None, signature_version=None, **kwargs):
         if hasattr(self, '_region'):
             region = self._region  # pylint: disable=no-member
 
@@ -5801,8 +5801,16 @@ class EC2NodeDriver(BaseEC2NodeDriver):
         self.token = token
         self.api_name = details['api_name']
         self.country = details['country']
-        self.signature_version = details.get('signature_version',
-                                             DEFAULT_SIGNATURE_VERSION)
+
+        # Precedencs goes as follow from highest to lowest:
+        # 1. signature_version constructor argument
+        # 2. signature_version in constants file
+        # 3. DEFAULT_SIGNATURE_VERSION constant
+        if signature_version:
+            self.signature_version = signature_version
+        else:
+            self.signature_version = details.get('signature_version',
+                                                 DEFAULT_SIGNATURE_VERSION)
 
         host = host or details['endpoint']
 
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 4814fe4..763ac83 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -106,6 +106,33 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.driver = EC2NodeDriver(*EC2_PARAMS,
                                     **{'region': self.region})
 
+    def test_regions_and_signature_versions(self):
+        # Verify that correct signature versions are used for each region
+        driver = EC2NodeDriver(*EC2_PARAMS, region="us-east-1")
+        self.assertEqual(driver.signature_version, "2")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="us-east-2")
+        self.assertEqual(driver.signature_version, "4")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="eu-west-1")
+        self.assertEqual(driver.signature_version, "2")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="eu-west-3")
+        self.assertEqual(driver.signature_version, "4")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="ca-central-1")
+        self.assertEqual(driver.signature_version, "4")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="eu-central-1")
+        self.assertEqual(driver.signature_version, "4")
+
+        # Verify that signature_version can be overriden via constructor argument
+        driver = EC2NodeDriver(*EC2_PARAMS, region="us-east-1", signature_version="4")
+        self.assertEqual(driver.signature_version, "4")
+
+        driver = EC2NodeDriver(*EC2_PARAMS, region="eu-central-1", signature_version="2")
+        self.assertEqual(driver.signature_version, "2")
+
     def test_instantiate_driver_with_token(self):
         token = 'temporary_credentials_token'
         driver = EC2NodeDriver(*EC2_PARAMS, **{'region': self.region, 'token': token})


Mime
View raw message