SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
Securing
Microservices
using Play and Akka HTTP
Rafal Gancarz
@RafalGancarz
1
About me
• Lead Consultant at
OpenCredo
• Helping companies transform
their IT platforms and the ways
their do business
• Technologist, architect,
developer
• Agile practitioner & evangelist
• Scala <- Java <- PHP
2
(Micro)services
• SOA reloaded
• Lightweight, open standards
• Loosely coupled, self-contained
• Independent and scalable
• Bounded context (part of business domain)
3
Securing the monolith
DB
authentication
Pros
• single entry point
• limited attack surface
• centralised authentication &
authorisation
Cons
• totally exposed when
compromised
4
Securing the monolith -
considerations
• Combined presentation and business logic tier
• End user login
• Session based authentication
• Single sign-on (usually with SAML)
5
Securing microservices
(first take)
DB
Pros
• siloed data
Cons
• large attack surface
• multiple auth enforcement
points
• shared auth data storeDB DB
6
• Who is the consumer (the end user vs the third-party system)?
• Is user context relevant?
• access control granularity
• act on behalf
• What are the security related requirements?
• highly sensitive data
• integration over public internet
• social login
• single sign-on (SSO)
Securing microservices - considerations
7
• What are commercial requirements for your project?
• time to market
• availability of skills / expertise
• buy vs build
• What about the legacy?
• existing security implementation
• interoperability with the legacy platform
Securing microservices - considerations
8
API gateway
DB DB DB
API gateway
Pros
• single point of entry
• limited surface attack
• configurable authentication
protocols and backends
• faster time to market
• gateway availability/scalability
Cons
• additional cost
• services unsecured internally
• HTTP level access control
• limited auth context
9
HTTP basic auth + client id&secret
DB DB DB
Pros
• easy
• good for third-party integration
• stateless
Cons
• requires TLS
• doesn’t expire
• difficult to enforce at scale
(unless used with API gateway)
client_id
client_secret
10
Play Framework
• Basic HTTP auth with HTTP filter
• Basic HTTP auth with Action builder
• Play2.x Authentication and Authorization module
(https://github.com/t2v/play2-auth)
• Pac4j module (https://github.com/leleuj/play-pac4j)
• Secure Social module (http://securesocial.ws/)
• Silhouette module (http://silhouette.mohiva.com/)
11
Akka HTTP
• authenticateBasicX directives
• http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/routing-dsl/directives/
security-directives/authenticateBasic.html#authenticatebasic
def myUserPassAuthenticator(credentials: Credentials): Future[Option[String]] =
credentials match {
case p @ Credentials.Provided(id) =>
Future {
// potentially
if (p.verify("s3cr3t")) Some(id)
else None
}
case _ => Future.successful(None)
}
val route =
Route.seal {
path("secured") {
authenticateBasicAsync(realm = "secure site", myUserPassAuthenticator)
{ userName =>
complete(s"The user is '$userName'")
}
}
}
12
OAuth2+OpenID Connect
DB DB DB
Auth Server
Pros
• standard based
• popular for social login & delegated
authorisation
• caters for browser, mobile and
server-to-server use cases
• token expiry
Cons
• requires TLS
• requires Authorisation Server
• developed initially as authorisation
framework
• numerous flavours used
• non-trivial to get right
• authentication impl out of scope
13
Play Framework
• Pac4j module (https://github.com/leleuj/play-pac4j)
- supports OAuth2, OAuth2 and OpenID
• Secure Social module (http://securesocial.ws/) -
supports OAuth1 and OAuth2
• Silhouette module (http://silhouette.mohiva.com/) -
supports OAuth1, OAuth2 and OpenID
14
Akka HTTP
• authenticateOAuth2X directives
• http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/
routing-dsl/directives/security-directives/
authenticateOAuth2.html#authenticateoauth2
def authenticateOAuth2[T](realm: String,
authenticator: Authenticator[T]):
AuthenticationDirective[T]
Usage the same as HTTP basic but requires validating access
token retrieved from the header (not supported natively).
15
OpenID Connect
• Nimbus (https://bitbucket.org/connect2id/
oauth-2.0-sdk-with-openid-connect-extensions)
• Apache Oltu (https://oltu.apache.org/)
https://openid.net/developers/specs/ 16
JSON Web Token
DB DB DB
Auth Server
Pros
• auth claims can be signed
(HMAC or RSA)
• compact (suitable for URLs,
headers, query params)
• self-contained, stateless
• excellent SAML alternative for
SSO
Cons
• requires TLS or encryption
• authentication impl out of scope
http://jwt.io/
17
JSON Web Token
• No built-in support in Play or Akka HTTP
• authentikat-jwt (https://github.com/jasongoodwin/
authentikat-jwt) - Scala
• iain-logan/jwt (https://github.com/iain-logan/jwt) - Scala
• jose4j (https://bitbucket.org/b_c/jose4j/wiki/Home) -
Java
• jjwt (https://github.com/jwtk/jjwt) - Java
18
Mutually authenticated TLS
DB DB DB
Pros
• strong point to point security
Cons
• requires PKI
• key management and
distribution challenging
• difficult to implement and
troubleshoot
• no user context
mTLS
19
Play Framework - server-side
• https://www.playframework.com/documentation/2.4.x/ConfiguringHttps
class CustomSSLEngineProvider(appProvider: ApplicationProvider) extends SSLEngineProvider {
def createSSLContext(applicationProvider: ApplicationProvider): SSLContext = {

val keyManagers = readKeyManagers()

val trustManagers = readTrustManagers()



val sslContext = SSLContext.getInstance("TLS")

sslContext.init(keyManagers, trustManagers, null)

sslContext

}
override def createSSLEngine(): SSLEngine = {
val sslContext = createSSLContext(appProvider)
val sslParameters = sslContext.getDefaultSSLParameters
sslParameters.setUseCipherSuitesOrder(true)
sslParameters.setNeedClientAuth(true)
val engine = sslContext.createSSLEngine

engine.setSSLParameters(sslParameters)
engine
}
}
20
Akka HTTP - server-side
• http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-
M2/scala/http/low-level-server-side-api.html#serversidehttps
def createSSLContext(): SSLContext = {

val keyManagers = readKeyManagers()

val trustManagers = readTrustManagers()



val sslContext = SSLContext.getInstance("TLS")

sslContext.init(keyManagers, trustManagers, null)

sslContext

}



def run() = {



implicit val system = ActorSystem("server")

implicit val materializer = ActorMaterializer()



val sslContext = createSSLContext()



val serverSource = Http().bind(interface = "localhost", port = 8200, ServerSettings(system),
Some(HttpsContext(sslContext, Some(immutable.Seq("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384")),
Some(immutable.Seq("TLSv1.2")), Some(Need), Some(sslContext.getDefaultSSLParameters))))



…



}
21
Authorisation
• At the perimeter or within the business logic?
• Where user roles/permissions are coming from
(each bounded context might have different
access control considerations)?
• How is the user context passed into the service?
22
Play Framework
• Authorisation with HTTP filter
• Authorisation with Action builder
• Deadbolt (http://deadbolt.ws/#/home) - works with
Silhouette and SecureSocial for authentication
23
Akka HTTP
• authorize directive
• http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/routing-dsl/
directives/security-directives/authorize.html#authorize
case class User(name: String)
val admins = Set("Peter")
def hasAdminPermissions(user: User): Boolean =
admins.contains(user.name)
val route =
Route.seal {
authenticateBasic(realm = "secure site", myUserPassAuthenticator) { user
=>
path("peters-lair") {
authorize(hasAdminPermissions(user)) {
complete(s"'${user.name}' visited Peter's lair")
}
}
}
}
24
Key takeaways
• Securing microservice based architectures is
challenging
• The technology landscape changes all the time
• One size (solution) doesn’t fit all
• Consider your requirements before committing to a
technical solution
25
Questions?
• Email: rafal.gancarz@opencredo.com
• Twitter: @RafalGancarz
• See me tomorrow at lunchtime for a Q&A session on
Securing Microservices using Play and Akka HTTP
• Visit OpenCredo’s booth tomorrow and enter a draw to
win Apple Watch!
• See you at the Scala Exchange party later :)
• Thank you!
26

Más contenido relacionado

La actualidad más candente

Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkLuciano Mammino
 
Scala play-framework
Scala play-frameworkScala play-framework
Scala play-frameworkAbdhesh Kumar
 
Spicing up JMX with Jolokia (Devoxx 2014)
Spicing up JMX with Jolokia (Devoxx 2014)Spicing up JMX with Jolokia (Devoxx 2014)
Spicing up JMX with Jolokia (Devoxx 2014)roland.huss
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture AppDynamics
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?Gavin Holt
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterKonstantin Tsykulenko
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaRyan Cuprak
 
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Andrea Dottor
 
Microservices with SenecaJS (part 2)
Microservices with SenecaJS (part 2)Microservices with SenecaJS (part 2)
Microservices with SenecaJS (part 2)Designveloper
 
4 JVM Web Frameworks
4 JVM Web Frameworks4 JVM Web Frameworks
4 JVM Web FrameworksJoe Kutner
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBValeri Karpov
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...Andrea Dottor
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Saeed Zarinfam
 
Introduction to Shield and kibana
Introduction to Shield and kibanaIntroduction to Shield and kibana
Introduction to Shield and kibanaKnoldus Inc.
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and QuickstartManish Pandit
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorialKaty Slemon
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
 

La actualidad más candente (20)

Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 
Scala play-framework
Scala play-frameworkScala play-framework
Scala play-framework
 
Spicing up JMX with Jolokia (Devoxx 2014)
Spicing up JMX with Jolokia (Devoxx 2014)Spicing up JMX with Jolokia (Devoxx 2014)
Spicing up JMX with Jolokia (Devoxx 2014)
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS Lambda
 
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
 
Microservices with SenecaJS (part 2)
Microservices with SenecaJS (part 2)Microservices with SenecaJS (part 2)
Microservices with SenecaJS (part 2)
 
4 JVM Web Frameworks
4 JVM Web Frameworks4 JVM Web Frameworks
4 JVM Web Frameworks
 
TDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDBTDD a REST API With Node.js and MongoDB
TDD a REST API With Node.js and MongoDB
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...
 
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
ASP.NET: Present and future
ASP.NET: Present and futureASP.NET: Present and future
ASP.NET: Present and future
 
Introduction to Shield and kibana
Introduction to Shield and kibanaIntroduction to Shield and kibana
Introduction to Shield and kibana
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and Quickstart
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorial
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 

Similar a Securing Microservices using Play and Akka HTTP

Security Architecture Consulting - Hiren Shah
Security Architecture Consulting - Hiren ShahSecurity Architecture Consulting - Hiren Shah
Security Architecture Consulting - Hiren ShahNSConclave
 
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능Hyperledger Korea User Group
 
Securing your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggSecuring your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggStreamNative
 
Spring4 security
Spring4 securitySpring4 security
Spring4 securitySang Shin
 
Super simple application security with Apache Shiro
Super simple application security with Apache ShiroSuper simple application security with Apache Shiro
Super simple application security with Apache ShiroMarakana Inc.
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Jim Manico
 
Managing your secrets in a cloud environment
Managing your secrets in a cloud environmentManaging your secrets in a cloud environment
Managing your secrets in a cloud environmentTaswar Bhatti
 
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...Christian Schneider
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application ServerPhil Windley
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningSean Chittenden
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationStuart (Pid) Williams
 
Hyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep DiveHyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep DiveDan Selman
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 

Similar a Securing Microservices using Play and Akka HTTP (20)

Security Architecture Consulting - Hiren Shah
Security Architecture Consulting - Hiren ShahSecurity Architecture Consulting - Hiren Shah
Security Architecture Consulting - Hiren Shah
 
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
 
Securing your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggSecuring your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris Kellogg
 
Spring4 security
Spring4 securitySpring4 security
Spring4 security
 
Intro to Apache Shiro
Intro to Apache ShiroIntro to Apache Shiro
Intro to Apache Shiro
 
Super simple application security with Apache Shiro
Super simple application security with Apache ShiroSuper simple application security with Apache Shiro
Super simple application security with Apache Shiro
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2
 
Managing your secrets in a cloud environment
Managing your secrets in a cloud environmentManaging your secrets in a cloud environment
Managing your secrets in a cloud environment
 
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...
Security DevOps - Free pentesters' time to focus on high-hanging fruits // Ha...
 
Rails Security
Rails SecurityRails Security
Rails Security
 
Aplicaciones distribuidas con Dapr
Aplicaciones distribuidas con DaprAplicaciones distribuidas con Dapr
Aplicaciones distribuidas con Dapr
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency Planning
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
4aa5 3404
4aa5 34044aa5 3404
4aa5 3404
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Hyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep DiveHyperleger Composer Architecure Deep Dive
Hyperleger Composer Architecure Deep Dive
 
Spa Secure Coding Guide
Spa Secure Coding GuideSpa Secure Coding Guide
Spa Secure Coding Guide
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 

Último

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Último (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Securing Microservices using Play and Akka HTTP

  • 1. Securing Microservices using Play and Akka HTTP Rafal Gancarz @RafalGancarz 1
  • 2. About me • Lead Consultant at OpenCredo • Helping companies transform their IT platforms and the ways their do business • Technologist, architect, developer • Agile practitioner & evangelist • Scala <- Java <- PHP 2
  • 3. (Micro)services • SOA reloaded • Lightweight, open standards • Loosely coupled, self-contained • Independent and scalable • Bounded context (part of business domain) 3
  • 4. Securing the monolith DB authentication Pros • single entry point • limited attack surface • centralised authentication & authorisation Cons • totally exposed when compromised 4
  • 5. Securing the monolith - considerations • Combined presentation and business logic tier • End user login • Session based authentication • Single sign-on (usually with SAML) 5
  • 6. Securing microservices (first take) DB Pros • siloed data Cons • large attack surface • multiple auth enforcement points • shared auth data storeDB DB 6
  • 7. • Who is the consumer (the end user vs the third-party system)? • Is user context relevant? • access control granularity • act on behalf • What are the security related requirements? • highly sensitive data • integration over public internet • social login • single sign-on (SSO) Securing microservices - considerations 7
  • 8. • What are commercial requirements for your project? • time to market • availability of skills / expertise • buy vs build • What about the legacy? • existing security implementation • interoperability with the legacy platform Securing microservices - considerations 8
  • 9. API gateway DB DB DB API gateway Pros • single point of entry • limited surface attack • configurable authentication protocols and backends • faster time to market • gateway availability/scalability Cons • additional cost • services unsecured internally • HTTP level access control • limited auth context 9
  • 10. HTTP basic auth + client id&secret DB DB DB Pros • easy • good for third-party integration • stateless Cons • requires TLS • doesn’t expire • difficult to enforce at scale (unless used with API gateway) client_id client_secret 10
  • 11. Play Framework • Basic HTTP auth with HTTP filter • Basic HTTP auth with Action builder • Play2.x Authentication and Authorization module (https://github.com/t2v/play2-auth) • Pac4j module (https://github.com/leleuj/play-pac4j) • Secure Social module (http://securesocial.ws/) • Silhouette module (http://silhouette.mohiva.com/) 11
  • 12. Akka HTTP • authenticateBasicX directives • http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/routing-dsl/directives/ security-directives/authenticateBasic.html#authenticatebasic def myUserPassAuthenticator(credentials: Credentials): Future[Option[String]] = credentials match { case p @ Credentials.Provided(id) => Future { // potentially if (p.verify("s3cr3t")) Some(id) else None } case _ => Future.successful(None) } val route = Route.seal { path("secured") { authenticateBasicAsync(realm = "secure site", myUserPassAuthenticator) { userName => complete(s"The user is '$userName'") } } } 12
  • 13. OAuth2+OpenID Connect DB DB DB Auth Server Pros • standard based • popular for social login & delegated authorisation • caters for browser, mobile and server-to-server use cases • token expiry Cons • requires TLS • requires Authorisation Server • developed initially as authorisation framework • numerous flavours used • non-trivial to get right • authentication impl out of scope 13
  • 14. Play Framework • Pac4j module (https://github.com/leleuj/play-pac4j) - supports OAuth2, OAuth2 and OpenID • Secure Social module (http://securesocial.ws/) - supports OAuth1 and OAuth2 • Silhouette module (http://silhouette.mohiva.com/) - supports OAuth1, OAuth2 and OpenID 14
  • 15. Akka HTTP • authenticateOAuth2X directives • http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/ routing-dsl/directives/security-directives/ authenticateOAuth2.html#authenticateoauth2 def authenticateOAuth2[T](realm: String, authenticator: Authenticator[T]): AuthenticationDirective[T] Usage the same as HTTP basic but requires validating access token retrieved from the header (not supported natively). 15
  • 16. OpenID Connect • Nimbus (https://bitbucket.org/connect2id/ oauth-2.0-sdk-with-openid-connect-extensions) • Apache Oltu (https://oltu.apache.org/) https://openid.net/developers/specs/ 16
  • 17. JSON Web Token DB DB DB Auth Server Pros • auth claims can be signed (HMAC or RSA) • compact (suitable for URLs, headers, query params) • self-contained, stateless • excellent SAML alternative for SSO Cons • requires TLS or encryption • authentication impl out of scope http://jwt.io/ 17
  • 18. JSON Web Token • No built-in support in Play or Akka HTTP • authentikat-jwt (https://github.com/jasongoodwin/ authentikat-jwt) - Scala • iain-logan/jwt (https://github.com/iain-logan/jwt) - Scala • jose4j (https://bitbucket.org/b_c/jose4j/wiki/Home) - Java • jjwt (https://github.com/jwtk/jjwt) - Java 18
  • 19. Mutually authenticated TLS DB DB DB Pros • strong point to point security Cons • requires PKI • key management and distribution challenging • difficult to implement and troubleshoot • no user context mTLS 19
  • 20. Play Framework - server-side • https://www.playframework.com/documentation/2.4.x/ConfiguringHttps class CustomSSLEngineProvider(appProvider: ApplicationProvider) extends SSLEngineProvider { def createSSLContext(applicationProvider: ApplicationProvider): SSLContext = {
 val keyManagers = readKeyManagers()
 val trustManagers = readTrustManagers()
 
 val sslContext = SSLContext.getInstance("TLS")
 sslContext.init(keyManagers, trustManagers, null)
 sslContext
 } override def createSSLEngine(): SSLEngine = { val sslContext = createSSLContext(appProvider) val sslParameters = sslContext.getDefaultSSLParameters sslParameters.setUseCipherSuitesOrder(true) sslParameters.setNeedClientAuth(true) val engine = sslContext.createSSLEngine
 engine.setSSLParameters(sslParameters) engine } } 20
  • 21. Akka HTTP - server-side • http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0- M2/scala/http/low-level-server-side-api.html#serversidehttps def createSSLContext(): SSLContext = {
 val keyManagers = readKeyManagers()
 val trustManagers = readTrustManagers()
 
 val sslContext = SSLContext.getInstance("TLS")
 sslContext.init(keyManagers, trustManagers, null)
 sslContext
 }
 
 def run() = {
 
 implicit val system = ActorSystem("server")
 implicit val materializer = ActorMaterializer()
 
 val sslContext = createSSLContext()
 
 val serverSource = Http().bind(interface = "localhost", port = 8200, ServerSettings(system), Some(HttpsContext(sslContext, Some(immutable.Seq("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384")), Some(immutable.Seq("TLSv1.2")), Some(Need), Some(sslContext.getDefaultSSLParameters))))
 
 …
 
 } 21
  • 22. Authorisation • At the perimeter or within the business logic? • Where user roles/permissions are coming from (each bounded context might have different access control considerations)? • How is the user context passed into the service? 22
  • 23. Play Framework • Authorisation with HTTP filter • Authorisation with Action builder • Deadbolt (http://deadbolt.ws/#/home) - works with Silhouette and SecureSocial for authentication 23
  • 24. Akka HTTP • authorize directive • http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0-M2/scala/http/routing-dsl/ directives/security-directives/authorize.html#authorize case class User(name: String) val admins = Set("Peter") def hasAdminPermissions(user: User): Boolean = admins.contains(user.name) val route = Route.seal { authenticateBasic(realm = "secure site", myUserPassAuthenticator) { user => path("peters-lair") { authorize(hasAdminPermissions(user)) { complete(s"'${user.name}' visited Peter's lair") } } } } 24
  • 25. Key takeaways • Securing microservice based architectures is challenging • The technology landscape changes all the time • One size (solution) doesn’t fit all • Consider your requirements before committing to a technical solution 25
  • 26. Questions? • Email: rafal.gancarz@opencredo.com • Twitter: @RafalGancarz • See me tomorrow at lunchtime for a Q&A session on Securing Microservices using Play and Akka HTTP • Visit OpenCredo’s booth tomorrow and enter a draw to win Apple Watch! • See you at the Scala Exchange party later :) • Thank you! 26