question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@aws_auth directive does not grant full access to query with multiple data sources

See original GitHub issue

Describe the bug When adding the @aws_auth directive to a specific Query, the user group does not get full access to all the attributes in the query

To Reproduce

  1. Create the following schema:
type Node {
     node_id: String!
     node_name: String
     location_id: String
     location_name: String
}

type Location {
    location_id: String
    location_name: String
}

type Query {
   getNode(node_id: String!): Node
}

The node_id, node_name and location_id fields are native fields within a DynamoDB table called Nodes, while the location_id and location_name fields are native to another DynamoDB table called Locations.

  1. Add a custom resolver the for the location_name field, since we want to fetch back the location_name along with a query for nodes.
Data Source: Locations 

Request Mapping Template
{
    "version" : "2017-02-28",
    "operation" : "Scan",
    "filter" : {
        "expression" : "location_id= :location_id",
        "expressionValues" : {
            ":location_id" : { "S" : "${ctx.source.location_id}" }
        }
        }
}

Response Mapping Template
$util.toJson($ctx.result.items[0].location_name)
  1. Select Authorization type as Amazon Cognito User Pool.

  2. Under User Pool configuration, select default action: DENY.

  3. Add the @aws_auth directive to the query

type Query {
   getNode(node_id: String!): Node
   @aws_auth(cognito_groups: ["Users"])
}
  1. Query getNode via the Queries console.

Expected behavior We get back the full record for the node. Instead, we get back the data for the node_id, node_name and location_id fields, but cannot resolve the location_name:

{
  "data": {
    "getNode": {
      "node_id": "111",
      "location_name": "ABC"
      "node_name": "Apple"
    }
  },
  "errors": [
    {
      "path": [
        "getNode",
        "location_name"
      ],
      "data": null,
      "errorType": "Unauthorized",
      "errorInfo": null,
      "locations": [
        {
          "line": 4,
          "column": 5,
          "sourceName": null
        }
      ],
      "message": "Not Authorized to access location_name on type Node"
    }
  ]
}

Additional context Any explanation on how exactly the @aws_auth directives work would be helpful. There seems to be limited documentation on this. Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mikeparisstuffcommented, Mar 8, 2019

When specifying the default action of DENY then you must explicitly allow access on the field. You may also set this value to ALLOW and I believe the full object should come back as expected.

1reaction
cy6581commented, Apr 30, 2019

Thank you @mikeparisstuff. Useful to know that we must explicitly allow access on custom-resolver fields, if we are using the DENY action.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authorization and authentication - AWS AppSync
This section describes options for configuring security and data protection for your applications. Authorization types. There are five ways you can ...
Read more >
API (GraphQL) - Setup authorization rules - AWS Amplify Docs
When using the @auth directive on a field definition, a resolver will be added to the field that authorize access based on attributes...
Read more >
Content-Security-Policy - HTTP - MDN Web Docs
The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed to load for a ...
Read more >
GRANT Statement | ClickHouse Docs
Grants privileges to ClickHouse user accounts or roles. ... Processing this query, ClickHouse does not return any data, even x and y ....
Read more >
Query access control | Databricks on AWS
There are four permission levels for a query: No Permissions, Can Run, Can Edit, and Can Manage. ... Change SQL warehouse or data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found