From 140e4b3d300db9fb04d4757d3162b76efd8d2d80 Mon Sep 17 00:00:00 2001 From: Saadi Myftija Date: Fri, 21 Aug 2026 16:59:12 +0200 Subject: [PATCH] feat(webapp): make deployment artifact and build env var limits configurable Adds DEPLOYMENT_CONTEXT_ARTIFACT_SIZE_LIMIT_BYTES, DEPLOYMENT_BUNDLE_ARTIFACT_SIZE_LIMIT_BYTES, DEPLOYMENT_BUILD_ENV_VARS_SIZE_LIMIT_BYTES (128 KB default) and DEPLOYMENT_BUILD_ENV_VARS_MAX_KEYS (400 default). The limit error messages now match the artifact size error wording. --- apps/webapp/app/env.server.ts | 13 +++++++++++++ apps/webapp/app/v3/services/artifacts.server.ts | 4 ++-- .../app/v3/services/initializeDeployment.server.ts | 14 ++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/webapp/app/env.server.ts b/apps/webapp/app/env.server.ts index 0b86f83b4..6c7452ace 100644 --- a/apps/webapp/app/env.server.ts +++ b/apps/webapp/app/env.server.ts @@ -816,6 +816,19 @@ const EnvironmentSchema = z .number() .int() .default(60 * 1000 * 15), // 15 minutes + DEPLOYMENT_CONTEXT_ARTIFACT_SIZE_LIMIT_BYTES: z.coerce + .number() + .int() + .default(100 * 1024 * 1024), // 100MB + DEPLOYMENT_BUNDLE_ARTIFACT_SIZE_LIMIT_BYTES: z.coerce + .number() + .int() + .default(100 * 1024 * 1024), // 100MB + DEPLOYMENT_BUILD_ENV_VARS_SIZE_LIMIT_BYTES: z.coerce + .number() + .int() + .default(128 * 1024), // 128KB + DEPLOYMENT_BUILD_ENV_VARS_MAX_KEYS: z.coerce.number().int().default(400), // When enabled, reject deploys made by v3 CLI versions (i.e. payloads that // omit the `type` field). v4 CLI versions always send `type` ("MANAGED" or "V1"), diff --git a/apps/webapp/app/v3/services/artifacts.server.ts b/apps/webapp/app/v3/services/artifacts.server.ts index 85a742629..2d1ef1909 100644 --- a/apps/webapp/app/v3/services/artifacts.server.ts +++ b/apps/webapp/app/v3/services/artifacts.server.ts @@ -28,8 +28,8 @@ const artifactKeyPrefixByType = { deployment_bundle: "bundles", } as const; const artifactBytesSizeLimitByType = { - deployment_context: 100 * 1024 * 1024, // 100MB - deployment_bundle: 100 * 1024 * 1024, // 100MB + deployment_context: env.DEPLOYMENT_CONTEXT_ARTIFACT_SIZE_LIMIT_BYTES, + deployment_bundle: env.DEPLOYMENT_BUNDLE_ARTIFACT_SIZE_LIMIT_BYTES, } as const; export class ArtifactsService extends BaseService { diff --git a/apps/webapp/app/v3/services/initializeDeployment.server.ts b/apps/webapp/app/v3/services/initializeDeployment.server.ts index eed46d7e6..3b8db11e6 100644 --- a/apps/webapp/app/v3/services/initializeDeployment.server.ts +++ b/apps/webapp/app/v3/services/initializeDeployment.server.ts @@ -30,10 +30,6 @@ import { errAsync } from "neverthrow"; const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz", 8); -// Build env vars expand into --build-arg values, so stay well under exec argv limits -const BUILD_ENV_VARS_MAX_BYTES = 128 * 1024; -const BUILD_ENV_VARS_MAX_KEYS = 200; - type DeploymentEventStream = { s2: { basin: string; @@ -286,17 +282,19 @@ export class InitializeDeploymentService extends BaseService { const buildEnvVars = payload.buildEnvVars; const keyCount = Object.keys(buildEnvVars).length; - if (keyCount > BUILD_ENV_VARS_MAX_KEYS) { + if (keyCount > env.DEPLOYMENT_BUILD_ENV_VARS_MAX_KEYS) { throw new ServiceValidationError( - `Too many build environment variables: ${keyCount} (max ${BUILD_ENV_VARS_MAX_KEYS}).` + `Build environment variable count (${keyCount}) exceeds the allowed limit of ${env.DEPLOYMENT_BUILD_ENV_VARS_MAX_KEYS}. Reach out to us if you are seeing this error consistently.` ); } const serialized = JSON.stringify(buildEnvVars); const serializedBytes = Buffer.byteLength(serialized, "utf8"); - if (serializedBytes > BUILD_ENV_VARS_MAX_BYTES) { + if (serializedBytes > env.DEPLOYMENT_BUILD_ENV_VARS_SIZE_LIMIT_BYTES) { + const sizeKB = parseFloat((serializedBytes / 1024).toFixed(1)); + const limitKB = parseFloat((env.DEPLOYMENT_BUILD_ENV_VARS_SIZE_LIMIT_BYTES / 1024).toFixed(1)); throw new ServiceValidationError( - `Build environment variables are too large: ${serializedBytes} bytes (max ${BUILD_ENV_VARS_MAX_BYTES}). Reduce the size of the env var values used by your build.` + `Build environment variables size (${sizeKB} KB) exceeds the allowed limit of ${limitKB} KB. Reach out to us if you are seeing this error consistently.` ); }