0:00 Welcome back. In the last video, we connected GitHub as our identity provider and proved that every user authenticates through Teleport, gets a short-lived certificate tied to their real identity. This is a massive improvement over the default kubeconfigs that you may get from your cloud provider, but. We left one thing wide open, the kube access or whatever role we used. Grants system, masters typically to everyone who logs in, not too dissimilar to what you get from your cloud provider. And that means that every authentic user has full admin access to the entire Cluster, every namespace, every resource, every,
0:44 and when it comes to production infrastructure. We want to focus on the principle of least privilege. That means that every user should have exactly the permissions they need to do their job, and nothing more. Overprivileged access is one of the most common root causes in Kubernetes security incidents In Kubernetes, security instance, an engineer with full cluster admin accidentally deletes the production deployment. The problem is the process, not their developer. A compromised developer laptop gives an attack of keys to every namespace. The problem is the process, not the developer. A contractor who only needs to view logs in a staging namespace
1:31 can access, can instead access all the secrets in production. Again, the problem is a process, not the contractor. Today I'm gonna show you how to fix the process. We're going to build a two layer RBAC model where teleport controls which Kubernetes groups use their certificate carries and Kubernetes RBAC controls what those groups are allowed to do. We'll use teleports deny rules to create hard boundaries that cannot be bypassed even if someone mis configures the Kubernetes side that look fun. Let's dive in. So the first step is setting up the namespace boundaries. We're going to create two name spaces, development and production.
2:29 in your organization, you more than likely have more, and these may be clusters, staging, monitoring, CI/CD, and so on. But for today's demo, I feel two namespace is more than enough to demonstrate the pattern. So let's take a look at our Create namespace script, which should be no surprise to anyone. This is a script that creates two namespaces development and production. I feel it's pretty safe just to yo us straight into our Cluster. And as you can see, we're continuing with my production Cluster from the previous videos. However, you should not be doing this in production.
3:22 I'm doing it to keep these demonstrations applicable to an almost real world scenario. So now that we have our namespace, we now need to. Create our Kubernetes roles, RBAC rules that define which each group can do within those two namespaces. And this is where our multi-layer model starts to take shape. Teleport is going to assert which group a user belongs to by embedding. And their certificate, Kubernetes is going to enforce what that group is allowed to do based on Kubernetes standard rules and rule bindings. So let's take a quick look at the manifests that we are gonna use in
4:05 the development namespace where we have a role for viewing the grants. Read-only access to core resources like pods, services, config maps, et. Think so here we have a Kubernetes rule dev viewer. We created this in the developing namespace with API groups resources and verbs. We have two different rules here. One is that pod services and config maps, we are gonna allow, get, list, and watch. But then if we move into the apps, API group, which is our deployments, replica sets, staple sets, et cetera. We have get list and watch as well. To make this work, we need a rule binding, and here we just say
4:47 we want to bind the dev viewer rule role to the teleport group. Teleport devs. And then if we take a look at the production site, besides the production industry's been different, we actually are giving them. Pretty much unlimited access to the core API group and the apps group with all resources and all verbs. And you should notice the intentionally symmetry here, right? Developers get read only access and the development namespace, but production admins get full access and production. Neither group can touch the other's namespace through Kubernetes RBAC alone, but we can add a second layer
5:27 of enforcement. Before we proceed, let's apply our Kubernetes RBAC files. To do so, we can run O2, and this just applies this to our Cluster. We have dev viewer and our production. Perfect. So now we have to handle the teleport side, and this is where Teleports rule system really shines. A teleport rule does three things for Kubernetes access. It determines which Kubernetes groups are embedded in the user certificate. It controls which clusters and namespace the user can reach, and it sets hard N rules to override everything else. So again, let's start with the dev team role and take a look.
6:16 Under teleport roles, we have dev team role where we have spec allow. We set the Kubernetes groups to teleport devs. This means that when a user with this teleport role, authenticate, their shortlist certificate will carry the teleport dev group. This is not a Kubernetes resource you can query, but it is part of their authentication system of their authentication. API. When that certificate reaches the Kubernetes API server, Kubernetes will match it against the rule binding we just created and grant read only access to the development namespace, but we can also set Kubernetes resources to allow access to only the development namespace.
6:54 Now, this is a teleport level restriction, even if someone managed to create a Cluster rule binding in the Kubernetes Cluster that granted teleport devs access to all namespace. Teleport would actually still block this request before it reached API Server. Defense in depth. Now here is the most important part, the deny rules under spec deny we explicitly block all resources in the Kube-system and production. namespace Deny rules and teleport always take precedence over all they allow rules. There is no way to override a deny rule with a more permissive allow rule. And this gives you a hard security boundary.
7:37 Even if someone creates additional teleport roles with broader allow rules and assigns them to the same user, the deny rules will always block access, in this case to production and Kube-system namespace. The pro team rule follows the same pattern, but in reverse. IT Grants teleport prod admins group allow access to the production namespace and denies access to Kube-system. Notice that we also provide a accession time to level four hours instead of eight because production access should have a shorter time to live to reduce the window of exposure if a certificate should ever somehow be compromised.
8:19 All right, let's apply these to our Cluster. And now we have links to click to gain access to our dev user and our pro user. And these are just gonna be created as local users because I can't fabricate GitHub users. Or I could, but I really don't want to. So give me just a moment to set up dev and production users and still the credentials in one password. I'm done Now. And your production scenario, you would of course have these roles mapped to GitHub teams instead. All right. Local users will still allow me to show how teleport rules affect your Kubernetes
8:58 access in the best possible way. So let me start by highlighting something subtle here. The teleport deny rules and the Kubernetes RBAC are enforcing the same boundary from different layers. The Kubernetes role is the namespace scoped, so Dev Your on the Grounds Access within development, the teleport Deny role explicitly blocks production. You might wonder why we need both. And the answer, as I said earlier, is defense in depth. If someone creates a Kubernetes Cluster rule that accidentally grants broader access, the teleport deny rule, we'll still hold true if someone modifies the teleport rule but forgets to update Kubernetes.
9:38 The namespace scope rule still holds true to independent layers. Each capable of blocking, unauthorized access on its own together. Defense in depth. So let's see this in action. We'll apply some sample workloads, just X deployments in both namespace. Then we'll log in as the developer and see what we can and cannot do. So if we run oh four. I've commented out all of the automation that will be available in your script, but this will handle the teleport login for you. Right now, I just want to get our pods deployed to the namespace. If we're on kubectl, let's start with Get Namespace.
10:29 We'll see. We have development and production. We can go to development, get pods. I do the same and production. Now, this is as my Kubernetes kube-admin Super root access, which we now want to blow away. I'm gonna take away all Teleport access as a goods, my real GitHub authenticated Teleport access that we've seen earlier, and instead, login as our development user. All right, so I spared you the building TSH login proxy. On this time, we used test user. Because this is a local user and not configured through the GitHub connector, we did have to provide the password and one time password as our second factor.
11:15 We can then run T-S-H-Q-L-S-T-S-H cube login, followed by the Cluster name. And this will add the context to our kubeconfig. Um, we should be able to run kubectl config, get context, and we'll see my admin token from earlier and my new teleport token, like, so we can then run kubectl dash n development, get pods, and we can see the pods running and the development namespace. If we try and change this to production or even kubectl, get Ns, we will get permission denied. Perfect. Alright. I've now logged in as our pro user, meaning I can do config
12:09 use context. And around kubectl, get pod and development, and this should fail pH. And if we run production perfect, and now we have two users with completely different scopes. But let's take a look at that second layer boundary teleport protecting us in the event of a misconfiguration at the Kubernetes level. Okay, last demo. Let's run kubectl Auth. Who am I? Who am I? I know authenticated as route again by switching to my admin Cluster. And what I wanna do is apply a Kubernetes RBAC escalation test with the Cluster rule binding. This is a Cluster role binding that takes our teleport prod admins
13:14 group and gives it Cluster admin. We can then switch back configs context to our teleport user where we run off to, am I? And that would be expected, but it does just prove that I'm not root in the Cluster anymore. So let's try production, get pods this works and development. Kube-system denied and if we take a closer look at these deny messages, it actually says, ask your teleport admin to ensure your teleport role has the right permissions. Awesome. So that was a look at using Teleports, advanced RBAC system with defense and depth, giving you a secure, configurable, fine-grained RBAC model
14:14 for all your Kubernetes clusters. Awesome. We'll see you in the next video.