Attack Protection
These rules are used to counter penetration tactics in the container environment, such as mitigating container information leakage and prohibiting execution of sensitive actions.
You can refer to the following format to define policies:
policy:
enforcer: AppArmorBPF
mode: EnhanceProtect
enhanceProtect:
attackProtectionRules:
- rules:
- mitigate-sa-leak
- rules:
- disable-write-etc
targets:
- "/bin/bash"
- "/usr/bin/bash"
Mitigating Information Leakage
mitigate-sa-leak
Mitigating ServiceAccount token leakage.
This rule prohibits container processes from reading sensitive Service Account-related information, including tokens, namespaces, and CA certificates. It helps prevent security risks arising from the leakage of Default ServiceAccount or misconfigured ServiceAccount. In the event that attackers gain access to a container through an RCE vulnerability, they often seek to further infiltrate by leaking ServiceAccount information.
In most user scenarios, there is no need for Pods to communicate with the API Server using ServiceAccounts. However, by default, Kubernetes still sets up default ServiceAccounts for Pods that do not require communication with the API Server.
Disallow reading ServiceAccount-related files.
- AppArmor
- BPF
mitigate-disk-device-number-leak
Mitigating host disk device number leakage.
Attackers may attempt to obtain host disk device numbers for subsequent container escape by reading the container process's mount information.
Disallow reading /proc/[PID]/mountinfo and /proc/partitions files.
- AppArmor
- BPF
mitigate-overlayfs-leak
Mitigating container overlayfs path leakage.
Attackers may attempt to obtain the overlayfs path of the container's rootfs on the host by accessing the container process's mount information, which could be used for subsequent container escape.
Disallow reading /proc/mounts, /proc/[PID]/mounts, and /proc/[PID]/mountinfo files.
This rule may impact some functionality of the mount command or syscall within containers.
- AppArmor
- BPF
mitigate-host-ip-leak
Mitigating host IP leakage.
After gaining access to a container through an RCE vulnerability, attackers often attempt further network penetration attacks. Therefore, restricting attackers from obtaining sensitive information such as host IP, MAC, and network segments through this vector can increase the difficulty and cost of their network penetration activities.
Disallow reading ARP address resolution tables (such as /proc/net/arp, /proc/[PID]/net/arp)
- AppArmor
- BPF
block-access-to-metadata-service
Disallow access to common metadata services.
This rule prohibits container processes from accessing common cloud provider Instance Metadata Services, including 169.254.169.254 (IPv4) and fd00:ec2::254 (IPv6 for AWS EC2) for AWS, GCP, Azure, and OpenStack, as well as 100.96.0.96 for Volc Engine and BytePlus.
For better performance and granular control, consider using provider-specific rules such as block-access-to-aws-metadata-service, block-access-to-volc-metadata-service, block-access-to-alibaba-metadata-service, or block-access-to-oci-metadata-service.
Attackers, upon gaining code execution privileges within a container, may attempt to access to cloud server's Metadata Service for information disclosure. In certain scenarios, attackers may obtain sensitive information, leading to privilege escalation and lateral movement.
Prohibit connections to Instance Metadata Services' IP addresses.
- BPF
block-access-to-aws-metadata-service
Disallow access to AWS, GCP, Azure, and OpenStack metadata services.
This rule prohibits container processes from accessing Instance Metadata Services for AWS, GCP, Azure, and OpenStack, including 169.254.169.254 (IPv4) and fd00:ec2::254 (IPv6 for AWS EC2).
Attackers, upon gaining code execution privileges within a container, may attempt to access to cloud server's Metadata Service for information disclosure. In certain scenarios, attackers may obtain sensitive information, leading to privilege escalation and lateral movement.
Prohibit connections to Instance Metadata Services' IP addresses.
- BPF
block-access-to-volc-metadata-service
Disallow access to Volc Engine and BytePlus metadata services.
This rule prohibits container processes from accessing Volc Engine and BytePlus Instance Metadata Services, including 100.96.0.96.
Attackers, upon gaining code execution privileges within a container, may attempt to access to cloud server's Metadata Service for information disclosure. In certain scenarios, attackers may obtain sensitive information, leading to privilege escalation and lateral movement.
Prohibit connections to Instance Metadata Services' IP addresses.
- BPF
block-access-to-alibaba-metadata-service
Disallow access to Alibaba Cloud (Aliyun) metadata services.
This rule prohibits container processes from accessing Alibaba Cloud Instance Metadata Services, including 100.100.100.200.
Attackers, upon gaining code execution privileges within a container, may attempt to access to cloud server's Metadata Service for information disclosure. In certain scenarios, attackers may obtain sensitive information, leading to privilege escalation and lateral movement.
Prohibit connections to Instance Metadata Services' IP addresses.
- BPF
block-access-to-oci-metadata-service
Disallow access to Oracle Cloud Infrastructure (OCI) metadata services.
This rule prohibits container processes from accessing Oracle Cloud Infrastructure Instance Metadata Services, including 192.0.0.192.
Attackers, upon gaining code execution privileges within a container, may attempt to access to cloud server's Metadata Service for information disclosure. In certain scenarios, attackers may obtain sensitive information, leading to privilege escalation and lateral movement.
Prohibit connections to Instance Metadata Services' IP addresses.
- BPF
Disabling Sensitive Operations
disable-write-etc
Prohibit writing to the /etc directory.
Attackers may attempt privilege escalation by modifying sensitive files in the /etc directory, such as altering /etc/bash.bashrc for watering hole attacks, editing /etc/passwd and /etc/shadow to add users for persistence, or modifying nginx.conf or /etc/ssh/ssh_config for persistence.
Disallow writing to the /etc directory.
- AppArmor
- BPF