Skip to content

Commit b30d338

Browse files
authored
fix(middleware-sdk-s3-control): do not validate for FIPS in S3 Outposts (#3027)
1 parent 8d76ab2 commit b30d338

File tree

4 files changed

+54
-65
lines changed

4 files changed

+54
-65
lines changed
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
import { getOutpostEndpoint } from "./getOutpostEndpoint";
22

33
describe(getOutpostEndpoint.name, () => {
4-
const mockRegion = "region";
5-
const mockDnsSuffix = "mockDnsSuffix";
6-
const mockHostname = `s3-control.${mockRegion}.${mockDnsSuffix}`;
74
const mockInput = { isCustomEndpoint: false, useFipsEndpoint: false };
8-
95
it("returns hostname if custom endpoint is set", () => {
6+
const mockHostname = "mock.hostname.com";
107
expect(getOutpostEndpoint(mockHostname, { ...mockInput, isCustomEndpoint: true })).toStrictEqual(mockHostname);
118
});
129

1310
describe("returns outpost endpoint", () => {
14-
it("uses region from hostname if regionOverride if provided", () => {
15-
expect(getOutpostEndpoint(mockHostname, mockInput)).toStrictEqual(`s3-outposts.${mockRegion}.${mockDnsSuffix}`);
16-
});
11+
const mockRegion = "region";
12+
const mockDnsSuffix = "mockDnsSuffix";
13+
14+
const testOutpostEndpoint = (useFipsEndpoint: boolean) => {
15+
const mockHostname = `s3-control${useFipsEndpoint ? "-fips" : ""}.${mockRegion}.${mockDnsSuffix}`;
16+
it("uses region from hostname if regionOverride if provided", () => {
17+
expect(getOutpostEndpoint(mockHostname, { ...mockInput, useFipsEndpoint })).toStrictEqual(
18+
`s3-outposts${useFipsEndpoint ? "-fips" : ""}.${mockRegion}.${mockDnsSuffix}`
19+
);
20+
});
21+
22+
it("uses region from regionOverride if provided", () => {
23+
const mockRegionOverride = "mockRegionOverride";
24+
expect(
25+
getOutpostEndpoint(mockHostname, { ...mockInput, useFipsEndpoint, regionOverride: mockRegionOverride })
26+
).toStrictEqual(`s3-outposts${useFipsEndpoint ? "-fips" : ""}.${mockRegionOverride}.${mockDnsSuffix}`);
27+
});
28+
};
1729

18-
it("uses region from regionOverride if provided", () => {
19-
const mockRegionOverride = "mockRegionOverride";
20-
expect(getOutpostEndpoint(mockHostname, { ...mockInput, regionOverride: mockRegionOverride })).toStrictEqual(
21-
`s3-outposts.${mockRegionOverride}.${mockDnsSuffix}`
22-
);
30+
describe("with FIPS", () => {
31+
testOutpostEndpoint(true);
2332
});
2433

25-
it(`adds suffix "-fips" if useFipsEndpoint is set`, () => {
26-
expect(getOutpostEndpoint(mockHostname, { ...mockInput, useFipsEndpoint: true })).toStrictEqual(
27-
`s3-outposts-fips.${mockRegion}.${mockDnsSuffix}`
28-
);
34+
describe("without FIPS", () => {
35+
testOutpostEndpoint(false);
2936
});
3037
});
3138
});
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const REGEX_S3CONTROL_HOSTNAME = /^(.+\.)?s3-control[.-]([a-z0-9-]+)\./;
1+
const REGEX_S3CONTROL_HOSTNAME = /^(.+\.)?s3-control(-fips)?[.-]([a-z0-9-]+)\./;
22

33
export interface GetOutpostEndpointOptions {
44
isCustomEndpoint?: boolean;
@@ -10,15 +10,17 @@ export const getOutpostEndpoint = (
1010
hostname: string,
1111
{ isCustomEndpoint, regionOverride, useFipsEndpoint }: GetOutpostEndpointOptions
1212
): string => {
13-
const [matched, prefix, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME)!;
14-
// hostname prefix will be ignored even if presents
15-
return isCustomEndpoint
16-
? hostname
17-
: [
18-
`s3-outposts${useFipsEndpoint ? "-fips" : ""}`,
19-
regionOverride || region,
20-
hostname.replace(new RegExp(`^${matched}`), ""),
21-
]
22-
.filter((part) => part !== undefined)
23-
.join(".");
13+
if (isCustomEndpoint) {
14+
return hostname;
15+
}
16+
17+
const [matched, prefix, fips, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME)!;
18+
// hostname prefix will be ignored even if it is present
19+
return [
20+
`s3-outposts${useFipsEndpoint ? "-fips" : ""}`,
21+
regionOverride || region,
22+
hostname.replace(new RegExp(`^${matched}`), ""),
23+
]
24+
.filter((part) => part !== undefined)
25+
.join(".");
2426
};

packages/middleware-sdk-s3-control/src/process-arnables-plugin/parse-outpost-arnables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const validateOutpostsArn = (
120120
clientRegion,
121121
clientSigningRegion: signingRegion,
122122
useFipsEndpoint,
123+
allowFipsRegion: true,
123124
});
124125
validateNoDualstack(useDualstackEndpoint);
125126
};

packages/middleware-sdk-s3-control/src/process-arnables-plugin/plugin.spec.ts

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ describe("getProcessArnablesMiddleware", () => {
169169
expect(context).toMatchObject({ signing_service: "s3-outposts", signing_region: "us-gov-east-1" });
170170
});
171171

172-
it("should validate when arn region is fips region", async () => {
173-
expect.assertions(1);
172+
it("should compute hostname for fips region", async () => {
173+
expect.assertions(4);
174174
const clientRegion = "us-gov-east-1";
175175
const hostname = `s3-control.${clientRegion}.amazonaws.com`;
176176
const options = setupPluginOptions({
@@ -181,36 +181,14 @@ describe("getProcessArnablesMiddleware", () => {
181181
});
182182
const stack = getStack(hostname, options);
183183
const handler = stack.resolve((() => {}) as any, {});
184-
try {
185-
await handler({
186-
input: {
187-
Name: "arn:aws-us-gov:s3-outposts:fips-us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint",
188-
},
189-
});
190-
} catch (e) {
191-
expect(e.message).toContain("FIPS region is not supported");
192-
}
193-
});
194-
195-
it("should update endpoint, headers and context correctly if client is fips region", async () => {
196-
expect.assertions(4);
197-
const clientRegion = "fip-us-gov-east-1";
198-
const hostname = `s3-control.${clientRegion}.amazonaws.com`;
199-
const options = setupPluginOptions({
200-
region: clientRegion,
201-
useArnRegion: true,
202-
regionInfoProvider: () => Promise.resolve({ hostname, partition: "aws-us-gov" }),
203-
});
204-
const stack = getStack(hostname, options);
205-
const handler = stack.resolve((() => {}) as any, {});
206184
const {
207185
output: { request, context, input },
208186
} = (await handler({
209187
input: {
210188
Name: "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint",
211189
},
212190
})) as any;
213-
expect(request.hostname).toBe("s3-outposts.us-gov-east-1.amazonaws.com");
191+
expect(request.hostname).toBe("s3-outposts-fips.us-gov-east-1.amazonaws.com");
214192
expect(request.headers).toMatchObject({ "x-amz-outpost-id": "op-01234567890123456" });
215193
expect(input.AccountId).toBe("123456789012");
216194
expect(context).toMatchObject({ signing_service: "s3-outposts", signing_region: "us-gov-east-1" });
@@ -391,8 +369,8 @@ describe("getProcessArnablesMiddleware", () => {
391369
expect(context).toMatchObject({ signing_service: "s3-outposts", signing_region: "us-gov-east-1" });
392370
});
393371

394-
it("should validate when arn region is fips region", async () => {
395-
expect.assertions(1);
372+
it("should compute hostname for fips region", async () => {
373+
expect.assertions(4);
396374
const clientRegion = "us-gov-east-1";
397375
const hostname = `s3-control.${clientRegion}.amazonaws.com`;
398376
const options = setupPluginOptions({
@@ -403,16 +381,17 @@ describe("getProcessArnablesMiddleware", () => {
403381
});
404382
const stack = getStack(hostname, options);
405383
const handler = stack.resolve((() => {}) as any, {});
406-
try {
407-
await handler({
408-
input: {
409-
Bucket:
410-
"arn:aws-us-gov:s3-outposts:fips-us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket",
411-
},
412-
});
413-
} catch (e) {
414-
expect(e.message).toContain("FIPS region is not supported");
415-
}
384+
const {
385+
output: { request, context, input },
386+
} = (await handler({
387+
input: {
388+
Bucket: "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket",
389+
},
390+
})) as any;
391+
expect(request.hostname).toBe("s3-outposts-fips.us-gov-east-1.amazonaws.com");
392+
expect(request.headers).toMatchObject({ "x-amz-outpost-id": "op-01234567890123456" });
393+
expect(input.AccountId).toBe("123456789012");
394+
expect(context).toMatchObject({ signing_service: "s3-outposts", signing_region: "us-gov-east-1" });
416395
});
417396

418397
it("should update endpoint, headers and context correctly if client is fips region", async () => {

0 commit comments

Comments
 (0)