SlideShare a Scribd company logo
DOMAIN ROUTING USING
SPRING CLOUD GATEWAY
Ashraf Mahmoud
Software Cloud engineer at Rackspace (EGYPT)
AGENDA
Introduction
Primary goals
Host routing in spring cloud gateway
Sub domain
Custom domain
20XX
Domain routing
2
INTRODUCTION
Spring cloud gateway is api gateway that help you to
route all requests to different services based on some
request parameters , it might be .​
• Headers
• Host
• Path
• Cookie
• Method
• Query
• ……
20XX Domain routing 3
PRIMARY GOALS
Building Sub domain and Custom Domain Service
Using Host routing in spring cloud gateway
PRIMARY GOALS
Think about building application like
Shopify , Zendesk , medium
SUB DOMAIN &CUSTOM
DOMAIN
20XX Domain routing 6
Let's take Zendesk as example
It’s a customer service solution
When you signup for Zendesk It will ask you to choose your unique domain
for example, asrevo.zendesk.com
also, you could add your custom domain for example , asrevo.com
and your users will be able to login from any of those domains (asrevo.zendesk.com,
asrevo.com)
SUB DOMAIN &CUSTOM
DOMAIN
20XX Domain routing 7
Could we build a sub domain & custom domain for our users using spring cloud
gateway ?
Answer: YES
Challenges:
• Sub domain : easy
• Custom domain : https problems
SUB DOMAIN
20XX Domain routing 8
Spring support URI Template variables like ={sub}.{x}.{y}, www.{x}.{y}, {x}.{y}
spring:
cloud:
gateway:
routes:
- id: app-ui
uri: http://localhost:8081
predicates:
- Host=www.{x}.{y},{x}.{y}
- id: profile-ui
uri: http://localhost:8082
predicates:
- Host={sub}.{x}.{y}
- id: profile
uri: http://localhost:8083
predicates:
- Path=/profile/**
SUB DOMAIN
20XX Domain routing 9
What is app & profile (it’s an angular nginx container ) so those are the static website
that will call beckend via rest to get dynamic content
App-ui (nginx angular ): Its main entry for your domain will work under
www.domain.com or domain.com might have logic for sign-in and sign-up for admin,
mange subscription plane , selecting unique domain , attaching your custom domain
Profile-ui (nginx angular): will serve profiles for example
https://ashraf.domain.com, https://ahmed.domain.com , https://jhone.domain.com also
custom domain https://asrevo.com , https://jone.me
Profile: backend application using spring boot responsible for calling database to save
or fetch profile data
SUB DOMAIN
20XX Domain routing 10
Profile challenge
How our backend translate https://ashraf.domain.com or https://asrevo.com to an id and
fetch profile data for those id?
Answer: building spring cloud gateway filter that map host to id and rewrite
URL before calling backend services
For example, convert https://asrevo.com/profile/find-one
to https://asrevo.com/profile/find-one?id={value-from-cache-based-on-host}
SUB DOMAIN
20XX Domain routing 11
Profile challenge
We decided to build a filter that will convert host to an id before sending it to backend service
Nice features to have in this filter:
1. Fetch data from in memory cache for example caffeine cache
2. Reject requests that not in your cache for example if jone.domain.com is not taken by any
of your customer reject it and don’t forward it to your backend services
Some links to help you to build your own filter
1. Writing Custom Spring Cloud Gateway Filters | Baeldung
2. Spring Cloud Gateway - Creating Custom Route Filters
(AbstractGatewayFilterFactory) – Woolha
3. Spring-Cloud-Gateway Custom Gateway Filter - SoByte
SUB DOMAIN
20XX Domain routing 12
Cache structure
If your domain is asrevo.com
Key is your domain
Value is your id
Key Value
ashraf.asrevo.com 1
jone.asrevo.com 2
SUB DOMAIN
20XX Domain routing 13
Profile challenge
Finally
Using DNS for example AWS route53 add A record for *.yourdomain and yourdomain to your gateway IP,
or LB
If you want support only sub domain routing not custom domain also , you can use AWS certificate
manger to generate SSL certificate for your website(*.yourdomain and yourdomain) and use AWS ALB to
point to this certificate
CUSTOM DOMAIN
20XX Domain routing 14
what is the problem? HTTPS
when you have a website that have certificate for *.asrevo.com and asrevo.com
If you add CNAME record to ashraf.me to ashraf.asrevo.com your browser will show you a
warning that you are trying to access ashraf.me but the certificate that it received is for
*.asrevo.com not ashraf.me
CUSTOM DOMAIN
20XX Domain routing 15
CUSTOM DOMAIN
20XX Domain routing 16
what is the solution?
Create your own certificate manger that generate certificates for every custom
domain your customer choose.
HOW?
You could build java application that generating certificates valid for 3 months once
your client asking you to accept his custom domain using https://letsencrypt.org
and shred/acme4j library
See acme4j/acme4j-example for how to generate certificate
I created my own with DNS challenge verification its easy
You should maintain those certificate and renew them every 3 months before it
expired
CUSTOM DOMAIN
20XX Domain routing 17
We build our certificate manger that able to issue certificate for every domain
Nice feature to have
• Store those certificate in a centralized object storage like s3
Note
We should NLB not ALB because we will handle https from spring cloud gateway server not from Load
balancer
CUSTOM DOMAIN
20XX Domain routing 18
What are is the missing step?
Telling spring cloud gateway to retrieve the certificate from s3 for every domain
For example, when calling ashraf.me from browser it should retrieve certificate from s3 for this
domain and serve the all the requests with this certificate
And at the same time should be able to handle other domains like jone.com, ali.me at the same
time
HOW
CUSTOM DOMAIN
20XX Domain routing 19
Building Dynamic SSL Loading using spring cloud gateway
Spring cloud gateway is built on top of reactor netty which is built on top of netty
so we will customize the server using
org.springframework.boot.web.embedded.netty.NettyServerCustomizer
CUSTOM DOMAIN
20XX Domain routing 20
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
import org.springframework.context.annotation.Configuration;
import reactor.netty.http.server.HttpServer;
import reactor.netty.tcp.SslProvider;
@Configuration
public class DynamicSslLoaderNettyCustomizer implements NettyServerCustomizer {
private final String fallbackHost = "asrevo.com";
@Override
public HttpServer apply(HttpServer httpServer) {
return httpServer.secure(sslContextSpec -> {
sslContextSpec.sslContext(getSslProvider(fallbackHost).getSslContext())
.setSniAsyncMappings((host, promise) -> {
return promise.setSuccess(getSslProvider(host));
});
});
} /* return SslProvider for host */
private SslProvider getSslProvider(String host) {
/*write code to get certificate from amazon s3 && write code to cache certificate for some time */
/*if host.endWith(fallbackHost) && !host.equal(fallbackHost) then host="*."+fallbackHost*/
/* if no certificate for certificate generated for this host return fallback certificate for your
fallbackHost*/
return null;
}
}
CUSTOM DOMAIN
20XX Domain routing 21
NettyServerCustomizer
@Override
public HttpServer apply(HttpServer httpServer) {
return httpServer.secure(sslContextSpec -> {
sslContextSpec.sslContext(getSslProvider(fallbackHost).getSslContext())
.setSniAsyncMappings((host, promise) -> {
return promise.setSuccess(getSslProvider(host));
});
});
}
The main method here is the setSniAsyncMappings
Its async function that take host as parameter and return a SslProvider
This will inspect the request header and extract host from the header and pass it to function you provide to
retrieve the SSL certificate for this host
it was not existed before version ` 1.0.19` until I asked from the reactor-Netty team to provide it an idea to
support dynamic https like (caddy server) ·
CUSTOM DOMAIN
20XX Domain routing 22
Build Effective Dynamic SSL Loading
Its mandatory to cache the SSL certificates because it was so bad to retrieve the certificate from
s3 before every request to your backend
you could use caffeine cache to cache the certificates and retrieve them from in memory cache
ABOUT ME
Ashraf Mahmoud
Sof tware cloud engineer
20XX Domain routing 23
THANK YOU
Email: ashraf1abdelrasool@gmail.com
GitHub: ashraf-revo (ashraf) (github.com)
LinkedIn: ashraf abd el rasool | LinkedIn
20XX Domain routing 24

