I want to create an API that requires an IAM role to access the data in the end-user's S3 buckets. I currently use the following flow:
- User logs on to the website and gets an ID token and access token (via OIDC).
- User invokes a call to my API and presents its ID token.
- My API fetches temporary credentials from Cognito Identity Pool using the presented ID token.
- Calls to S3 can be made using the temporary credentials.
Although this works, there is a flaw in this flow. The website got an ID token during the Open ID Connect login, but ID tokens shouldn't be used to pass to an API (that's what access tokens are for). I would rather pass an access token instead, but I can't get the AWS credentials using an access token.
What is the appropriate solution here? I checked if I could get an ID token from an access token. I have several options:
- Just pass the ID-token to the API, because we want to pass our identity (IAM role) so the API can impersonate. This makes it reasonable to pass an ID token instead of an access token.
- The API should obtain an ID-token based on the access-token. Although I can fetch all identity claims from the OIDC userinfo endpoint, this isn't an ID token, so I can't use it to fetch the AWS credentials using Cognito's identity pool.
- Completely ditch Cognito Identity Pool and grant the API role STS policies, so it can assume the role that is linked to the user. I rather not have high-privilege roles in my services.
All three solutions are not ideal. But what's the best scenario? Or did I forget something?