Threat detection with Falco and EKS Audit Logs
In this tutorial, I will show how to:
- Install Falco to your EKS cluster using helm chart
- Enable EKS audit logs for your cluster
- Detect security events based on EKS audit logs activity.
- Overview of most useful rules for my opinion
- How to add custom rules
- Example of how to trigger specific rule
What is Falco?
Prerequisites
- Existing EKS cluster
Enable EKS audit logs for your cluster
In AWS console -> Elastic Kubernetes Cluster -> choose you cluster -> Observability tab -> Manage logging
In Manage logging, enable ‘Audit’ and click ‘Save changes’
Create IAM role and policy for Falco
On EKS, the audit logs are sent to cloud watch logs, in order for Falco to pull those events we need read access for cloud watch logs:
This policy must be attached to role you creating: ‘falco-k8s-role’ for example
falco-k8s-role’ IAM role will be used with IRSA (IAM Roles for service accounts) in Falco
To make it work with IRSA need to define ‘Trust relationship’ for this role
- REGION: Region of your EKS cluster
- ACCOUNT_ID: The account ID of EKS cluster
- CLUSTER_NAME: EKS cluster name
- OIDC_PROVIDER_ID: OIDC Provider ID, to find it: go to IAM -> Identity Providers, you need to enable if not for IRSA to work.
Install Falco to your EKS cluster using helm chart
values.yaml
- CLUSTER_NAME: must be replaced with you EKS cluster name
- ROLE_ARN: IAM role arn for ‘falco-k8s-role’
If you have taints defined for your k8s worker nodes, add tolerations section to your values.yaml, for example to run Falco on ‘on-demand-large-node’ nodes:
Installation of Falco helm chart
hmm, I see Falco pod in ‘CrashLoopBackOff’ state:
Checking the logs I see ‘AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity’ message:
Meaning I need to validate IAM role created properly.
Need to validate:
- The name of the role is correct, same as you defined in values.yaml under service account annotations:
- In AWS Console -> IAM -> Role name -> Under Trust relationship tab, validate condition:
The ‘system:serviceaccount:falco:falco’, meaning you must have ‘falco’ service account in falco namespace, if you installed it to other namespace you will see this error, please change namespace accordingly!
In case of successful Install you will see output like this:
Last two rows is important:
- Enabled event sources: k8s_audit
- Opening ‘k8s_audit’ source with plugin ‘k8saudit-eks’
You can ‘kubectl exec’ the pod and see default set of rules is downloaded and used with k8s audit plugin, it’s k8s_audit_rules.yaml:
To see all triggered alerts by Falco run:
Overview of most useful rules for my opinion
The default set of rules for EKS audit logs plugin is heavy and added too much noise for me!
For example:
- Error K8s Secret Get Successfully (user=system:serviceaccount:operators:external-secrets …
I am using external secrets to sync secrets for k8s with AWS secrets manager, which is ok by me.
I saw more than 200 alerts of this type, after installation of Falco, meaning you need to do a lot of tuning after installation.
List of alerts that created a lot of noise for me, especially the last one:
- K8s Deployment Created
- K8s Deployment Deleted
- K8s Service Created
- K8s Service Deleted
- K8s ConfigMap Created
- K8s ConfigMap Deleted
- K8s Serviceaccount Created
- K8s Serviceaccount Deleted
- K8s Role/Clusterrole Created
- K8s Secret Get Successfully
Eventually I ended using only specific set of rules for my case, from here:
- Create Privileged Pod
- Attach/Exec Pod
- Attach to cluster-admin Role
- Full K8s Administrative Access
- Ingress Object without TLS Certificate Created
- Untrusted Node Successfully Joined the Cluster
- Untrusted Node Unsuccessfully Tried to Join the Cluster
Using custom rules
In order to use custom rules you need to add this section to values.yaml
In my case I disabled all default rules, by removing ‘k8s_audit_rules.yaml’ rules_file from values.yaml :
picked a set of rules I wrote above and added those rules under custom_rules section in values.yaml.
In logs you will see ‘ Loading rules from file /etc/falco/rules.d/custom_rules.yaml’, and will not see same line for k8s_audit_rules.yaml.
How to test you rule set?
Let’s test ‘Attach/Exec Pod’ rule for example, for this you need to exec into any pod in your cluster:
In logs (‘kubectl logs falco’) you must see: ‘ Attach/Exec to pod’ message.
Thank you for reading, I hope you enjoyed it, see you in the next post.
The code of helm chart created you can find in my repo
Please subscribe to my YT channel and twitter, to be notified when the next tutorial is published.