More Related Content

What's hot

Introducing Amazon EKS Anywhere On Apache CloudStack
Introducing Amazon EKS Anywhere On Apache CloudStackIntroducing Amazon EKS Anywhere On Apache CloudStack
Introducing Amazon EKS Anywhere On Apache CloudStack
ShapeBlue
 
Disaster Recovery Planning using Azure Site Recovery
Disaster Recovery Planning using Azure Site RecoveryDisaster Recovery Planning using Azure Site Recovery
Disaster Recovery Planning using Azure Site Recovery
Nitin Agarwal
 
Bilgi Güvenliğinde Sızma Testleri
Bilgi Güvenliğinde Sızma TestleriBilgi Güvenliğinde Sızma Testleri
Bilgi Güvenliğinde Sızma Testleri
BGA Cyber Security
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
Edureka!
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaDocker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Edureka!
 
Advanced performance troubleshooting using esxtop
Advanced performance troubleshooting using esxtopAdvanced performance troubleshooting using esxtop
Advanced performance troubleshooting using esxtop
Alan Renouf
 
10 Key Considerations For Selecting Hyper-Converged Infrastructure
10 Key Considerations For Selecting Hyper-Converged Infrastructure10 Key Considerations For Selecting Hyper-Converged Infrastructure
10 Key Considerations For Selecting Hyper-Converged Infrastructure
Heather Salmons Newswanger
 
