I'm working on an AWS project. We want to be able to issue STS temporary security credentials, with limited permissions, in order to access AWS services. We're working in .Net Core with C#.
We're using STS AssumeRoleAsync()
, which is the .Net SDK's method for using the AWS AssumeRole action, to generate these credentials. The response from the call to AssumeRoleAsync()
is an AssumeRoleResponse
object, which is comprised in part of an AssumeRoleUser
object and a Credentials
object. One of the properties of AssumedRoleUser
is AssumedRoleId
, which is in the form of role-id:role-session-name
.
We have a Lambda function which handles calling AssumeRoleAsync
and returning the generated credentials in the form of a JSON object. That Lambda function is called via an API Gateway method.
All of this is working fine. The above was just to set the scene.
The next thing we want to be able to do is to use the STS temporary credentials to make other calls into AWS services. When that happens, we want be able to use GetCallerIdentity()
to retrieve the AssumedRoleId
for the person to whom the credentials were issued. In particular, the role-session-name
is of interest to us.
So to try to accomplish this, I created another Lambda function behind another API Gateway method. I set this API Gateway method to use AWS_IAM
authorization in its Method Request configuration. In its Integration Request, I configured it to Invoke with caller credentials
. The Lambda function simply accepts the incoming request and calls GetCallerIdentity()
and returns the result. I used the credentials returned from the previous AssumeRoleAsync()
call in the request's authorization header.
Based on the information found in the docs for GetCallerIdentity and in the Principal Table to which that page refers, I expect to receive the following items in response from the GetCallerIdentity()
call:
Account
Arn
UserId
(this is the important bit for this discussion)
The UserId
should be in the form of role-id:caller-specified-role-name
, exactly the same form in which the AssumedRoleId
from the call to AssumeRoleAsync
was returned. That would allow me to get the caller-specified-role-name
and do what we need to do with it.
But that isn't what is returned in the UserId
property of the response from GetCallerIdentity()
.
Instead, all that the UserId
property contains is the role-id
— it completely omits the essential caller-specified-role-name
.
Has anyone else seen this behavior? Am I overlooking something simple? Could this be a bug in the response from GetCallerIdentity
?
I'm using the following Amazon SDK components and versions to make these various calls:
- Amazon.Lambda.Core/1.0.0
- Amazon.Lambda.Serialization.Json/1.1.0
- AWSSDK.Core/3.3.14
- AWSSDK.Lambda/3.3.6.2
- AWSSDK.SecurityToken/3.3.1.9
Thanks for any help you can suggest!
Derek