{{announcement.body}}
{{announcement.title}}

Security With Falco

DZone 's Guide to

Security With Falco

Securing a container platform is a multi-step process spanning from development to production. Find out what steps to take!

· Security Zone ·
Free Resource

Introduction

Securing a container platform is a multi-step process spanning from development to production. The process of securing containers is continuous. It should be integrated into your development process, automated to remove the number of manual touchpoints, and extended into the maintenance and operation of the underlying infrastructure. Container security thus is the process of implementing security tools and policies to ensure that your container is running as intended.  

docker containerThere are a lot of Docker security practices and Kubernetes security practices. But there are gaps: there could be Image vulnerabilities or container abnormalities still. Some of these can be captured and addressed using various static container image scanning tools. But there is a need to analyze the container behavior at run-time to detect any bogus configurations, which are intentional or not, leading to data loss, security intrusions, and eventually leading to different vulnerabilities. If a container is not running as expected, then it could attack that exploited an existing vulnerability. So the run-time container scanning is essential to detect any action that deviates from the norm.

There are a lot of exposed Kubernetes dashboards or exposed Kubelet APIs because people are opening every port to the internet.

“Runtime security is a critical piece in a cloud-native security story, said Kris Nova, Sysdig’s chief open source advocate. “Access control and policy enforcement are important prevention techniques, but runtime security is needed to detect threats that evade preventions.” 

Falco

Falco (created originally by Sysdig company) is an open-source run-time behavioral activity monitor for container-native infrastructure. Its a CNCF incubator project and Falco software have become the de-facto open-source standard for cloud-native runtime security.  Falco focuses on behavior monitoring. 

FalcoFalco gains visibility inside the containers through system call instrumentation, with great performance and very little overhead, so can run in production systems. System call instrumentation is completely transparent to the containers, so there is no need to modify the code, container images, or inject or preload libraries. System call interception is done either through a simple kernel module dynamically compiled with DKMS or through an eBPF probe.

When an anomalous activity is detected, a security event is logged and alert is triggered based on the rules and policies that we can define in the software (similar to tcpdump and sysdig rules). We can write custom rules also as needed. Falco is container-native, so rules and alerts are going to understand what is a process but also a container or a Kubernetes pod.

Problems That Falco Detects

1. Are the hosts or containers doing something that they should not?

2. Are there any spawned or unexpected processes running in the container?

3. Any changes to the running container configuration detected?

4. Any new ports opened or any unexpected network activity happened?

5. Does any user spawn a shell into the container?

Falco Architecture

Falco can detect and alert on any behavior that involves making Linux system calls. Falco alerts can be triggered by the use of specific system calls, their arguments, and by properties of the calling process.  Falco operates at the user space and kernel space. The system calls are interpreted by the Falco kernel module. The syscalls are then analyzed using the sysdig libraries in the userspace. The events are then filtered using a rules engine where the Falco rules expressions are configured. Suspicious events are then alerted to an output mechanism, configured as Syslog, files, or stdout solutions. 

Falco architecture

Falco Detection Workflow in Kubernetes

Falco also helps to capture K8 audit events. K8s audit events provide a chronological set of records documenting changes to cluster and each record is a JSON object. The detection workflow is the same as explained in the earlier section. 

falco workflow

falco rules

Falco Runtime Monitoring Solution in K8 Cluster

Falco can be integrated with an external monitoring solution like EFK or ELK. For Demo purposes, implemented below solution in a Kubernetes cluster on AWS. 

Falco Clustering

Steps to implement:

1. Bring up an AWS cluster with one master and two nodes. 

2. Falco was installed directly on each of the host systems using the below commands. 

Plain Text
 




xxxxxxxxxx
1


 
1
curl -s https://falco.org/repo/falcosecurity-3672BA8F.asc | apt-key add - echo "deb https://dl.bintray.com/falcosecurity/deb stable main" | tee -a /etc/apt/sources.list.d/falcosecurity.list apt-get update -y


Plain Text
 




xxxxxxxxxx
1


 
1
apt-get -y install linux-headers-$(uname -r)


Plain Text
 




xxxxxxxxxx
1


 
1
apt-get install -y falco


2. Falco runs as a service on each of the nodes.

Plain Text
 




xxxxxxxxxx
1


 
1
 systemctl start falco


3. Once Falco services are running, we have to change the /etc/Falco/Falco.YAML file, and enable jso output to true. Also, configure the file path where Falco logs will be captured.  

