Skip to content

Commit

Permalink
Fix salt-cloud ec2 requests containing spaces.
Browse files Browse the repository at this point in the history
salt-cloud receives an error when trying to create an EC2 instance when
any number of argument values contain a space. This happens because
salt-cloud is incorrectly building the url string when calculating the
signature. AWS signature algorithm #2 requires that spaces be encoded
using %20, however python's urlencode method replaces them with a +.
The easy fix is to just search and replace in the encoded string.

I encountered this myself with a security group with a space in it.
This was reported in issue #10181
#10181

The error looks like this:
someinstancename:
    ----------
    Errors:
        ----------
        Error:
            ----------
            Code:
                SignatureDoesNotMatch
            Message:
                The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
    RequestID:
        12345678-9abc-def0-1234-56789abcdef0
  • Loading branch information
markdoliner authored and rallytime committed Oct 8, 2014
1 parent 0ab7e3d commit 7ac4f42
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions salt/cloud/clouds/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ def query(params=None, setname=None, requesturl=None, location=None,
values = map(params_with_headers.get, keys)
querystring = urllib.urlencode(list(zip(keys, values)))

# AWS signature version 2 requires that spaces be encoded as
# %20, however urlencode uses '+'. So replace pluses with %20.
querystring = querystring.replace('+', '%20')

uri = '{0}\n{1}\n/\n{2}'.format(method.encode('utf-8'),
endpoint.encode('utf-8'),
querystring.encode('utf-8'))
Expand Down

0 comments on commit 7ac4f42

Please sign in to comment.