In my most recent Kubernetes attack and defense webinar, I demonstrate a Kubernetes attack through a Scott Pilgrim-themed scenario. If you haven’t seen the Scott Pilgrim movie, definitely check it out!
The attacks in my webinar demonstrate defeating the “evil ex” bad guys of the movie as you escalate privilege through a Linux-based Kubernetes cluster. In one step, we gain a password through a monkey-in-the-middle (MitM) attack, where we intercept a communication between two containers in the cluster. It’s much easier than it sounds!
There are a number of defenses we discuss in the webinar. The most widely applicable is Kubernetes’ primary authorization rules language, called role-based access control (RBAC). RBAC is pretty easy to learn.
You use RBAC to help implement least privilege by defining what accounts (user accounts or service accounts) can perform what actions to what resources. You’d expect this would mean that we create a number of rule objects, like so:
User Jay may list pods
User Mary may list pods
User Alice may get, list, watch, create, update, patch, delete pods
To ease handling a large number of accounts, RBAC uses a sort of intermediate item called a binding. You create “roles,” which have a set of capabilities, then give each user one or more roles via a “rolebinding.” That last example would use a pair of custom roles:
Role pod-lister may list pods
Role pod-rw may get, list, watch, create, update, patch, delete pods
Then you create rolebindings, giving Jay and Mary the pod-lister role, while you give Alice the pod-rw role, like so:
User Jay has role pod-lister
User Mary has role pod-lister
User Alice has role pod-rw
Once this makes sense to you, you only need to grasp one additional concept. Kubernetes ties all of these to “namespaces,” an organizational unit that is customarily used to separate development teams or projects from one another in a cluster. So, you create these roles (sets of actions) and rolebindings (grants of roles to users) in one namespace at a time. For a rare set of cases where you need the capabilities to affect the entire cluster, not just one namespace, you can create “cluster roles” and “cluster rolebindings.”
But wait, you say, isn’t this all supposed to be expressed in YAML? (Footnote: YAML stands for “YAML Ain’t Markup Language). Yes, it is, but it’s quite a bit easier to understand the YAML when you know what it’s supposed to be doing.
Here’s the YAML version of “Role pod-lister may list pods”:
- apiGroups: [""]
Here’s the YAML version of “User Jay has role pod-lister”
- kind: User
There’s a lot more you can learn about how to effectively and efficiently leverage RBAC, but what you’ve learned in this blog post is enough for you to defend the Kubernetes cluster we attack in my on-demand webinar. Follow along here: Attacking and Defending Kubernetes Scott Pilgrim–Style.
Jay Beale, CEO, CTO at InGuardians, Inc.
Jay Beale has created several defensive security tools, including Bastille Linux/UNIX and the CIS Linux Scoring Tool, both of which were used widely throughout industry and government. He has served as an invited speaker at many industry and government conferences, a columnist for Information Security Magazine, SecurityPortal and SecurityFocus, and a contributor to nine books, including those in his Open Source Security Series and the “Stealing the Network” series. He has led training classes on Linux Hardening and other topics at Black Hat, CanSecWest, RSA, and IDG conferences, as well as in private corporate training. Jay is a co-founder, Chief Operating Officer and CTO of the information security consulting company InGuardians.