- Newest
- Most votes
- Most comments
Hi,
IAM API reference Document for GetPolicy shows the sample request as "Version=2010-05-08".
https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html
I verified that if you change:
From:
&Version=2013-10-15
To:
&Version=2010-05-08
It will fix the problem "Could not find operation GetPolicy for version 2013-10-15". After fixing that problem, you will then get the error:
<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.</Message>
This is because you need to url encode the Arn of the policy including the slashes. You will need to change your code below, like the following to get it to work:
At the top of the file, add:
import urllib.parse
Then change the following:
From:
request_parameters = 'Action=GetPolicy&PolicyArn=arn:aws:iam::111111111111:policy/my-policy&Version=2010-05-08'
To:
# note: in below, safe= <empty string>
myArn = urllib.parse.quote(arn:aws:iam::111111111111:policy/my-policy', safe='')
request_parameters = 'Action=GetPolicy&PolicyArn=' + myArn + '&Version=2010-05-08'
After making the above changes, I was able to successfully run the program in my environment.
-randy
Edited by: RandyTakeshita on Oct 6, 2019 4:47 PM
Thanks for the reply Randy. I also tried several different "Version" options and encountered the same issue you did. My suspicion is that the 2010-05-08 version doesn't support v4 signature signing. I say that because the signature error returned doesn't actually match the error that the documentation says should be returned:
https://docs.aws.amazon.com/general/latest/gr/signature-v4-troubleshooting.html
<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<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.
The canonical string for this request should have been 'GET / Action=ListGroupsForUser&MaxItems=100&UserName=Test&Version=2010-05-08&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential
=AKIAIOSFODNN7EXAMPLE%2F20120223%2Fus-east-1%2Fiam%2Faws4_request&X-Amz-Date=20120223T063000Z&X-Amz-SignedHeaders=host
host:iam.amazonaws.com
host
<hashed-value>'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20120223T063000Z
20120223/us-east-1/iam/aws4_request
<hashed-value>'
</Message>
</Error>
<RequestId>4ced6e96-5de8-11e1-aa78-a56908bdf8eb</RequestId>
</ErrorResponse>
Using the 2013-10-15 version doesn't encounter the signature signing error but then the InvalidAction comes up. But according to the docs, this is not an invalid action:
https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html
Sample Request
https://iam.amazonaws.com/?Action=GetPolicy
&PolicyArn=arn:aws:iam::123456789012:policy/S3-read-only-example-bucket
&Version=2010-05-08
&AUTHPARAMS
Replace "GetPolicy" with any other action documented here and none of those work either: https://docs.aws.amazon.com/IAM/latest/APIReference/Welcome.html
Clearly there is a discrepancy somewhere in the documentation. I also find it interesting that there aren't very many posts related to using the IAM endpoint with v4 signature signing here in the AWS forums or on stackoverflow, especially given the inconsistency of the docs. My conclusion from that is that nobody is interfacing with IAM in that way (probably using the SDKs instead), which makes me question whether it even works at all.
Thanks,
Tom
Hi Tom,
Did you see the second part of my post. I was able to get the GetAPI call to return successfully using the same code by adding/replacing the following:
import urllib.parse
You then need to url encode the ARN, so that it will properly accepted the request parameters:
# note: in below, safe= <empty string>
myArn = urllib.parse.quote(arn:aws:iam::111111111111:policy/my-policy', safe='')
request_parameters = 'Action=GetPolicy&PolicyArn=' + myArn + '&Version=2010-05-08'
After encoding the policy Arn in my environment using the same base code you were using, this is what was returned from the call:
Response code: 200
<GetPolicyResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
<GetPolicyResult>
<Policy>
<PermissionsBoundaryUsageCount>0</PermissionsBoundaryUsageCount>
<Path>/service-role/</Path>
<UpdateDate>2019-08-28T04:18:12Z</UpdateDate>
<DefaultVersionId>v2</DefaultVersionId>
<PolicyId>ANPA2WRKRNZMSHOZDHNWZ</PolicyId>
<IsAttachable>true</IsAttachable>
<PolicyName>AWSCodePipelineServiceRole-us-east-1-MyFirstPipeline</PolicyName>
<Description>Policy used in trust relationship with CodePipeline</Description>
<AttachmentCount>2</AttachmentCount>
<Arn>arn:aws:iam::xxxxxxxxxxxxx:policy/service-role/AWSCodePipelineServiceRole-us-east-1-MyFirstPipeline</Arn>
<CreateDate>2019-08-28T03:25:55Z</CreateDate>
</Policy>
</GetPolicyResult>
<ResponseMetadata>
<RequestId>xxxxxxxxx-e8c7-11e9-xxxxxxxxxxxxx1</RequestId>
</ResponseMetadata>
</GetPolicyResponse>
-randy
Ugh. Not sure why I missed that on the first read through. Thanks for your patience Randy. I'll take another crack at it with the url encoded.
Best,
Tom
Relevant content
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago