SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Building Container
Defence an
Executable at a Time
Suraj Deshmukh
About Me
• Senior Software Engineer at Microsoft.
• Kubernetes Bangalore Meetup organizer.
• Find me at:
@surajd_
suraj.io
surajd.service@gmail.com
Threat Model
• An attacker who has container’s shell access tries to do malicious
activities using the container’s identity, network, cloud privileges,
volume and secret, etc.
Attack Vector
• Attacker tries to write and execute binaries to container filesystem.
• Mitigation/Defense:
• Disallow execution of binaries not shipped with container image.
Existing Solutions
• Read-only filesystem
• /dev partition is still writable.
• Scratch base image
• Only suitable for apps with static binaries.
New Solution
Know about binary execution even before it is executed from inside the container!
Container
rootfs
Policy
Enforcer
Executing Binary /bin/foo
✅ OR ❌
How do you get those notifications?
• Enter fanotify
• A filesystem notification framework in Linux.
What is fanotify?
From fanotify man page:
The fanotify API provides notification and interception of filesystem
events. Use cases include virus scanning and hierarchical storage
management.
… monitor all of the objects in a mounted filesystem, make access
permission decisions, and the possibility to read or modify files before
access by other applications.
Source: https://man7.org/linux/man-pages/man7/fanotify.7.html
Fanotify in Action
Container
Runtime
Container App Kernel
1. Unpack rootfs
2. New container created?
3. Yes
4. Monitor container rootfs
5. File descriptor
6. Execute binary /bin/foo
7. Execute binary /bin/foo ?
8. Allow
9. Execute binary /bin/bar
10. Execute binary /bin/bar ?
11. Deny
12. EPERM: Operation not permitted
Fanotify as system calls
int fanotify_init(unsigned int flags, unsigned int event_f_flags);
int fanotify_mark(int fanotify_fd, unsigned int flags, uint64_t mask,
int dirfd, const char *pathname);
• Watch the rootfs of the container.
• Send events/notifications when a permission to open a file for
execution is requested i.e. FAN_OPEN_EXEC_PERM.
/* Create an fanotify file descriptor with unlimited queue and unlimited
marks */
fd = fanotify_init(FAN_CLASS_CONTENT | FAN_UNLIMITED_QUEUE |
FAN_UNLIMITED_MARKS,
O_RDONLY | O_LARGEFILE | O_CLOEXEC);
/* Place a mark on the container's rootfs. Which can be derived from the
container's PID1 and looks like /proc/PID/root. */
ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
AT_FDCWD, path);
Design 1: Policy Enforcer for Containers
• Runtime Verifier using diff APIs.
Detour: Layers in container image
$ docker run --name=example
-it fedora /bin/bash -c
'touch foobar && rm
/usr/bin/touch'
$ docker diff example
A /foobar
C /usr
C /usr/bin
D /usr/bin/touch
Container
image layer
Container
layer
Union
Filesystem
/foobar
/foobar
/usr/bin/touch
❌
Runtime Verifier
Kernel App
1. Executing /bin/foo
2. Get the current diff in layer 0
3. Current diff in layer 0
4. Check if binary path
exists in returned diff
5. Allow if binary not in diff
5. Deny if binary in diff
Container
Runtime
Design 2: Policy Enforcer for Containers
• Pre-run: Trusted Source of Truth
• Runtime Verifier using above “Source of Truth”.
Pre-run: Trusted Source of Truth
• Source of truth is a list of binaries
and their hashes/signatures.
• Trusted sources:
• An image built with that metadata in
a “Secure Software Supply Chain”
environment.
• Calculate the hashes after rootfs has
been unpacked and before PID1 of
container starts.
• A service that calculates the hashes of
binaries in the image and provides
that over a REST call.
42a340d1ff0747a52db7b372eeb906d8a6de6c0d0627265
f2f09ddfefd2b0ce2 /usr/bin/ls
598bb15167292c328a9869e5cc301f3d4f92ec0a7f9bc91
351203844d70ff94e /usr/bin/cp
6a4a2172c6a818d218bc28384b9ccc068791c2f0d980775
287f47ca5d2591cbc /usr/bin/touch
6a4833060350d2434944d5d35693ac02bf0c869623e4918
4d2ea20adaf47c107 /usr/bin/less
c34dfda3e53b26d9b09ec3b1ac03ea25b04977736ab5b39
9410ddfb09748ec45 /usr/bin/awk
3f794988bc9b6e734d06c6507b4335054d01760a741b601
04a49543cf7a964ed /usr/bin/cd
581975f0d51f108bf51714664406f98fbef25a14da6d29f
f84840e2c89fc6350 /usr/bin/cat
6443adf01b4bac47cc87f41a293130431f42b1c31c09568
f4a3dc548c5e644f2 /usr/bin/chmod
Runtime Verifier
Kernel App Filesystem
1. Executing /bin/foo
2. Calculate current hash of
/bin/foo in rootfs
3. Current hash
4. Match current hash
with existing hash
5. Allow if hashes match
5. Deny if hashes don’t match
Design 1 vs Design 2
Design 1 Design 2
Does not need pre-computed hashes. Needs pre-computed hashes to function.
Depends on the container runtime to provide diffs. Container runtime agnostic.
Adds dependency on the runtime to be online. Regardless of uptime of runtime, it will continue to
run.
Policy Enforcer App
• Standalone app that runs as a daemon (using systemd or Kubernetes
Daemonset).
• Pros: Flexible in policy change enforcement, can be backed by an operator,
ease of deployment.
• Cons: A single daemon monitoring all node containers, can have late start
issues.
• Code as a part of custom containerd-shim.
• Pros: A single-daemon single-container mapping.
• Cons: Inflexibility in policy change enforcement, needs changes to installation
processes.
Advantages over the existing solutions
• Read-only filesystem
• Everything is writable but not executable.
• Scratch base image
• Run apps needing interpreter without fear of being compromised because of
the baggage.
Demo
Disadvantages of Fanotify based eventing
• Userspace program could slow down the container application due to
the kernel-mode user-mode transition, hash-calculation, etc.
• Limited by memory available for storing events.
• Events could be bypassed using memfd.
• Streaming scripts to interpreter like Python.
• Possibility to create deadlocks.
Roadmap
• A fine-grained policy allowing user to provide allowlist and denylist of
paths.
• Disallow apps from using STDIN as input.**
Further Links
• Application code
• Recording of the talk

