-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add k8s deployment yaml files for audit purpose only
Signed-off-by: Benjamin <benjamin@yunify.com>
- Loading branch information
Benjamin
committed
Jul 19, 2019
1 parent
a084f8c
commit 2e5b224
Showing
6 changed files
with
375 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Example Kubernetes Deployments for Sysdig Falco | ||
|
||
This directory gives you the required YAML files to stand up Sysdig Falco on Kubernetes only for audit purpose as a Deployment. | ||
|
||
To deploy Falco on Kubernetes for audit: | ||
- `k8s-with-rbac` - This directory provides a definition to deploy a Deployment on Kubernetes with RBAC enabled. | ||
|
||
Also provided: | ||
- `falco-event-generator-deployment.yaml` - A Kubernetes Deployment to generate sample events. This is useful for testing, but note it will generate a large number of events. | ||
|
||
## Deploying to Kubernetes with RBAC enabled | ||
|
||
Since v1.8 RBAC has been available in Kubernetes, and running with RBAC enabled is considered the best practice. The `k8s-with-rbac` directory provides the YAML to create a Service Account for Falco, as well as the ClusterRoles and bindings to grant the appropriate permissions to the Service Account. | ||
|
||
``` | ||
k8s-using-deployment$ kubectl create -f k8s-with-rbac/falco-k8s-audit-account.yaml | ||
serviceaccount "falco-account" created | ||
clusterrole "falco-cluster-role" created | ||
clusterrolebinding "falco-cluster-role-binding" created | ||
k8s-using-deployment$ | ||
``` | ||
|
||
We also create a service that allows other services to reach the embedded webserver in falco, which listens on https port 8765: | ||
|
||
``` | ||
k8s-using-deployment$ kubectl create -f k8s-with-rbac/falco-k8s-audit-service.yaml | ||
service/falco-service created | ||
k8s-using-deployment$ | ||
``` | ||
|
||
The Deployment also relies on a Kubernetes ConfigMap to store the Falco configuration and make the configuration available to the Falco Pods. This allows you to manage custom configuration without rebuilding and redeploying the underlying Pods. In order to create the ConfigMap you'll first need to copy the required configuration from their location in this GitHub repo to the `k8s-with-rbac/falco-config/` directory (please note that you will need to create the /falco-config directory). Any modification of the configuration should be performed on these copies rather than the original files. | ||
|
||
``` | ||
k8s-using-deployment$ mkdir -p k8s-with-rbac/falco-config | ||
k8s-using-deployment$ cp ./falco.yaml k8s-with-rbac/falco-config/ | ||
k8s-using-deployment$ cp ../../rules/k8s_audit_rules.yaml k8s-with-rbac/falco-config/ | ||
``` | ||
|
||
If you want to send Falco alerts to a Slack channel, you'll want to modify the `falco.yaml` file to point to your Slack webhook. For more information on getting a webhook URL for your Slack team, refer to the [Slack documentation](https://api.slack.com/incoming-webhooks). Add the below to the bottom of the `falco.yaml` config file you just copied to enable Slack messages. | ||
|
||
``` | ||
program_output: | ||
enabled: true | ||
keep_alive: false | ||
program: "jq '{text: .output}' | curl -d @- -X POST https://hooks.slack.com/services/see_your_slack_team/apps_settings_for/a_webhook_url" | ||
``` | ||
|
||
You will also need to enable JSON output. Find the `json_output: false` setting in the `falco.yaml` file and change it to read `json_output: true`. Any custom rules for your environment can be added to into the `falco_rules.local.yaml` file and they will be picked up by Falco at start time. You can now create the ConfigMap in Kubernetes. | ||
|
||
``` | ||
k8s-using-deployment$ kubectl create configmap falco-config --from-file=k8s-with-rbac/falco-config | ||
configmap "falco-config" created | ||
k8s-using-deployment$ | ||
``` | ||
|
||
Now that we have the requirements for our Deployment in place, we can create our Deployment. | ||
|
||
``` | ||
k8s-using-deployment$ kubectl create -f k8s-with-rbac/falco-k8s-audit-deployment.yaml | ||
daemonset "falco" created | ||
k8s-using-deployment$ | ||
``` |
17 changes: 17 additions & 0 deletions
17
integrations/k8s-using-deployment/falco-event-generator-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: falco-event-generator-deployment | ||
labels: | ||
name: falco-event-generator-deployment | ||
app: demo | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: falco-event-generator | ||
spec: | ||
containers: | ||
- name: falco-event-generator | ||
image: sysdig/falco-event-generator:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# | ||
# Copyright (C) 2016-2018 Draios Inc dba Sysdig. | ||
# | ||
# This file is part of falco . | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# File(s) or Directories containing Falco rules, loaded at startup. | ||
# The name "rules_file" is only for backwards compatibility. | ||
# If the entry is a file, it will be read directly. If the entry is a directory, | ||
# every file in that directory will be read, in alphabetical order. | ||
# | ||
# falco_rules.yaml ships with the falco package and is overridden with | ||
# every new software version. falco_rules.local.yaml is only created | ||
# if it doesn't exist. If you want to customize the set of rules, add | ||
# your customizations to falco_rules.local.yaml. | ||
# | ||
# The files will be read in the order presented here, so make sure if | ||
# you have overrides they appear in later files. | ||
rules_file: | ||
- /etc/falco/falco_rules.local.yaml | ||
- /etc/falco/k8s_audit_rules.yaml | ||
- /etc/falco/rules.d | ||
|
||
# If true, the times displayed in log messages and output messages | ||
# will be in ISO 8601. By default, times are displayed in the local | ||
# time zone, as governed by /etc/localtime. | ||
time_format_iso_8601: false | ||
|
||
# Whether to output events in json or text | ||
json_output: true | ||
|
||
# When using json output, whether or not to include the "output" property | ||
# itself (e.g. "File below a known binary directory opened for writing | ||
# (user=root ....") in the json output. | ||
json_include_output_property: true | ||
|
||
# Send information logs to stderr and/or syslog Note these are *not* security | ||
# notification logs! These are just Falco lifecycle (and possibly error) logs. | ||
log_stderr: true | ||
log_syslog: true | ||
|
||
# Minimum log level to include in logs. Note: these levels are | ||
# separate from the priority field of rules. This refers only to the | ||
# log level of falco's internal logging. Can be one of "emergency", | ||
# "alert", "critical", "error", "warning", "notice", "info", "debug". | ||
log_level: info | ||
|
||
# Minimum rule priority level to load and run. All rules having a | ||
# priority more severe than this level will be loaded/run. Can be one | ||
# of "emergency", "alert", "critical", "error", "warning", "notice", | ||
# "info", "debug". | ||
priority: debug | ||
|
||
# Whether or not output to any of the output channels below is | ||
# buffered. Defaults to false | ||
buffered_outputs: false | ||
|
||
# Falco uses a shared buffer between the kernel and userspace to pass | ||
# system call information. When falco detects that this buffer is | ||
# full and system calls have been dropped, it can take one or more of | ||
# the following actions: | ||
# - "ignore": do nothing. If an empty list is provided, ignore is assumed. | ||
# - "log": log a CRITICAL message noting that the buffer was full. | ||
# - "alert": emit a falco alert noting that the buffer was full. | ||
# - "exit": exit falco with a non-zero rc. | ||
# | ||
# The rate at which log/alert messages are emitted is governed by a | ||
# token bucket. The rate corresponds to one message every 30 seconds | ||
# with a burst of 10 messages. | ||
|
||
syscall_event_drops: | ||
actions: | ||
- log | ||
- alert | ||
rate: .03333 | ||
max_burst: 10 | ||
|
||
# A throttling mechanism implemented as a token bucket limits the | ||
# rate of falco notifications. This throttling is controlled by the following configuration | ||
# options: | ||
# - rate: the number of tokens (i.e. right to send a notification) | ||
# gained per second. Defaults to 1. | ||
# - max_burst: the maximum number of tokens outstanding. Defaults to 1000. | ||
# | ||
# With these defaults, falco could send up to 1000 notifications after | ||
# an initial quiet period, and then up to 1 notification per second | ||
# afterward. It would gain the full burst back after 1000 seconds of | ||
# no activity. | ||
|
||
outputs: | ||
rate: 1 | ||
max_burst: 1000 | ||
|
||
# Where security notifications should go. | ||
# Multiple outputs can be enabled. | ||
|
||
syslog_output: | ||
enabled: true | ||
|
||
# If keep_alive is set to true, the file will be opened once and | ||
# continuously written to, with each output message on its own | ||
# line. If keep_alive is set to false, the file will be re-opened | ||
# for each output message. | ||
# | ||
# Also, the file will be closed and reopened if falco is signaled with | ||
# SIGUSR1. | ||
|
||
file_output: | ||
enabled: false | ||
keep_alive: false | ||
filename: ./events.txt | ||
|
||
stdout_output: | ||
enabled: true | ||
|
||
# Falco contains an embedded webserver that can be used to accept K8s | ||
# Audit Events. These config options control the behavior of that | ||
# webserver. (By default, the webserver is disabled). | ||
# | ||
# The ssl_certificate is a combination SSL Certificate and corresponding | ||
# key contained in a single file. You can generate a key/cert as follows: | ||
# | ||
# $ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem | ||
# $ cat certificate.pem key.pem > falco.pem | ||
# $ sudo cp falco.pem /etc/falco/falco.pem | ||
|
||
webserver: | ||
enabled: true | ||
listen_port: 8765 | ||
k8s_audit_endpoint: /k8s_audit | ||
ssl_enabled: false | ||
ssl_certificate: /etc/falco/falco.pem | ||
|
||
# Possible additional things you might want to do with program output: | ||
# - send to a slack webhook: | ||
# program: "jq '{text: .output}' | curl -d @- -X POST https://hooks.slack.com/services/XXX" | ||
# - logging (alternate method than syslog): | ||
# program: logger -t falco-test | ||
# - send over a network connection: | ||
# program: nc host.example.com 80 | ||
|
||
# If keep_alive is set to true, the program will be started once and | ||
# continuously written to, with each output message on its own | ||
# line. If keep_alive is set to false, the program will be re-spawned | ||
# for each output message. | ||
# | ||
# Also, the program will be closed and reopened if falco is signaled with | ||
# SIGUSR1. | ||
program_output: | ||
enabled: false | ||
keep_alive: false | ||
program: "jq '{text: .output}' | curl -d @- -X POST https://hooks.slack.com/services/XXX" | ||
|
||
http_output: | ||
enabled: false | ||
url: http://some.url |
38 changes: 38 additions & 0 deletions
38
integrations/k8s-using-deployment/k8s-with-rbac/falco-k8s-audit-account.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: falco-account | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
--- | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
metadata: | ||
name: falco-cluster-role | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
rules: | ||
- apiGroups: ["extensions",""] | ||
resources: ["nodes","namespaces","pods","replicationcontrollers","replicasets","services","daemonsets","deployments","events","configmaps"] | ||
verbs: ["get","list","watch"] | ||
- nonResourceURLs: ["/healthz", "/healthz/*"] | ||
verbs: ["get"] | ||
--- | ||
kind: ClusterRoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
metadata: | ||
name: falco-cluster-role-binding | ||
namespace: default | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
subjects: | ||
- kind: ServiceAccount | ||
name: falco-account | ||
namespace: default | ||
roleRef: | ||
kind: ClusterRole | ||
name: falco-cluster-role | ||
apiGroup: rbac.authorization.k8s.io |
77 changes: 77 additions & 0 deletions
77
integrations/k8s-using-deployment/k8s-with-rbac/falco-k8s-audit-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: falco-k8s-audit | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: falco-k8s-audit | ||
template: | ||
metadata: | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
spec: | ||
serviceAccount: falco-account | ||
containers: | ||
- name: falco | ||
image: falcosecurity/falco:latest | ||
securityContext: | ||
privileged: true | ||
args: [ "/usr/bin/falco", "--cri", "/host/run/containerd/containerd.sock", "-K", "/var/run/secrets/kubernetes.io/serviceaccount/token", "-k", "https://$(KUBERNETES_SERVICE_HOST)", "-pk"] | ||
volumeMounts: | ||
- mountPath: /host/var/run/docker.sock | ||
name: docker-socket | ||
- mountPath: /host/run/containerd/containerd.sock | ||
name: containerd-socket | ||
- mountPath: /host/dev | ||
name: dev-fs | ||
- mountPath: /host/proc | ||
name: proc-fs | ||
readOnly: true | ||
- mountPath: /host/boot | ||
name: boot-fs | ||
readOnly: true | ||
- mountPath: /host/lib/modules | ||
name: lib-modules | ||
readOnly: true | ||
- mountPath: /host/usr | ||
name: usr-fs | ||
readOnly: true | ||
- mountPath: /host/etc/ | ||
name: etc-fs | ||
readOnly: true | ||
- mountPath: /etc/falco | ||
name: falco-config | ||
volumes: | ||
- name: docker-socket | ||
hostPath: | ||
path: /var/run/docker.sock | ||
- name: containerd-socket | ||
hostPath: | ||
path: /run/containerd/containerd.sock | ||
- name: dev-fs | ||
hostPath: | ||
path: /dev | ||
- name: proc-fs | ||
hostPath: | ||
path: /proc | ||
- name: boot-fs | ||
hostPath: | ||
path: /boot | ||
- name: lib-modules | ||
hostPath: | ||
path: /lib/modules | ||
- name: usr-fs | ||
hostPath: | ||
path: /usr | ||
- name: etc-fs | ||
hostPath: | ||
path: /etc | ||
- name: falco-config | ||
configMap: | ||
name: falco-config |
13 changes: 13 additions & 0 deletions
13
integrations/k8s-using-deployment/k8s-with-rbac/falco-k8s-audit-service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: falco-k8s-audit | ||
labels: | ||
app: falco-k8s-audit | ||
role: security | ||
spec: | ||
selector: | ||
app: falco-k8s-audit | ||
ports: | ||
- protocol: TCP | ||
port: 8765 |