Merge ~mitchdz/ubuntu/+source/hibagent:mitch/bionic-imdsv2 into ubuntu/+source/hibagent:ubuntu/devel

Proposed by Mitchell Dzurick
Status: Superseded
Proposed branch: ~mitchdz/ubuntu/+source/hibagent:mitch/bionic-imdsv2
Merge into: ubuntu/+source/hibagent:ubuntu/devel
Diff against target: 253 lines (+189/-0) (has conflicts)
7 files modified
debian/changelog (+24/-0)
debian/control (+1/-0)
debian/patches/disable-hibernate-test.patch (+4/-0)
debian/patches/do-nothing-if-ODH-is-configured.patch (+77/-0)
debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch (+33/-0)
debian/patches/series (+6/-0)
debian/patches/use-imdsv2.patch (+44/-0)
Conflict in debian/changelog
Conflict in debian/patches/disable-hibernate-test.patch
Conflict in debian/patches/series
Reviewer Review Type Date Requested Status
git-ubuntu import Pending
Review via email: mp+455904@code.launchpad.net
To post a comment you must log in.

Unmerged commits

ad55c07... by Mitchell Dzurick

changelog

4a1d248... by Mitchell Dzurick

d/p/disable-hibernate-test.patch: disable a test that only works on an actual EC2 instance

1f8ebb2... by Mitchell Dzurick

d/p/do-nothing-if-ODH-is-configured.patch: Do nothing if ODH is enabled

fc14b3f... by Mitchell Dzurick

d/p/use-imdsv2.patch: use IMDSv2

b676b27... by Alberto Contreras

changelog

