Skip to content

Commit 8edaef1

Browse files
authored
fix: update protobuf version for <= 3.12 (cve fix) (#1837)
* bump protobuf version for <= 3.12 * update grpc * mount protobuf & grpc * mount protobuf & grpc * mount protobuf & grpc * lint
1 parent 4453464 commit 8edaef1

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

eng/ci/public-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ extends:
7474
# Skip the build stage for SDK and Extensions release branches. This stage will fail because pyproject.toml contains the updated (and unreleased) library version
7575
condition: and(eq(variables.isSdkRelease, false), eq(variables.isExtensionsRelease, false), eq(variables['USETESTPYTHONSDK'], false), eq(variables['USETESTPYTHONEXTENSIONS'], false))
7676
- stage: CheckPythonWorkerDependencies
77-
dependsOn: []
77+
dependsOn: BuildPythonWorker
7878
jobs:
7979
- template: /eng/templates/jobs/ci-dependency-check.yml@self
8080
parameters:
8181
PoolName: 1es-pool-azfunc-public
8282
- stage: RunWorkerUnitTests
83-
dependsOn: CheckPythonWorkerDependencies
83+
dependsOn: BuildPythonWorker
8484
jobs:
8585
- template: /eng/templates/jobs/ci-unit-tests.yml@self
8686
parameters:
8787
PROJECT_DIRECTORY: 'workers'
8888
PoolName: 1es-pool-azfunc-public
8989
- stage: RunWorkerEmulatorTests
90-
dependsOn: CheckPythonWorkerDependencies
90+
dependsOn: BuildPythonWorker
9191
jobs:
9292
- template: /eng/templates/jobs/ci-emulator-tests.yml@self
9393
parameters:

workers/pyproject.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ dependencies = [
2828
"azure-functions==1.24.0; python_version < '3.10'",
2929
"azure-functions==1.25.0b4; python_version >= '3.10'",
3030
"python-dateutil~=2.9.0",
31-
"protobuf~=4.25.3; python_version < '3.13'",
32-
"protobuf~=5.29.0; python_version == '3.13'",
31+
"protobuf~=5.29.0; python_version <= '3.13'",
3332
"protobuf~=6.33.1; python_version == '3.14'",
34-
"grpcio-tools~=1.59.0;python_version < '3.13'",
35-
"grpcio-tools~=1.70.0; python_version == '3.13'",
33+
"grpcio-tools~=1.70.0; python_version <= '3.13'",
3634
"grpcio-tools~=1.75.1; python_version == '3.14'",
37-
"grpcio~=1.59.0; python_version < '3.13'",
38-
"grpcio~=1.70.0; python_version == '3.13'",
35+
"grpcio~=1.70.0; python_version <= '3.13'",
3936
"grpcio~=1.75.1; python_version == '3.14'",
4037
"uvloop~=0.21.0; python_version == '3.13' and sys_platform != 'win32'",
4138
"uvloop~=0.22.0; python_version == '3.14' and sys_platform != 'win32'",

workers/tests/unittests/test_utilities_dependency.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,12 @@ def test_newrelic_protobuf_import_scenario_worker_deps(self):
661661

662662
DependencyManager.prioritize_customer_dependencies()
663663

664-
# protobuf v4 is found
664+
# protobuf v5 is found
665665
from google.protobuf import __version__
666666

667667
protobuf_version = tuple(int(v) for v in __version__.split("."))
668668
self.assertIsNotNone(protobuf_version)
669-
self.assertEqual(protobuf_version[0], 4)
669+
self.assertEqual(protobuf_version[0], 5)
670670

671671
@unittest.skipIf(sys.version_info.minor <= 7,
672672
"The worker brings different protobuf versions"
@@ -692,8 +692,8 @@ def test_newrelic_protobuf_import_scenario_user_deps(self):
692692
protobuf_version = tuple(int(v) for v in __version__.split("."))
693693
self.assertIsNotNone(protobuf_version)
694694

695-
# newrelic tries to import protobuf v4
696-
self.assertEqual(protobuf_version[0], 4)
695+
# newrelic tries to import protobuf v5
696+
self.assertEqual(protobuf_version[0], 5)
697697

698698
# newrelic tries to import protobuf v3
699699
self.assertNotEqual(protobuf_version[0], 3)

workers/tests/utils/testutils_lc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,31 @@ def spawn_container(self,
242242
'-extensions-dev/azurefunctions-extensions-base'
243243
'/azurefunctions/extensions/base'
244244
)
245+
246+
# Get paths to google.protobuf and grpcio packages to mount them
247+
# This ensures the container uses the same protobuf/grpc versions
248+
# as the host, which is critical when protobuf files are generated
249+
# with v5.x but the container has v4.x
250+
try:
251+
import google.protobuf
252+
import grpc
253+
protobuf_path = os.path.dirname(google.protobuf.__file__)
254+
grpc_path = os.path.dirname(grpc.__file__)
255+
256+
# Container paths for protobuf and grpcio
257+
container_protobuf_path = (
258+
f"/azure-functions-host/workers/python/{self._py_version}/"
259+
"LINUX/X64/google/protobuf"
260+
)
261+
container_grpc_path = (
262+
f"/azure-functions-host/workers/python/{self._py_version}/"
263+
"LINUX/X64/grpc"
264+
)
265+
except ImportError as e:
266+
print(f"Warning: Could not import google.protobuf or grpc: {e}")
267+
protobuf_path = None
268+
grpc_path = None
269+
245270
run_cmd = []
246271
run_cmd.extend([self._docker_cmd, "run", "-p", "0:80", "-d"])
247272
run_cmd.extend(["--name", self._uuid, "--privileged"])
@@ -258,6 +283,12 @@ def spawn_container(self,
258283
run_cmd.extend(["-v",
259284
f'{base_ext_local_path}:{base_ext_container_path}'])
260285

286+
# Mount protobuf and grpcio packages if they were found
287+
if protobuf_path:
288+
run_cmd.extend(["-v", f'{protobuf_path}:{container_protobuf_path}'])
289+
if grpc_path:
290+
run_cmd.extend(["-v", f'{grpc_path}:{container_grpc_path}'])
291+
261292
for key, value in env.items():
262293
run_cmd.extend(["-e", f"{key}={value}"])
263294
run_cmd.append(image)

0 commit comments

Comments
 (0)