Skip to content
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

HDDS-7035. Generate strToSign before applying virtual host style filter. #5123

Merged
merged 6 commits into from Sep 21, 2023

Conversation

SaketaChalamchala
Copy link
Contributor

@SaketaChalamchala SaketaChalamchala commented Jul 27, 2023

What changes were proposed in this pull request?

When using Virtual-Host Style addressing using AWS CLI the client uses / as the canonical URI when generating the S3 request. At the server side, VirtualHostStyleFilter.java extracts bucket name from the host value and appends it to the URI. This causes the signature validation to fail because the canonical URI used to generating string to sign is /bucketname. But, this is also necessary to resource match the request to the correct endpoint.

Proposed change introduces an

  • AuthorizationFilter.java and moves the string to sign generation function from OzoneClientProducer.java to AuthorizationFilter.java. The filter runs before the VirtualHostStyleFilter.java where the URI is changed.
  • Repurposes SignatureInfo object to store String to Sign information.
  • Fixed a bug in VirtualHostStyleFilter.java: URIs with keynames were generated as /bucketnamekeyname instead of /bucketname/keyname
  • Minor changes: Used a standard approach to assign prioritues to filters.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-7035

How was this patch tested?

  • Unit Tests
  • Acceptance Tests

@errose28 errose28 requested a review from kerneltime July 31, 2023 16:38
@errose28
Copy link
Contributor

cc @tanvipenumudy for review

@tanvipenumudy
Copy link
Contributor

Thanks @SaketaChalamchala for the patch!

Minor NIT: Would it be helpful to have a test where virtual-host style addressing is not used to verify if the canonical URI remains unchanged?

@SaketaChalamchala
Copy link
Contributor Author

Thanks @SaketaChalamchala for the patch!

Minor NIT: Would it be helpful to have a test where virtual-host style addressing is not used to verify if the canonical URI remains unchanged?

Thanks for the review @tanvipenumudy, there are existing tests in TestStringToSignProducer.java#test and TestVirtualHostStyleFilter.java#testPathStyle that cover path style addressing.

Copy link
Contributor

@errose28 errose28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @SaketaChalamchala. I'm not very familiar with this area of the code or the AWS virtual/path style specs, but I did a pass cross-referencing with the AWS documentation.

@@ -269,4 +271,60 @@ public void testValidateCanonicalHeaders(

Assert.assertEquals(expectedResult, actualResult);
}

@Test
public void testVirtualStyleAddressURI() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the other test in this class to testPathStyleAddressURI to clarify the difference?

Comment on lines 67 to 71
public static final String ENDPOINT_STYLE_PARAM = "endpoint-style";

public static final String ENDPOINT_STYLE_PATH = "path";

public static final String ENDPOINT_STYLE_VIRTUAL = "virtual";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did these values come from? I can't find them documented by AWS anywhere, for example at https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these internally to identify when virtual host style addressing is used.

Comment on lines 110 to 111
"/mybucket/myfile?" + S3Consts.ENDPOINT_STYLE_PARAM + "=" +
S3Consts.ENDPOINT_STYLE_VIRTUAL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to examples in s3 docs, no extra query parameters are required. The tests should run the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @errose28 I added the extra parameters are added internally in VirtualHostStyleFilter.java so that when we do signature validation late we know to use the original request URI sent by the client and not the URI with bucket name that is appended in VirtualHostStyleFilter.java.

@errose28
Copy link
Contributor

Also, why did our existing secure S3 acceptance tests not catch this? Since path style is deprecated, I would assume the s3 client we are using in those tests is calling s3 gateway with virtual style. Can you provide an acceptance test that passes only after the fix is applied?

@kerneltime
Copy link
Contributor

Also, why did our existing secure S3 acceptance tests not catch this? Since path style is deprecated, I would assume the s3 client we are using in those tests is calling s3 gateway with virtual style. Can you provide an acceptance test that passes only after the fix is applied?

Even though path style is deprecated, most on prem deployments still use it. It is rare to find clients using virtual host style bucket addressing due to the complexity of bucket creation and DNS updates needed.

@SaketaChalamchala
Copy link
Contributor Author

@errose28 & @kerneltime,
I modified the patch to include an AuthorizationFilter before all other filters and added an acceptance test.
Updated the PR description accordingly.

@SaketaChalamchala SaketaChalamchala changed the title HDDS-7035. With virtual style addressing do not append bucketname from host to canonical URI for signature validation. HDDS-7035. Generate strToSign before applying virtual host style filter. Aug 29, 2023
@SaketaChalamchala
Copy link
Contributor Author

Looks like there are some acceptance test failures. Working on them.

@kerneltime kerneltime merged commit 1c48935 into apache:master Sep 21, 2023
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants