Skip to content

fix(middleware-bucket-endpoint): bugfixing the s3 endpoint arn parser #2093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/middleware-bucket-endpoint/src/bucketHostname.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe("bucketHostname", () => {
[
{
bucketArn: "arn:aws:sqs:us-west-2:123456789012:someresource",
message: "Expect 's3' or 's3-outposts' in ARN service component",
message: "Expect 's3' or 's3-outposts' or 's3-object-lambda' in ARN service component",
},
{
bucketArn: "arn:aws:s3:us-west-2:123456789012:bucket_name:mybucket",
Expand Down Expand Up @@ -713,4 +713,23 @@ describe("bucketHostname", () => {
expect(signingService).toBe("s3-outposts");
});
});

describe("from Object Lamdba ARN", () => {
describe("populates access point endpoint from ARN", () => {
it("should use the proper endpoint", () => {
const region = "eu-west-1";
const expectedEndpoint = "js-sdk-ap-name-123456789012.s3-object-lambda.eu-west-1.amazonaws.com";
["arn:aws:s3-object-lambda:eu-west-1:123456789012:accesspoint/js-sdk-ap-name"].forEach((outpostArn) => {
const { bucketEndpoint, hostname } = bucketHostname({
bucketName: parseArn(outpostArn),
baseHostname: "s3.eu-west-1.amazonaws.com",
isCustomEndpoint: false,
clientRegion: region,
});
expect(bucketEndpoint).toBe(true);
expect(hostname).toBe(expectedEndpoint);
});
});
});
});
});
17 changes: 13 additions & 4 deletions packages/middleware-bucket-endpoint/src/bucketHostname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,26 @@ const getEndpointFromArn = (options: ArnHostnameParams & { isCustomEndpoint: boo
validateAccountId(accountId);
validateRegion(region, { useArnRegion, clientRegion, clientSigningRegion });
const { accesspointName, outpostId } = getArnResources(resource);
validateDNSHostLabel(`${accesspointName}-${accountId}`, { tlsCompatible });
const DNSHostLabel = `${accesspointName}-${accountId}`;
validateDNSHostLabel(DNSHostLabel, { tlsCompatible });

const endpointRegion = useArnRegion ? region : clientRegion;
const signingRegion = useArnRegion ? region : clientSigningRegion;
if (outpostId) {
if (service === "s3-object-lambda") {
validateNoDualstack(dualstackEndpoint);
return {
bucketEndpoint: true,
hostname: `${DNSHostLabel}.${service}.${endpointRegion}.${hostnameSuffix}`,
signingRegion,
signingService: service,
};
} else if (outpostId) {
// if this is an Outpost ARN
validateOutpostService(service);
validateDNSHostLabel(outpostId, { tlsCompatible });
validateNoDualstack(dualstackEndpoint);
validateNoFIPS(endpointRegion);
const hostnamePrefix = `${accesspointName}-${accountId}.${outpostId}`;
const hostnamePrefix = `${DNSHostLabel}.${outpostId}`;
return {
bucketEndpoint: true,
hostname: `${hostnamePrefix}${isCustomEndpoint ? "" : `.s3-outposts.${endpointRegion}`}.${hostnameSuffix}`,
Expand All @@ -88,7 +97,7 @@ const getEndpointFromArn = (options: ArnHostnameParams & { isCustomEndpoint: boo
}
// construct endpoint from Accesspoint ARN
validateS3Service(service);
const hostnamePrefix = `${accesspointName}-${accountId}`;
const hostnamePrefix = `${DNSHostLabel}`;
return {
bucketEndpoint: true,
hostname: `${hostnamePrefix}${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export const validateArnEndpointOptions = (options: {
};

export const validateService = (service: string) => {
if (service !== "s3" && service !== "s3-outposts") {
throw new Error("Expect 's3' or 's3-outposts' in ARN service component");
if (service !== "s3"
&& service !== "s3-outposts"
&& service !== "s3-object-lambda") {
throw new Error("Expect 's3' or 's3-outposts' or 's3-object-lambda' in ARN service component");
}
};

Expand Down