I can't see a good design for claims- or role-based authorization over an AWS PaaS (gateway/lambda) API. Right now, there seems to be a functionality blindspot regardless of how you combine the following:
- gateway cognito user pool or custom authorizers
- cognito identity pools used for web and user pool identity federation
- IAM roles for gateway execution authorization
Specifically, the blindspot seems to be associating cognito identities with roles (more varied than keys and suffixes in dynamo and s3) based on user attributes in a way that:
- doesn't require a custom endpoint in your API to vend IAM temp creds (and consequently using something other than the supplied and/or generated SDKs)
- doesn't require authorization logic in every lambda function
- doesn't require persisting the above mapping in dynamo, cognito sync, etc
- doesn't layer or sequence a separate flow for authorization (e.g. separate token)
- lets your users sign in using external idps
I assume the following is impossible or excessively hacky:
- cognito user pools that overlap or moving users between pools to represent the configuration of their roles
- directly getting cognito user pool attributes from congito identity pool identity tokens (GetOpenIdToken)
- having a readily-modifiable client pick its own privileges (e.g. choose an IAM role)
- running every request as dry-run in a custom authorizer or otherwise shadow-implementing IAM
- securing actually role-specific IAM roles with some kind of shared secret, etc.
Here are some examples and their shortcomings:
- A user logs in with user pool credentials and attempts to execute a gateway api method.
- A cognito authorizer over gateway api methods would let me say autheticated-therefore-authorized and map attributes/claims into the integration request, still leaving it to the lambda function to implement actual authorization logic.
- A custom authorizer won't automatically validate and parse a user pool token, but I could still do so and conditionally construct a role.
- A user logs in with google+ credentials, having a user pool identity as well, and attempts to execute a gateway api method.
- A cognito authorizer is useless.
- A custom authorizer won't automatically validate and parse the google+ token, but I could still do so and conditionally construct a role. Only now I'd need to map this to a user pool identity manually. Cognito adds no value at all here -- just an awkward document database as a service.
- A user logs in with google+ credentials, having a user pool identity as well, then gets an identity pool token (GetOpenIdToken) and attempts to execute a gateway api method.
- A cognito authorizer is useless.
- A custom authorizer won't automatically validate and parse the cognito identity token, but I could still do so and conditionally construct a role. I still need to do manual mapping because I won't get the user pool attributes with this intermediate token.
- A user logs in with google+ credentials, having a user pool identity as well, then gets temp creds (GetCredentialsForIdentity) and attempts to execute a gateway api method.
- The default authorizer is useless. You just get authenticated-therefore-authorized.
- A cognito authorizer is useless.
- A custom authorizer is useless.