-
Notifications
You must be signed in to change notification settings - Fork 5.5k
aws-signing: add es and glacier for payloads special treatment #12020
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
Changes from 8 commits
befb45c
2ecb848
6926b4a
dce46eb
92a519d
45f4cf4
89348f5
280d36e
d25421f
e428afa
375e25c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,27 @@ class SignerImplTest : public testing::Test { | |
| message_->body() = std::make_unique<Buffer::OwnedImpl>(body); | ||
| } | ||
|
|
||
| void expectSignHeaders(absl::string_view service_name, absl::string_view signature, | ||
| absl::string_view payload) { | ||
| auto* credentials_provider = new NiceMock<MockCredentialsProvider>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why use new and then create a shared_ptr later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe no member named 'gmock_getCredentials' in 'Envoy::Extensions::Common::Aws::CredentialsProvider' |
||
| EXPECT_CALL(*credentials_provider, getCredentials()).WillOnce(Return(credentials_)); | ||
| Http::TestRequestHeaderMapImpl headers{}; | ||
| headers.setMethod("GET"); | ||
| headers.setPath("/"); | ||
| headers.addCopy(Http::LowerCaseString("host"), "www.example.com"); | ||
|
|
||
| SignerImpl signer(service_name, "region", CredentialsProviderSharedPtr{credentials_provider}, | ||
| time_system_); | ||
| signer.sign(headers); | ||
|
|
||
| EXPECT_EQ(fmt::format("AWS4-HMAC-SHA256 Credential=akid/20180102/region/{}/aws4_request, " | ||
| "SignedHeaders=host;x-amz-content-sha256;x-amz-date, " | ||
| "Signature={}", | ||
| service_name, signature), | ||
| headers.get(Http::CustomHeaders::get().Authorization)->value().getStringView()); | ||
| EXPECT_EQ(payload, headers.get(SignatureHeaders::get().ContentSha256)->value().getStringView()); | ||
| } | ||
|
|
||
| NiceMock<MockCredentialsProvider>* credentials_provider_; | ||
| Event::SimulatedTimeSystem time_system_; | ||
| Http::RequestMessagePtr message_; | ||
|
|
@@ -169,46 +190,16 @@ TEST_F(SignerImplTest, SignHostHeader) { | |
| message_->headers().get(Http::CustomHeaders::get().Authorization)->value().getStringView()); | ||
| } | ||
|
|
||
| // Verify signing headers for S3 | ||
| TEST_F(SignerImplTest, SignHeadersS3) { | ||
| auto* credentials_provider = new NiceMock<MockCredentialsProvider>(); | ||
| EXPECT_CALL(*credentials_provider, getCredentials()).WillOnce(Return(credentials_)); | ||
| Http::TestRequestHeaderMapImpl headers{}; | ||
| headers.setMethod("GET"); | ||
| headers.setPath("/"); | ||
| headers.addCopy(Http::LowerCaseString("host"), "www.example.com"); | ||
|
|
||
| SignerImpl signer("s3", "region", CredentialsProviderSharedPtr{credentials_provider}, | ||
| time_system_); | ||
| signer.sign(headers); | ||
|
|
||
| EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/s3/aws4_request, " | ||
| "SignedHeaders=host;x-amz-content-sha256;x-amz-date, " | ||
| "Signature=d97cae067345792b78d2bad746f25c729b9eb4701127e13a7c80398f8216a167", | ||
| headers.get(Http::CustomHeaders::get().Authorization)->value().getStringView()); | ||
| EXPECT_EQ(SignatureConstants::get().UnsignedPayload, | ||
| headers.get(SignatureHeaders::get().ContentSha256)->value().getStringView()); | ||
| } | ||
|
|
||
| // Verify signing headers for non S3 | ||
| TEST_F(SignerImplTest, SignHeadersNonS3) { | ||
| auto* credentials_provider = new NiceMock<MockCredentialsProvider>(); | ||
| EXPECT_CALL(*credentials_provider, getCredentials()).WillOnce(Return(credentials_)); | ||
| Http::TestRequestHeaderMapImpl headers{}; | ||
| headers.setMethod("GET"); | ||
| headers.setPath("/"); | ||
| headers.addCopy(Http::LowerCaseString("host"), "www.example.com"); | ||
|
|
||
| SignerImpl signer("service", "region", CredentialsProviderSharedPtr{credentials_provider}, | ||
| time_system_); | ||
| signer.sign(headers); | ||
|
|
||
| EXPECT_EQ("AWS4-HMAC-SHA256 Credential=akid/20180102/region/service/aws4_request, " | ||
| "SignedHeaders=host;x-amz-content-sha256;x-amz-date, " | ||
| "Signature=d9fd9be575a254c924d843964b063d770181d938ae818f5b603ef0575a5ce2cd", | ||
| headers.get(Http::CustomHeaders::get().Authorization)->value().getStringView()); | ||
| EXPECT_EQ(SignatureConstants::get().HashedEmptyString, | ||
| headers.get(SignatureHeaders::get().ContentSha256)->value().getStringView()); | ||
| // Verify signing headers for services. | ||
| TEST_F(SignerImplTest, SignHeadersByService) { | ||
| expectSignHeaders("s3", "d97cae067345792b78d2bad746f25c729b9eb4701127e13a7c80398f8216a167", | ||
| SignatureConstants::get().UnsignedPayload); | ||
| expectSignHeaders("service", "d9fd9be575a254c924d843964b063d770181d938ae818f5b603ef0575a5ce2cd", | ||
| SignatureConstants::get().HashedEmptyString); | ||
| expectSignHeaders("es", "0fd9c974bb2ad16c8d8a314dca4f6db151d32cbd04748d9c018afee2a685a02e", | ||
| SignatureConstants::get().UnsignedPayload); | ||
| expectSignHeaders("glacier", "8d1f241d77c64cda57b042cd312180f16e98dbd7a96e5545681430f8dbde45a0", | ||
| SignatureConstants::get().UnsignedPayload); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ GCP | |
| GETting | ||
| GLB | ||
| GOAWAY | ||
| Glacier | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Glacier' shouldn't need to be in this file. You had to add it probably because it was misspelled earlier?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was. |
||
| GRPC | ||
| GSS | ||
| GTEST | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think we can have this decision at initialization. Let's have a
const boolmember variable (not sure about the name, e.g.require_special_treatment_). We can initialize that bool withrequire_special_treatment_(service_name_ == "s3" || service_name_ == "glacier" || service_name_ == "es")and use that here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok