diff --git a/base/comps/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch b/base/comps/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch new file mode 100644 index 00000000000..d3a943cb821 --- /dev/null +++ b/base/comps/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch @@ -0,0 +1,81 @@ +From 2ee17f7ebc8b09bdc75f017480ff0bcb27aefa9d Mon Sep 17 00:00:00 2001 +From: Jonathan Brenes +Date: Thu, 7 May 2026 16:30:06 -0600 +Subject: [PATCH] [azure] Refactor IMDS collection with pretty-printed JSON + +Replace the curl-based IMDS metadata collection with a +Python-based approach using urllib. This produces +pretty-printed JSON output (4-space indentation) for +improved readability in the sos report. + +Update the IMDS API version from 2023-07-01 to 2025-04-07, +the latest supported version as documented at: +https://learn.microsoft.com/en-us/azure/virtual-machines/ +instance-metadata-service + +Collect the full instance metadata (/metadata/instance) +instead of only /metadata/instance/compute, which now also +includes network information. + +Signed-off-by: Jonathan Brenes +[Backported to sos 4.11.0 which does not import glob.] +--- + sos/report/plugins/azure.py | 35 ++++++++++++++++++++++++++++++----- + 1 file changed, 30 insertions(+), 5 deletions(-) + +diff --git a/sos/report/plugins/azure.py b/sos/report/plugins/azure.py +--- a/sos/report/plugins/azure.py ++++ b/sos/report/plugins/azure.py +@@ -8,10 +8,18 @@ + # + # See the LICENSE file in the source distribution for further information. + ++import json + import os ++from urllib.error import URLError ++from urllib.request import Request, urlopen ++ + from sos.report.plugins import Plugin, UbuntuPlugin, RedHatPlugin + + ++IMDS_URL = ("http://169.254.169.254/metadata/instance?" ++ "api-version=2025-04-07&format=json") ++ ++ + class Azure(Plugin, UbuntuPlugin): + + short_desc = 'Microsoft Azure client' +@@ -40,11 +48,28 @@ def setup(self): + for name in files: + self.add_copy_spec(self.path_join(path, name), sizelimit=limit) + +- self.add_cmd_output(( +- 'curl -s -H Metadata:true --noproxy "*" ' +- '"http://169.254.169.254/metadata/instance/compute?' +- 'api-version=2023-07-01&format=json"' +- ), suggest_filename='instance_metadata.json') ++ def collect(self): ++ with self.collection_file('instance_metadata.json') as mfile: ++ try: ++ metadata = self._get_imds_metadata() ++ mfile.write(json.dumps(metadata, indent=4)) ++ except RuntimeError as err: ++ mfile.write(str(err)) ++ ++ @staticmethod ++ def _get_imds_metadata(): ++ """Retrieve instance metadata from the Azure IMDS endpoint.""" ++ try: ++ req = Request(IMDS_URL, headers={'Metadata': 'true'}) ++ with urlopen(req, timeout=5) as resp: ++ if resp.status != 200: ++ raise RuntimeError( ++ f"IMDS returned HTTP {resp.status}: " ++ + resp.read().decode()) ++ return json.loads(resp.read().decode()) ++ except URLError as err: ++ raise RuntimeError( ++ "Failed to query Azure IMDS: " + str(err)) from err + + + class RedHatAzure(Azure, RedHatPlugin): diff --git a/base/comps/sos/sos.comp.toml b/base/comps/sos/sos.comp.toml index 70ca82d1c08..8ba493040fa 100644 --- a/base/comps/sos/sos.comp.toml +++ b/base/comps/sos/sos.comp.toml @@ -23,3 +23,9 @@ description = "Add dnf5 support in dnf plugin" type = "patch-add" file = "dnf-initial-dnf5-support-in-dnf-plugin.patch" source = "dnf-initial-dnf5-support-in-dnf-plugin.patch" + +[[components.sos.overlays]] +description = "Refactor Azure IMDS collection to use Python urllib with pretty-printed JSON output and bump API version to 2025-04-07 (upstream PR sosreport/sos#4322)" +type = "patch-add" +file = "azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch" +source = "azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch" diff --git a/locks/sos.lock b/locks/sos.lock index 7225174af07..3e6f5b090c1 100644 --- a/locks/sos.lock +++ b/locks/sos.lock @@ -2,5 +2,5 @@ version = 1 import-commit = 'f3ecbda85d52c61c5c80ee3fe5c2a31886f040c6' upstream-commit = 'f3ecbda85d52c61c5c80ee3fe5c2a31886f040c6' -input-fingerprint = 'sha256:b74987eb020f7a34c1dc1c947727059d365fa5e02a93228b7deeba26bb4b6fa9' +input-fingerprint = 'sha256:101251d17cda36055f0e7ad02807397ba3ed4a6f85cb2f2020aa03855287aa2e' resolution-input-hash = 'sha256:466421704711c4fd3c71f0b2ed715a0e61d49e3e26f3a2637fee755795849c8e' diff --git a/specs/s/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch b/specs/s/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch new file mode 100644 index 00000000000..d3a943cb821 --- /dev/null +++ b/specs/s/sos/azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch @@ -0,0 +1,81 @@ +From 2ee17f7ebc8b09bdc75f017480ff0bcb27aefa9d Mon Sep 17 00:00:00 2001 +From: Jonathan Brenes +Date: Thu, 7 May 2026 16:30:06 -0600 +Subject: [PATCH] [azure] Refactor IMDS collection with pretty-printed JSON + +Replace the curl-based IMDS metadata collection with a +Python-based approach using urllib. This produces +pretty-printed JSON output (4-space indentation) for +improved readability in the sos report. + +Update the IMDS API version from 2023-07-01 to 2025-04-07, +the latest supported version as documented at: +https://learn.microsoft.com/en-us/azure/virtual-machines/ +instance-metadata-service + +Collect the full instance metadata (/metadata/instance) +instead of only /metadata/instance/compute, which now also +includes network information. + +Signed-off-by: Jonathan Brenes +[Backported to sos 4.11.0 which does not import glob.] +--- + sos/report/plugins/azure.py | 35 ++++++++++++++++++++++++++++++----- + 1 file changed, 30 insertions(+), 5 deletions(-) + +diff --git a/sos/report/plugins/azure.py b/sos/report/plugins/azure.py +--- a/sos/report/plugins/azure.py ++++ b/sos/report/plugins/azure.py +@@ -8,10 +8,18 @@ + # + # See the LICENSE file in the source distribution for further information. + ++import json + import os ++from urllib.error import URLError ++from urllib.request import Request, urlopen ++ + from sos.report.plugins import Plugin, UbuntuPlugin, RedHatPlugin + + ++IMDS_URL = ("http://169.254.169.254/metadata/instance?" ++ "api-version=2025-04-07&format=json") ++ ++ + class Azure(Plugin, UbuntuPlugin): + + short_desc = 'Microsoft Azure client' +@@ -40,11 +48,28 @@ def setup(self): + for name in files: + self.add_copy_spec(self.path_join(path, name), sizelimit=limit) + +- self.add_cmd_output(( +- 'curl -s -H Metadata:true --noproxy "*" ' +- '"http://169.254.169.254/metadata/instance/compute?' +- 'api-version=2023-07-01&format=json"' +- ), suggest_filename='instance_metadata.json') ++ def collect(self): ++ with self.collection_file('instance_metadata.json') as mfile: ++ try: ++ metadata = self._get_imds_metadata() ++ mfile.write(json.dumps(metadata, indent=4)) ++ except RuntimeError as err: ++ mfile.write(str(err)) ++ ++ @staticmethod ++ def _get_imds_metadata(): ++ """Retrieve instance metadata from the Azure IMDS endpoint.""" ++ try: ++ req = Request(IMDS_URL, headers={'Metadata': 'true'}) ++ with urlopen(req, timeout=5) as resp: ++ if resp.status != 200: ++ raise RuntimeError( ++ f"IMDS returned HTTP {resp.status}: " ++ + resp.read().decode()) ++ return json.loads(resp.read().decode()) ++ except URLError as err: ++ raise RuntimeError( ++ "Failed to query Azure IMDS: " + str(err)) from err + + + class RedHatAzure(Azure, RedHatPlugin): diff --git a/specs/s/sos/sos.spec b/specs/s/sos/sos.spec index 5e7d514d622..b6d04df7b54 100644 --- a/specs/s/sos/sos.spec +++ b/specs/s/sos/sos.spec @@ -2,7 +2,7 @@ ## (rpmautospec version 0.8.3) ## RPMAUTOSPEC: autorelease, autochangelog %define autorelease(e:s:pb:n) %{?-p:0.}%{lua: - release_number = 5; + release_number = 6; base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}")); print(release_number + base_release_number - 1); }%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}} @@ -46,6 +46,7 @@ Patch0: Policy-Fix-os_release_name-value.patch Patch1: Policy-Add-os_release_id-check.patch Patch2: cloud_init-add-missing-systemd-service-units.patch Patch3: dnf-initial-dnf5-support-in-dnf-plugin.patch +Patch4: azure-refactor-IMDS-collection-with-pretty-printed-JSON.patch %description Sos is a set of tools that gathers information about system hardware and configuration. The information can then be used for @@ -120,6 +121,9 @@ rm -rf %{buildroot}/usr/config/ %changelog ## START: Generated by rpmautospec +* Tue May 19 2026 Jonathan Brenes - 4.11.0-6 +- fix(sos): refactor Azure IMDS collection with pretty-printed JSON + * Mon May 11 2026 Jonathan Brenes - 4.11.0-5 - fix(sos): add all missing cloud-init systemd service units