DevOps - Interview Question.pdf
DevOps - Interview Question.pdfDevOps - Interview Question.pdf
DevOps - Interview Question.pdf
MinhTrnNht7
 
ccnp-enterprise-core-networking-encor-product-overview.pptx
ccnp-enterprise-core-networking-encor-product-overview.pptxccnp-enterprise-core-networking-encor-product-overview.pptx
ccnp-enterprise-core-networking-encor-product-overview.pptx
ssuserff1f40
 
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
SlideTeam
 
Client Side Exploits using PDF
Client Side Exploits using PDFClient Side Exploits using PDF
Client Side Exploits using PDF
n|u - The Open Security Community
 
확장가능한 웹 아키텍쳐 구축 방안
확장가능한 웹 아키텍쳐 구축 방안 확장가능한 웹 아키텍쳐 구축 방안
확장가능한 웹 아키텍쳐 구축 방안
IMQA
 
Snort IPS(Intrusion Prevention System) Eğitimi
Snort IPS(Intrusion Prevention System) EğitimiSnort IPS(Intrusion Prevention System) Eğitimi
Snort IPS(Intrusion Prevention System) EğitimiBGA Cyber Security
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
Eueung Mulyana
 
Building a Stretched Cluster using Virtual SAN 6.1
Building a Stretched Cluster using Virtual SAN 6.1Building a Stretched Cluster using Virtual SAN 6.1
Building a Stretched Cluster using Virtual SAN 6.1
Duncan Epping
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
Sim Janghoon
 
Deploy Secure Network Architectures for The Connected Enterprise
Deploy Secure Network Architectures for The Connected EnterpriseDeploy Secure Network Architectures for The Connected Enterprise
Deploy Secure Network Architectures for The Connected Enterprise
Rockwell Automation
 
Introdução Vue JS
Introdução Vue JSIntrodução Vue JS
Introdução Vue JS
Leonardo Thizon Waterkemper
 
