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

Feature/aws session token #1399

Merged
merged 3 commits into from
May 9, 2024
Merged
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
2 changes: 2 additions & 0 deletions docs/backends/amazon-S3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ searches for them:
#. ``session_profile`` or ``AWS_S3_SESSION_PROFILE``
#. ``access_key`` or ``AWS_S3_ACCESS_KEY_ID`` or ``AWS_S3_SECRET_ACCESS_KEY``
#. ``secret_key`` or ``AWS_ACCESS_KEY_ID`` or ``AWS_SECRET_ACCESS_KEY``
#. ``security_token`` or ``AWS_SESSION_TOKEN`` or ``AWS_SECURITY_TOKEN``
#. The environment variables AWS_S3_ACCESS_KEY_ID and AWS_S3_SECRET_ACCESS_KEY
#. The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
#. The environment variables AWS_SESSION_TOKEN and AWS_SECURITY_TOKEN
#. Use Boto3's default session

Settings
Expand Down
6 changes: 5 additions & 1 deletion storages/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ def get_default_settings(self):
),
),
"security_token": setting(
"AWS_SESSION_TOKEN", setting("AWS_SECURITY_TOKEN")
"AWS_SESSION_TOKEN",
setting(
"AWS_SECURITY_TOKEN",
lookup_env(["AWS_SESSION_TOKEN", "AWS_SECURITY_TOKEN"]),
),
),
"session_profile": setting(
"AWS_S3_SESSION_PROFILE", lookup_env(["AWS_S3_SESSION_PROFILE"])
Expand Down
23 changes: 23 additions & 0 deletions tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,29 @@ def test_auth_config(self):
access_key="foo", secret_key="boo", session_profile="moo"
)

def test_security_token(self):
with override_settings(AWS_SESSION_TOKEN="baz"):
storage = s3.S3Storage()
self.assertEqual(storage.security_token, "baz")

with override_settings(AWS_SECURITY_TOKEN="baz"):
storage = s3.S3Storage()
self.assertEqual(storage.security_token, "baz")

with mock.patch.dict(
os.environ,
{"AWS_SESSION_TOKEN": "baz"},
):
storage = s3.S3Storage()
self.assertEqual(storage.security_token, "baz")

with mock.patch.dict(
os.environ,
{"AWS_SECURITY_TOKEN": "baz"},
):
storage = s3.S3Storage()
self.assertEqual(storage.security_token, "baz")


class S3StaticStorageTests(TestCase):
def setUp(self):
Expand Down
Loading