Accessing the Cluster as a User

Learn how to impersonate the new user John and try to get the access authenticated.

Authentication#

Since John is not around, we’ll do some role-playing and impersonate him.

Configuring kubectl#

John will first have to set the cluster using the address and the certificate authority we sent him.

Configuring kubectl

We created a new cluster called jdoe.

Please note that the command we executed created just another config entry that enables to access all resources that currently exist in the cluster. It manipulated local text file, without changing anything in the existing cluster.

Setting the credentials#

Next, he’ll have to set the credentials using the certificate and the key we created for him.

Setting credentials

We created a new set of credentials called jdoe.

Creating a new context#

Finally, John will have to create a new context.

Creating new context

We created the context jdoe that uses the newly created cluster and the user. We also made sure that we’re using the newly created context.

Let’s take a look at the config.

View config

The output, limited to John’s settings, is as follows.

Selected output of 'config view'

No authorization#

John should be happy thinking that he can access our cluster. Since he’s a curious person, he’ll want to see the Pods we’re running.

Get pods

The output is as follows.

Output of above commands

That’s frustrating. John can reach our cluster, but he cannot retrieve the list of Pods. Since hope dies last, John might check whether he is forbidden from seeing other types of objects.

Get all objects

The output is a long list of all the objects he’s forbidden from seeing. So, in other words, John is authenticated successfully, but he is not authorized to view objects in the cluster.

John picks up his phone to beg not only that you give him access to the cluster but also the permissions to “play” with it.

Try it yourself#

A list of all the commands used in the lesson is given below.

Commands used in this lesson

You can practice the commands in the following terminal by pressing the Click to Connect button and waiting for the cluster to set up:

Terminal 1
Terminal

Click to Connect...

Creating Users to Access the Cluster
Exploring RBAC Authorization
Mark as Completed
Report an Issue