Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(docker): fail the image build when the generated prisma engine paths drift off /opt/prisma (#35979)

Yassin Kortam4562b539d822
diff --git a/Dockerfile b/Dockerfile
index 1fb34f6ebf9..66ce3af4a65 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -134,7 +134,8 @@ RUN find /app/.venv -type f -path "*/tornado/test/*" -delete && \
find /app/.venv -type d -path "*/tornado/test" -delete && \
chmod -R a+rX /opt/prisma && \
test -x /opt/prisma/binaries/node_modules/.bin/prisma && \
- test -f /opt/prisma/binaries/node_modules/prisma/build/index.js
+ test -f /opt/prisma/binaries/node_modules/prisma/build/index.js && \
+ python -c "from prisma.client import BINARY_PATHS; paths = list(BINARY_PATHS.query_engine.values()); assert paths and all(p.startswith('/opt/prisma/') for p in paths), paths"
EXPOSE 4000/tcp
diff --git a/docker/Dockerfile.database b/docker/Dockerfile.database
index c93a08409a2..4bf3ae2b417 100644
--- a/docker/Dockerfile.database
+++ b/docker/Dockerfile.database
@@ -133,7 +133,8 @@ RUN find /app/.venv -type f -path "*/tornado/test/*" -delete && \
find /app/.venv -type d -path "*/tornado/test" -delete && \
chmod -R a+rX /opt/prisma && \
test -x /opt/prisma/binaries/node_modules/.bin/prisma && \
- test -f /opt/prisma/binaries/node_modules/prisma/build/index.js
+ test -f /opt/prisma/binaries/node_modules/prisma/build/index.js && \
+ python -c "from prisma.client import BINARY_PATHS; paths = list(BINARY_PATHS.query_engine.values()); assert paths and all(p.startswith('/opt/prisma/') for p in paths), paths"
EXPOSE 4000/tcp
diff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_root
index 1545a84d379..7392cc09a0d 100644
--- a/docker/Dockerfile.non_root
+++ b/docker/Dockerfile.non_root
@@ -185,7 +185,8 @@ RUN mkdir -p /nonexistent /app/.cache /var/lib/litellm/assets /var/lib/litellm/u
chmod -R a+rX /opt/prisma && \
test -x /opt/prisma/binaries/node_modules/.bin/prisma && \
test -f /opt/prisma/binaries/node_modules/prisma/build/index.js && \
- ls /opt/prisma/binaries/node_modules/@prisma/engines/query-engine-* >/dev/null 2>&1
+ ls /opt/prisma/binaries/node_modules/@prisma/engines/query-engine-* >/dev/null 2>&1 && \
+ python -c "from prisma.client import BINARY_PATHS; paths = list(BINARY_PATHS.query_engine.values()); assert paths and all(p.startswith('/opt/prisma/') for p in paths), paths"
USER 65534
diff --git a/tests/proxy_migration_tests/test_offline_image_migration.py b/tests/proxy_migration_tests/test_offline_image_migration.py
index ae2ba703420..be2f0537576 100644
--- a/tests/proxy_migration_tests/test_offline_image_migration.py
+++ b/tests/proxy_migration_tests/test_offline_image_migration.py
@@ -131,6 +131,48 @@ def test_migration_offline_as_non_root_uid(offline_postgres):
)
+QUERY_ENGINE_PROBE = """
+from pathlib import Path
+from prisma.client import BINARY_PATHS
+
+for path in BINARY_PATHS.query_engine.values():
+ print(path, Path(path).exists())
+"""
+
+
+def test_baked_query_engine_paths_resolve_for_any_uid():
+ """The generated client's query engine paths survive resolution as an arbitrary uid.
+
+ prisma-python resolves the baked BINARY_PATHS eagerly, before it reads the
+ PRISMA_QUERY_ENGINE_BINARY override, and its existence check propagates
+ EACCES instead of skipping the candidate. A path baked under a build-time
+ HOME is unreadable to a different runtime uid, so client startup dies with a
+ PermissionError that no env override can rescue. Baking under the fixed,
+ world-readable /opt/prisma is what keeps that scan from raising.
+ """
+ assert IMAGE is not None
+ probe = _docker(
+ "run", "--rm", "--user", NON_ROOT_UID, "--entrypoint", "python",
+ IMAGE, "-c", QUERY_ENGINE_PROBE,
+ check=False,
+ )
+
+ assert probe.returncode == 0, (
+ f"resolving the baked query engine paths failed as uid {NON_ROOT_UID}\n"
+ f"stdout:\n{probe.stdout}\nstderr:\n{probe.stderr}"
+ )
+
+ paths = [line.split()[0] for line in probe.stdout.splitlines() if line.startswith("/")]
+ assert paths, f"the generated client baked no query engine paths\nstdout:\n{probe.stdout}"
+
+ outside = [path for path in paths if not path.startswith("/opt/prisma/")]
+ assert not outside, (
+ f"query engine paths baked outside the fixed /opt/prisma location: {outside}. "
+ "Whatever uid can read them at build time is the only uid that can start the "
+ "client, and the PRISMA_QUERY_ENGINE_BINARY override cannot recover from it."
+ )
+
+
def test_runtime_cache_env_not_read_only():
"""No runtime cache env var may point at the world-read-only /opt/prisma bake.