Weitere ähnliche Inhalte

Ähnlich wie Building Container Defence Executable at a Time.pdf

WTF my container just spawned a shell!
WTF my container just spawned a shell!WTF my container just spawned a shell!
WTF my container just spawned a shell!Sysdig
 
Contain your risk: Deploy secure containers with trust and confidence
Contain your risk: Deploy secure containers with trust and confidenceContain your risk: Deploy secure containers with trust and confidence
Contain your risk: Deploy secure containers with trust and confidenceBlack Duck by Synopsys
 
"Docker best practice", Станислав Коленкин (senior devops, DataArt)
"Docker best practice", Станислав Коленкин (senior devops, DataArt)"Docker best practice", Станислав Коленкин (senior devops, DataArt)
"Docker best practice", Станислав Коленкин (senior devops, DataArt)DataArt
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworksphanleson
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned RightScale
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Paul Jones
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Paul Jones
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)ClubHack
 
Designing a Docker Stack for Symfony apps: lessons learned
Designing a Docker Stack  for Symfony apps: lessons learnedDesigning a Docker Stack  for Symfony apps: lessons learned
Designing a Docker Stack for Symfony apps: lessons learnedGaetano Giunta
 
Hackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we MakeHackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we Makeesben1962
 
VM vs Docker-Based Pipelines
VM vs Docker-Based PipelinesVM vs Docker-Based Pipelines
VM vs Docker-Based PipelinesCodefresh
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build TechnologyPhilip Johnson
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersRyanISI
 
