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

aws_ssm signed url using v2 and thus aws_ssm generates incompatible curl request to download s3 object for ansible python #352

Merged
merged 5 commits into from
Jan 13, 2021
Merged
Changes from 3 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
12 changes: 9 additions & 3 deletions plugins/connection/aws_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
import os
import getpass
import json
import os
import pty
import random
import re
Expand All @@ -177,6 +176,7 @@
except ImportError as e:
HAS_BOTO_3_ERROR = str(e)
HAS_BOTO_3 = False
from botocore.client import Config

from functools import wraps
from ansible import constants as C
Expand Down Expand Up @@ -497,7 +497,11 @@ def _flush_stderr(self, subprocess):

def _get_url(self, client_method, bucket_name, out_path, http_method):
''' Generate URL for get_object / put_object '''
client = self._get_boto_client('s3')
if self.get_option('region') is None:
region_name = 'us-east-1'
else:
region_name = self.get_option('region')
Copy link
Member

Choose a reason for hiding this comment

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

You can actually just do, and this will also cover the case where the region is an empty string:

region_name = self.get_option('region') or 'us-east-1'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been addressed with the new commits.

client = self._get_boto_client('s3', region_name)
return client.generate_presigned_url(client_method, Params={'Bucket': bucket_name, 'Key': out_path}, ExpiresIn=3600, HttpMethod=http_method)

def _get_boto_client(self, service, region_name=None):
Expand All @@ -515,7 +519,9 @@ def _get_boto_client(self, service, region_name=None):
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
region_name=region_name)
region_name=region_name,
config=Config(signature_version="s3v4")
)
return client

@_ssm_retry
Expand Down