SlideShare a Scribd company logo
Microservices Security:
Dos and Don'ts
Stefano Di Paola, CTO & Chief Scientist @ Minded Security
July 2018 Summit
$ whoami
• Research
– Bug Hunter & Sec Research (Pdf
UXSS, Flash Security, HPP, JS
Security DOMinator/BlueClosure)
– Software Security Since ~'99
– CTO @ Minded Security
– Chief Scientist @ Minded Security
2
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
3
Goal
• Talk about Security in Microservices
Architectures
• Give insights about some of the most
interesting issues found in the last years
while testing the security of Multilayered
Microservices Architectures and how they
were fxed
• Will not talk about AWS misconfgurations
(too much to tell:)
4
Monolithic vs Microservices
•
5
Why Microservices?
• Scalability
• Maintainability
• Easy Refactor (No language constraint)
• Agile SDLC
• Fast+Continuous Deploy
6
Monolithic vs Microservices
•
7
Rings a bell?
Procedural vs Object Oriented
8
Scalability
9
●
X-axis scaling: scaling an application by running
clones behind a load balancer.
●
Y-axis scaling: splits the application into multiple,
different services.
●
The microservice architecture is an application of Y-
axis.
– Each service is responsible for one or more
closely related functions.
●
Two ways of decomposing the application into services.
– By Action: Verb-based decomposition and
define services that implement a single use case
such as checkout.
– By Context: decompose the application by noun
and create services responsible for all operations
related to a particular entity such as customer
management.
●
Mixed Action+Context works too.
Maintainability+Easy Refactor
• A component is a unit of software that is
independently replaceable and upgradeable.
• Services as components
– because services are independently deployable
• A service could be deployed on
– a fully controlled server on a container
– serverless (AWS Lambda, Google/Azure cloud
functions…)
– .. or in house of course
1
0
Communication between MS
• REST/Queues
• Remote calls are more
expensive than in-process
calls.
• Remote APIs need to be
coarser-grained
• Change the allocation of
responsibilities between
components.
1
1
Asynchronicity
• No more monolithic app means no more
single thread.
• Each Microservice can be considered as
a separate process
• If a process takes too much to fullfll its
duty it’ll block every one in the stack.
• Microservices must be Asynchronous as
much as possible
1
2
Common Pattern: API GW
1
3
Common Pattern: API GW
1
4
Common Pattern: Multi-API GW
15
WHAT ABOUT SECURITY??
17
A Case Study of Microservice Security
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
1
8
Auth and Authz in MS
1
9
REST REQUEST
'http://localhost:8003/products/the_odyssey'
REST REQUEST
'http://localhost:8003/rest/login'
Auth and Authz in MS
2
0
REST REQUEST
'http://localhost:8003/products/the_odyssey'
REST REQUEST
'http://localhost:8003/rest/login'
RESPONSE:
JWT:
{“user”:”stefano”,”id”: 22}.[CRYPTOGRAFICALLYSIGNED]
Auth and Authz in MS
2
1
REST REQUEST
'http://localhost:8003/products/the_odyssey'
REST REQUEST
'http://localhost:8003/rest/order/54252'
JWT: {“user”:”stefano”,”id”: 22}.
[CRYPTOGRAFICALLYSIGNED]
Is Logged In?
Auth and Authz in MS
2
2
Is Logged In?YES!
REST REQUEST
'http://localhost:8003/rest/order/54252'
JWT: {“user”:”stefano”,”id”: 22}.
[CRYPTOGRAFICALLYSIGNED]
Auth and Authz in MS
2
3
OKAY! GO ON!REST REQUEST
'http://localhost:8003/rest/order/54252'
JWT: {“user”:”stefano”,”id”: 22}.
[CRYPTOGRAFICALLYSIGNED]
Auth and Authz in MS
2
4
REST REQUEST
'http://localhost:8003/products/the_odyssey'
REST REQUEST
'http://localhost:8003/rest/order/54252'
JWT: {“user”:”stefano”,”id”: 22}.
[CRYPTOGRAFICALLYSIGNED]
OKAY! GO ON!
Authorization != Authentication
• Microservices must be aware at some point
who can do/has access to what.
• Design decisions must be made and
implemented.
• Defense in Depth is the most appreciated:
– Implement a Identity Management System
– Each MS will request if token X is allowed to
execute the service.
• Each MS is responsible for the data it manages
2
5
The Fix
2
6
Each MS Should ask if User is allowed
to use the service
The Fix
2
7
Protect data from
Indirect Object Reference!
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
2
8
Order Request
2
9
REST REQUEST
'http://localhost:8003/products/the_odyssey'
REST REQUEST
'http://localhost:8003/rest/products/the_odyssey'
Order Request
3
0
REST REQUEST
'http://localhost:8003/rest/products/the_odyssey'
INTERNAL REST
'http://localhost:8003/product/the_odyssey'
Order Request
3
1
REST REQUEST
'http://localhost:8003/rest/products/the_odyssey'
INTERNAL REST
'http://localhost:8003/product/the_odyssey'
Order Request
3
2
REST REQUEST
'http://localhost:8003/rest/products/the_odyssey'
INTERNAL REST
'http://localhost:8003/product/the_odyssey'
FINAL RESPONSE
{
"id": "the_odyssey",
"title": "The Odyssey",
"passenger_capacity": 101,
"maximum_speed": 5,
"in_stock": 10
}
Order Request
3
3
REST REQUEST
'http://localhost:8003/products/the_odyssey'
LET’S PLACE AN ORDER!
POST http://localhost:8003/orders
{
"order_details": [
{
"product_id": "the_odyssey",
"quantity": 1
}
]
}
Order Request
3
4
REST REQUEST
'http://localhost:8003/products/the_odyssey'
LET’S PLACE AN ORDER!
POST http://localhost:8003/orders
{
"order_details": [
{
"product_id": "the_odyssey",
"quantity": 1
}
]
}
DO WE HAVE ANY
the_odyssey?
Order Request
3
5
REST REQUEST
'http://localhost:8003/products/the_odyssey'
LET’S PLACE AN ORDER!
POST http://localhost:8003/orders
{
"order_details": [
{
"product_id": "the_odyssey",
"quantity": 1
}
]
}
DO WE HAVE ANY
the_odyssey?
YES!
Order Request
3
6
REST REQUEST
'http://localhost:8003/products/the_odyssey'
LET’S PLACE AN ORDER!
POST http://localhost:8003/orders
{
"order_details": [
{
"product_id": "the_odyssey",
"quantity": 1
}
]
}
OKAY!
-1 FOR the_odyssey!
Order Request
3
7
REST REQUEST
'http://localhost:8003/products/the_odyssey'
LET’S PLACE AN ORDER!
POST http://localhost:8003/orders
{
"order_details": [
{
"product_id": "the_odyssey",
"quantity": 1
}
]
}
RESPONSE : {"order_id": 2131}
Beware of Asynchronicity!
3
8
39
Race Condition!
Orders MS
Products
MS
40
Race Condition Schematics
Orders MS Products MSClient Request
1
1
Is the_odyssey in?
Yes!
1
1
-1 the_odyssey
The_odyssey: #1
The_odyssey: #01
Order Placed!
41
Race Condition Schematics
Orders MS Products MSClient Request
The_odyssey: #1
The_odyssey: #0
1
1
Is the_odyssey in?
Yes!
1
1
-1 the_odyssey
1
Order Placed!
2
2
Is the_odyssey in?
Yes!
2
2
-1 the_odyssey
2
Order Placed!
The_odyssey: #-1
The Fix
4
2
THE REST ENDPOINT MUST PERFORM
ATOMIC OPERATION WHEN MULTIPLE
ASYNCRONOUS MS ARE INVOLVED
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
4
3
Requestor MicroService
4
4
REST REQUEST
PUT 'http://localhost:8003/rest/products/the_odyssey'
{“image”:”http://www.imghost.com/image.png”}
Http Request
To retrieve the URL
Requestor MicroService
4
5
REST REQUEST
PUT 'http://localhost:8003/rest/products/the_odyssey'
{“image”:”http://www.imghost.com/image.png”}
Http Request
To retrieve the URL
Requesting Arbitrary URL?
• Feature found several times during the years
• Sometimes correctly implemented.
• Sometimes not.
• Problems: Arbitrary requests to any internal
node.
• It might be called
SSRF By design
4
6
Is this fx correct?
4
7
Is this fx correct?
4
8
The Fix
• Containerize the service
• Deploy the container outside the other
sensitive services network
• Hardenize the container!
• Do not rely on DNS/IP black lists. Easy
to bypass! (at least keep the 1st
resolution!)
• Block requests to 127.0.0.1/8!!
4
9
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
5
0
Rest Gateway
5
1
/user/:id
We discover that PRIVATE SERVER has a
undocumented endpoint
Rest Gateway
5
2
REST REQUEST
http://localhost:8003/rest/user/23
/user/:id
Rest Gateway
5
3
REST REQUEST
http://localhost:8003/rest/user/23
/user/:id
I knew it!
Not Externally Mapped!
You’re not going to pown me!
Rest Gateway
5
4
REST REQUEST
http://localhost:8003/rest/products/%252e%252e%252fuser%252f1
/user/:id
The Attack
• Double Encoding
• %2e => .
• %2f => /
• %25 => %
%252e => %2e => .
%252f => %2f => /
5
5
http://hostname:8003/rest/products/%252e%252e%252fuser%252f1
The Attack
●
API GATEWAY SEES
http://hostname:8003/rest/products/%2e%2e%2fuser%2f1
id= “%2e%2e%2fuser%2f1”
and sends http://privateserver/products/%2e%2e%2fuser
%2f1
But HttpClient/private server normalizes the URL to :
●
http://privateserver/user/1
5
6
http://hostname:8003/rest/products/%252e%252e%252fuser%252f1
PRIVATE SERVER REST APP SEES: /user/1
The Fix
• Apply Defense in depth
– Each MS should validate input data
– Each MS should encode data according to
the context when it’s sent to another layer
– Separate services based on endpoints
sematic groups.
5
7
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services
– PDF Generator
5
8
59
Cloud Functions
The Threat
• In recent months, several articles and blog posts
exposed how malicious attackers are abusing
cloud environments in order to infect them with
crypto-mining malware.
• February 2018, cybersecurity firm Redlock
reported that hackers had secretly infiltrated
public cloud environments and were using the
compute instances to mine cryptocurrencies.
• Cloud Functions fit very well here! (AWS
Lamba, Google Cloud Functions etc…)
• Hardened Containers as well!!
6
0
The Threat
6
1
• One vulnerability is
enough RCE/Code
Injection.
• When you realize you’ve
been attacked it’s
probably too late:
Several $$ have
already been billed.
Eg:
AWS Lambda Scaling:
AWS Lambda will dynamically scale capacity in
response to increased trafic, subject to your
account's Account Level Concurrent Execution Limit.
To handle any burst in trafic, Lambda will
immediately increase your concurrently executing
functions by a predetermined amount, dependent on
which region it's executed
By default, the concurrent execution limit is enforced
against the sum of the concurrent executions of all
functions. The shared concurrent execution pool is
referred to as the unreserved concurrency allocation.
The default is set to 1,000.
Agenda
• Microservices Vs Monolithic Apps
• Security in Microservice Architectures
• Common Services: Security Exposed
– Authorization Flow
– Microservice Events
– Requestor Microservice
– REST Aggregator/Forwarder
– Serverless services.
– PDF Generator
6
2
63
PDF Exporter
The Feature
• Export orders in PDF.
• Application is a Single Page Application using JS
Framework.
• The idea is to use
– WebKitToPDF
– a headless Chrome
– Custom Electron with Webview
• To export the rendered html as pdf.
EASY PEASY!
6
4
The Feature
• Create a local web page using USER data
• Save it as PDF
• Send it back to the USER
• Problem:
– How to build the page?
– How user data is imported?
6
5
The Feature
• POST /create/pdf
htmlData=<body>...</body>
●
Is that a Cross Site Scripting?
●
Yeah but it’s a self XSS, no impact right?
6
6
A Simple Attack
<iframe src=”http://internalHost/”></iframe>
6
7
The Attack
• It’s like having physical access to a browser on a
machine in hosts private network!
• In some case attacker might have access to
Filesystem (I.e read files in host FS)
• Attacker could also execute JavaScript
• ..and even implant a(nother) Cryptominer!
6
8
The Fix
• From a Browser perspective there’s no easy fix
but there’s a set of mitigations, too long to explain
but:
– Set browser to Offline (partially bypasssable)
– Disable JavaScript (bypassable)
– Intercept and block all request (partially
bypassable)
– Close process as soon as possible
• Mostly hardenize the container!!
6
9
Last question:
• How do we deploy?
• Infrastructure as code
• In the repository with
the rest of the code.
• Where are the access
keys and passwords?
• Is the repository
private? To whom?
7
0
Conclusions
• Microservices introduce new (old)
unexpected security scenarios
• Developers and System architects must
work together to generate ad hoc
containers to mitigate by design dangerous
features
• Complexity of the fows requires careful
design in grouping microservices together
• Never underestimate attackers
• Apply defense in depth!!!!
7
1
Questions?
Mail:
stefano.dipaola@mindedsecurity.com
Mobile: +39 3209495590
Global Corporate Site:
http://www.mindedsecurity.com
Blog: http://blog.mindedsecurity.com
Twitter: http://www.twitter.com/mindedsecurity
YouTube:
http://www.youtube.com/user/mindedsecurity
Thanks!
 

More Related Content

PPTX
Security in microservices architectures
PPTX
Zero trust Architecture
PDF
API Security In Cloud Native Era
PPTX
CSA Presentation - Software Defined Perimeter
PDF
[OPD 2019] Web Apps vs Blockchain dApps
PPTX
Cryptzone: The Software-Defined Perimeter
PPTX
Cryptzone AppGate Technical Architecture
PPTX
Operational Complexity: The Biggest Security Threat to Your AWS Environment
Security in microservices architectures
Zero trust Architecture
API Security In Cloud Native Era
CSA Presentation - Software Defined Perimeter
[OPD 2019] Web Apps vs Blockchain dApps
Cryptzone: The Software-Defined Perimeter
Cryptzone AppGate Technical Architecture
Operational Complexity: The Biggest Security Threat to Your AWS Environment

What's hot (20)

PPTX
AppGate: Achieving Compliance in the Cloud
PPTX
Cryptzone: What is a Software-Defined Perimeter?
PDF
[OPD 2019] Threat modeling at scale
PDF
API Security in a Microservices World
PDF
Software Defined Perimeter - A New Paradigm for Securing Digital Infrastructu...
PDF
Identiverse - Microservices Security
PPTX
Web API Management meets the Internet of Things
PPTX
Windows Azure Security & Compliance
PPTX
Securing Microservices with Spring Cloud Security
PDF
Service Mesh vs. Frameworks: Where to put the resilience?
PDF
Centralize and Simplify Secrets Management for Red Hat OpenShift Container En...
PDF
How to integration DataPower with Zos
PDF
Gravitee.io
PPTX
OpenId Connect Protocol
PPTX
Hashitalks 2021 - How the Dynamic Duo of Vault and Puppet Tame SSL Certificates
PDF
[OPD 2019] Trusted types and the end of DOM XSS
PPTX
The Future of PKI. Using automation tools and protocols to bootstrap trust in...
PPTX
Ledingkart Meetup #3: Security Basics for Developers
PDF
Comparison of Current Service Mesh Architectures
PDF
Virtual Meetup - API Security Best Practices
AppGate: Achieving Compliance in the Cloud
Cryptzone: What is a Software-Defined Perimeter?
[OPD 2019] Threat modeling at scale
API Security in a Microservices World
Software Defined Perimeter - A New Paradigm for Securing Digital Infrastructu...
Identiverse - Microservices Security
Web API Management meets the Internet of Things
Windows Azure Security & Compliance
Securing Microservices with Spring Cloud Security
Service Mesh vs. Frameworks: Where to put the resilience?
Centralize and Simplify Secrets Management for Red Hat OpenShift Container En...
How to integration DataPower with Zos
Gravitee.io
OpenId Connect Protocol
Hashitalks 2021 - How the Dynamic Duo of Vault and Puppet Tame SSL Certificates
[OPD 2019] Trusted types and the end of DOM XSS
The Future of PKI. Using automation tools and protocols to bootstrap trust in...
Ledingkart Meetup #3: Security Basics for Developers
Comparison of Current Service Mesh Architectures
Virtual Meetup - API Security Best Practices
Ad

Similar to Microservices Security: dos and don'ts (20)

PPTX
Microservice Pattern Launguage
PPTX
Do You Need A Service Mesh?
PDF
Building data-driven microservices
PPT
Securing elastic applications_on_mobile_devices
PPTX
Microservices: Yes or not?
PPTX
Microservices: A developer's approach
PPTX
Internet of Things and Edge Compute at Chick-fil-A
PPTX
Application security meetup k8_s security with zero trust_29072021
PDF
MongoDB .local London 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
PPTX
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
PPTX
Microservices architecture
PDF
Monoliths, Myths, and Microservices - CfgMgmtCamp
PPTX
Service Discovery and Registration in a Microservices Architecture
PPTX
Microservices-101
PPTX
Webdays blida mobile top 10 risks
PPTX
Grokking microservices in 5 minutes
PDF
170215 msa intro
PDF
APIdays Paris 2019 - RASP for APIs and Microservices by Jean-Baptiste Aviat, ...
PDF
Istio as an Enabler for Migrating Monolithic Applications to Microservices v1.3
PDF
Service Mesh Talk for CTO Forum
Microservice Pattern Launguage
Do You Need A Service Mesh?
Building data-driven microservices
Securing elastic applications_on_mobile_devices
Microservices: Yes or not?
Microservices: A developer's approach
Internet of Things and Edge Compute at Chick-fil-A
Application security meetup k8_s security with zero trust_29072021
MongoDB .local London 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
Microservices architecture
Monoliths, Myths, and Microservices - CfgMgmtCamp
Service Discovery and Registration in a Microservices Architecture
Microservices-101
Webdays blida mobile top 10 risks
Grokking microservices in 5 minutes
170215 msa intro
APIdays Paris 2019 - RASP for APIs and Microservices by Jean-Baptiste Aviat, ...
Istio as an Enabler for Migrating Monolithic Applications to Microservices v1.3
Service Mesh Talk for CTO Forum
Ad

More from Minded Security (15)

PDF
Ieee S&P 2020 - Software Security: from Research to Industry.
PDF
Matteo Meucci - Security Summit 12th March 2019
PDF
Live hacking Demo
PDF
Js deobfuscation with JStillery - bsides-roma 2018
PDF
Matteo Meucci Isaca Venice - 2017
PDF
BlueClosure Pitch - Cybertech Europe 2017
PDF
Minded Security - Fabrizio Bugli - (3rd) party like nobody's watching...
PDF
Matteo meucci Software Security - Napoli 10112016
PDF
Matteo Meucci Software Security in practice - Aiea torino - 30-10-2015
PDF
Advanced JS Deobfuscation
PDF
Sandboxing JS and HTML. A lession Learned
PDF
Concrete5 Sendmail RCE Advisory
PDF
Concrete5 Multiple Reflected XSS Advisory
PDF
PHP Object Injection
PDF
iOS Masque Attack
Ieee S&P 2020 - Software Security: from Research to Industry.
Matteo Meucci - Security Summit 12th March 2019
Live hacking Demo
Js deobfuscation with JStillery - bsides-roma 2018
Matteo Meucci Isaca Venice - 2017
BlueClosure Pitch - Cybertech Europe 2017
Minded Security - Fabrizio Bugli - (3rd) party like nobody's watching...
Matteo meucci Software Security - Napoli 10112016
Matteo Meucci Software Security in practice - Aiea torino - 30-10-2015
Advanced JS Deobfuscation
Sandboxing JS and HTML. A lession Learned
Concrete5 Sendmail RCE Advisory
Concrete5 Multiple Reflected XSS Advisory
PHP Object Injection
iOS Masque Attack

Recently uploaded (20)

PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPT
tcp ip networks nd ip layering assotred slides
PPTX
Introduction to Information and Communication Technology
PPTX
Funds Management Learning Material for Beg
PPTX
Internet___Basics___Styled_ presentation
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PPTX
Digital Literacy And Online Safety on internet
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
522797556-Unit-2-Temperature-measurement-1-1.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
The New Creative Director: How AI Tools for Social Media Content Creation Are...
tcp ip networks nd ip layering assotred slides
Introduction to Information and Communication Technology
Funds Management Learning Material for Beg
Internet___Basics___Styled_ presentation
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Paper PDF World Game (s) Great Redesign.pdf
QR Codes Qr codecodecodecodecocodedecodecode
Digital Literacy And Online Safety on internet
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
SAP Ariba Sourcing PPT for learning material
Job_Card_System_Styled_lorem_ipsum_.pptx
presentation_pfe-universite-molay-seltan.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
An introduction to the IFRS (ISSB) Stndards.pdf

Microservices Security: dos and don'ts

  • 1. Microservices Security: Dos and Don'ts Stefano Di Paola, CTO & Chief Scientist @ Minded Security July 2018 Summit
  • 2. $ whoami • Research – Bug Hunter & Sec Research (Pdf UXSS, Flash Security, HPP, JS Security DOMinator/BlueClosure) – Software Security Since ~'99 – CTO @ Minded Security – Chief Scientist @ Minded Security 2
  • 3. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 3
  • 4. Goal • Talk about Security in Microservices Architectures • Give insights about some of the most interesting issues found in the last years while testing the security of Multilayered Microservices Architectures and how they were fxed • Will not talk about AWS misconfgurations (too much to tell:) 4
  • 6. Why Microservices? • Scalability • Maintainability • Easy Refactor (No language constraint) • Agile SDLC • Fast+Continuous Deploy 6
  • 8. Rings a bell? Procedural vs Object Oriented 8
  • 9. Scalability 9 ● X-axis scaling: scaling an application by running clones behind a load balancer. ● Y-axis scaling: splits the application into multiple, different services. ● The microservice architecture is an application of Y- axis. – Each service is responsible for one or more closely related functions. ● Two ways of decomposing the application into services. – By Action: Verb-based decomposition and define services that implement a single use case such as checkout. – By Context: decompose the application by noun and create services responsible for all operations related to a particular entity such as customer management. ● Mixed Action+Context works too.
  • 10. Maintainability+Easy Refactor • A component is a unit of software that is independently replaceable and upgradeable. • Services as components – because services are independently deployable • A service could be deployed on – a fully controlled server on a container – serverless (AWS Lambda, Google/Azure cloud functions…) – .. or in house of course 1 0
  • 11. Communication between MS • REST/Queues • Remote calls are more expensive than in-process calls. • Remote APIs need to be coarser-grained • Change the allocation of responsibilities between components. 1 1
  • 12. Asynchronicity • No more monolithic app means no more single thread. • Each Microservice can be considered as a separate process • If a process takes too much to fullfll its duty it’ll block every one in the stack. • Microservices must be Asynchronous as much as possible 1 2
  • 17. 17 A Case Study of Microservice Security
  • 18. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 1 8
  • 19. Auth and Authz in MS 1 9 REST REQUEST 'http://localhost:8003/products/the_odyssey' REST REQUEST 'http://localhost:8003/rest/login'
  • 20. Auth and Authz in MS 2 0 REST REQUEST 'http://localhost:8003/products/the_odyssey' REST REQUEST 'http://localhost:8003/rest/login' RESPONSE: JWT: {“user”:”stefano”,”id”: 22}.[CRYPTOGRAFICALLYSIGNED]
  • 21. Auth and Authz in MS 2 1 REST REQUEST 'http://localhost:8003/products/the_odyssey' REST REQUEST 'http://localhost:8003/rest/order/54252' JWT: {“user”:”stefano”,”id”: 22}. [CRYPTOGRAFICALLYSIGNED] Is Logged In?
  • 22. Auth and Authz in MS 2 2 Is Logged In?YES! REST REQUEST 'http://localhost:8003/rest/order/54252' JWT: {“user”:”stefano”,”id”: 22}. [CRYPTOGRAFICALLYSIGNED]
  • 23. Auth and Authz in MS 2 3 OKAY! GO ON!REST REQUEST 'http://localhost:8003/rest/order/54252' JWT: {“user”:”stefano”,”id”: 22}. [CRYPTOGRAFICALLYSIGNED]
  • 24. Auth and Authz in MS 2 4 REST REQUEST 'http://localhost:8003/products/the_odyssey' REST REQUEST 'http://localhost:8003/rest/order/54252' JWT: {“user”:”stefano”,”id”: 22}. [CRYPTOGRAFICALLYSIGNED] OKAY! GO ON!
  • 25. Authorization != Authentication • Microservices must be aware at some point who can do/has access to what. • Design decisions must be made and implemented. • Defense in Depth is the most appreciated: – Implement a Identity Management System – Each MS will request if token X is allowed to execute the service. • Each MS is responsible for the data it manages 2 5
  • 26. The Fix 2 6 Each MS Should ask if User is allowed to use the service
  • 27. The Fix 2 7 Protect data from Indirect Object Reference!
  • 28. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 2 8
  • 29. Order Request 2 9 REST REQUEST 'http://localhost:8003/products/the_odyssey' REST REQUEST 'http://localhost:8003/rest/products/the_odyssey'
  • 32. Order Request 3 2 REST REQUEST 'http://localhost:8003/rest/products/the_odyssey' INTERNAL REST 'http://localhost:8003/product/the_odyssey' FINAL RESPONSE { "id": "the_odyssey", "title": "The Odyssey", "passenger_capacity": 101, "maximum_speed": 5, "in_stock": 10 }
  • 33. Order Request 3 3 REST REQUEST 'http://localhost:8003/products/the_odyssey' LET’S PLACE AN ORDER! POST http://localhost:8003/orders { "order_details": [ { "product_id": "the_odyssey", "quantity": 1 } ] }
  • 34. Order Request 3 4 REST REQUEST 'http://localhost:8003/products/the_odyssey' LET’S PLACE AN ORDER! POST http://localhost:8003/orders { "order_details": [ { "product_id": "the_odyssey", "quantity": 1 } ] } DO WE HAVE ANY the_odyssey?
  • 35. Order Request 3 5 REST REQUEST 'http://localhost:8003/products/the_odyssey' LET’S PLACE AN ORDER! POST http://localhost:8003/orders { "order_details": [ { "product_id": "the_odyssey", "quantity": 1 } ] } DO WE HAVE ANY the_odyssey? YES!
  • 36. Order Request 3 6 REST REQUEST 'http://localhost:8003/products/the_odyssey' LET’S PLACE AN ORDER! POST http://localhost:8003/orders { "order_details": [ { "product_id": "the_odyssey", "quantity": 1 } ] } OKAY! -1 FOR the_odyssey!
  • 37. Order Request 3 7 REST REQUEST 'http://localhost:8003/products/the_odyssey' LET’S PLACE AN ORDER! POST http://localhost:8003/orders { "order_details": [ { "product_id": "the_odyssey", "quantity": 1 } ] } RESPONSE : {"order_id": 2131}
  • 40. 40 Race Condition Schematics Orders MS Products MSClient Request 1 1 Is the_odyssey in? Yes! 1 1 -1 the_odyssey The_odyssey: #1 The_odyssey: #01 Order Placed!
  • 41. 41 Race Condition Schematics Orders MS Products MSClient Request The_odyssey: #1 The_odyssey: #0 1 1 Is the_odyssey in? Yes! 1 1 -1 the_odyssey 1 Order Placed! 2 2 Is the_odyssey in? Yes! 2 2 -1 the_odyssey 2 Order Placed! The_odyssey: #-1
  • 42. The Fix 4 2 THE REST ENDPOINT MUST PERFORM ATOMIC OPERATION WHEN MULTIPLE ASYNCRONOUS MS ARE INVOLVED
  • 43. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 4 3
  • 44. Requestor MicroService 4 4 REST REQUEST PUT 'http://localhost:8003/rest/products/the_odyssey' {“image”:”http://www.imghost.com/image.png”} Http Request To retrieve the URL
  • 45. Requestor MicroService 4 5 REST REQUEST PUT 'http://localhost:8003/rest/products/the_odyssey' {“image”:”http://www.imghost.com/image.png”} Http Request To retrieve the URL
  • 46. Requesting Arbitrary URL? • Feature found several times during the years • Sometimes correctly implemented. • Sometimes not. • Problems: Arbitrary requests to any internal node. • It might be called SSRF By design 4 6
  • 47. Is this fx correct? 4 7
  • 48. Is this fx correct? 4 8
  • 49. The Fix • Containerize the service • Deploy the container outside the other sensitive services network • Hardenize the container! • Do not rely on DNS/IP black lists. Easy to bypass! (at least keep the 1st resolution!) • Block requests to 127.0.0.1/8!! 4 9
  • 50. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 5 0
  • 51. Rest Gateway 5 1 /user/:id We discover that PRIVATE SERVER has a undocumented endpoint
  • 53. Rest Gateway 5 3 REST REQUEST http://localhost:8003/rest/user/23 /user/:id I knew it! Not Externally Mapped! You’re not going to pown me!
  • 55. The Attack • Double Encoding • %2e => . • %2f => / • %25 => % %252e => %2e => . %252f => %2f => / 5 5 http://hostname:8003/rest/products/%252e%252e%252fuser%252f1
  • 56. The Attack ● API GATEWAY SEES http://hostname:8003/rest/products/%2e%2e%2fuser%2f1 id= “%2e%2e%2fuser%2f1” and sends http://privateserver/products/%2e%2e%2fuser %2f1 But HttpClient/private server normalizes the URL to : ● http://privateserver/user/1 5 6 http://hostname:8003/rest/products/%252e%252e%252fuser%252f1 PRIVATE SERVER REST APP SEES: /user/1
  • 57. The Fix • Apply Defense in depth – Each MS should validate input data – Each MS should encode data according to the context when it’s sent to another layer – Separate services based on endpoints sematic groups. 5 7
  • 58. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services – PDF Generator 5 8
  • 60. The Threat • In recent months, several articles and blog posts exposed how malicious attackers are abusing cloud environments in order to infect them with crypto-mining malware. • February 2018, cybersecurity firm Redlock reported that hackers had secretly infiltrated public cloud environments and were using the compute instances to mine cryptocurrencies. • Cloud Functions fit very well here! (AWS Lamba, Google Cloud Functions etc…) • Hardened Containers as well!! 6 0
  • 61. The Threat 6 1 • One vulnerability is enough RCE/Code Injection. • When you realize you’ve been attacked it’s probably too late: Several $$ have already been billed. Eg: AWS Lambda Scaling: AWS Lambda will dynamically scale capacity in response to increased trafic, subject to your account's Account Level Concurrent Execution Limit. To handle any burst in trafic, Lambda will immediately increase your concurrently executing functions by a predetermined amount, dependent on which region it's executed By default, the concurrent execution limit is enforced against the sum of the concurrent executions of all functions. The shared concurrent execution pool is referred to as the unreserved concurrency allocation. The default is set to 1,000.
  • 62. Agenda • Microservices Vs Monolithic Apps • Security in Microservice Architectures • Common Services: Security Exposed – Authorization Flow – Microservice Events – Requestor Microservice – REST Aggregator/Forwarder – Serverless services. – PDF Generator 6 2
  • 64. The Feature • Export orders in PDF. • Application is a Single Page Application using JS Framework. • The idea is to use – WebKitToPDF – a headless Chrome – Custom Electron with Webview • To export the rendered html as pdf. EASY PEASY! 6 4
  • 65. The Feature • Create a local web page using USER data • Save it as PDF • Send it back to the USER • Problem: – How to build the page? – How user data is imported? 6 5
  • 66. The Feature • POST /create/pdf htmlData=<body>...</body> ● Is that a Cross Site Scripting? ● Yeah but it’s a self XSS, no impact right? 6 6
  • 67. A Simple Attack <iframe src=”http://internalHost/”></iframe> 6 7
  • 68. The Attack • It’s like having physical access to a browser on a machine in hosts private network! • In some case attacker might have access to Filesystem (I.e read files in host FS) • Attacker could also execute JavaScript • ..and even implant a(nother) Cryptominer! 6 8
  • 69. The Fix • From a Browser perspective there’s no easy fix but there’s a set of mitigations, too long to explain but: – Set browser to Offline (partially bypasssable) – Disable JavaScript (bypassable) – Intercept and block all request (partially bypassable) – Close process as soon as possible • Mostly hardenize the container!! 6 9
  • 70. Last question: • How do we deploy? • Infrastructure as code • In the repository with the rest of the code. • Where are the access keys and passwords? • Is the repository private? To whom? 7 0
  • 71. Conclusions • Microservices introduce new (old) unexpected security scenarios • Developers and System architects must work together to generate ad hoc containers to mitigate by design dangerous features • Complexity of the fows requires careful design in grouping microservices together • Never underestimate attackers • Apply defense in depth!!!! 7 1
  • 72. Questions? Mail: stefano.dipaola@mindedsecurity.com Mobile: +39 3209495590 Global Corporate Site: http://www.mindedsecurity.com Blog: http://blog.mindedsecurity.com Twitter: http://www.twitter.com/mindedsecurity YouTube: http://www.youtube.com/user/mindedsecurity Thanks!