SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
© 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.

Más contenido relacionado

La actualidad más candente

MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
Amazon Web Services Korea
 
A Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security KnowledgeA Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security Knowledge
Vaticle
 

La actualidad más candente (20)

Graph Database Meetup in Seoul #1. What is Graph Database? (그래프 데이터베이스 소개)
Graph Database Meetup in Seoul #1. What is Graph Database? (그래프 데이터베이스 소개)Graph Database Meetup in Seoul #1. What is Graph Database? (그래프 데이터베이스 소개)
Graph Database Meetup in Seoul #1. What is Graph Database? (그래프 데이터베이스 소개)
 
Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28
 
MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
MSA를 넘어 Function의 로의 진화::주경호 수석::AWS Summit Seoul 2018
 
Building the Data Lake with Azure Data Factory and Data Lake Analytics
Building the Data Lake with Azure Data Factory and Data Lake AnalyticsBuilding the Data Lake with Azure Data Factory and Data Lake Analytics
Building the Data Lake with Azure Data Factory and Data Lake Analytics
 
Enterprise guide to building a Data Mesh
Enterprise guide to building a Data MeshEnterprise guide to building a Data Mesh
Enterprise guide to building a Data Mesh
 
Leveraging Generative AI to Accelerate Graph Innovation for National Security...
Leveraging Generative AI to Accelerate Graph Innovation for National Security...Leveraging Generative AI to Accelerate Graph Innovation for National Security...
Leveraging Generative AI to Accelerate Graph Innovation for National Security...
 
Graph and Amazon Neptune
Graph and Amazon NeptuneGraph and Amazon Neptune
Graph and Amazon Neptune
 
Tiger graph 2021 corporate overview [read only]
Tiger graph 2021 corporate overview [read only]Tiger graph 2021 corporate overview [read only]
Tiger graph 2021 corporate overview [read only]
 
Splunk 소개서 2015_06
Splunk 소개서 2015_06Splunk 소개서 2015_06
Splunk 소개서 2015_06
 
[DevGround] 린하게 구축하는 스타트업 데이터파이프라인
[DevGround] 린하게 구축하는 스타트업 데이터파이프라인[DevGround] 린하게 구축하는 스타트업 데이터파이프라인
[DevGround] 린하게 구축하는 스타트업 데이터파이프라인
 
Introduction to Google Cloud Platform for Big Data - Trusted Conf
Introduction to Google Cloud Platform for Big Data - Trusted ConfIntroduction to Google Cloud Platform for Big Data - Trusted Conf
Introduction to Google Cloud Platform for Big Data - Trusted Conf
 
Graph Database Meetup in Korea #6. Graph Database 5 Offerings_ AssetManager (...
Graph Database Meetup in Korea #6. Graph Database 5 Offerings_ AssetManager (...Graph Database Meetup in Korea #6. Graph Database 5 Offerings_ AssetManager (...
Graph Database Meetup in Korea #6. Graph Database 5 Offerings_ AssetManager (...
 
Workshop - Build a Graph Solution
Workshop - Build a Graph SolutionWorkshop - Build a Graph Solution
Workshop - Build a Graph Solution
 
Apigee Demo: API Platform Overview
Apigee Demo: API Platform OverviewApigee Demo: API Platform Overview
Apigee Demo: API Platform Overview
 
Work Backwards to Your Graph Data Model & Queries with Amazon Neptune (DAT330...
Work Backwards to Your Graph Data Model & Queries with Amazon Neptune (DAT330...Work Backwards to Your Graph Data Model & Queries with Amazon Neptune (DAT330...
Work Backwards to Your Graph Data Model & Queries with Amazon Neptune (DAT330...
 
领域驱动设计精要 (Domain Driven Design Inside and Outside)
领域驱动设计精要 (Domain Driven Design Inside and Outside)领域驱动设计精要 (Domain Driven Design Inside and Outside)
领域驱动设计精要 (Domain Driven Design Inside and Outside)
 
Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기
 
A Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security KnowledgeA Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security Knowledge
 
ABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWSABD201-Big Data Architectural Patterns and Best Practices on AWS
ABD201-Big Data Architectural Patterns and Best Practices on AWS
 
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
 

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

Similar a 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
 

Más de 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
 

Más de 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.