Secure Your GraphQL Endpoints With Tyk in 5 Minutes

Rate this content
Bookmark

If you have existing GraphQL APIs or plan on building them in the future, join us for a 5-minute session to show you how to quickly secure them using Tyk.

This talk has been presented at GraphQL Galaxy 2020, check out the latest edition of this Tech Conference.

FAQ

The purpose of the lightning talk is to demonstrate how to secure GraphQL endpoints using Tyke in five minutes.

The presenter of the talk is Matt Tanner, a product evangelist at Tyke.

The talk addresses adding authorization and authentication mechanisms, securing the schema to restrict field access to specific users, and protecting against denial of service attacks.

'Batteries included security' means that Tyke provides all necessary security features within its gateway without the need for additional plugins.

Tyke secures a GraphQL schema by adding field-based permissions and query depth limiting to prevent unauthorized access and denial of service attacks.

Tyke supports various authentication modes including authentication tokens, mutual TLS, OAuth 2.0, and JWTs.

Query depth limiting in Tyke is used to protect against denial of service attacks by restricting the depth of nested queries.

Rate limiting and throttling can be enforced in Tyke by setting per-API limits and usage quotas within policies.

If a query violates the set field-based permissions in Tyke, the system will restrict access to the specified fields and return an error message.

Tyke handles unauthorized access attempts by requiring an authentication token and enforcing policies that restrict access based on predefined permissions and limits.

Matt Tanner
Matt Tanner
8 min
02 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

In this video, you'll learn how to secure GraphQL endpoints using Tyk in just five minutes. The talk covers adding authorization, securing the schema, and protecting against denial of service attacks. Tyk offers various authentication modes like authentication tokens, mutual TLS, OAuth 2.0, and JOTS. It also supports rate limiting, throttling, and query depth limiting. The process is demonstrated using the TrevorBlades countries API. You'll see how to generate API keys, create policies, and set field-based permissions. The video also explains how to use Tyk with Docker Compose for easy setup. By adding an authorization header with the API key, you can access the GraphQL proxy playground. The depth limit feature is shown by running nested queries, ensuring the API is secured efficiently.

1. Introduction to Securing GraphQL Endpoints

Short description:

In this lightning talk, we will explore how to secure your GraphQL endpoints in five minutes using Tyke. We will address problems such as adding authorization, securing the schema, and protecting against denial of service attacks. Tyke provides batteries included security, eliminating the need for additional plugins. We will demonstrate the process by securing the TrevorBlades countries API through Tyke's proxy.

Hello, everyone, and welcome to this lightning talk about how to secure your GraphQL endpoints in five minutes, and we're going to be doing that using Tyke. So my name is Matt Tanner. I am a product evangelist here at Tyke, and I'm going to be walking you through this.

So getting right down to it, since we have a limited amount of time, let's look at a few problems that we're going to solve within securing GraphQL. First one is adding authorization. So authorization authentication, adding in those mechanisms quickly, securing the schema, so making sure that only specific users have access to specific fields, and then also looking at protecting us against denial of service attacks. How do we do that? Well, we have batteries included security, which is a phrase that we like to use at Tyke to say everything that's within our gateway is included. There's no plugins or anything like that, that you need to add. And for that, we're going to add that right in. Then we're going to, as part of that, put in some field-based permissions to secure the schema, and then we're going to add some query depth limiting to it as well for those denial of service attacks.

So let's see how it works. Let's just get right to it. I'm going to jump out of this. And here I am in the Tyke dashboard. What I'm going to do is first I'm going to show you what I want to secure. There's this TrevorBlades countries API, GraphQL API, that right now is completely open. And I can hit it. There's no security, no type of security at all. What I'm going to do is proxy to that through Tyke, and then secure it using Tyke. So I'm going to grab this. This is as if it was your API. You come over into Tyke and we come over to APIs. Add new API. I'm going to call it countries. It is a GraphQL API. We're going to proxy to an existing GraphQL service, and you'll see that I have the TrevorBlades countries URL in there. Now, at this point, believe it or not, we already have some authorization built in. We've now proxied to it. If I come over to the playground, which is built into Tyke, and I run, if I just hide this here, hide meeting controls. If I come over here and grab this query, and I come over back to here, and run this query, you'll see that it says authorization field is missing.

2. Securing GraphQL Endpoints

Short description:

We support various authentication modes such as authentication tokens, mutual TLS, OAuth 2.0, and JOTS. To access the API, keys need to be generated and a policy created. The policy includes settings for rate limiting, throttling, and query depth limiting. Field-based permissions can be set to restrict access to specific fields. Finally, keys are added to the policy, and the GraphQL proxy playground can be accessed through the API.

That's great. That means we're already enforcing an authentication token. Where is that specified? Well, in our setup right down here. We support quite a few different things, but today we're going to use authentication tokens just for brevity. We also support mutual TLS, OAuth 2.0, JOTS, all of those good type of authentication modes.

In order to access this now, I need to generate some keys. In order to have some keys, I need to have a policy created. Let's save this. Jump over to policies, which is down here in the corner. Add policy. I'm going to cover my countries API. Come over to configurations here. I'm just going to call this countries policy. My keys that I generate are never going to expire. Then, I'm going to hop back over here to access rights, and there's a few things that we're going to do. To set per API limits and quota, I'm going to turn this on. This here would allow us to enforce rate limiting, throttling, usage quotas, all that stuff. We won't worry about that today.

What we are going to worry about here is this query depth limiting. What I'm going to do is I'm going to make my maximum query depth five. I'll demonstrate that to you in a moment here. Just with that, now that will be enforced. What I'm also going to do under field-based permissions, I'm not going to allow any of my users of this policy to access. As you can see, you can see all the types available through this API, as well as all the fields individually. I don't want them to have access to continent code or country code. Then I'm going to create policy. There we go. The policy has been created, and now I'm going to hop over to keys. I'm going to add a key for this policy, create key, and with that, my key is created. Now if I come back over to APIs, I'm going to open in a new tab, come over here and come to countries, which is our created GraphQL proxy playground.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura