SlideShare a Scribd company logo
1 of 40
Download to read offline
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Authentication & Authorization in
GraphQL with AWS AppSync
Karthik Saligrama
Software Development Engineer
AWS Mobile
M O B 4 0 2
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What to expect from this session
Learn how to implement identity management for GraphQL apps using
• AWS AppSync
• Amazon Cognito User Pools
• Amazon Cognito Federated Identities
• AWS Identity and Access Management (AWS IAM)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
You need
Some knowledge of
• AWS IAM policies
• Amazon Cognito User Pools
• GraphQL & AWS AppSync
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What is identity management?
“Enables the right individuals to access the right
resources at the right times and for the right
reasons”
— Wikipedia
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Data access patterns
• Public data access
• Private data access
• Custom data access
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Public data access
• Data is not user specific
• No restriction is imposed on the data
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Private data access
• Data can be private to a specific user
• Access to data is privileged/restricted
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Custom data access
• Data can be private/public
• Access to data can be privileged/restricted
• Access to data can be further guarded by application logic
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Identity Management
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync: Four types of authorization
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
API key
Role
AWS Cloud
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon Cognito User Pools
Role
AWS Cloud
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
OpenID
OpenID Connect authorizer
Role
AWS Cloud
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Identity
System
AWS IAM authorization
Role
AWS Cloud
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Types of authorization
• Implicit authorization
• Coarse grained authorization
• Fine grained authorization
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coarse grained authorization
type Query {
allUsers: [User]!
me: User!
}
type User {
id: ID!
firstName: String!
lastName: String!
bffs: [User!]!
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coarse grained authorization—Amazon Cognito User Pools
type Query {
allUsers: [User]!
@aws_auth(cognito-groups:["Admin"])
me: User!
}
type User {
id: ID!
firstName: String!
lastName: String!
bffs: [User!]!
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coarse grained authorization—AWS IAM authorization
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "appsync:GraphQL",
"Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/*"
}]
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coarse grained authorization—AWS IAM authorization
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "appsync:GraphQL",
"Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/*"
},{
"Effect": "Deny",
"Action": "appsync:GraphQL",
"Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/allUsers"
}]
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coarse grained authorization—Using mapping templates
#if(!$context.request.headers.get(‘x-api-key’) == “<some api key>”)
//do some task
#else
$utils.unauthorized()
#end
#if(!$context.identity.username == “<username>”)
//do some task
#else
$utils.unauthorized()
#end
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
• Using data access control of underlying data sources
• Using intelligent schema design patterns
• Pipeline resolvers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
{
"version" : "2017-02-28",
"operation" : "Query",
"index" : ”role-index",
"query" : {
"expression": ”contains(role, :role)",
"expressionValues" : {
":role" : {
"S":"ADMIN"
}
}
},
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.after, null)),
}
Using data access control of underlying data sources
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
{
"version":"2017-02-28",
"operation":"GET",
"path":"/id/post/_search",
"params":{
"headers":{},
"queryString":{},
"body":{
"from":0,
"size":50,
"query":{
"term" :{
”role":”ADMIN"
}
}
}
}
}
Using data access control of underlying data sources
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
{
"version": "2018-05-29",
"statements": [
"SELECT * FROM Users u WHERE u.id = :ID AND EXISTS (SELECT
id FROM UserRole r WHERE r.id = :RID AND r.role = 'ADMIN')"
],
"variableMap": {
":ID": "$ctx.args.id",
":RID" : "$ctx.identity.sub"
}
}
Fine grained data access control
Using data access control of underlying data sources
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Id firstName
1 Nadia
2 Shaggy
3 Pancho
UserId Role
1 ADMIN
2 USER
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
type Query {
adminGetUserDetails(id: ID!): User!
me: User!
}
type User {
id: ID!
firstName: String!
lastName: String!
bffs: [User!]!
}
type Query {
adminGetUserDetails(id: ID!): UserData!
me: User!
}
type User {
id: ID!
firstName: String!
lastName: String!
bffs: [UserData!]!
}
type UserData {
id : ID!
user: User!
}
Using intelligent schema design patterns
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Using intelligent schema design patterns
Id firstName
1 Nadia
2 Shaggy
3 Pancho
UserId Role
1 ADMIN
2 USER
query {
adminGetUserDetails (id: “1”) {
user {
firstName
lastName
}
}
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Pipeline resolvers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
• Reusable/composable auth across all resolvers
• No schema restructuring needed
• No leaky abstraction
Pipeline resolvers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Pipeline resolvers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Pipeline resolvers
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Fine grained data access control
Pipeline resolvers
query {
adminGetUserDetails(id: "1") {
id
firstName
}
}
UserId Role
1 ADMIN
2 USER
Id firstName
1 Nadia
2 Shaggy
3 Pancho
{
"data":{
"adminGetUserDetails":{
"id":"1",
"firstName":"Nadia"
}
}
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Useful tips
1. Keep authorization logic simple
2. Keep your functions lean
3. Functions are reusable, take advantage of them
4. Be mindful of limits
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Resources
• https://hackernoon.com/tackling-user-authorization-in-graphql-with-
aws-appsync-7886aef60b4a
• https://medium.com/open-graphql/authenticating-an-aws-appsync-
graphql-api-with-auth0-48835691810a
• https://hackernoon.com/graphql-authorization-with-multiple-data-
sources-using-aws-appsync-dfae2e350bf2
Thank you!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Karthik Saligrama
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

More Related Content

What's hot

Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
ShingalaKrupa
 

What's hot (20)

Java beans
Java beansJava beans
Java beans
 
Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScript
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Visual basic concepts
Visual basic conceptsVisual basic concepts
Visual basic concepts
 
React Native Workshop
React Native WorkshopReact Native Workshop
React Native Workshop
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with Testcontainers
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Welcome to the Jungle: Pentesting AWS
Welcome to the Jungle: Pentesting AWSWelcome to the Jungle: Pentesting AWS
Welcome to the Jungle: Pentesting AWS
 
React js
React jsReact js
React js
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
 

Similar to Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:Invent 2018

Similar to Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:Invent 2018 (20)

Identity Round Robin Workshop - Serverless Round: Security Week at the SF Loft
Identity Round Robin Workshop - Serverless Round: Security Week at the SF LoftIdentity Round Robin Workshop - Serverless Round: Security Week at the SF Loft
Identity Round Robin Workshop - Serverless Round: Security Week at the SF Loft
 
Building Real-time Serverless Backends
Building Real-time Serverless BackendsBuilding Real-time Serverless Backends
Building Real-time Serverless Backends
 
Building Real-time Serverless Backends with GraphQL
Building Real-time Serverless Backends with GraphQLBuilding Real-time Serverless Backends with GraphQL
Building Real-time Serverless Backends with GraphQL
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
AWS Security Week: Cloud-Scale Authentication & Advanced Authorization with A...
AWS Security Week: Cloud-Scale Authentication & Advanced Authorization with A...AWS Security Week: Cloud-Scale Authentication & Advanced Authorization with A...
AWS Security Week: Cloud-Scale Authentication & Advanced Authorization with A...
 
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
IAM for Enterprises: How Vanguard Matured IAM Controls to Support Micro Accou...
 
Build a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSyncBuild a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSync
 
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
Serverless Architectural Patterns and Best Practices (ARC305-R2) - AWS re:Inv...
 
Module 3 - AWSome Day Online Conference 2018
Module 3 - AWSome Day Online Conference 2018Module 3 - AWSome Day Online Conference 2018
Module 3 - AWSome Day Online Conference 2018
 
Security & Compliance for Modern Serverless Applications (SRV319-R1) - AWS re...
Security & Compliance for Modern Serverless Applications (SRV319-R1) - AWS re...Security & Compliance for Modern Serverless Applications (SRV319-R1) - AWS re...
Security & Compliance for Modern Serverless Applications (SRV319-R1) - AWS re...
 
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
 
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
 
善用 GraphQL 與 AWS AppSync 讓您的 Progressive Web App (PWA) 加速進化 (Level 200)
善用  GraphQL 與 AWS AppSync 讓您的  Progressive Web App (PWA) 加速進化 (Level 200)善用  GraphQL 與 AWS AppSync 讓您的  Progressive Web App (PWA) 加速進化 (Level 200)
善用 GraphQL 與 AWS AppSync 讓您的 Progressive Web App (PWA) 加速進化 (Level 200)
 
Foundations: Understanding the Critical Building Blocks of AWS Identity and G...
Foundations: Understanding the Critical Building Blocks of AWS Identity and G...Foundations: Understanding the Critical Building Blocks of AWS Identity and G...
Foundations: Understanding the Critical Building Blocks of AWS Identity and G...
 
Deconstructing SaaS: A Deep Dive into Building Multi-tenant Solutions on AWS ...
Deconstructing SaaS: A Deep Dive into Building Multi-tenant Solutions on AWS ...Deconstructing SaaS: A Deep Dive into Building Multi-tenant Solutions on AWS ...
Deconstructing SaaS: A Deep Dive into Building Multi-tenant Solutions on AWS ...
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Supercharging Applications with GraphQL and AWS AppSync
Supercharging Applications with GraphQL and AWS AppSyncSupercharging Applications with GraphQL and AWS AppSync
Supercharging Applications with GraphQL and AWS AppSync
 
Build Enterprise-Grade Serverless Apps
Build Enterprise-Grade Serverless Apps Build Enterprise-Grade Serverless Apps
Build Enterprise-Grade Serverless Apps
 
Build Your Own Log Analytics Solutions on AWS (ANT323-R) - AWS re:Invent 2018
Build Your Own Log Analytics Solutions on AWS (ANT323-R) - AWS re:Invent 2018Build Your Own Log Analytics Solutions on AWS (ANT323-R) - AWS re:Invent 2018
Build Your Own Log Analytics Solutions on AWS (ANT323-R) - AWS re:Invent 2018
 
Mastering Identity at Every Layer of the Cake (SEC401-R1) - AWS re:Invent 2018
Mastering Identity at Every Layer of the Cake (SEC401-R1) - AWS re:Invent 2018Mastering Identity at Every Layer of the Cake (SEC401-R1) - AWS re:Invent 2018
Mastering Identity at Every Layer of the Cake (SEC401-R1) - AWS re:Invent 2018
 

More from Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:Invent 2018

  • 1.
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Authentication & Authorization in GraphQL with AWS AppSync Karthik Saligrama Software Development Engineer AWS Mobile M O B 4 0 2
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What to expect from this session Learn how to implement identity management for GraphQL apps using • AWS AppSync • Amazon Cognito User Pools • Amazon Cognito Federated Identities • AWS Identity and Access Management (AWS IAM)
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. You need Some knowledge of • AWS IAM policies • Amazon Cognito User Pools • GraphQL & AWS AppSync
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is identity management? “Enables the right individuals to access the right resources at the right times and for the right reasons” — Wikipedia
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Data access patterns • Public data access • Private data access • Custom data access
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Public data access • Data is not user specific • No restriction is imposed on the data
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Private data access • Data can be private to a specific user • Access to data is privileged/restricted
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Custom data access • Data can be private/public • Access to data can be privileged/restricted • Access to data can be further guarded by application logic
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Identity Management
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync: Four types of authorization
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. API key Role AWS Cloud
  • 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Cognito User Pools Role AWS Cloud
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. OpenID OpenID Connect authorizer Role AWS Cloud
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Identity System AWS IAM authorization Role AWS Cloud
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Types of authorization • Implicit authorization • Coarse grained authorization • Fine grained authorization
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coarse grained authorization type Query { allUsers: [User]! me: User! } type User { id: ID! firstName: String! lastName: String! bffs: [User!]! }
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coarse grained authorization—Amazon Cognito User Pools type Query { allUsers: [User]! @aws_auth(cognito-groups:["Admin"]) me: User! } type User { id: ID! firstName: String! lastName: String! bffs: [User!]! }
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coarse grained authorization—AWS IAM authorization { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "appsync:GraphQL", "Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/*" }] }
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coarse grained authorization—AWS IAM authorization { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "appsync:GraphQL", "Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/*" },{ "Effect": "Deny", "Action": "appsync:GraphQL", "Resource": "arn:aws:appsync:*:*:apis/*/types/Query/fields/allUsers" }] }
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coarse grained authorization—Using mapping templates #if(!$context.request.headers.get(‘x-api-key’) == “<some api key>”) //do some task #else $utils.unauthorized() #end #if(!$context.identity.username == “<username>”) //do some task #else $utils.unauthorized() #end
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control • Using data access control of underlying data sources • Using intelligent schema design patterns • Pipeline resolvers
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control { "version" : "2017-02-28", "operation" : "Query", "index" : ”role-index", "query" : { "expression": ”contains(role, :role)", "expressionValues" : { ":role" : { "S":"ADMIN" } } }, "nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.after, null)), } Using data access control of underlying data sources
  • 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control { "version":"2017-02-28", "operation":"GET", "path":"/id/post/_search", "params":{ "headers":{}, "queryString":{}, "body":{ "from":0, "size":50, "query":{ "term" :{ ”role":”ADMIN" } } } } } Using data access control of underlying data sources
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. { "version": "2018-05-29", "statements": [ "SELECT * FROM Users u WHERE u.id = :ID AND EXISTS (SELECT id FROM UserRole r WHERE r.id = :RID AND r.role = 'ADMIN')" ], "variableMap": { ":ID": "$ctx.args.id", ":RID" : "$ctx.identity.sub" } } Fine grained data access control Using data access control of underlying data sources
  • 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Id firstName 1 Nadia 2 Shaggy 3 Pancho UserId Role 1 ADMIN 2 USER
  • 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control type Query { adminGetUserDetails(id: ID!): User! me: User! } type User { id: ID! firstName: String! lastName: String! bffs: [User!]! } type Query { adminGetUserDetails(id: ID!): UserData! me: User! } type User { id: ID! firstName: String! lastName: String! bffs: [UserData!]! } type UserData { id : ID! user: User! } Using intelligent schema design patterns
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Using intelligent schema design patterns Id firstName 1 Nadia 2 Shaggy 3 Pancho UserId Role 1 ADMIN 2 USER query { adminGetUserDetails (id: “1”) { user { firstName lastName } } }
  • 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Pipeline resolvers
  • 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control • Reusable/composable auth across all resolvers • No schema restructuring needed • No leaky abstraction Pipeline resolvers
  • 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Pipeline resolvers
  • 34. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Pipeline resolvers
  • 35. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fine grained data access control Pipeline resolvers query { adminGetUserDetails(id: "1") { id firstName } } UserId Role 1 ADMIN 2 USER Id firstName 1 Nadia 2 Shaggy 3 Pancho { "data":{ "adminGetUserDetails":{ "id":"1", "firstName":"Nadia" } } }
  • 36. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 37. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Useful tips 1. Keep authorization logic simple 2. Keep your functions lean 3. Functions are reusable, take advantage of them 4. Be mindful of limits
  • 38. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Resources • https://hackernoon.com/tackling-user-authorization-in-graphql-with- aws-appsync-7886aef60b4a • https://medium.com/open-graphql/authenticating-an-aws-appsync- graphql-api-with-auth0-48835691810a • https://hackernoon.com/graphql-authorization-with-multiple-data- sources-using-aws-appsync-dfae2e350bf2
  • 39. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Karthik Saligrama
  • 40. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.