YAML
 




xxxxxxxxxx
1
10


 
1
# Whether to output events in json or text
2
 
          
3
json_output: true
4
file_output:
5
 
          
6
  enabled: true
7
 
          
8
  keep_alive: false
9
 
          
10
  filename: /etc/falco/falco.txt



4. Restart Falco daemon on the nodes. 

5. Falco will start monitoring and redirect the logs to /etc/falco/falco.txt

6. Install filebeats and ELK stack using helm charts. 

7. In the Filebeats YAML file, change to include Falco log output path. 

8. Open Kibana and you can configure different reports from Falco configured as:

 >>> Table of Falco alerts by Kubernetes Node

  • Split Rows
  • Aggregation: Significant Terms
  • Field: Kubernetes.host.keyword
  • Count: 20

 >>> Pie chart of top 10 Falco rules triggered.

  • Split Slices
  • Aggregation: Significant Terms
  • Field: rule.keyword
  • Count: 10 

>>> Area chart of all Falco alerts over time.

  • Aggregation: Date Histogram
  • Field: @timestamp
  • Interval: Minute

Some of the error logs captured are:

Plain Text
 




xxxxxxxxxx
1
15


 
1
{"output":"13:35:55.104817000: Notice Privileged container started 
2
 
          
3
{"output":"13:37:18.578581433: Error File below /etc opened for writing
4
 
          
5
{"output":"13:36:21.084924818: Notice Namespace change (setns) by unexpected program 
6
 
          
7
{"output":"13:37:24.618659538: Error File below a known binary directory opened for writing 
8
 
          
9
{"output":"13:37:27.714296811: Notice Unexpected setuid call by non-sudo, non-root program 
10
 
          
11
{"output":"13:37:41.848085676: Warning Sensitive file opened for reading by trusted program after startup 
12
 
          
13
{"output":"13:37:50.994157670: Error Rpm database opened for writing by a non-rpm program 
14
 
          
15
{"output":"13:37:21.617518572: Notice System user ran an interactive command 


Falco alerts

NOTE:  The above is the most secure way of running Falco. We can also install Falco using a helm chart. Falco install using Helm is generally as follows :

Plain Text
 




xxxxxxxxxx
1


 
1
 helm repo add falcosecurity https://falcosecurity.github.io/charts



Plain Text
 




xxxxxxxxxx
1


 
1
helm repo update


Plain Text
 




xxxxxxxxxx
1


 
1
helm install falco falcosecurity/falco


 This will result in a Falco Pod being deployed to each node (including master), and thus the ability to monitor any running containers for abnormal behavior.

Falco agents will be spinning up on each node in the cluster. After a few seconds, they will start monitoring the containers looking for security issues. 

Configuration Inputs (Custom Files)

 The values.yaml that have the parameter values to be set during the Falco install.  The JSON output and the file log path can be changed in the values.yaml. 

Plain Text
 




xxxxxxxxxx
1


 
1
helm install falco -f values.yaml falcosecurity/falco



This chart adds Falco to all nodes in the cluster using a DaemonSet. All the alerts will be to Syslog and the same can be integrated with ELK stack to capture events on the kibana dashboard.  

Falco and Kubernetes Security Stack

Falco and Kubernetes stackWhile detecting anomalous behavior in your containers is step one, and step two is responding to or mitigating the attack in an automated way. In the above automation, Falco evaluates the rules and triggers alerts. A small forwarder in a container within the same pod reads the alerts through a named pipe and then sends them to NATS using TLS.  NATS is a messaging broker so other parties can consume security events.

  • Falco – agent that detects the wrong behavior
  • NATS – Open Source Messaging system, a response engine that routes the messages to an endpoint
  • Playbooks or functions — to mitigate those issues caught and respond to the security incident. A Function is an independent unit of deployment, like a microservice. It's merely code, deployed in the cloud, that is most often written to perform a single job 

Conclusion

Falco is extremely effective in part because its rules can use context from the low-level operating system interface (syscalls) together with Docker container or Kubernetes orchestration metadata (container information, namespaces, deployment, pods, etc). Any reaction to a security incident needs to be fast. Because containers have short lifespans, it’s essential to find the culprit before the container causes any real damage or simply disappears or moves somewhere else. Automation is more important than ever, and writing response procedures as code playbooks is the best approach.

Topics:
container security, devops, falco, kubernetes, security

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}