Open palpatim opened 1 month ago
Note: We also need to make sure this fix properly handles the EventInvocationResponse
type for .async()
function handlers (see https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#async-function-handlers). It should, since that type must be specified in the schema, but we'll want a specific test for it.
We do plan on addressing this. In the meantime, here are a few workarounds:
If you only need to access a custom operation via IAM, you can set the API's default authorization mode to iam
export const data = defineData({
authorizationModes: {
defaultAuthorizationMode: "iam",
},
...
This instructs AppSync to use IAM authorization on all access by default. However, this will not work if you also need additional authorization modes on a custom operation, since explicitly adding an authorization rule to a field overrides the default authorization mode.
Use scalar return type for the return type of the custom operation:
foo: a
.mutation()
.arguments({
id: a.string().required(),
})
// v------- NOTE the return type is a scalar, which needs no further authorization
.returns(a.integer())
...
Convert the return type to a model
rather than a customType
, and disable all operations:
Foo: a
.model({
value: a.integer(),
})
.disableOperations(["mutations", "subscriptions", "queries"])
.authorization((allow) => [allow.group("ZZZDOESNOTEXIST")]),
...
foo: a
.mutation()
.arguments({
id: a.string().required(),
})
// v------- NOTE the return type is the model
.returns(a.ref('Foo'))
This has the downside of creating an empty DynamoDB table for the return type, but by disabling operations and explicitly setting an unreachable authorization mode, it ensures that only IAM access is authorized on the type.
This works because Amplify supports adding implicit IAM authorization to models even if you specify other explicit authorization modes.
Environment information
Data packages
Description
During investigation of https://github.com/aws-amplify/amplify-category-api/issues/2837, @atierian noted a case not covered by the fix. In the case of a schema with only custom operations and types, the
@aws_iam
annotation won't get automatically added to the custom type. E.g., in the following schema:The transformed schema would correctly include
@aws_iam
on thegetFoo
field, but not on theFoo
type itself, meaning that a properly authorizedgetFoo
query would be unable to view the actual result.There are a couple of notes to help gauge priority:
A workaround for this bug is to add a static auth rule to the field, which triggers the auth transformer to process the field:
This does not pertain to custom operation fields that have scalar types: the below example works fine after the fix in #2921: