Describe the bug
Allow public IAM @auth
on @function
outside of @model
Amplify CLI Version
3.17.0
To Reproduce
@function
public outside of a @model
, eg.type Query {
getStripeClientSecret: String
@function(name: "foo-${env}")
@auth(rules: [{ allow: public, provider: iam }])
}
query {
getStripeClientSecret
}
Gives error:
{
"data": {
"getStripeClientSecret": null
},
"errors": [
{
"path": [
"getStripeClientSecret"
],
"data": null,
"errorType": "Unauthorized",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Not Authorized to access getStripeClientSecret on type Query"
}
]
}
If I edit the resolver, I see this stanza:
## [Start] Throw if unauthorized **
#if( !($getStripeClientSecret_isStaticGroupAuthorized == true || $isDynamicGroupAuthorized == true || $isOwnerAuthorized == true) )
$util.unauthorized()
#end
## [End] Throw if unauthorized **
Commenting out $util.unauthorized()
causes the query to succeed.
Expected behavior
Query succeeds.
Additional context
@patspam, https://github.com/aws-amplify/amplify-cli/pull/2607 enabled this scenario, but it seems to lack the support for multiple authorization types, we'll take a look, thanks for reporting!
I may be mistaken, but could you add to your API's CustomResources.json
like so:
"Parameters": {
"authRoleName": {
"Type": "String"
},
"unauthRoleName": {
"Type": "String"
},
....
},
....
"Resources": {
"AuthRolePolicy": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "appsync-authrole-policy-custom",
"Roles": [
{
"Ref": "authRoleName"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["appsync:GraphQL"],
"Resource": [
{
"Fn::Sub": [
"arn:aws:appsync:${AWS::Region}:${AWS::AccountId}:apis/${apiId}/types/${typeName}/fields/${fieldName}",
{
"apiId": {
"Ref": "AppSyncApiId"
},
"typeName": "Query",
"fieldName": "getStripeClientSecret"
}
]
},
...
and
"Resources": {
"UnauthRolePolicy": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "appsync-unauthrole-policy-custom",
"Roles": [
{
"Ref": "unauthRoleName"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["appsync:GraphQL"],
"Resource": [
{
"Fn::Sub": [
"arn:aws:appsync:${AWS::Region}:${AWS::AccountId}:apis/${apiId}/types/${typeName}/fields/${fieldName}",
{
"apiId": {
"Ref": "AppSyncApiId"
},
"typeName": "Query",
"fieldName": "getStripeClientSecret"
}
]
},
...
I鈥檝e hit more or less the exact same scenario and I鈥檓 also hoping to see improvements to this soon. I did try adding the configuration in CustomResources.json
but I did not add it for both unAuthRole and authRole as it was not described in that issue comment, so it didn鈥檛 work.
I have the same problem, any news about this?
+1
same for private IAM and API Key.
any news?
Most helpful comment
I have the same problem, any news about this?