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

Populate available session token in presigned_url() #1000

Merged
merged 5 commits into from
Oct 14, 2020

Conversation

dtaniwaki
Copy link
Contributor

Minio's Presigned URL didn't support an IAM role which requires a session token for a presigned URL.

I followed the code of the botocore.
https://github.com/boto/botocore/blob/30206ab9e9081c80fa68e8b2cb56296b09be6337/botocore/auth.py#L484-L492

This PR has includes the fix of #998 because it cannot test the function without it.

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

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

Below is the actual way to fix the issue.

diff --git a/minio/api.py b/minio/api.py
index b4d9187..3bc4a5e 100644
--- a/minio/api.py
+++ b/minio/api.py
@@ -1601,6 +1601,9 @@ class Minio:  # pylint: disable=too-many-public-methods
         query_params = extra_query_params or {}
         query_params.update({"versionId": version_id} if version_id else {})
         query_params.update(response_headers or {})
+        creds = self._provider.retrieve() if self._provider else None
+        if creds and creds.session_token:
+            query_params["X-Amz-Security-Token"] = creds.session_token
         url = self._base_url.build(
             method,
             region,
@@ -1609,12 +1612,12 @@ class Minio:  # pylint: disable=too-many-public-methods
             query_params=query_params,
         )
 
-        if self._provider:
+        if creds:
             url = presign_v4(
                 method,
                 url,
                 region,
-                self._provider.retrieve(),
+                creds,
                 request_date or datetime.utcnow(),
                 int(expires.total_seconds()),
             )
diff --git a/minio/credentials/providers.py b/minio/credentials/providers.py
index 28b17e3..e3c5910 100644
--- a/minio/credentials/providers.py
+++ b/minio/credentials/providers.py
@@ -563,7 +563,7 @@ class WebIdentityClientGrantsProvider(Provider):
 
         jwt = self._jwt_provider_func()
 
-        query_params = {"Version", "2011-06-15"}
+        query_params = {"Version": "2011-06-15"}
         duration_seconds = self._get_duration_seconds(
             int(jwt.get("expires_in", "0")),
         )

@balamurugana balamurugana changed the title Support Presigned URL by IAM Role Populate available session token in presigned_url() Oct 14, 2020
@harshavardhana harshavardhana merged commit ae70733 into minio:master Oct 14, 2020
@dtaniwaki dtaniwaki deleted the support-iam-role-presigned-url branch October 15, 2020 01:54
@dtaniwaki dtaniwaki restored the support-iam-role-presigned-url branch October 15, 2020 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants