SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Connecting the Dots
Kong for GraphQL Endpoints
Julien Bataillé
Software Engineer / Rakuten, Inc.
Rakuten, Inc.
How to manage GraphQL
APIs with Kong?
Agenda
• Quick introduction to GraphQL
• Differences between REST and GraphQL
• API Management for GraphQL
• Kong Plugins (demo)
• Developed by Facebook in 2012 / publicly released in 2015 / GraphQL Foundation in 2018
• Server and Client implementations are available for major languages (JS, Java, Python, C#...)
• Supports reading (query), writing (mutation) and subscribing to data changes (subscriptions)
• Solves the Over-Fetching and Under-Fetching problems
(Credits: https://graphql.org/)
A familiar use case: Kong Admin
Data Fetching with REST
HTTP GET /services
{
"next": null,
"data": [
{
"host": "10.0.2.2",
"created_at": 1560781137,
"connect_timeout": 60000,
"id": "3692da97-e066-46e6-9739-3da47cfe4abd",
"protocol": "http",
"name": "starwars-server",
"read_timeout": 60000,
"port": 8080,
"path": "/graphql",
"updated_at": 1561016983,
"retries": 5,
"write_timeout": 60000,
"tags": null
},
{
"host": "mockbin.org",
"created_at": 1560797940,
"connect_timeout": 60000,
"id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87",
"protocol": "http",
"name": "mockbin",
"read_timeout": 60000,
"port": 80,
"path": "/request",
"updated_at": 1561017861,
"retries": 5,
"write_timeout": 60000,
"tags": null
}
]
}
HTTP GET /services/{service-id}/plugins x2
{
"next": null,
"data": [
{
"created_at": 1560860735,
"config": {
"block_introspection_queries": false
},
"id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf",
"service": {
"id": "3692da97-e066-46e6-9739-3da47cfe4abd"
},
"name": "graphql-operation-whitelist",
"protocols": [
"http",
"https"
],
"enabled": true,
"run_on": "first",
"consumer": null,
"route": null,
"tags": null
}
]
}
Data Fetching with REST vs GraphQL
query {
services {
name
host
created_at
plugins {
name
}
}
}
HTTP POST /kong-graphql-admin
HTTP GET /services
{
"next": null,
"data": [
{
"host": "10.0.2.2",
"created_at": 1560781137,
"connect_timeout": 60000,
"id": "3692da97-e066-46e6-9739-3da47cfe4abd",
"protocol": "http",
"name": "starwars-server",
"read_timeout": 60000,
"port": 8080,
"path": "/graphql",
"updated_at": 1561016983,
"retries": 5,
"write_timeout": 60000,
"tags": null
},
{
"host": "mockbin.org",
"created_at": 1560797940,
"connect_timeout": 60000,
"id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87",
"protocol": "http",
"name": "mockbin",
"read_timeout": 60000,
"port": 80,
"path": "/request",
"updated_at": 1561017861,
"retries": 5,
"write_timeout": 60000,
"tags": null
}
]
}
HTTP GET /services/{service-id}/plugins x2
{
"next": null,
"data": [
{
"created_at": 1560860735,
"config": {
"block_introspection_queries": false
},
"id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf",
"service": {
"id": "3692da97-e066-46e6-9739-3da47cfe4abd"
},
"name": "graphql-operation-whitelist",
"protocols": [
"http",
"https"
],
"enabled": true,
"run_on": "first",
"consumer": null,
"route": null,
"tags": null
}
]
}
Data Fetching with REST vs GraphQL
query {
services {
name
host
created_at
plugins {
name
}
}
}
HTTP POST /kong-graphql-admin
{
"data": {
"services": [
{
"name": "starwars-server",
"host": "10.0.2.2",
"plugins": [
{
"name": "graphql-operation-whitelist"
}
],
"created_at": 1560781137
},
{
"name": "mockbin",
"host": "mockbin.org",
"plugins": [
{
"name": "basic-auth"
}
],
"created_at": 1560797940
}
]
HTTP GET /services
{
"next": null,
"data": [
{
"host": "10.0.2.2",
"created_at": 1560781137,
"connect_timeout": 60000,
"id": "3692da97-e066-46e6-9739-3da47cfe4abd",
"protocol": "http",
"name": "starwars-server",
"read_timeout": 60000,
"port": 8080,
"path": "/graphql",
"updated_at": 1561016983,
"retries": 5,
"write_timeout": 60000,
"tags": null
},
{
"host": "mockbin.org",
"created_at": 1560797940,
"connect_timeout": 60000,
"id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87",
"protocol": "http",
"name": "mockbin",
"read_timeout": 60000,
"port": 80,
"path": "/request",
"updated_at": 1561017861,
"retries": 5,
"write_timeout": 60000,
"tags": null
}
]
}
HTTP GET /services/{service-id}/plugins x2
{
"next": null,
"data": [
{
"created_at": 1560860735,
"config": {
"block_introspection_queries": false
},
"id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf",
"service": {
"id": "3692da97-e066-46e6-9739-3da47cfe4abd"
},
"name": "graphql-operation-whitelist",
"protocols": [
"http",
"https"
],
"enabled": true,
"run_on": "first",
"consumer": null,
"route": null,
"tags": null
}
]
}
API Management with REST vs GraphQL
• API has many endpoints
• Resource selection is defined in route
• HTTP verbs define the operation
(GET, POST, DELETE...)
REST
• API has a single endpoint
• Resource selection is defined in body
• HTTP POST for every operations
(query or mutation defined in request body)
GraphQL
To manage GraphQL Endpoints, we have to look into the query
and extract some characteristics to implement policies.
Query characteristics examples
Nesting
Measure the nesting level of a query.
Query Cost Analysis
Count the amount of resources requested by a query.
Query whitelisting
Verify the query belongs to a group of authorized queries.
Query characteristics examples
Nesting
Measure the nesting level of a query.
Query Cost Analysis
Count the amount of resources requested by a query.
Query whitelisting
Verify the query belongs to a group of authorized queries.
50 = 50 repositories
+
50 x 10 = 500 repository issues
= 550 total nodes
Query characteristics examples
Nesting
Measure the nesting level of a query.
Query Cost Analysis
Count the amount of resources requested by a query.
Query whitelisting
Verify the query belongs to a group of authorized queries.
Existing solutions are language-specific libraries
API - 1
(JS)
Nesting Limit
Node Count Limit
Query Whitelisting
API - 2
(Java)
Nesting Limit
Node Count Limit
API - 3
(Python)
API - 1
(JS)
API - 2
(Java)
API - 3
(Python)
Kong
Plugins: Nesting Limit, Node Count Limit,
Query Whitelisting...
 Non-intrusive: no code or configuration change on your
GraphQL server.
 Language-agnostic: same features and performance
for all GraphQL implementations .
Two proof-of-concept Kong plugins developed at Rakuten
1. Depth Limit
Limit the complexity of GraphQL queries based on their depth.
https://github.com/rakutentech/kong-plugin-graphql-depth-limit
2. Operation Whitelist
Whitelist operations that your consumers can send to your GraphQL server.
https://github.com/rakutentech/kong-plugin-graphql-operation-whitelist
Operation Whitelist Plugin
Requirements
 Queries and Mutations blocked if not whitelisted
 Equivalent operations represented as a single entry
PDK Features Usage
 Storing/Caching Custom Entities
 Admin API Extension to manage the Whitelist
Client UpstreamKong
Query
Parsing
Signature
Generation
Signature
Hashing
Whitelist
Check
DEMO
Credits and references
• Securing Your GraphQL API from Malicious Queries (Apollo)
https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b
• GraphQL API Management (IBM)
https://www.ibm.com/blogs/research/2019/02/graphql-api-management/
• GraphQL Lua (@bjornbytes)
https://github.com/bjornbytes/graphql-lua
Thank you
Conclusion and Next Steps
• Kong extensibility is a key factor, look into plugin and Admin API
• GraphQL is still relatively new, but it’s popular and we need to address the security aspect
• Load and Performance testing
• Hardening the code
• Merging all the plugins in a single one
• Implement a Query Cost Analysis Plugin
Connecting the Dots: Kong for GraphQL Endpoints

Weitere ähnliche Inhalte

Was ist angesagt?

EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...AWSKRUG - AWS한국사용자모임
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다KWON JUNHYEOK
 
Build Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBBuild Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBScyllaDB
 
Microservices
MicroservicesMicroservices
MicroservicesSmartBear
 
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on Kubernetes
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on KubernetesDoK Talks #91- Leveraging Druid Operator to manage Apache Druid on Kubernetes
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on KubernetesDoKC
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advanceDaeMyung Kang
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetesrajdeep
 

Was ist angesagt? (20)

InnoDB Locking Explained with Stick Figures
InnoDB Locking Explained with Stick FiguresInnoDB Locking Explained with Stick Figures
InnoDB Locking Explained with Stick Figures
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다
[Devil's camp 2019] 혹시 Elixir 아십니까? 정.말.갓.언.어.입.니.다
 
Docker compose
Docker composeDocker compose
Docker compose
 
Benefits of DevSecOps
Benefits of DevSecOpsBenefits of DevSecOps
Benefits of DevSecOps
 
Build Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBBuild Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDB
 
Microservices
MicroservicesMicroservices
Microservices
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on Kubernetes
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on KubernetesDoK Talks #91- Leveraging Druid Operator to manage Apache Druid on Kubernetes
DoK Talks #91- Leveraging Druid Operator to manage Apache Druid on Kubernetes
 
DevOps and Tools
DevOps and ToolsDevOps and Tools
DevOps and Tools
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advance
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Micro Front Ends : Divided We Rule by Parth Ghiya - AhmedabadJS
Micro Front Ends : Divided We Rule by Parth Ghiya - AhmedabadJSMicro Front Ends : Divided We Rule by Parth Ghiya - AhmedabadJS
Micro Front Ends : Divided We Rule by Parth Ghiya - AhmedabadJS
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 

Ähnlich wie Connecting the Dots: Kong for GraphQL Endpoints

Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCTim Burks
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherSashko Stubailo
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays
 
20170624 GraphQL Presentation
20170624 GraphQL Presentation20170624 GraphQL Presentation
20170624 GraphQL PresentationMartin Heidegger
 
LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions LF_APIStrat
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack APIKrunal Jain
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...François-Guillaume Ribreau
 
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchNikolas Burk
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009marpierc
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWTArnaud Tournier
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primerBruce McPherson
 
Hannes end-of-the-router-tnc17
Hannes end-of-the-router-tnc17Hannes end-of-the-router-tnc17
Hannes end-of-the-router-tnc17Hannes Gredler
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Startedguest1af57e
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overviewmarpierc
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)Rob Crowley
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceLuca Mattia Ferrari
 
Saving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureSaving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureAtlassian
 

Ähnlich wie Connecting the Dots: Kong for GraphQL Endpoints (20)

Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPC
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
 
20170624 GraphQL Presentation
20170624 GraphQL Presentation20170624 GraphQL Presentation
20170624 GraphQL Presentation
 
LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions LF_APIStrat17_REST API Microversions
LF_APIStrat17_REST API Microversions
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack API
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
 
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from Scratch
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWT
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
Hannes end-of-the-router-tnc17
Hannes end-of-the-router-tnc17Hannes end-of-the-router-tnc17
Hannes end-of-the-router-tnc17
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 
Saving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On InfrastructureSaving Money by Optimizing Your Cloud Add-On Infrastructure
Saving Money by Optimizing Your Cloud Add-On Infrastructure
 
Gohan
GohanGohan
Gohan
 

Kürzlich hochgeladen

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

Kürzlich hochgeladen (20)

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

Connecting the Dots: Kong for GraphQL Endpoints

  • 1. Connecting the Dots Kong for GraphQL Endpoints Julien Bataillé Software Engineer / Rakuten, Inc.
  • 3. How to manage GraphQL APIs with Kong?
  • 4. Agenda • Quick introduction to GraphQL • Differences between REST and GraphQL • API Management for GraphQL • Kong Plugins (demo)
  • 5. • Developed by Facebook in 2012 / publicly released in 2015 / GraphQL Foundation in 2018 • Server and Client implementations are available for major languages (JS, Java, Python, C#...) • Supports reading (query), writing (mutation) and subscribing to data changes (subscriptions) • Solves the Over-Fetching and Under-Fetching problems (Credits: https://graphql.org/)
  • 6. A familiar use case: Kong Admin
  • 7. Data Fetching with REST HTTP GET /services { "next": null, "data": [ { "host": "10.0.2.2", "created_at": 1560781137, "connect_timeout": 60000, "id": "3692da97-e066-46e6-9739-3da47cfe4abd", "protocol": "http", "name": "starwars-server", "read_timeout": 60000, "port": 8080, "path": "/graphql", "updated_at": 1561016983, "retries": 5, "write_timeout": 60000, "tags": null }, { "host": "mockbin.org", "created_at": 1560797940, "connect_timeout": 60000, "id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87", "protocol": "http", "name": "mockbin", "read_timeout": 60000, "port": 80, "path": "/request", "updated_at": 1561017861, "retries": 5, "write_timeout": 60000, "tags": null } ] } HTTP GET /services/{service-id}/plugins x2 { "next": null, "data": [ { "created_at": 1560860735, "config": { "block_introspection_queries": false }, "id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf", "service": { "id": "3692da97-e066-46e6-9739-3da47cfe4abd" }, "name": "graphql-operation-whitelist", "protocols": [ "http", "https" ], "enabled": true, "run_on": "first", "consumer": null, "route": null, "tags": null } ] }
  • 8. Data Fetching with REST vs GraphQL query { services { name host created_at plugins { name } } } HTTP POST /kong-graphql-admin HTTP GET /services { "next": null, "data": [ { "host": "10.0.2.2", "created_at": 1560781137, "connect_timeout": 60000, "id": "3692da97-e066-46e6-9739-3da47cfe4abd", "protocol": "http", "name": "starwars-server", "read_timeout": 60000, "port": 8080, "path": "/graphql", "updated_at": 1561016983, "retries": 5, "write_timeout": 60000, "tags": null }, { "host": "mockbin.org", "created_at": 1560797940, "connect_timeout": 60000, "id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87", "protocol": "http", "name": "mockbin", "read_timeout": 60000, "port": 80, "path": "/request", "updated_at": 1561017861, "retries": 5, "write_timeout": 60000, "tags": null } ] } HTTP GET /services/{service-id}/plugins x2 { "next": null, "data": [ { "created_at": 1560860735, "config": { "block_introspection_queries": false }, "id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf", "service": { "id": "3692da97-e066-46e6-9739-3da47cfe4abd" }, "name": "graphql-operation-whitelist", "protocols": [ "http", "https" ], "enabled": true, "run_on": "first", "consumer": null, "route": null, "tags": null } ] }
  • 9. Data Fetching with REST vs GraphQL query { services { name host created_at plugins { name } } } HTTP POST /kong-graphql-admin { "data": { "services": [ { "name": "starwars-server", "host": "10.0.2.2", "plugins": [ { "name": "graphql-operation-whitelist" } ], "created_at": 1560781137 }, { "name": "mockbin", "host": "mockbin.org", "plugins": [ { "name": "basic-auth" } ], "created_at": 1560797940 } ] HTTP GET /services { "next": null, "data": [ { "host": "10.0.2.2", "created_at": 1560781137, "connect_timeout": 60000, "id": "3692da97-e066-46e6-9739-3da47cfe4abd", "protocol": "http", "name": "starwars-server", "read_timeout": 60000, "port": 8080, "path": "/graphql", "updated_at": 1561016983, "retries": 5, "write_timeout": 60000, "tags": null }, { "host": "mockbin.org", "created_at": 1560797940, "connect_timeout": 60000, "id": "81c4c6b5-746a-4421-ad0d-cddc0aa3ed87", "protocol": "http", "name": "mockbin", "read_timeout": 60000, "port": 80, "path": "/request", "updated_at": 1561017861, "retries": 5, "write_timeout": 60000, "tags": null } ] } HTTP GET /services/{service-id}/plugins x2 { "next": null, "data": [ { "created_at": 1560860735, "config": { "block_introspection_queries": false }, "id": "e0fcaa8b-167f-4f62-bf22-43dae04e91bf", "service": { "id": "3692da97-e066-46e6-9739-3da47cfe4abd" }, "name": "graphql-operation-whitelist", "protocols": [ "http", "https" ], "enabled": true, "run_on": "first", "consumer": null, "route": null, "tags": null } ] }
  • 10. API Management with REST vs GraphQL • API has many endpoints • Resource selection is defined in route • HTTP verbs define the operation (GET, POST, DELETE...) REST • API has a single endpoint • Resource selection is defined in body • HTTP POST for every operations (query or mutation defined in request body) GraphQL To manage GraphQL Endpoints, we have to look into the query and extract some characteristics to implement policies.
  • 11. Query characteristics examples Nesting Measure the nesting level of a query. Query Cost Analysis Count the amount of resources requested by a query. Query whitelisting Verify the query belongs to a group of authorized queries.
  • 12. Query characteristics examples Nesting Measure the nesting level of a query. Query Cost Analysis Count the amount of resources requested by a query. Query whitelisting Verify the query belongs to a group of authorized queries. 50 = 50 repositories + 50 x 10 = 500 repository issues = 550 total nodes
  • 13. Query characteristics examples Nesting Measure the nesting level of a query. Query Cost Analysis Count the amount of resources requested by a query. Query whitelisting Verify the query belongs to a group of authorized queries.
  • 14. Existing solutions are language-specific libraries API - 1 (JS) Nesting Limit Node Count Limit Query Whitelisting API - 2 (Java) Nesting Limit Node Count Limit API - 3 (Python) API - 1 (JS) API - 2 (Java) API - 3 (Python) Kong Plugins: Nesting Limit, Node Count Limit, Query Whitelisting...  Non-intrusive: no code or configuration change on your GraphQL server.  Language-agnostic: same features and performance for all GraphQL implementations .
  • 15. Two proof-of-concept Kong plugins developed at Rakuten 1. Depth Limit Limit the complexity of GraphQL queries based on their depth. https://github.com/rakutentech/kong-plugin-graphql-depth-limit 2. Operation Whitelist Whitelist operations that your consumers can send to your GraphQL server. https://github.com/rakutentech/kong-plugin-graphql-operation-whitelist
  • 16. Operation Whitelist Plugin Requirements  Queries and Mutations blocked if not whitelisted  Equivalent operations represented as a single entry PDK Features Usage  Storing/Caching Custom Entities  Admin API Extension to manage the Whitelist Client UpstreamKong Query Parsing Signature Generation Signature Hashing Whitelist Check
  • 17. DEMO
  • 18. Credits and references • Securing Your GraphQL API from Malicious Queries (Apollo) https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b • GraphQL API Management (IBM) https://www.ibm.com/blogs/research/2019/02/graphql-api-management/ • GraphQL Lua (@bjornbytes) https://github.com/bjornbytes/graphql-lua
  • 20. Conclusion and Next Steps • Kong extensibility is a key factor, look into plugin and Admin API • GraphQL is still relatively new, but it’s popular and we need to address the security aspect • Load and Performance testing • Hardening the code • Merging all the plugins in a single one • Implement a Query Cost Analysis Plugin

Hinweis der Redaktion

  1. Good afternoon everyone, I'm Julien Bataillé , I'm a software engineer at Rakuten and I work with a team in charge of developing and maintaining the API Gateway for our entire group of companies.
  2. If you attended the session this morning "Building the Next Era of Software" maybe you heard my colleague Alex talking about the challenges of providing Kong to such a large and diverse organization. Today, I'd like to talk about one particular use case that came to us earlier this year. We were talking with one of our largest team here in the US about getting onboard and expose their APIs through our shared instance of Kong. They were interested, Kong is a great product after all, but they raised one important question:
  3. how Kong can help to manage GraphQL APIs? And this is the question I'd like to try to answer with today’s presentation.
  4. this is the agenda for today’s talk. First, I will start with a very quick introduction to GraphQL. Then I will try to highlight the differences between REST and GraphQL and how it’s impacting the rules and policies we use to manage APIs. Finally, I will show you some examples of Kong plugins we developed with a live demo if we have enough time.
  5. But first, a few words about GraphQL. It’s a very popular alternative to REST for front end applications. Since it was open sourced by Facebook in 2015, adoption has been really strong and nowadays you can find both server and client implementations for almost every stacks. It allows the client to define the structure of the data required and the server will return exactly that and nothing else. This is why it’s often considered a great solution to solve the so-called Over-fetching and under-fetching problems. It’s doing much more than that but I’d like to insist on this point because I think this is one of the most relevant to today’s topic.
  6. So to illustrate this I’d like to take an example that is probably very familiar to today’s audience. The Kong Admin REST API. How many of you used or know about the Kong Admin API? So let’s say I want to display the list of services configured on my Kong cluster and in the same page I want to see the list of plugins activated on each service.
  7. To achieve this, I first need to call the services endpoints and it will return the name, host and creation time for each of my services. Notice that I also receive a lot of fields in the response that are not required to display this page to the user. This is Over-fetching: I get data in the server’s response that are useless to my application. But the plugins for each service are missing from this first response so I need to make another round trip to the server to get this additional piece of information. Not only one but 2 calls in this example because I need to display 2 serrvices. At least I can send those two last requests in parallel but in more complex scenarios it is sometime not even possible to do so. This I hope is a good example of under-fetching. Now let’s compare it to how we would achieve the same result with GraphQL:
  8. First on the client we would build a query that would contain only the information we need: name, host, creation time, plugins. On this plugins entity we specify only the fields we want, in this example the name of the plugin. We would POST this query inside the body of a HTTP request to the Kong GraphQL Admin API
  9. and the response would contain exactly the fields specified in the query. We get the all the information we need to display our page in a single round trip to the server. So from this example you can already notice a few differences between REST and GraphQL that will have an impact how we implement API Management policies.
  10. First, instead of many endpoints in a typical REST API we now have a single endpoint for GraphQL. The resource selection with REST is usually defined in the route or path of the request whereas with GraphQL this resource selection is specified by the operation sent in the body. With REST, we are used to conventions on the HTTP verb to define operations: GET, POST, PATCH, DELETE can be used to implement policies or restrictions on the API usage. For most common GraphQL implementations only POST operations are necessary. Finally, as we just saw in the previous example One GraphQL call can replace multiple REST calls. How do we implement Rate Limiting in this case, does it even make sense to use rate limiting? I hope a this point you will agree that to manage GraphQL endpoints, we have to look into the GraphQL operation to extract some characteristics about the query or mutation and use those characteristics to implement our API Management policies.
  11. To make things more concrete let me share a few examples of what we can look into. First we could measure the nesting of a query and impose some arbitrary limits to avoid this kind of recursive query.
  12. Next, we can measure the cost of a query by counting the number of entities required by the client. this example is from the Github GraphQL API: the client requested the 50 first repositories from an account and for each repository the first 10 issues for a total of 550 nodes. This is how Github implements rate limiting: instead of a number of 5,000 request per hour, they set a limit of points per hour. Each type of node costing an arbitrary number of points.
  13. Query whitelisting is another policy we can implement if we have the capability to compare GraphQL operations and determine when two operations are functionally equivalent or not. I will develop this one in just a moment.
  14. But first I want to mention that you will find libraries that implement the policies I just showed. Those are language specific solutions so it means you need to modify or reconfigure your GraphQL server to enable it. This is where I believe Kong brings a better alternative: as for REST APIs, we want to move the implementation to Kong plugins instead of each individual upstream API. It gives us the opportunity to enforce the same policies across all our GraphQL servers implemented in Javascript, Python or Java.
  15. In the past few months we implemented two Kong plugins at Rakuten to validate this approach: the first one is fairly basic and implements the Depth limit policy I talked about earlier. It allowed us to verify we could parse a GraphQL query in a Kong plugin. The second one is a little more complex and this is the one I’d like to demo today.
  16. There is no Open Source without a Community.