Hello community,

here is the log from the commit of package python3-ec2metadata for 
openSUSE:Factory checked in at 2020-08-04 20:22:53
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python3-ec2metadata (Old)
 and      /work/SRC/openSUSE:Factory/.python3-ec2metadata.new.3592 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python3-ec2metadata"

Tue Aug  4 20:22:53 2020 rev:2 rq:824207 version:3.0.3

Changes:
--------
--- /work/SRC/openSUSE:Factory/python3-ec2metadata/python3-ec2metadata.changes  
2019-12-05 17:33:51.969452195 +0100
+++ 
/work/SRC/openSUSE:Factory/.python3-ec2metadata.new.3592/python3-ec2metadata.changes
        2020-08-04 20:23:13.061007757 +0200
@@ -1,0 +2,7 @@
+Mon Aug  3 18:30:06 UTC 2020 - Robert Schweikert <[email protected]>
+
+- Update to version 3.0.3 (bsc#1174743, bsc#1174837)
+  + Prefer IMDSv2 and switch all IMDS access requests to support v2 token
+    based access method.
+
+-------------------------------------------------------------------

Old:
----
  ec2metadata-3.0.2.tar.bz2

New:
----
  ec2metadata-3.0.3.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python3-ec2metadata.spec ++++++
--- /var/tmp/diff_new_pack.YHyPyK/_old  2020-08-04 20:23:14.333007919 +0200
+++ /var/tmp/diff_new_pack.YHyPyK/_new  2020-08-04 20:23:14.337007919 +0200
@@ -1,7 +1,7 @@
 #
-# spec file for package python-ec2metadata
+# spec file for package python3-ec2metadata
 #
-# Copyright (c) 2018 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -12,19 +12,18 @@
 # license that conforms to the Open Source Definition (Version 1.9)
 # published by the Open Source Initiative.
 
-# Please submit bugfixes or comments via http://bugs.opensuse.org/
+# Please submit bugfixes or comments via https://bugs.opensuse.org/
 #
 
-# MUST remain Python 2 based until EOL of SLES 11 in March 2019
 
 %define upstream_name ec2metadata
 Name:           python3-ec2metadata
-Version:        3.0.2
+Version:        3.0.3
 Release:        0
 Summary:        Collect instance metadata in EC2
-License:        GPL-3.0+
+License:        GPL-3.0-or-later
 Group:          System/Management
-Url:            https://github.com/SUSE-Enceladus/ec2metadata
+URL:            https://github.com/SUSE-Enceladus/ec2metadata
 Source0:        %{upstream_name}-%{version}.tar.bz2
 Requires:       python3
 BuildRequires:  python3-setuptools
@@ -36,7 +35,6 @@
 Provides:       python-ec2metadata = %{version}
 Obsoletes:      python-ec2metadata < %{version}
 
-
 %description
 Collect instance meta data in Amazon Compute CLoud instances
 

++++++ ec2metadata-3.0.2.tar.bz2 -> ec2metadata-3.0.3.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ec2metadata-3.0.2/lib/ec2metadata/VERSION 
new/ec2metadata-3.0.3/lib/ec2metadata/VERSION
--- old/ec2metadata-3.0.2/lib/ec2metadata/VERSION       2019-12-04 
23:20:58.061334443 +0100
+++ new/ec2metadata-3.0.3/lib/ec2metadata/VERSION       2020-08-03 
20:29:28.212509248 +0200
@@ -1 +1 @@
-3.0.2
\ No newline at end of file
+3.0.3
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ec2metadata-3.0.2/lib/ec2metadata/__init__.py 
new/ec2metadata-3.0.3/lib/ec2metadata/__init__.py
--- old/ec2metadata-3.0.2/lib/ec2metadata/__init__.py   2019-12-04 
23:20:58.061334443 +0100
+++ new/ec2metadata-3.0.3/lib/ec2metadata/__init__.py   2020-08-03 
20:29:28.212509248 +0200
@@ -34,12 +34,12 @@
         self.addr = addr
         self.api = api
         self.data_categories = ['dynamic/', 'meta-data/']
-        self.token_access = False
 
         if not self._test_connectivity(self.addr, 80):
             msg = 'Could not establish connection to: %s' % self.addr
             raise EC2MetadataError(msg)
 
+        self._set_api_header()
         self._reset_meta_options_api_map()
         self._set_meta_options()
 
@@ -76,33 +76,13 @@
 
     def _get(self, uri):
         url = 'http://%s/%s/%s' % (self.addr, self.api, uri)
-        token = None
         data_request = None
         value = b''
-        if self.token_access:
-            req = urllib.request.Request(
-                'http://169.254.169.254/latest/api/token',
-                headers={'X-aws-ec2-metadata-token-ttl-seconds': '21600'},
-                method='PUT'
-            )
-            try:
-                token = urllib.request.urlopen(req).read().decode()
-            except urllib.error.URLError:
-                msg = 'Unable to obtain token from metadata server'
-                raise EC2MetadataError(msg)
-            data_request = urllib.request.Request(
-                url,
-                headers={'X-aws-ec2-metadata-token': token}
-            )
-        else:
-            data_request = urllib.request.Request(url)
+        data_request = urllib.request.Request(url, headers=self.request_header)
         try:
             value = urllib.request.urlopen(data_request).read()
         except urllib.error.URLError:
-            if self.token_access:
-                return None
-            self.use_token_access()
-            self._get(uri)
+            return None
 
         return value.decode()
 
@@ -113,6 +93,21 @@
             'user-data': 'user-data'
         }
 
+    def _set_api_header(self):
+        """Set the header to be used in requests to the metadata service,
+           IMDs. Prefer IMDSv2 which requires a token."""
+        request = urllib.request.Request(
+            'http://169.254.169.254/latest/api/token',
+            headers={'X-aws-ec2-metadata-token-ttl-seconds': '21600'},
+            method='PUT'
+        )
+        try:
+            token = urllib.request.urlopen(request).read().decode()
+        except urllib.error.URLError:
+            self.request_header = {}
+
+        self.request_header = {'X-aws-ec2-metadata-token': token}
+        
     def _set_meta_options(self):
         """Set the metadata options for the current API on this object."""
         for path in self.data_categories:
@@ -143,8 +138,7 @@
     def get_available_api_versions(self):
         """Return a list of the available API versions"""
         url = 'http://%s/' % self.addr
-        # Handle token access here as well FIXME
-        req = urllib.request.Request(url)
+        req = urllib.request.Request(url, headers=self.request_header)
         value = urllib.request.urlopen(req).read().decode()
         apiVers = value.split('\n')
         return apiVers
@@ -160,9 +154,8 @@
         if not api_version:
             # Nothing to do
             return self.api
-        # Handle token access here as well FIXME
         url = 'http://%s' % self.addr
-        req = urllib.request.Request(url)
+        req = urllib.request.Request(url, headers=self.request_header)
         meta_apis = urllib.request.urlopen(req).read().decode().split('\n')
         if api_version not in meta_apis:
             msg = 'Requested API version "%s" not available' % api_version


Reply via email to