:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): pin rasterizer IRSA credential refresh to a direct handler (#73696)
Tue Haulund49bd90c43042
diff --git a/nodejs/package.json b/nodejs/package.jsonindex aff075fb5088..9d3bd29613dd 100644--- a/nodejs/package.json+++ b/nodejs/package.json@@ -98,6 +98,7 @@"@posthog/siphash": "1.1.1","@pyroscope/nodejs": "^0.4.8","@segment/action-destinations": "3.387.0",+ "@smithy/node-http-handler": "4.4.9","@temporalio/activity": "1.15.0","@temporalio/client": "1.15.0","@temporalio/common": "1.15.0",diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/storage.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/storage.test.tsindex 51ed8e2e243b..a5397c00f331 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/storage.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/storage.test.ts@@ -134,6 +134,11 @@ jest.mock('@aws-sdk/credential-provider-node', () => ({defaultProvider: (init: unknown) => mockDefaultProvider(init),}))+jest.mock('@smithy/node-http-handler', () => ({+ NodeHttpHandler: jest.fn().mockImplementation(() => ({ __directHandler: true })),+}))+const { NodeHttpHandler: NodeHttpHandlerMock } = require('@smithy/node-http-handler')+const ORIGINAL_ENV = process.envdescribe('S3 client proxy routing', () => {@@ -167,6 +172,7 @@ describe('S3 client proxy routing', () => {jest.doMock('@aws-sdk/credential-provider-node', () => ({defaultProvider: (init: unknown) => mockDefaultProvider(init),}))+ jest.doMock('@smithy/node-http-handler', () => ({ NodeHttpHandler: NodeHttpHandlerMock }))const { uploadToS3: fresh } = require('~/session-replay/recording-rasterizer/storage')await fresh('/tmp/v.mp4', 'b', 'p', 'i')mock = require('@aws-sdk/client-s3').S3Client as jest.Mock@@ -180,6 +186,8 @@ describe('S3 client proxy routing', () => {expect(config).not.toHaveProperty('requestHandler')expect(config).not.toHaveProperty('credentials')expect(HttpsProxyAgentMock).not.toHaveBeenCalled()+ expect(mockDefaultProvider).not.toHaveBeenCalled()+ expect(NodeHttpHandlerMock).not.toHaveBeenCalled()})it.each([@@ -187,20 +195,28 @@ describe('S3 client proxy routing', () => {{ source: 'HTTP_PROXY fallback', env: 'HTTP_PROXY' as const },{ source: 'lowercase https_proxy', env: 'https_proxy' as const },{ source: 'lowercase http_proxy', env: 'http_proxy' as const },- ])('routes S3 through the proxy but leaves credential refresh direct when $source is set', async ({ env }) => {- process.env[env] = 'http://smokescreen.smokescreen.svc.cluster.local:4750'- const s3Client = await triggerS3Client()- const [config] = s3Client.mock.calls[0]- expect(HttpsProxyAgentMock).toHaveBeenCalledWith('http://smokescreen.smokescreen.svc.cluster.local:4750')- // S3 requests go through smokescreen- expect(config.requestHandler).toEqual({- httpsAgent: { __proxyAgent: 'http://smokescreen.smokescreen.svc.cluster.local:4750' },- })- // IRSA credential refresh must NOT be routed through the proxy: we don't- // override credentials, so the SDK default provider dials STS direct.- expect(config).not.toHaveProperty('credentials')- expect(mockDefaultProvider).not.toHaveBeenCalled()- })+ ])(+ 'routes S3 through the proxy and pins credential refresh to a direct handler when $source is set',+ async ({ env }) => {+ process.env[env] = 'http://smokescreen.smokescreen.svc.cluster.local:4750'+ const s3Client = await triggerS3Client()+ const [config] = s3Client.mock.calls[0]+ expect(HttpsProxyAgentMock).toHaveBeenCalledWith('http://smokescreen.smokescreen.svc.cluster.local:4750')+ // S3 requests go through smokescreen+ expect(config.requestHandler).toEqual({+ httpsAgent: { __proxyAgent: 'http://smokescreen.smokescreen.svc.cluster.local:4750' },+ })+ // IRSA credential refresh must NOT be routed through the proxy. The SDK's+ // nested STS client inherits the parent client's requestHandler, so the+ // credential provider gets its own direct handler, distinct from the proxied one.+ expect(mockDefaultProvider).toHaveBeenCalledWith({+ clientConfig: { requestHandler: { __directHandler: true } },+ })+ expect(config.credentials).toEqual({+ __credentialsProvider: { clientConfig: { requestHandler: { __directHandler: true } } },+ })+ }+ )it.each(['false', 'False', 'FALSE', '0', 'no', 'off', ' false '])('RASTERIZER_USE_PROXY=%j keeps S3 direct even when HTTPS_PROXY is set',@@ -212,6 +228,8 @@ describe('S3 client proxy routing', () => {expect(config).not.toHaveProperty('requestHandler')expect(config).not.toHaveProperty('credentials')expect(HttpsProxyAgentMock).not.toHaveBeenCalled()+ expect(mockDefaultProvider).not.toHaveBeenCalled()+ expect(NodeHttpHandlerMock).not.toHaveBeenCalled()})@@ -223,7 +241,7 @@ describe('S3 client proxy routing', () => {const s3Client = await triggerS3Client()const [config] = s3Client.mock.calls[0]expect(config.requestHandler).toBeDefined()- expect(config).not.toHaveProperty('credentials')+ expect(config.credentials).toBeDefined()expect(HttpsProxyAgentMock).toHaveBeenCalledWith('http://smokescreen:4750')})diff --git a/nodejs/src/session-replay/recording-rasterizer/storage.ts b/nodejs/src/session-replay/recording-rasterizer/storage.tsindex a279f56992a5..33f3b8285c59 100644--- a/nodejs/src/session-replay/recording-rasterizer/storage.ts+++ b/nodejs/src/session-replay/recording-rasterizer/storage.ts@@ -1,5 +1,7 @@import { S3Client } from '@aws-sdk/client-s3'+import { defaultProvider } from '@aws-sdk/credential-provider-node'import { Upload } from '@aws-sdk/lib-storage'+import { NodeHttpHandler } from '@smithy/node-http-handler'import * as fs from 'fs'import { HttpsProxyAgent } from 'https-proxy-agent'@@ -54,10 +56,13 @@ function getS3Client(): S3Client {region: config.s3Region,...(config.s3Endpoint ? { endpoint: config.s3Endpoint, forcePathStyle: true } : {}),...(requestHandler ? { requestHandler } : {}),- // S3 goes through the proxy, but credential refresh must dial direct- // (the SDK does not honor NO_PROXY). The default credential provider- // does this on its own, so long as we don't hand it our proxied- // requestHandler.+ // DO NOT REMOVE this credentials override. The SDK's nested STS client inherits+ // the parent's requestHandler (parentClientConfig); without an explicit unproxied+ // handler, IRSA STS credential refresh gets routed through the proxy, which rejects+ // it (407) and fails every S3 upload.+ ...(requestHandler+ ? { credentials: defaultProvider({ clientConfig: { requestHandler: new NodeHttpHandler() } }) }+ : {}),})}return s3Clientdiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0956e2ea8289..4e809f4327c2 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1570,6 +1570,9 @@ importers:'@segment/action-destinations':specifier: 3.387.0version: 3.387.0([email protected])([email protected])+ '@smithy/node-http-handler':+ specifier: 4.4.9+ version: 4.4.9'@temporalio/activity':specifier: 1.15.0version: 1.15.0