🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(blob-storage): log non-reversible S3 credential shape on signing failures (#14401)
Niklas Semmler3a3c6daa49c6
diff --git a/packages/shared/src/server/services/StorageService.ts b/packages/shared/src/server/services/StorageService.tsindex e48b100c59..efaed17dda 100644--- a/packages/shared/src/server/services/StorageService.ts+++ b/packages/shared/src/server/services/StorageService.ts@@ -28,6 +28,7 @@ import { S3ChunkedUploadStrategy } from "./S3ChunkedUploadStrategy";import {buildS3RequestDiagnostics,isS3SigningError,+ summarizeCredentialShape,type S3SigningDiagnosticsContext,} from "./s3SigningDiagnostics";import * as objectstorage from "oci-objectstorage";@@ -671,6 +672,18 @@ class S3StorageService implements StorageService {endpoint: params.endpoint,region: params.region,forcePathStyle: params.forcePathStyle,+ // Non-reversible shape of the credentials (length + character-class+ // flags, never the value) so a SignatureDoesNotMatch can be triaged as a+ // truncated/altered/mismatched secret without another round of re-pasting.+ // Derived from the same AND-gated `credentials` the S3Client received, not+ // raw params: when only one of id/secret is set, the SDK falls back to the+ // default credential chain, and the shape must report `absent` to match —+ // otherwise a partial config logs a phantom empty-secret for creds the SDK+ // never used.+ credentials: summarizeCredentialShape(+ credentials?.accessKeyId,+ credentials?.secretAccessKey,+ ),});// Create a separate client for generating presigned URLsdiff --git a/packages/shared/src/server/services/s3SigningDiagnostics.test.ts b/packages/shared/src/server/services/s3SigningDiagnostics.test.tsindex 2ab3b65c29..b6a2c39e3c 100644--- a/packages/shared/src/server/services/s3SigningDiagnostics.test.ts+++ b/packages/shared/src/server/services/s3SigningDiagnostics.test.ts@@ -3,6 +3,7 @@ import {buildS3RequestDiagnostics,classifyContentSha256Mode,isS3SigningError,+ summarizeCredentialShape,summarizeS3Error,summarizeS3SigningHeaders,} from "./s3SigningDiagnostics";@@ -164,6 +165,99 @@ describe("buildS3RequestDiagnostics", () => {});});+describe("summarizeCredentialShape", () => {+ // A representative GCS HMAC secret: 40 chars, base64 alphabet, no whitespace.+ const cleanGcsSecret = "Ab3+/Cd4ef5GH6ij7KL8mn9OP0qr1ST2uv3WX4yz";++ it("reports a clean GCS HMAC credential pair", () => {+ const shape = summarizeCredentialShape(+ "GOOG1EXAMPLEACCESSKEYID",+ cleanGcsSecret,+ );++ expect(shape).toEqual({+ accessKeyIdPresent: true,+ accessKeyIdLength: 23,+ accessKeyIdType: "gcs-hmac",+ secretPresent: true,+ secretLength: 40,+ secretLooksBase64: true,+ secretHasWhitespace: false,+ secretHasSurroundingWhitespace: false,+ secretHasNonAscii: false,+ });+ });++ it("flags a truncated secret (wrong length, the SignatureDoesNotMatch tell)", () => {+ const shape = summarizeCredentialShape(+ "GOOG1EXAMPLE",+ cleanGcsSecret.slice(0, 20),+ );+ expect(shape.secretLength).toBe(20);+ expect(shape.secretPresent).toBe(true);+ });++ it("flags stray surrounding whitespace from a sloppy paste", () => {+ const shape = summarizeCredentialShape(+ "GOOG1EXAMPLE",+ ` ${cleanGcsSecret}\n`,+ );+ expect(shape.secretHasWhitespace).toBe(true);+ expect(shape.secretHasSurroundingWhitespace).toBe(true);+ });++ it("flags a trailing non-breaking space across every relevant signal", () => {+ // U+00A0 (NBSP) is a Unicode space separator: ECMAScript WhiteSpace+ // includes it, so `\s` matches it and `trim()` strips it. A trailing NBSP+ // therefore lights up all three signals — assert each so none regresses.+ const nbsp = String.fromCharCode(0x00a0);+ const shape = summarizeCredentialShape(+ "GOOG1EXAMPLE",+ `${cleanGcsSecret}${nbsp}`,+ );+ expect(shape.secretHasWhitespace).toBe(true);+ expect(shape.secretHasSurroundingWhitespace).toBe(true);+ expect(shape.secretHasNonAscii).toBe(true);+ expect(shape.secretLooksBase64).toBe(false);+ });++ it("flags a non-ascii character that the whitespace checks miss", () => {+ // The reason secretHasNonAscii exists separately: a non-whitespace unicode+ // char (here a “smart” double quote, U+201C) is neither matched by `\s`+ // nor stripped by `trim()`, so only secretHasNonAscii catches it.+ const smartQuote = String.fromCharCode(0x201c);+ const shape = summarizeCredentialShape(+ "GOOG1EXAMPLE",+ `${smartQuote}${cleanGcsSecret}`,+ );+ expect(shape.secretHasNonAscii).toBe(true);+ expect(shape.secretHasWhitespace).toBe(false);+ expect(shape.secretHasSurroundingWhitespace).toBe(false);+ expect(shape.secretLooksBase64).toBe(false);+ });++ it("classifies an AWS-style access key id (wrong-provider paste)", () => {+ const shape = summarizeCredentialShape(+ "AKIAIOSFODNN7EXAMPLE",+ cleanGcsSecret,+ );+ expect(shape.accessKeyIdType).toBe("aws");+ });++ it("handles absent credentials (host/instance-role) without throwing", () => {+ const shape = summarizeCredentialShape(undefined, undefined);+ expect(shape.accessKeyIdPresent).toBe(false);+ expect(shape.accessKeyIdType).toBe("absent");+ expect(shape.secretPresent).toBe(false);+ expect(shape.secretLength).toBe(0);+ });++ it("never embeds the secret value", () => {+ const shape = summarizeCredentialShape("GOOG1EXAMPLE", cleanGcsSecret);+ expect(JSON.stringify(shape)).not.toContain(cleanGcsSecret);+ });+});+describe("isS3SigningError", () => {it("matches signing/authorization error codes by name or Code", () => {for (const code of [diff --git a/packages/shared/src/server/services/s3SigningDiagnostics.ts b/packages/shared/src/server/services/s3SigningDiagnostics.tsindex 5ad099e488..213f01789e 100644--- a/packages/shared/src/server/services/s3SigningDiagnostics.ts+++ b/packages/shared/src/server/services/s3SigningDiagnostics.ts@@ -12,16 +12,87 @@* credentials.** These helpers summarize the *signing inputs* of the request that failed so- * the difference shows up in logs. They never read credentials (no- * `Authorization` header), the secret, or the payload — only the framing- * headers and the structured error fields.+ * the difference shows up in logs. They never log the credential values (no+ * `Authorization` header, no secret) or the payload — only the framing+ * headers, the structured error fields, and a non-reversible *shape* of the+ * credentials (length + character-class flags; see {@link S3CredentialShape}).*/+/**+ * Non-reversible *shape* of the configured S3 credentials. Surfaced so a+ * `SignatureDoesNotMatch` can be triaged when the operator insists the+ * key/secret are correct and re-pasting them has not helped.+ *+ * `SignatureDoesNotMatch` (vs `InvalidAccessKeyId`/`AccessDenied`) means the+ * backend matched the access key id but the HMAC computed from the secret did+ * not — i.e. the stored secret is not the partner of the stored access key.+ * The usual culprits are a truncated or altered paste (wrong length, stray+ * whitespace, or a stray non-ascii character such as a "smart" quote or+ * zero-width space that survives `trim()`) or a secret from a different/rotated+ * key pair. These fields expose exactly those signals without ever logging the+ * credential value: only the length, whether it matches the base64 alphabet,+ * and whitespace/non-ascii flags. (Note: a non-breaking space is a Unicode+ * space separator, so it is caught by both the whitespace flags and+ * `secretHasNonAscii`; `secretHasNonAscii` earns its keep on non-whitespace+ * characters the others miss.)+ *+ * The access key id is an identifier (sent in plaintext in every signed+ * request's `Authorization` header), not a secret; even so we never log it+ * verbatim — we classify it (`gcs-hmac` for `GOOG…`, `aws` for `AKIA`/`ASIA`)+ * so a key pasted into the wrong provider's field is obvious.+ */+export interface S3CredentialShape {+ accessKeyIdPresent: boolean;+ accessKeyIdLength: number;+ accessKeyIdType: "gcs-hmac" | "aws" | "other" | "absent";+ secretPresent: boolean;+ secretLength: number;+ secretLooksBase64: boolean;+ secretHasWhitespace: boolean;+ secretHasSurroundingWhitespace: boolean;+ secretHasNonAscii: boolean;+}++function classifyAccessKeyIdType(+ id: string,+): Exclude<S3CredentialShape["accessKeyIdType"], "absent"> {+ if (id.startsWith("GOOG")) return "gcs-hmac";+ if (/^A(KIA|SIA)/.test(id)) return "aws";+ return "other";+}++/**+ * Summarize the credential pair without exposing either value. Null-safe so+ * host/instance-role configs (no explicit credentials) report `absent` rather+ * than throwing.+ */+export function summarizeCredentialShape(+ accessKeyId: string | undefined,+ secretAccessKey: string | undefined,+): S3CredentialShape {+ const id = accessKeyId ?? "";+ const secret = secretAccessKey ?? "";+ return {+ accessKeyIdPresent: id.length > 0,+ accessKeyIdLength: id.length,+ accessKeyIdType: id.length === 0 ? "absent" : classifyAccessKeyIdType(id),+ secretPresent: secret.length > 0,+ secretLength: secret.length,+ secretLooksBase64:+ secret.length > 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(secret),+ secretHasWhitespace: /\s/.test(secret),+ secretHasSurroundingWhitespace: secret !== secret.trim(),+ // Anything outside printable ASCII (0x20–0x7E): NBSP, smart quotes, etc.+ secretHasNonAscii: /[^\x20-\x7e]/.test(secret),+ };+}+export interface S3SigningDiagnosticsContext {bucketName: string;endpoint?: string;region?: string;forcePathStyle: boolean;+ credentials?: S3CredentialShape;}/**