Skip to content

Commit

Permalink
Fixed Sigv4 Signing for Managed Service (#279)
Browse files Browse the repository at this point in the history
Fixed SigV4 Signing for Async Requests with QueryStrings

Signed-off-by: Theo Truong <[email protected]>

Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong authored Jan 24, 2023
1 parent 4059251 commit 58aa041
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unified-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
stack_version: ['2.1.0']
stack_version: ['2.1.1']

steps:
- name: Checkout
Expand Down
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# CHANGELOG
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
## [2.1.1]
### Added
### Changed
### Deprecated

### Removed

### Fixed
- Fixed SigV4 Signing for Managed Service ([#279](https://github.com/opensearch-project/opensearch-py/pull/279))
- Fixed SigV4 Signing for Async Requests with QueryStrings ([#272](https://github.com/opensearch-project/opensearch-py/pull/279))
### Security

## [2.1.0]
### Added
- Added Support for AOSS ([#268](https://github.com/opensearch-project/opensearch-py/pull/268))
### Changed
### Deprecated
### Removed
### Fixed
### Security

## [2.0.1]
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
# specific language governing permissions and limitations
# under the License.

__versionstr__ = "2.1.0"
__versionstr__ = "2.1.1"
4 changes: 3 additions & 1 deletion opensearchpy/helpers/asyncsigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ def _sign_request(self, method, url, query_string, body):
# create an AWS request object and sign it using SigV4Auth
aws_request = AWSRequest(
method=method,
url="".join([url, query_string]),
url=url,
data=body,
)

sig_v4_auth = SigV4Auth(self.credentials, self.service, self.region)
sig_v4_auth.add_auth(aws_request)
aws_request.headers["X-Amz-Content-SHA256"] = sig_v4_auth.payload(aws_request)

# copy the headers from AWS request object into the prepared_request
return dict(aws_request.headers.items())
4 changes: 4 additions & 0 deletions opensearchpy/helpers/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ def _sign_request(self, prepared_request): # type: ignore
aws_request = AWSRequest(
method=prepared_request.method.upper(),
url=url,
data=prepared_request.body,
)

sig_v4_auth = SigV4Auth(self.credentials, self.service, self.region)
sig_v4_auth.add_auth(aws_request)

# copy the headers from AWS request object into the prepared_request
prepared_request.headers.update(dict(aws_request.headers.items()))
prepared_request.headers["X-Amz-Content-SHA256"] = sig_v4_auth.payload(
aws_request
)

return prepared_request
1 change: 1 addition & 0 deletions test_opensearchpy/test_async/test_asyncsigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ async def test_aws_signer_async_when_service_is_specified(self):
self.assertIn("Authorization", headers)
self.assertIn("X-Amz-Date", headers)
self.assertIn("X-Amz-Security-Token", headers)
self.assertIn("X-Amz-Content-SHA256", headers)
1 change: 1 addition & 0 deletions test_opensearchpy/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def test_aws_signer_as_http_auth(self):
self.assertIn("Authorization", prepared_request.headers)
self.assertIn("X-Amz-Date", prepared_request.headers)
self.assertIn("X-Amz-Security-Token", prepared_request.headers)
self.assertIn("X-Amz-Content-SHA256", prepared_request.headers)

@pytest.mark.skipif(
sys.version_info < (3, 6), reason="AWSV4SignerAuth requires python3.6+"
Expand Down

0 comments on commit 58aa041

Please sign in to comment.