amplify-category-api
amplify-category-api copied to clipboard
@auth Combining Owner/Groups rules for Multi-Tenant Apps
Is your feature request related to a problem? Please describe.
Ability to support multi-tenancy thru AppSync where individual items are "owned/belong" to a tenant instead of a user and we still have the ability to permission queries and mutations. Generated resolvers today effectively use isOwner || isInGroup(x for x in cognitoGroups) logic so multiple @auth rules cannot be combined to create more granular permissions.
Describe the solution you'd like A few ideas:
- Provide the ability to declare the combination logic before transformation so we could generate
isOwner && isInGroup(x for x in cognitoGroups)when we have both rules types declared - Create a new @auth tenant strategy which uses the existing ownership transformation code behind the scenes but automatically changes the combination logic to
isTenant && (isOwner || isInGroup(x for x in cognitoGroups))
Describe alternatives you've considered Currently using the existing @auth owner strategy with custom ownerField and identityFIeld values, and setting the tid claim on the token with a pre-token generation Lambda function:
@auth(rules: [{allow: owner, ownerField: "tid", identityField: "claims.tid"}])
When used as the only @auth strategy, it works as intended (e.g. inserting the correct tid value during mutations; filters by tid value during queries, etc.).
But when I combine with @auth static groups strategy for permissions, the authorisation checks use OR logic instead of AND logic. I can't check for instance that a record both belongs to Tenant A (which the user belongs to) and has Permission X.