From b2efa239dbe0dad66a9ed8d61d4a2d8ca2bb21b1 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Thu, 5 Feb 2026 20:47:04 +0100 Subject: [PATCH] feat: add glance-api urllib user-agent header patch --- kolla-build.conf | 6 ++- ...8c265bb_add_urllib_user_agent_header.patch | 46 +++++++++++++++++++ patches/glance-api/series | 1 + template_overrides.j2 | 7 +++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 patches/glance-api/8c265bb_add_urllib_user_agent_header.patch create mode 100644 patches/glance-api/series diff --git a/kolla-build.conf b/kolla-build.conf index 6d42f7d..d4a54c8 100644 --- a/kolla-build.conf +++ b/kolla-build.conf @@ -10,6 +10,10 @@ template_override = template_overrides.j2 # not supported yet # patches_path = patches +[glance-api-additions-patches] +type = local +location = patches/glance-api/ + [neutron-l3-agent-additions-patches] type = local location = patches/neutron-l3-agent/ @@ -19,4 +23,4 @@ type = local location = patches/neutron-bgp-dragent/ [profiles] -custom = fluentd,^keystone$,neutron-l3-agent,neutron-bgp-dragent +custom = fluentd,^keystone$,glance-api,neutron-l3-agent,neutron-bgp-dragent diff --git a/patches/glance-api/8c265bb_add_urllib_user_agent_header.patch b/patches/glance-api/8c265bb_add_urllib_user_agent_header.patch new file mode 100644 index 0000000..5807a74 --- /dev/null +++ b/patches/glance-api/8c265bb_add_urllib_user_agent_header.patch @@ -0,0 +1,46 @@ +From 8c265bb5a376e3aed5a59e0b69c4f851a94cc242 Mon Sep 17 00:00:00 2001 +From: Mathieu Tortuyaux +Date: Mon, 05 Jan 2026 14:28:42 +0100 +Subject: [PATCH] glance/utils: override urllib 'User-agent' header + +Using default urllib 'User-agent' header creates error 403 +with CloudFlare in web-download image import. + +Change-Id: Ieb9ef2775dc3ebfab46c9cd3b4dc29a5a3ec6093 +Closes-Bug: #2137731 +Signed-off-by: Mathieu Tortuyaux +--- + +diff --git a/glance/async_/flows/ovf_process.py b/glance/async_/flows/ovf_process.py +index 2f3ac15..f8f5042 100644 +--- a/glance/async_/flows/ovf_process.py ++++ b/glance/async_/flows/ovf_process.py +@@ -75,7 +75,12 @@ + uri = uri.split("file://")[-1] + return open(uri, "rb") + +- return urllib.request.urlopen(uri) ++ # Override 'User-agent' header to avoid CloudFlare 403 errors. ++ req = urllib.request.Request( ++ uri, ++ headers={'User-agent': 'glance-client'}, ++ ) ++ return urllib.request.urlopen(req) + + def execute(self, image_id, file_path): + """ +diff --git a/glance/common/scripts/utils.py b/glance/common/scripts/utils.py +index f7c6a9f..bc3d07d 100644 +--- a/glance/common/scripts/utils.py ++++ b/glance/common/scripts/utils.py +@@ -148,7 +148,9 @@ + # into memory. Some images may be quite heavy. + return open(uri, "rb") + +- return urllib.request.urlopen(uri) ++ # Override 'User-agent' header to avoid CloudFlare 403 errors. ++ req = urllib.request.Request(uri, headers={'User-agent': 'glance-client'}) ++ return urllib.request.urlopen(req) + + + class CallbackIterator(object): diff --git a/patches/glance-api/series b/patches/glance-api/series new file mode 100644 index 0000000..9dcc014 --- /dev/null +++ b/patches/glance-api/series @@ -0,0 +1 @@ +8c265bb_add_urllib_user_agent_header.patch diff --git a/template_overrides.j2 b/template_overrides.j2 index c9c2035..bf928f1 100644 --- a/template_overrides.j2 +++ b/template_overrides.j2 @@ -12,6 +12,13 @@ RUN dnf install -y --enablerepo epel \ && dnf clean all {% endblock %} +# glance +{% set glance_base_packages_append = ['patch'] %} +{% block glance_api_footer %} +ADD additions-archive / +RUN bash -c 'while read patch; do patch -d /var/lib/kolla/venv/lib/python3.9/site-packages -p 1 -i /additions/$patch; done < /additions/series' +{% endblock %} + # neutron {% set neutron_base_packages_append = ['patch'] %} {% block neutron_l3_agent_footer %}