Limiting the Memory available to the container has operational as well as security benefits. In the context of security this is about limiting the impact of potential denial of service attacks to affecting the app rather than the node and potentially the whole cluster.
We have 2 different apps - both run on the same node (with different pods). That basically means that the 2 apps share the same resources.
This is an example for an app without any resourse limitation as part of the deployment config.
The app exposes 3 APIs:
/app1/mem
- display the total and available memory on the pod/app1/allocate?MBs=10&Secs=10
- allocates specific amount of memory on the backend side (10 MBs for 10 secs in this case)/app1/stress
- tries to allocate all of the free memory on the pod
Those APIs demo logic that can lead into performance issues on the backend side (memory issues in our case).
Malicious users can use them and drain the memory resources from the pod. Another example is DDOS attack that can use the same logic to allocate resources of apps, and block other users from accessing those apps.
Without any resource limitations of the pod, the malicious users can also effect the performance of other pods that run on the same node.
This app exposes only the /app1/mem
API - so you can check the affect of App 1 on it.
- Go to your Kubernetes dashboard and look for the IP of the application
- Go to
Discovery and Load Balancing -> Ingresses
- Take the IP of
resource-limitation-pod-ingress
- Go to
- Open 2 different tabs:
- Start monitoring the status of App 2 by refrashing the page http://IP/app2/mem
- Start allocating memory on App 1 by surfing http://IP/app1/allocate?MBs=200&Secs=10
- This will allocate 100 MBs for 10 secs
- Look for the memory status of App 2 - the amount of available memory should decrease in ~100 MBs
- Keep playing with that setup :) you can also use http://IP/app1/stress
In order to fix that issue, one should add resourse limitation for the pod:
- Clean your environment by running the cleaning script
- Change the deployment config and uncomment the resources block:
resources:
limits:
memory: 50Mi
requests:
memory: 50Mi
- Setup your environment again by running the building script
- Return on the exploit steps from above. You can see that this time when you try to allocate memory on App 1 (http://IP/app1/allocate?MBs=200&Secs=10), the allocation fails with
Failed to allocate 200MB
. - Pay attention that you can still allocate small amount of memory like - http://IP/app1/allocate?MBs=2&Secs=10