Secure Software Development Lifecycle - Devoxx MA 2018
Secure Software Development Lifecycle - Devoxx MA 2018Secure Software Development Lifecycle - Devoxx MA 2018
Secure Software Development Lifecycle - Devoxx MA 2018
Imola Informatica
 

What's hot (20)

Introducing Amazon EKS Anywhere On Apache CloudStack
Introducing Amazon EKS Anywhere On Apache CloudStackIntroducing Amazon EKS Anywhere On Apache CloudStack
Introducing Amazon EKS Anywhere On Apache CloudStack
 
Disaster Recovery Planning using Azure Site Recovery
Disaster Recovery Planning using Azure Site RecoveryDisaster Recovery Planning using Azure Site Recovery
Disaster Recovery Planning using Azure Site Recovery
 
Bilgi Güvenliğinde Sızma Testleri
Bilgi Güvenliğinde Sızma TestleriBilgi Güvenliğinde Sızma Testleri
Bilgi Güvenliğinde Sızma Testleri
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaDocker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
 
Advanced performance troubleshooting using esxtop
Advanced performance troubleshooting using esxtopAdvanced performance troubleshooting using esxtop
Advanced performance troubleshooting using esxtop
 
10 Key Considerations For Selecting Hyper-Converged Infrastructure
10 Key Considerations For Selecting Hyper-Converged Infrastructure10 Key Considerations For Selecting Hyper-Converged Infrastructure
10 Key Considerations For Selecting Hyper-Converged Infrastructure
 
DevOps - Interview Question.pdf
DevOps - Interview Question.pdfDevOps - Interview Question.pdf
DevOps - Interview Question.pdf
 
ccnp-enterprise-core-networking-encor-product-overview.pptx
ccnp-enterprise-core-networking-encor-product-overview.pptxccnp-enterprise-core-networking-encor-product-overview.pptx
ccnp-enterprise-core-networking-encor-product-overview.pptx
 
Kablosuz Ağlarda Güvenlik
Kablosuz Ağlarda GüvenlikKablosuz Ağlarda Güvenlik
Kablosuz Ağlarda Güvenlik
 
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
Kubernetes Docker Container Implementation Ppt PowerPoint Presentation Slide ...
 
Client Side Exploits using PDF
Client Side Exploits using PDFClient Side Exploits using PDF
Client Side Exploits using PDF
 
확장가능한 웹 아키텍쳐 구축 방안
확장가능한 웹 아키텍쳐 구축 방안 확장가능한 웹 아키텍쳐 구축 방안
확장가능한 웹 아키텍쳐 구축 방안
 
Snort IPS(Intrusion Prevention System) Eğitimi
Snort IPS(Intrusion Prevention System) EğitimiSnort IPS(Intrusion Prevention System) Eğitimi
Snort IPS(Intrusion Prevention System) Eğitimi
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Building a Stretched Cluster using Virtual SAN 6.1
Building a Stretched Cluster using Virtual SAN 6.1Building a Stretched Cluster using Virtual SAN 6.1
Building a Stretched Cluster using Virtual SAN 6.1
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
 
Deploy Secure Network Architectures for The Connected Enterprise
Deploy Secure Network Architectures for The Connected EnterpriseDeploy Secure Network Architectures for The Connected Enterprise
Deploy Secure Network Architectures for The Connected Enterprise
 
Introdução Vue JS
Introdução Vue JSIntrodução Vue JS
Introdução Vue JS
 
Secure Software Development Lifecycle - Devoxx MA 2018
Secure Software Development Lifecycle - Devoxx MA 2018Secure Software Development Lifecycle - Devoxx MA 2018
Secure Software Development Lifecycle - Devoxx MA 2018
 

Similar to domain-routing.pptx

CTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
CTD201_Introduction to Amazon CloudFront and AWS Lambda@EdgeCTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
CTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
Amazon Web Services
 
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
Amazon Web Services
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
Mikael Puittinen
 
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
Chef
 
Cloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWSCloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWS
Amine Sadry
 
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
Amazon Web Services
 
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
Amazon Web Services
 
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
PolarSeven Pty Ltd
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of Serverless
Yoav Avrahami
 
Domain and hostion
Domain and hostionDomain and hostion
Domain and hostion
university of Gujrat, pakistan
 
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
Amazon Web Services
 
20200803 - Serverless with AWS @ HELTECH
20200803 - Serverless with AWS @ HELTECH20200803 - Serverless with AWS @ HELTECH
20200803 - Serverless with AWS @ HELTECH
Marcia Villalba
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
Atlassian
 
Build a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a RideBuild a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a Ride
Amazon Web Services
 
Build a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a RideBuild a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a Ride
Amazon Web Services
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
Amazon Web Services
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginx
Vmoksha Admin
 
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Niels de Bruijn
 
The CAA-Record for increased encryption security
The CAA-Record for increased encryption securityThe CAA-Record for increased encryption security
The CAA-Record for increased encryption security
Men and Mice
 
Creating a RDS MySQL instance from AWS Console and CloudFormation
Creating a RDS MySQL instance from AWS Console and CloudFormationCreating a RDS MySQL instance from AWS Console and CloudFormation
Creating a RDS MySQL instance from AWS Console and CloudFormation
Subhamay Bhattacharyya
 

Similar to domain-routing.pptx (20)

CTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
CTD201_Introduction to Amazon CloudFront and AWS Lambda@EdgeCTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
CTD201_Introduction to Amazon CloudFront and AWS Lambda@Edge
 
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
Introduction to Amazon CloudFront and AWS Lambda@Edge - CTD201 - re:Invent 2017
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
AWS Presents: Infrastructure as Code on AWS - ChefConf 2015
 
Cloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWSCloud 101: Hands-on Heroku & AWS
Cloud 101: Hands-on Heroku & AWS
 
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
VMware Cloud on AWS: A World of Unique Integrations Between VMware and AWS - ...
 
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
Running Serverless at The Edge (CTD302) - AWS re:Invent 2018
 
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of Serverless
 
Domain and hostion
Domain and hostionDomain and hostion
Domain and hostion
 
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
High Velocity DevOps: Four Ways to Leverage CloudFront in Faster DevOps Workf...
 
20200803 - Serverless with AWS @ HELTECH
20200803 - Serverless with AWS @ HELTECH20200803 - Serverless with AWS @ HELTECH
20200803 - Serverless with AWS @ HELTECH
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
 
Build a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a RideBuild a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a Ride
 
Build a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a RideBuild a Serverless Backend for Requesting a Ride
Build a Serverless Backend for Requesting a Ride
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginx
 
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
 
The CAA-Record for increased encryption security
The CAA-Record for increased encryption securityThe CAA-Record for increased encryption security
The CAA-Record for increased encryption security
 
Creating a RDS MySQL instance from AWS Console and CloudFormation
Creating a RDS MySQL instance from AWS Console and CloudFormationCreating a RDS MySQL instance from AWS Console and CloudFormation
Creating a RDS MySQL instance from AWS Console and CloudFormation
 

Recently uploaded

Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
jrodriguezq3110
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
campbellclarkson
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
vaishalijagtap12
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
Zycus
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
Softradix Technologies
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 

Recently uploaded (20)

Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 

