-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[v2] Implement opting out of S3 Express session auth via config variables. #10105
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
Open
aemous
wants to merge
8
commits into
aws:v2
Choose a base branch
from
aemous:disable-s3-express-auth
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+218
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9c8453
Implement opting out of S3 Express session auth via config variables.
aemous 44cffc9
Mock utcnow in test_disable_s3_express_auth to fix failing test.
aemous e693c57
Remove reference to client configuration setting in changelog entry.
aemous 58b4039
Update s3-config topic with extra config setting.
aemous 23504c2
Progress on args.py s3 express opt-out port.
aemous 43188ce
Update wording on changelog entry.
aemous fd47b59
Finalize port after rebasing against client context params.
aemous 728830e
Fix bug where unsupported S3 shared config settings were being used i…
aemous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "type": "enhancement", | ||
| "category": "``s3``", | ||
| "description": "Added support for opting out of Amazon S3 Express session authentication via the new ``AWS_S3_DISABLE_EXPRESS_SESSION_AUTH`` environment variable, or the ``s3_disable_express_session_auth`` shared configuration setting." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/functional/botocore/test_disable_s3_express_auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
| import datetime | ||
| import os | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
| from dateutil.tz import tzutc | ||
|
|
||
| from botocore.config import Config | ||
| from tests import ClientHTTPStubber, temporary_file | ||
|
|
||
|
|
||
| class TestDisableS3ExpressAuth: | ||
| DATE = datetime.datetime(2024, 11, 30, 23, 59, 59, tzinfo=tzutc()) | ||
| BUCKET_NAME = 'mybucket--usw2-az1--x-s3' | ||
|
|
||
| CREATE_SESSION_RESPONSE = b'<?xml version="1.0" encoding="UTF-8"?>\n<CreateSessionResult><Credentials><AccessKeyId>test-key</AccessKeyId><Expiration>2024-12-31T23:59:59Z</Expiration><SecretAccessKey>test-secret</SecretAccessKey><SessionToken>test-token</SessionToken></Credentials></CreateSessionResult>' | ||
| LIST_OBJECTS_RESPONSE = b'<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>mybucket--usw2-az1--x-s3</Name><Prefix/><KeyCount>0</KeyCount><MaxKeys>1000</MaxKeys><EncodingType>url</EncodingType><IsTruncated>false</IsTruncated></ListBucketResult>' | ||
|
|
||
| @pytest.fixture | ||
| def mock_datetime(self): | ||
| with mock.patch('datetime.datetime', spec=True) as mock_dt: | ||
| mock_dt.now.return_value = self.DATE | ||
| mock_dt.utcnow.return_value = self.DATE | ||
| yield mock_dt | ||
|
|
||
| def test_disable_s3_express_auth_enabled( | ||
| self, patched_session, mock_datetime | ||
| ): | ||
| config = Config(s3={'disable_s3_express_session_auth': True}) | ||
| s3_client = patched_session.create_client( | ||
| 's3', | ||
| config=config, | ||
| region_name='us-west-2', | ||
| ) | ||
|
|
||
| with ClientHTTPStubber(s3_client, strict=True) as stubber: | ||
| stubber.add_response(body=self.LIST_OBJECTS_RESPONSE) | ||
| s3_client.list_objects_v2(Bucket=self.BUCKET_NAME) | ||
|
|
||
| assert len(stubber.requests) == 1 | ||
|
|
||
| def test_disable_s3_express_auth_enabled_env_var( | ||
| self, patched_session, mock_datetime | ||
| ): | ||
| os.environ['AWS_S3_DISABLE_EXPRESS_SESSION_AUTH'] = 'true' | ||
| s3_client = patched_session.create_client( | ||
| 's3', | ||
| region_name='us-west-2', | ||
| ) | ||
|
|
||
| with ClientHTTPStubber(s3_client, strict=True) as stubber: | ||
| stubber.add_response(body=self.LIST_OBJECTS_RESPONSE) | ||
| s3_client.list_objects_v2(Bucket=self.BUCKET_NAME) | ||
|
|
||
| assert len(stubber.requests) == 1 | ||
|
|
||
| def test_disable_s3_express_auth_enabled_shared_config( | ||
| self, patched_session, mock_datetime | ||
| ): | ||
| with temporary_file('w') as f: | ||
| os.environ['AWS_CONFIG_FILE'] = f.name | ||
| f.write('[default]\n') | ||
| f.write('s3_disable_express_session_auth = true\n') | ||
| f.flush() | ||
|
|
||
| s3_client = patched_session.create_client( | ||
| 's3', | ||
| region_name='us-west-2', | ||
| ) | ||
|
|
||
| with ClientHTTPStubber(s3_client, strict=True) as stubber: | ||
| stubber.add_response(body=self.LIST_OBJECTS_RESPONSE) | ||
| s3_client.list_objects_v2(Bucket=self.BUCKET_NAME) | ||
|
|
||
| assert len(stubber.requests) == 1 | ||
|
|
||
| def test_disable_s3_express_auth_disabled( | ||
| self, patched_session, mock_datetime | ||
| ): | ||
| config = Config(s3={'disable_s3_express_session_auth': False}) | ||
| s3_client = patched_session.create_client( | ||
| 's3', | ||
| config=config, | ||
| region_name='us-west-2', | ||
| ) | ||
|
|
||
| with ClientHTTPStubber(s3_client, strict=True) as stubber: | ||
| stubber.add_response(body=self.CREATE_SESSION_RESPONSE) | ||
| stubber.add_response(body=self.LIST_OBJECTS_RESPONSE) | ||
| s3_client.list_objects_v2(Bucket=self.BUCKET_NAME) | ||
|
|
||
| assert len(stubber.requests) == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.