4092f2a... by Alberto Contreras

  * d/p/lp1896638-set-resume-device-by-partition-uuid: Set resume device
    by PARTUUID instead of by name. Thanks to Tony Nie <email address hidden>.
    (LP: #1896638)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 3c8851c..3439e3b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,4 @@
1<<<<<<< debian/changelog
1hibagent (1.0.1+git20230216.9ac1209f7-0ubuntu1) lunar; urgency=medium2hibagent (1.0.1+git20230216.9ac1209f7-0ubuntu1) lunar; urgency=medium
23
3 * New upstream snapshot from their `ubuntu` branch (LP: #1896638)4 * New upstream snapshot from their `ubuntu` branch (LP: #1896638)
@@ -15,6 +16,29 @@ hibagent (1.0.1-0ubuntu2) hirsute; urgency=medium
15 * Use Thread.is_alive() for Python 3.9 compatibility and fix FTBFS16 * Use Thread.is_alive() for Python 3.9 compatibility and fix FTBFS
1617
17 -- Balint Reczey <rbalint@ubuntu.com> Wed, 20 Jan 2021 18:10:31 +010018 -- Balint Reczey <rbalint@ubuntu.com> Wed, 20 Jan 2021 18:10:31 +0100
19=======
20hibagent (1.0.1-0ubuntu1.18.04.2) bionic; urgency=medium
21
22 * Use imdsv2 and do nothing if ODH is configured (LP: #2043739).
23 - d/p/disable-hibernate-test.patch: disable a test that only works on an
24 actual EC2 instance.
25 - d/p/use-imdsv2: use IMDSv2 instead of IMDSv1. This is important because
26 IMDSv1 is an insecure protocol.
27 - d/control: add python3-requests as Depends.
28 - d/p/do-nothing-if-ODH-is-configured.patch: do nothing if ODH is configured
29 this fixes an issue when this package and ec2-hibinit-agent are installed
30 and configured at the same time.
31
32 -- Mitchell Dzurick <mitchell.dzurick@canonical.com> Thu, 16 Nov 2023 16:19:12 -0700
33
34hibagent (1.0.1-0ubuntu1.18.04.1) bionic; urgency=medium
35
36 * d/p/lp1896638-set-resume-device-by-partition-uuid: Set resume device
37 by PARTUUID instead of by name. Thanks to Tony Nie <zirann@amazon.com>.
38 (LP: #1896638)
39
40 -- Alberto Contreras <alberto.contreras@canonical.com> Fri, 31 Mar 2023 10:02:42 +0200
41>>>>>>> debian/changelog
1842
19hibagent (1.0.1-0ubuntu1) bionic; urgency=medium43hibagent (1.0.1-0ubuntu1) bionic; urgency=medium
2044
diff --git a/debian/control b/debian/control
index 60fac58..eb13a13 100644
--- a/debian/control
+++ b/debian/control
@@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 9),
7 dh-python,7 dh-python,
8 python3-all,8 python3-all,
9 python3-pytest,9 python3-pytest,
10 python3-requests,
10 python3-setuptools11 python3-setuptools
11Standards-Version: 3.9.612Standards-Version: 3.9.6
1213
diff --git a/debian/patches/disable-hibernate-test.patch b/debian/patches/disable-hibernate-test.patch
index 0e2896a..27c86ee 100644
--- a/debian/patches/disable-hibernate-test.patch
+++ b/debian/patches/disable-hibernate-test.patch
@@ -1,4 +1,8 @@
1<<<<<<< debian/patches/disable-hibernate-test.patch
1Description: Skip test needing EC2 instance2Description: Skip test needing EC2 instance
3=======
4IDescription: Skip test needing EC2 instance
5>>>>>>> debian/patches/disable-hibernate-test.patch
2 The polling test now actually needs to be run on an EC2 instance as it tries6 The polling test now actually needs to be run on an EC2 instance as it tries
3 to contact an HTTP endpoint on a hardcoded link-local IP that matches the monitoring7 to contact an HTTP endpoint on a hardcoded link-local IP that matches the monitoring
4 system at AWS. We don't have this in our builders or autopkgtests.8 system at AWS. We don't have this in our builders or autopkgtests.
diff --git a/debian/patches/do-nothing-if-ODH-is-configured.patch b/debian/patches/do-nothing-if-ODH-is-configured.patch
5new file mode 1006449new file mode 100644
index 0000000..8be4ec2
--- /dev/null
+++ b/debian/patches/do-nothing-if-ODH-is-configured.patch
@@ -0,0 +1,77 @@
1Description: Update the Spot hibernate agent to do nothing if ODH is configured
2Author: Jeongin Cho <achojeon@amazon.com>
3Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/2ee4ae3fd1333fb3c9aab25bf02b109c3b7b8d9f
4Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/hibagent/+bug/2043739
5Last-Update: 2023-11-16
6---
7This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
8--- a/agent/hibagent
9+++ b/agent/hibagent
10@@ -18,6 +18,7 @@
11 import struct
12 import sys
13 import syslog
14+import requests
15 from subprocess import check_call, check_output
16 from threading import Thread
17 from math import ceil
18@@ -39,6 +40,9 @@
19 log_to_syslog = True
20 log_to_stderr = True
21
22+IMDS_BASEURL = 'http://169.254.169.254'
23+IMDS_API_TOKEN_PATH = 'latest/api/token'
24+IMDS_SPOT_ACTION_PATH = 'latest/meta-data/hibernation/configured'
25
26 def log(message):
27 if log_to_syslog:
28@@ -511,6 +515,37 @@
29 log("Failed to adjust pm_freeze_timeout to %d. Error: %s" % (timeout, str(e)))
30 exit(1)
31
32+def get_imds_token(seconds=21600):
33+ """ Get a token to access instance metadata. """
34+ log("Requesting new IMDSv2 token.")
35+ request_header = {'X-aws-ec2-metadata-token-ttl-seconds': '{}'.format(seconds)}
36+ token_url = '{}/{}'.format(IMDS_BASEURL, IMDS_API_TOKEN_PATH)
37+ response = requests.put(token_url, headers=request_header)
38+ response.close()
39+ if response.status_code != requests.codes.ok:
40+ return None
41+
42+ return response.text
43+
44+def hibernation_enabled():
45+ """Returns a boolean indicating whether hibernation-option.configured is enabled or not."""
46+
47+ imds_token = get_imds_token()
48+ if imds_token is None:
49+ log("IMDS_V2 http endpoint is disabled")
50+ # IMDS http endpoint is disabled
51+ return False
52+
53+ request_header = {'X-aws-ec2-metadata-token': imds_token}
54+ response = requests.get("{}/{}".format(IMDS_BASEURL, IMDS_SPOT_ACTION_PATH),
55+ headers=request_header)
56+ response.close()
57+ if response.status_code != requests.codes.ok or response.text.lower() == "false":
58+ return False
59+
60+ log("Hibernation Configured Flag found")
61+
62+ return True
63
64 def main():
65 # Parse arguments
66@@ -550,6 +585,11 @@
67
68 log("Effective config: %s" % config)
69
70+ # Let's first check if we need to kill the Spot Hibernate Agent
71+ if hibernation_enabled():
72+ log("Spot Instance Launch has enabled Hibernation Configured Flag. hibagent exiting!!")
73+ exit(0)
74+
75 target_swap_size = config.swap_mb * 1024 * 1024
76 ram_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
77 swap_percentage_size = ram_bytes * config.swap_percentage // 100
diff --git a/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch b/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch
0new file mode 10064478new file mode 100644
index 0000000..39ef202
--- /dev/null
+++ b/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch
@@ -0,0 +1,33 @@
1From: Tony Nie <zirann@amazon.com>
2Subject: Set resume device by PARTUUID instead of by device name
3Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/ec2-hibinit-agent/+bug/1896638
4Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/43636fcf
5---
6 agent/hibagent | 7 +++++++
7 1 file changed, 7 insertions(+)
8
9Index: b/agent/hibagent
10===================================================================
11--- a/agent/hibagent 2023-03-24 13:12:50.192981414 +0100
12+++ b/agent/hibagent 2023-03-24 13:17:13.151025129 +0100
13@@ -99,6 +99,11 @@ def get_swap_space():
14 return int(lines[0].split()[2]) * 1024
15
16
17+def get_partuuid(device):
18+ return check_output(
19+ ['lsblk', '-dno', 'PARTUUID', device]).decode('ascii').strip()
20+
21+
22 def patch_grub_config(swap_device, offset, grub_file, grub2_dir):
23 log("Updating GRUB to use the device %s with offset %d for resume" % (swap_device, offset))
24 lines = []
25@@ -128,6 +133,8 @@ def patch_grub_config(swap_device, offse
26 # Do GRUB2 update as well
27 if grub2_dir and os.path.exists(grub2_dir):
28 offset_file = os.path.join(grub2_dir, '99-set-swap.cfg')
29+ if swap_device.startswith("/dev"):
30+ swap_device = "PARTUUID=%s" % get_partuuid(swap_device)
31 if not os.path.exists(offset_file):
32 with open(offset_file, 'w') as fl:
33 fl.write('GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT no_console_suspend=1 '
diff --git a/debian/patches/series b/debian/patches/series
index 5568008..4b29cf9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -6,6 +6,12 @@ detect-hibernate-cmd-by-default.patch
6use-sh-for-init-scripts.patch6use-sh-for-init-scripts.patch
7add-lsb-init-info.patch7add-lsb-init-info.patch
8fix-enable-ec2-spot-hibernation.patch8fix-enable-ec2-spot-hibernation.patch
9<<<<<<< debian/patches/series
90009-Use-Thread.is_alive-for-Python-3.9-compatibility.patch100009-Use-Thread.is_alive-for-Python-3.9-compatibility.patch
10setuptools-fix-package-discovery.patch11setuptools-fix-package-discovery.patch
12=======
13lp1896638-set-resume-device-by-partition-uuid.patch
14use-imdsv2.patch
15do-nothing-if-ODH-is-configured.patch
16>>>>>>> debian/patches/series
11disable-hibernate-test.patch17disable-hibernate-test.patch
diff --git a/debian/patches/use-imdsv2.patch b/debian/patches/use-imdsv2.patch
12new file mode 10064418new file mode 100644
index 0000000..6c91a91
--- /dev/null
+++ b/debian/patches/use-imdsv2.patch
@@ -0,0 +1,44 @@
1Description: IMDS V2 updates
2Author: shivasan@ <shivasan@amazon.com>
3Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/559558f28de4456f14b38539eed967df6e1f9217
4Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/hibagent/+bug/2043739
5Last-Update: 2023-11-16
6---
7This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
8--- a/agent/hibagent
9+++ b/agent/hibagent
10@@ -315,16 +315,28 @@
11
12 def poll_for_termination(self):
13 # noinspection PyBroadException
14- response = None
15+ response1 = None
16+ response2 = None
17 try:
18- response = urlopen(self.url)
19- res_str = response.read()
20- return b"hibernate" in res_str
21+ request1 = Request("http://169.254.169.254/latest/api/token")
22+ request1.add_header('X-aws-ec2-metadata-token-ttl-seconds', '21600')
23+ request1.get_method = lambda:"PUT"
24+ response1 = urlopen(request1)
25+
26+ token = response1.read()
27+
28+ request2 = Request(self.url)
29+ request2.add_header('X-aws-ec2-metadata-token', token)
30+ response2 = urlopen(request2)
31+ res = response2.read()
32+ return b"hibernate" in res
33 except:
34 return False
35 finally:
36- if response:
37- response.close()
38+ if response1:
39+ response1.close()
40+ if response2:
41+ response2.close()
42
43 def do_hibernate(self):
44 log("Attempting to hibernate")

Subscribers

People subscribed via source and target branches