domain-routing.pptx

  • 1. DOMAIN ROUTING USING SPRING CLOUD GATEWAY Ashraf Mahmoud Software Cloud engineer at Rackspace (EGYPT)
  • 2. AGENDA Introduction Primary goals Host routing in spring cloud gateway Sub domain Custom domain 20XX Domain routing 2
  • 3. INTRODUCTION Spring cloud gateway is api gateway that help you to route all requests to different services based on some request parameters , it might be .​ • Headers • Host • Path • Cookie • Method • Query • …… 20XX Domain routing 3
  • 4. PRIMARY GOALS Building Sub domain and Custom Domain Service Using Host routing in spring cloud gateway
  • 5. PRIMARY GOALS Think about building application like Shopify , Zendesk , medium
  • 6. SUB DOMAIN &CUSTOM DOMAIN 20XX Domain routing 6 Let's take Zendesk as example It’s a customer service solution When you signup for Zendesk It will ask you to choose your unique domain for example, asrevo.zendesk.com also, you could add your custom domain for example , asrevo.com and your users will be able to login from any of those domains (asrevo.zendesk.com, asrevo.com)
  • 7. SUB DOMAIN &CUSTOM DOMAIN 20XX Domain routing 7 Could we build a sub domain & custom domain for our users using spring cloud gateway ? Answer: YES Challenges: • Sub domain : easy • Custom domain : https problems
  • 8. SUB DOMAIN 20XX Domain routing 8 Spring support URI Template variables like ={sub}.{x}.{y}, www.{x}.{y}, {x}.{y} spring: cloud: gateway: routes: - id: app-ui uri: http://localhost:8081 predicates: - Host=www.{x}.{y},{x}.{y} - id: profile-ui uri: http://localhost:8082 predicates: - Host={sub}.{x}.{y} - id: profile uri: http://localhost:8083 predicates: - Path=/profile/**
  • 9. SUB DOMAIN 20XX Domain routing 9 What is app & profile (it’s an angular nginx container ) so those are the static website that will call beckend via rest to get dynamic content App-ui (nginx angular ): Its main entry for your domain will work under www.domain.com or domain.com might have logic for sign-in and sign-up for admin, mange subscription plane , selecting unique domain , attaching your custom domain Profile-ui (nginx angular): will serve profiles for example https://ashraf.domain.com, https://ahmed.domain.com , https://jhone.domain.com also custom domain https://asrevo.com , https://jone.me Profile: backend application using spring boot responsible for calling database to save or fetch profile data
  • 10. SUB DOMAIN 20XX Domain routing 10 Profile challenge How our backend translate https://ashraf.domain.com or https://asrevo.com to an id and fetch profile data for those id? Answer: building spring cloud gateway filter that map host to id and rewrite URL before calling backend services For example, convert https://asrevo.com/profile/find-one to https://asrevo.com/profile/find-one?id={value-from-cache-based-on-host}
  • 11. SUB DOMAIN 20XX Domain routing 11 Profile challenge We decided to build a filter that will convert host to an id before sending it to backend service Nice features to have in this filter: 1. Fetch data from in memory cache for example caffeine cache 2. Reject requests that not in your cache for example if jone.domain.com is not taken by any of your customer reject it and don’t forward it to your backend services Some links to help you to build your own filter 1. Writing Custom Spring Cloud Gateway Filters | Baeldung 2. Spring Cloud Gateway - Creating Custom Route Filters (AbstractGatewayFilterFactory) – Woolha 3. Spring-Cloud-Gateway Custom Gateway Filter - SoByte
  • 12. SUB DOMAIN 20XX Domain routing 12 Cache structure If your domain is asrevo.com Key is your domain Value is your id Key Value ashraf.asrevo.com 1 jone.asrevo.com 2
  • 13. SUB DOMAIN 20XX Domain routing 13 Profile challenge Finally Using DNS for example AWS route53 add A record for *.yourdomain and yourdomain to your gateway IP, or LB If you want support only sub domain routing not custom domain also , you can use AWS certificate manger to generate SSL certificate for your website(*.yourdomain and yourdomain) and use AWS ALB to point to this certificate
  • 14. CUSTOM DOMAIN 20XX Domain routing 14 what is the problem? HTTPS when you have a website that have certificate for *.asrevo.com and asrevo.com If you add CNAME record to ashraf.me to ashraf.asrevo.com your browser will show you a warning that you are trying to access ashraf.me but the certificate that it received is for *.asrevo.com not ashraf.me
  • 16. CUSTOM DOMAIN 20XX Domain routing 16 what is the solution? Create your own certificate manger that generate certificates for every custom domain your customer choose. HOW? You could build java application that generating certificates valid for 3 months once your client asking you to accept his custom domain using https://letsencrypt.org and shred/acme4j library See acme4j/acme4j-example for how to generate certificate I created my own with DNS challenge verification its easy You should maintain those certificate and renew them every 3 months before it expired
  • 17. CUSTOM DOMAIN 20XX Domain routing 17 We build our certificate manger that able to issue certificate for every domain Nice feature to have • Store those certificate in a centralized object storage like s3 Note We should NLB not ALB because we will handle https from spring cloud gateway server not from Load balancer
  • 18. CUSTOM DOMAIN 20XX Domain routing 18 What are is the missing step? Telling spring cloud gateway to retrieve the certificate from s3 for every domain For example, when calling ashraf.me from browser it should retrieve certificate from s3 for this domain and serve the all the requests with this certificate And at the same time should be able to handle other domains like jone.com, ali.me at the same time HOW
  • 19. CUSTOM DOMAIN 20XX Domain routing 19 Building Dynamic SSL Loading using spring cloud gateway Spring cloud gateway is built on top of reactor netty which is built on top of netty so we will customize the server using org.springframework.boot.web.embedded.netty.NettyServerCustomizer
  • 20. CUSTOM DOMAIN 20XX Domain routing 20 import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; import org.springframework.context.annotation.Configuration; import reactor.netty.http.server.HttpServer; import reactor.netty.tcp.SslProvider; @Configuration public class DynamicSslLoaderNettyCustomizer implements NettyServerCustomizer { private final String fallbackHost = "asrevo.com"; @Override public HttpServer apply(HttpServer httpServer) { return httpServer.secure(sslContextSpec -> { sslContextSpec.sslContext(getSslProvider(fallbackHost).getSslContext()) .setSniAsyncMappings((host, promise) -> { return promise.setSuccess(getSslProvider(host)); }); }); } /* return SslProvider for host */ private SslProvider getSslProvider(String host) { /*write code to get certificate from amazon s3 && write code to cache certificate for some time */ /*if host.endWith(fallbackHost) && !host.equal(fallbackHost) then host="*."+fallbackHost*/ /* if no certificate for certificate generated for this host return fallback certificate for your fallbackHost*/ return null; } }
  • 21. CUSTOM DOMAIN 20XX Domain routing 21 NettyServerCustomizer @Override public HttpServer apply(HttpServer httpServer) { return httpServer.secure(sslContextSpec -> { sslContextSpec.sslContext(getSslProvider(fallbackHost).getSslContext()) .setSniAsyncMappings((host, promise) -> { return promise.setSuccess(getSslProvider(host)); }); }); } The main method here is the setSniAsyncMappings Its async function that take host as parameter and return a SslProvider This will inspect the request header and extract host from the header and pass it to function you provide to retrieve the SSL certificate for this host it was not existed before version ` 1.0.19` until I asked from the reactor-Netty team to provide it an idea to support dynamic https like (caddy server) ·
  • 22. CUSTOM DOMAIN 20XX Domain routing 22 Build Effective Dynamic SSL Loading Its mandatory to cache the SSL certificates because it was so bad to retrieve the certificate from s3 before every request to your backend you could use caffeine cache to cache the certificates and retrieve them from in memory cache
  • 23. ABOUT ME Ashraf Mahmoud Sof tware cloud engineer 20XX Domain routing 23
  • 24. THANK YOU Email: ashraf1abdelrasool@gmail.com GitHub: ashraf-revo (ashraf) (github.com) LinkedIn: ashraf abd el rasool | LinkedIn 20XX Domain routing 24