- Elastic Docs/
- Solutions and use cases/
- Security solution/
- Cloud Security/
- Cloud workload protection for Kubernetes
Get started with Defend for Containers for Kubernetes
This page describes how to set up Defend for Containers (D4C) for Kubernetes.
- Kubernetes node operating systems must have Linux kernels 5.10.16 or higher.
- Elastic Stack version 9.3 or higher.
First, you’ll need to deploy Elastic’s Defend for Containers integration to the Kubernetes clusters you wish to monitor.
FindContainer Workload Security in the navigation menu or use theglobal search field. ClickAdd D4C Integration.
Name the integration. The default name, which you can change, is
cloud_defend-1.(Optional) Adjust theSelectors andResponses sections in theintegration’s policy to modify the core container workload protection capabilities that the D4C integration policy will implement. You can change these later, if needed.
UnderWhere to add this integration, select an existing or new agent policy.
ClickSave & Continue, thenAdd Elastic Agent to your hosts.
On the Elastic Agent policy page, clickAdd agent to open the Add agent flyout.
In the flyout, go to step 3 (Install Elastic Agent on your host) and select theKubernetes tab.
Download or copy the manifest (
elastic-agent-managed-kubernetes.yml).Open the manifest using your favorite editor, and uncomment the
#capabilitiessection:#capabilities:# add:# - BPF # (Since Linux 5.8) allows loading of BPF programs, create most map types, load BTF, iterate programs and maps.# - PERFMON # (Since Linux 5.8) allows attaching of BPF programs used for performance metrics and observability operations.# - SYS_RESOURCE # Allow use of special resources or raising of resource limits. Used by 'Defend for Containers' to modify 'rlimit_memlock'# - SYS_ADMIN # Required if using Defend for Containers on Azure Kubernetes Service (AKS)- (Since Linux 5.8) allows loading of BPF programs, create most map types, load BTF, iterate programs and maps.
- (Since Linux 5.8) allows attaching of BPF programs used for performance metrics and observability operations.
- Allow use of special resources or raising of resource limits. Used by 'Defend for Containers' to modify 'rlimit_memlock'
- Required if using Defend for Containers on Azure Kubernetes Service (AKS)
From the directory where you saved the manifest, run the command
kubectl apply -f elastic-agent-managed-kubernetes.yml.Wait for theConfirm agent enrollment dialogue to show that data has started flowing from your newly-installed agent, then clickClose.
Thedefault D4C policy provides threat detection capabilities. It is designed to send process telemetry events (fork andexec) to Elasticsearch.
To detect threats using this data, you’ll need activedetection rules. You can use Elastic's prebuilt rules that are designed for this data or createcustom rules.
To set up threat detection, install and enable Elastic's prebuilt rules that use data ingested by D4C:
- FindDetection rules (SIEM) in the navigation menu or use theglobal search field. ClickAdd Elastic rules.
- Click theTags filter next to the search bar, and search for the
Data Source: Elastic Defend for Containerstag. - Select all the displayed rules, then clickInstallx selected rule(s).
- Return to theRules page. Click theTags filter next to the search bar, and search for the
Data Source: Elastic Defend for Containerstag. - Select all the rules with the tag, and then clickBulk actions > Enable.
Elastic Security defines container drift as the creation or modification of an executable within a container. Blocking drift restricts the number of attack vectors available to bad actors by prohibiting them from using external tools.
Thedefault D4C policy provides drift detection and prevention capabilities. Before you enable drift detection, do the following:
- Make sure the default D4C policy is active.
- Make sure you've installed and enabled the "Container Workload Protection" prebuilt rule. The steps for installing and enabling prebuilt rules are above.
To enable drift prevention, create a new policy:
- FindContainer Workload Security in the navigation menu or use theglobal search field, then select your integration.
- UnderSelectors, clickAdd selector > File Selector. By default, it selects the operations
createExecutableandmodifyExecutable. - Name the selector, for example:
blockDrift. - Scroll down to theResponses section and clickAdd response > File Response.
- UnderMatch selectors, add the name of your new selector, for example:
blockDrift. - Select theAlert andBlock actions.
- ClickSave integration.
Before you enable blocking, we strongly recommend you observe a production workload that’s using the default D4C policy to ensure that the workload does not create or modify executables as part of its normal operation.
To ensure the stability of your production workloads, you should test policy changes before implementing them in production workloads. We also recommend you test policy changes on a simulated environment with workloads similar to production. This approach allows you to test that policy changes prevent undesirable behavior without disrupting your production workloads.