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.
This commit is contained in:
Saadi Myftija
2026-08-21 16:59:12 +02:00
parent 9ca53a074c
commit 140e4b3d30
3 changed files with 21 additions and 10 deletions
+13
View File
@@ -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"),
@@ -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 {
@@ -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.`
);
}