Effectively using Open Source with conda
Effectively using Open Source with condaEffectively using Open Source with conda
Effectively using Open Source with condaTravis Oliphant
 
Docker Security
Docker SecurityDocker Security
Docker Securityantitree
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC DeploymentsSujit Kumar
 
Vulnex app secusa2013
Vulnex app secusa2013Vulnex app secusa2013
Vulnex app secusa2013drewz lin
 

Ähnlich wie Building Container Defence Executable at a Time.pdf (20)

WTF my container just spawned a shell!
WTF my container just spawned a shell!WTF my container just spawned a shell!
WTF my container just spawned a shell!
 
Contain your risk: Deploy secure containers with trust and confidence
Contain your risk: Deploy secure containers with trust and confidenceContain your risk: Deploy secure containers with trust and confidence
Contain your risk: Deploy secure containers with trust and confidence
 
Securing Docker Containers
Securing Docker ContainersSecuring Docker Containers
Securing Docker Containers
 
"Docker best practice", Станислав Коленкин (senior devops, DataArt)
"Docker best practice", Станислав Коленкин (senior devops, DataArt)"Docker best practice", Станислав Коленкин (senior devops, DataArt)
"Docker best practice", Станислав Коленкин (senior devops, DataArt)
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)
 
Designing a Docker Stack for Symfony apps: lessons learned
Designing a Docker Stack  for Symfony apps: lessons learnedDesigning a Docker Stack  for Symfony apps: lessons learned
Designing a Docker Stack for Symfony apps: lessons learned
 
Docker best Practices
Docker best PracticesDocker best Practices
Docker best Practices
 
Hackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we MakeHackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we Make
 
VM vs Docker-Based Pipelines
VM vs Docker-Based PipelinesVM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build Technology
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for Beginners
 
Wissbi osdc pdf
Wissbi osdc pdfWissbi osdc pdf
Wissbi osdc pdf
 
Effectively using Open Source with conda
Effectively using Open Source with condaEffectively using Open Source with conda
Effectively using Open Source with conda
 
Docker Security
Docker SecurityDocker Security
Docker Security
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
 
Vulnex app secusa2013
Vulnex app secusa2013Vulnex app secusa2013
Vulnex app secusa2013
 

Mehr von Suraj Deshmukh

Kubernetes psp and beyond
Kubernetes psp and beyondKubernetes psp and beyond
Kubernetes psp and beyondSuraj Deshmukh
 
Hardening Kubernetes by Securing Pods
Hardening Kubernetes by Securing PodsHardening Kubernetes by Securing Pods
Hardening Kubernetes by Securing PodsSuraj Deshmukh
 
Kubernetes Security Updates from Kubecon 2018 Seattle
Kubernetes Security Updates from Kubecon 2018 SeattleKubernetes Security Updates from Kubecon 2018 Seattle
Kubernetes Security Updates from Kubecon 2018 SeattleSuraj Deshmukh
 
Making kubernetes simple for developers
Making kubernetes simple for developersMaking kubernetes simple for developers
Making kubernetes simple for developersSuraj Deshmukh
 
Microservices on Kubernetes - The simple way
Microservices on Kubernetes - The simple wayMicroservices on Kubernetes - The simple way
Microservices on Kubernetes - The simple waySuraj Deshmukh
 
Taking containers from development to production
Taking containers from development to productionTaking containers from development to production
Taking containers from development to productionSuraj Deshmukh
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golangSuraj Deshmukh
 
What's new in kubernetes 1.3?
What's new in kubernetes 1.3?What's new in kubernetes 1.3?
What's new in kubernetes 1.3?Suraj Deshmukh
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytestSuraj Deshmukh
 
OpenShift meetup Bangalore
OpenShift meetup BangaloreOpenShift meetup Bangalore
OpenShift meetup BangaloreSuraj Deshmukh
 

Mehr von Suraj Deshmukh (13)

Kubernetes psp and beyond
Kubernetes psp and beyondKubernetes psp and beyond
Kubernetes psp and beyond
 
Hardening Kubernetes by Securing Pods
Hardening Kubernetes by Securing PodsHardening Kubernetes by Securing Pods
Hardening Kubernetes by Securing Pods
 
Kubernetes Security Updates from Kubecon 2018 Seattle
Kubernetes Security Updates from Kubecon 2018 SeattleKubernetes Security Updates from Kubecon 2018 Seattle
Kubernetes Security Updates from Kubecon 2018 Seattle
 
Making kubernetes simple for developers
Making kubernetes simple for developersMaking kubernetes simple for developers
Making kubernetes simple for developers
 
Microservices on Kubernetes - The simple way
Microservices on Kubernetes - The simple wayMicroservices on Kubernetes - The simple way
Microservices on Kubernetes - The simple way
 
Kubernetes on CRI-O
Kubernetes on CRI-OKubernetes on CRI-O
Kubernetes on CRI-O
 
Taking containers from development to production
Taking containers from development to productionTaking containers from development to production
Taking containers from development to production
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
 
What's new in kubernetes 1.3?
What's new in kubernetes 1.3?What's new in kubernetes 1.3?
What's new in kubernetes 1.3?
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
OpenShift meetup Bangalore
OpenShift meetup BangaloreOpenShift meetup Bangalore
OpenShift meetup Bangalore
 
macvlan and ipvlan
macvlan and ipvlanmacvlan and ipvlan
macvlan and ipvlan
 
Henge
HengeHenge
Henge
 

Kürzlich hochgeladen

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 

Kürzlich hochgeladen (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Building Container Defence Executable at a Time.pdf

  • 1. Building Container Defence an Executable at a Time Suraj Deshmukh
  • 2. About Me • Senior Software Engineer at Microsoft. • Kubernetes Bangalore Meetup organizer. • Find me at: @surajd_ suraj.io surajd.service@gmail.com
  • 3. Threat Model • An attacker who has container’s shell access tries to do malicious activities using the container’s identity, network, cloud privileges, volume and secret, etc.
  • 4. Attack Vector • Attacker tries to write and execute binaries to container filesystem. • Mitigation/Defense: • Disallow execution of binaries not shipped with container image.
  • 5. Existing Solutions • Read-only filesystem • /dev partition is still writable. • Scratch base image • Only suitable for apps with static binaries.
  • 6. New Solution Know about binary execution even before it is executed from inside the container! Container rootfs Policy Enforcer Executing Binary /bin/foo ✅ OR ❌
  • 7. How do you get those notifications? • Enter fanotify • A filesystem notification framework in Linux.
  • 8. What is fanotify? From fanotify man page: The fanotify API provides notification and interception of filesystem events. Use cases include virus scanning and hierarchical storage management. … monitor all of the objects in a mounted filesystem, make access permission decisions, and the possibility to read or modify files before access by other applications. Source: https://man7.org/linux/man-pages/man7/fanotify.7.html
  • 9. Fanotify in Action Container Runtime Container App Kernel 1. Unpack rootfs 2. New container created? 3. Yes 4. Monitor container rootfs 5. File descriptor 6. Execute binary /bin/foo 7. Execute binary /bin/foo ? 8. Allow 9. Execute binary /bin/bar 10. Execute binary /bin/bar ? 11. Deny 12. EPERM: Operation not permitted
  • 10. Fanotify as system calls int fanotify_init(unsigned int flags, unsigned int event_f_flags); int fanotify_mark(int fanotify_fd, unsigned int flags, uint64_t mask, int dirfd, const char *pathname);
  • 11. • Watch the rootfs of the container. • Send events/notifications when a permission to open a file for execution is requested i.e. FAN_OPEN_EXEC_PERM. /* Create an fanotify file descriptor with unlimited queue and unlimited marks */ fd = fanotify_init(FAN_CLASS_CONTENT | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS, O_RDONLY | O_LARGEFILE | O_CLOEXEC); /* Place a mark on the container's rootfs. Which can be derived from the container's PID1 and looks like /proc/PID/root. */ ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD, AT_FDCWD, path);
  • 12. Design 1: Policy Enforcer for Containers • Runtime Verifier using diff APIs.
  • 13. Detour: Layers in container image $ docker run --name=example -it fedora /bin/bash -c 'touch foobar && rm /usr/bin/touch' $ docker diff example A /foobar C /usr C /usr/bin D /usr/bin/touch Container image layer Container layer Union Filesystem /foobar /foobar /usr/bin/touch ❌
  • 14. Runtime Verifier Kernel App 1. Executing /bin/foo 2. Get the current diff in layer 0 3. Current diff in layer 0 4. Check if binary path exists in returned diff 5. Allow if binary not in diff 5. Deny if binary in diff Container Runtime
  • 15. Design 2: Policy Enforcer for Containers • Pre-run: Trusted Source of Truth • Runtime Verifier using above “Source of Truth”.
  • 16. Pre-run: Trusted Source of Truth • Source of truth is a list of binaries and their hashes/signatures. • Trusted sources: • An image built with that metadata in a “Secure Software Supply Chain” environment. • Calculate the hashes after rootfs has been unpacked and before PID1 of container starts. • A service that calculates the hashes of binaries in the image and provides that over a REST call. 42a340d1ff0747a52db7b372eeb906d8a6de6c0d0627265 f2f09ddfefd2b0ce2 /usr/bin/ls 598bb15167292c328a9869e5cc301f3d4f92ec0a7f9bc91 351203844d70ff94e /usr/bin/cp 6a4a2172c6a818d218bc28384b9ccc068791c2f0d980775 287f47ca5d2591cbc /usr/bin/touch 6a4833060350d2434944d5d35693ac02bf0c869623e4918 4d2ea20adaf47c107 /usr/bin/less c34dfda3e53b26d9b09ec3b1ac03ea25b04977736ab5b39 9410ddfb09748ec45 /usr/bin/awk 3f794988bc9b6e734d06c6507b4335054d01760a741b601 04a49543cf7a964ed /usr/bin/cd 581975f0d51f108bf51714664406f98fbef25a14da6d29f f84840e2c89fc6350 /usr/bin/cat 6443adf01b4bac47cc87f41a293130431f42b1c31c09568 f4a3dc548c5e644f2 /usr/bin/chmod
  • 17. Runtime Verifier Kernel App Filesystem 1. Executing /bin/foo 2. Calculate current hash of /bin/foo in rootfs 3. Current hash 4. Match current hash with existing hash 5. Allow if hashes match 5. Deny if hashes don’t match
  • 18. Design 1 vs Design 2 Design 1 Design 2 Does not need pre-computed hashes. Needs pre-computed hashes to function. Depends on the container runtime to provide diffs. Container runtime agnostic. Adds dependency on the runtime to be online. Regardless of uptime of runtime, it will continue to run.
  • 19. Policy Enforcer App • Standalone app that runs as a daemon (using systemd or Kubernetes Daemonset). • Pros: Flexible in policy change enforcement, can be backed by an operator, ease of deployment. • Cons: A single daemon monitoring all node containers, can have late start issues. • Code as a part of custom containerd-shim. • Pros: A single-daemon single-container mapping. • Cons: Inflexibility in policy change enforcement, needs changes to installation processes.
  • 20. Advantages over the existing solutions • Read-only filesystem • Everything is writable but not executable. • Scratch base image • Run apps needing interpreter without fear of being compromised because of the baggage.
  • 21. Demo
  • 22. Disadvantages of Fanotify based eventing • Userspace program could slow down the container application due to the kernel-mode user-mode transition, hash-calculation, etc. • Limited by memory available for storing events. • Events could be bypassed using memfd. • Streaming scripts to interpreter like Python. • Possibility to create deadlocks.
  • 23. Roadmap • A fine-grained policy allowing user to provide allowlist and denylist of paths. • Disallow apps from using STDIN as input.**
  • 24. Further Links • Application code • Recording of the talk