From aed02020a95c67bfeb745c366ae7fb170ca89fe3 Mon Sep 17 00:00:00 2001 From: jmho Date: Wed, 18 Nov 2026 16:26:20 -0500 Subject: [PATCH] feat(webapp): make IAM-mode object store path style configurable (PLT-1715) The AWS SDK object store client hardcoded forcePathStyle: true. AWS FIPS endpoints (s3-fips..amazonaws.com), which FedStart requires, only accept virtual-hosted-style requests, so IAM-mode packet uploads and presigned URLs could not work there. Add OBJECT_STORE_FORCE_PATH_STYLE (and OBJECT_STORE__FORCE_PATH_STYLE for named providers), defaulting to true so existing installs keep path-style addressing. Only the IAM-mode client reads it. Co-Authored-By: Claude Opus 5.5 --- apps/webapp/app/env.server.ts | 2 + apps/webapp/app/v3/objectStore.server.ts | 5 ++ .../webapp/app/v3/objectStoreClient.server.ts | 10 +++- apps/webapp/test/objectStoreClient.test.ts | 53 +++++++++++++++++++ docs/self-hosting/env/webapp.mdx | 2 + 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 apps/webapp/test/objectStoreClient.test.ts diff --git a/apps/webapp/app/env.server.ts b/apps/webapp/app/env.server.ts index 56b69f7f727..49dd6f959e6 100644 --- a/apps/webapp/app/env.server.ts +++ b/apps/webapp/app/env.server.ts @@ -715,6 +715,8 @@ const EnvironmentSchema = z OBJECT_STORE_SECRET_ACCESS_KEY: z.string().optional(), OBJECT_STORE_REGION: z.string().optional(), OBJECT_STORE_SERVICE: z.string().default("s3"), + // IAM mode only. Set false for endpoints that reject path-style requests (AWS FIPS endpoints). + OBJECT_STORE_FORCE_PATH_STYLE: BoolEnv.default(true), // Protocol to use for new uploads (e.g., "s3", "r2"). Data without protocol uses default provider above. // If specified, you must configure the corresponding provider using OBJECT_STORE_{PROTOCOL}_* env vars. diff --git a/apps/webapp/app/v3/objectStore.server.ts b/apps/webapp/app/v3/objectStore.server.ts index 159f2f41c6f..57b3ceded3b 100644 --- a/apps/webapp/app/v3/objectStore.server.ts +++ b/apps/webapp/app/v3/objectStore.server.ts @@ -5,6 +5,7 @@ import { type AuthenticatedEnvironment } from "~/services/apiAuth.server"; import { logger } from "~/services/logger.server"; import { ServiceValidationError } from "~/v3/services/common.server"; import { singleton } from "~/utils/singleton"; +import { BoolEnv } from "~/utils/boolEnv"; import { normalizeObjectStoreLogicalKeyPathname, ObjectStoreClient, @@ -182,6 +183,9 @@ function getObjectStoreConfig(protocol?: string): ObjectStoreClientConfig | unde secretAccessKey: process.env[`${prefix}SECRET_ACCESS_KEY`] || undefined, region: process.env[`${prefix}REGION`] || undefined, service: process.env[`${prefix}SERVICE`] || undefined, + forcePathStyle: BoolEnv.optional().parse( + process.env[`${prefix}FORCE_PATH_STYLE`] || undefined + ), }; } @@ -197,6 +201,7 @@ function getObjectStoreConfig(protocol?: string): ObjectStoreClientConfig | unde secretAccessKey: env.OBJECT_STORE_SECRET_ACCESS_KEY || undefined, region: env.OBJECT_STORE_REGION || undefined, service: env.OBJECT_STORE_SERVICE || undefined, + forcePathStyle: env.OBJECT_STORE_FORCE_PATH_STYLE, }; } diff --git a/apps/webapp/app/v3/objectStoreClient.server.ts b/apps/webapp/app/v3/objectStoreClient.server.ts index 790530de352..0082c7f393b 100644 --- a/apps/webapp/app/v3/objectStoreClient.server.ts +++ b/apps/webapp/app/v3/objectStoreClient.server.ts @@ -87,6 +87,7 @@ type AwsSdkConfig = { bucket: string; baseUrl: string; region?: string; + forcePathStyle: boolean; }; class AwsSdkClient implements IObjectStoreClient { @@ -95,7 +96,7 @@ class AwsSdkClient implements IObjectStoreClient { constructor(private readonly config: AwsSdkConfig) { this.s3Client = new S3Client({ endpoint: config.baseUrl, - forcePathStyle: true, + forcePathStyle: config.forcePathStyle, ...(config.region ? { region: config.region } : {}), }); } @@ -164,6 +165,12 @@ export type ObjectStoreClientConfig = { secretAccessKey?: string; region?: string; service?: string; + /** + * IAM mode only: address objects as `//` (true, the default) or + * `./` (false). AWS FIPS endpoints such as + * `s3-fips.us-gov-west-1.amazonaws.com` only accept the virtual-hosted form. + */ + forcePathStyle?: boolean; }; export class ObjectStoreClient implements IObjectStoreClient { @@ -199,6 +206,7 @@ export class ObjectStoreClient implements IObjectStoreClient { bucket: config.bucket, baseUrl: config.baseUrl, region: config.region, + forcePathStyle: config.forcePathStyle ?? true, }), config.bucket ); diff --git a/apps/webapp/test/objectStoreClient.test.ts b/apps/webapp/test/objectStoreClient.test.ts new file mode 100644 index 00000000000..077774f1fba --- /dev/null +++ b/apps/webapp/test/objectStoreClient.test.ts @@ -0,0 +1,53 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { ObjectStoreClient } from "~/v3/objectStoreClient.server"; + +// Presigning is local SigV4 signing, so these tests need no network or containers. +// Static env credentials stand in for the IAM credential chain the client resolves at sign time. +const FIPS_ENDPOINT = "https://s3-fips.us-gov-west-1.amazonaws.com"; +const BUCKET = "trigger-bucket"; +const KEY = `${BUCKET}/packets/proj_123/run_456/payload.json`; + +function iamClient(forcePathStyle?: boolean) { + return ObjectStoreClient.create({ + baseUrl: FIPS_ENDPOINT, + bucket: BUCKET, + region: "us-gov-west-1", + ...(forcePathStyle === undefined ? {} : { forcePathStyle }), + }); +} + +describe("ObjectStoreClient IAM-mode addressing", () => { + beforeEach(() => { + vi.stubEnv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE"); + vi.stubEnv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"); + vi.stubEnv("AWS_SESSION_TOKEN", undefined); + vi.stubEnv("AWS_PROFILE", undefined); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + }); + + it("keeps path-style URLs when forcePathStyle is not set", async () => { + const url = new URL(await iamClient().presign(KEY, "PUT", 300)); + + expect(url.host).toBe("s3-fips.us-gov-west-1.amazonaws.com"); + expect(url.pathname).toBe(`/${KEY}`); + }); + + it("uses virtual-hosted URLs when forcePathStyle is false", async () => { + const url = new URL(await iamClient(false).presign(KEY, "PUT", 300)); + + expect(url.host).toBe(`${BUCKET}.s3-fips.us-gov-west-1.amazonaws.com`); + expect(url.pathname).toBe("/packets/proj_123/run_456/payload.json"); + expect(url.searchParams.get("X-Amz-Algorithm")).toBe("AWS4-HMAC-SHA256"); + expect(url.searchParams.get("X-Amz-Expires")).toBe("300"); + }); + + it("applies the same addressing to GET presigns", async () => { + const url = new URL(await iamClient(false).presign(KEY, "GET", 300)); + + expect(url.host).toBe(`${BUCKET}.s3-fips.us-gov-west-1.amazonaws.com`); + expect(url.pathname).toBe("/packets/proj_123/run_456/payload.json"); + }); +}); diff --git a/docs/self-hosting/env/webapp.mdx b/docs/self-hosting/env/webapp.mdx index 09416f0f38f..ac558242765 100644 --- a/docs/self-hosting/env/webapp.mdx +++ b/docs/self-hosting/env/webapp.mdx @@ -88,12 +88,14 @@ mode: "wide" | `OBJECT_STORE_SECRET_ACCESS_KEY` | No | — | Object store secret key (default provider). | | `OBJECT_STORE_REGION` | No | — | Object store region (default provider). | | `OBJECT_STORE_SERVICE` | No | s3 | Object store service (default provider). | +| `OBJECT_STORE_FORCE_PATH_STYLE` | No | true | IAM mode only (no access keys). Set `false` for virtual-hosted addressing, which AWS FIPS endpoints require. | | `OBJECT_STORE_DEFAULT_PROTOCOL` | No | — | Protocol for new uploads (e.g. `s3`, `r2`). Enables protocol-prefixed storage. See migration guide below. | | `OBJECT_STORE_{PROTOCOL}_BASE_URL` | No | — | Named provider base URL (replace `{PROTOCOL}`, e.g. `OBJECT_STORE_S3_BASE_URL`). | | `OBJECT_STORE_{PROTOCOL}_ACCESS_KEY_ID` | No | — | Named provider access key. | | `OBJECT_STORE_{PROTOCOL}_SECRET_ACCESS_KEY` | No | — | Named provider secret key. | | `OBJECT_STORE_{PROTOCOL}_REGION` | No | — | Named provider region. | | `OBJECT_STORE_{PROTOCOL}_SERVICE` | No | — | Named provider service. | +| `OBJECT_STORE_{PROTOCOL}_FORCE_PATH_STYLE` | No | true | Named provider path-style addressing (IAM mode only). | | `ARTIFACTS_OBJECT_STORE_BUCKET` | No | — | Optional separate bucket for artifacts. If not set, uses main object store. | | `ARTIFACTS_OBJECT_STORE_BASE_URL` | No | — | Optional artifacts store base URL. | | `ARTIFACTS_OBJECT_STORE_ACCESS_KEY_ID` | No | — | Optional artifacts store access key. |