Skip to main content

A few of use were talking about the differences between Linux distributions over on the Hub Discussion board and as always our talk wandered into other areas and corners. One of the things we discussed were minimal installs that you can do with Linux distros. This led me to comment that containers are even more minimal and that for some strange reason made me remember some CKS training about not letting the bad folks get too many privileges/access/or even have a working shell  inside your containers as they can do bad things. 

So here is an amateur demo.

 

First we create a simple nginx pod:

k run nginx --image=nginx
create a pod
​​​​​​

Next lets see if we can get a simple shell in the pod:

k exec nginx -it -- sh
See if there is a shell in the Container
 

Not only is there a shell but there is also a bash shell :) 

bash
we got a bash shell

Now lets say we want to sniff the cluster network, lets try tcpdump

tcpdump
No luck

No luck there is no tcpdump binary. Never fear Bad Burke is here!!

Lets try doing an apt update:

apt update
apt update

Right that is good 🙂 May I now be so bold as to try and install my beloved little sniffer? 

apt install tcpdump
tcpdump install
Well Well

It is asking me to confirm.. I should have just used -y but this has more “shock and awe” value.

Obviously we choose Y.

done

Looks like it went and installed tcpdump and all of its dependencies. 

To use tcpdump you need to tell it which interface I believe but what would that be in an nginx container?

A bit of googling and I know where to look:

/sys/class/net/

its eth0 

Ok so good old eth0

So let’s go for it:

tcpdump -i eth0
sniffing

Not much happening. This is to be honest Burke’s boring Rancher Desktop on his laptop where nothing exciting ever happens only work. So lets open another terminal and try and generate some cluster traffic:

Open new terminal and type:

k get pods
get the pods

Now let’s head back to our nginx bash shell and check out tcpdump:

look at that

Boom! look at that action. Hey it seems that Mr. Burke has Kasten installed on this cluster judging by the intercept.. that means he is aware of data protection and security. Most l likely he also follows @Rick Vanover Rickatron’s 3 -2 -1 etc rule…  I won’t mess with this fellow, I will instead head off to another Kubernetes cluster and do my bad hacking!!! 

Very cool demo for sure with this.  👍🏼


BAD MR BURKE! 🤣😂 Good writeup Geoff. 


BAD MR BURKE! 🤣😂 Good writeup Geoff. 

Thanks. Believe me this was a very simplified example but you get the picture. One thing that I should have added here was to have performed a 

ps

command to show what the processes were running as. Here obviously they were running as root, hence my ability to apt update and install. So one of the important things to do is make sure they run not as root. Some helm charts do this like the bitnami ones. Additionally there are ways to restrict pods from starting if they are trying to run as root. 


“..one of the important things to do is make sure they run not as root.” In my Linux journey on Pluralsight, Andrew Mallett discusses this very thing, for ex. when installing a web server on Linux, to run the service as the apache account.


Comment