From 008dc18b53c6045b77826b581bf8586c4fea33b5 Mon Sep 17 00:00:00 2001 From: Grant Soyka Date: Wed, 11 Oct 2017 15:15:58 -0600 Subject: [PATCH 1/5] Set null value for response --- s3iam.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/s3iam.py b/s3iam.py index 169cdf6..0ebb7ef 100755 --- a/s3iam.py +++ b/s3iam.py @@ -233,7 +233,8 @@ def get_role(self): "http://169.254.169.254", "/latest/meta-data/iam/security-credentials/" )) - + + response = None try: response = urllib2.urlopen(request) self.iamrole = (response.read()) From 7b77f349f6f3cc2e3ce8f8ca4379f47562cb78a9 Mon Sep 17 00:00:00 2001 From: Grant Soyka Date: Wed, 11 Oct 2017 15:33:37 -0600 Subject: [PATCH 2/5] Add timeout --- s3iam.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/s3iam.py b/s3iam.py index 0ebb7ef..ce2b5b2 100755 --- a/s3iam.py +++ b/s3iam.py @@ -234,9 +234,8 @@ def get_role(self): "/latest/meta-data/iam/security-credentials/" )) - response = None try: - response = urllib2.urlopen(request) + response = urllib2.urlopen(request, timeout=2) self.iamrole = (response.read()) except Exception: response = None From f259933c070cdcf1f33dfd906827bc57f73a5830 Mon Sep 17 00:00:00 2001 From: Grant Soyka Date: Wed, 11 Oct 2017 15:39:08 -0600 Subject: [PATCH 3/5] Add another timeout --- s3iam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s3iam.py b/s3iam.py index ce2b5b2..9d8b1da 100755 --- a/s3iam.py +++ b/s3iam.py @@ -257,7 +257,7 @@ def get_credentials(self): ), self.iamrole)) try: - response = urllib2.urlopen(request) + response = urllib2.urlopen(request, timeout=2) data = json.loads(response.read()) self.access_key = data['AccessKeyId'] self.secret_key = data['SecretAccessKey'] From 5c3a5748646ee9eb429a2ab81041a86b2d7d4f92 Mon Sep 17 00:00:00 2001 From: Grant Soyka Date: Wed, 11 Oct 2017 15:41:48 -0600 Subject: [PATCH 4/5] Add timeouts to all metadata related queries --- s3iam.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s3iam.py b/s3iam.py index 9d8b1da..adfd1b0 100755 --- a/s3iam.py +++ b/s3iam.py @@ -315,7 +315,7 @@ def get_instance_region(self): response = None try: - response = urllib2.urlopen(request) + response = urllib2.urlopen(request, timeout=2) data = response.read() finally: if response: @@ -345,7 +345,7 @@ def urlgrab(self, url, filename=None, **kwargs): out = open(filename, 'w+') while retries > 0: try: - response = urllib2.urlopen(request) + response = urllib2.urlopen(request, timeout=2) buff = response.read(BUFFER_SIZE) while buff: out.write(buff) From a9b70d6931accf8e6f9c45e754ee38ba8251754c Mon Sep 17 00:00:00 2001 From: Grant Soyka Date: Wed, 11 Oct 2017 15:47:06 -0600 Subject: [PATCH 5/5] Reduce timeout duration --- s3iam.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/s3iam.py b/s3iam.py index adfd1b0..2325ef0 100755 --- a/s3iam.py +++ b/s3iam.py @@ -235,7 +235,7 @@ def get_role(self): )) try: - response = urllib2.urlopen(request, timeout=2) + response = urllib2.urlopen(request, timeout=1) self.iamrole = (response.read()) except Exception: response = None @@ -257,7 +257,7 @@ def get_credentials(self): ), self.iamrole)) try: - response = urllib2.urlopen(request, timeout=2) + response = urllib2.urlopen(request, timeout=1) data = json.loads(response.read()) self.access_key = data['AccessKeyId'] self.secret_key = data['SecretAccessKey'] @@ -315,7 +315,7 @@ def get_instance_region(self): response = None try: - response = urllib2.urlopen(request, timeout=2) + response = urllib2.urlopen(request, timeout=1) data = response.read() finally: if response: @@ -345,7 +345,7 @@ def urlgrab(self, url, filename=None, **kwargs): out = open(filename, 'w+') while retries > 0: try: - response = urllib2.urlopen(request, timeout=2) + response = urllib2.urlopen(request, timeout=1) buff = response.read(BUFFER_SIZE) while buff: out.write(buff)