
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Grant the GKE Admin Cloud IAM Role to username 2
/ 20
Grant the ServiceAccountUser IAM Role to Username 2
/ 20
Create a GKE cluster
/ 20
Create the namespaces and labels
/ 20
Apply the manifest to the 'restricted-ns' namespace
/ 20
You will control access to GKE clusters using IAM. You will create a pod security policy to restrict privileged Pod creation, and you will test that policy. You will also perform IP address and credential rotation.
In this lab, you learn how to perform the following tasks:
After a moment of provisioning, the Cloud Shell prompt appears.
While logged in as Username 2, on the Navigation menu (), click Kubernetes Engine > Clusters.
Make sure that your lab Project ID is selected at the top of the page.
Notice that the option to create a cluster is disabled.
You will now allow Username 2 to create a GKE cluster and deploy workloads by using primitive roles to grant a user permissions to administer all GKE clusters and manage resources inside those clusters in this project. The Username 1 account has project owner rights and you will use that account to grant Username 2 more rights.
On the Navigation menu (), click IAM & admin > IAM.
In the IAM console, locate the row that corresponds to Username 2, and then click on the pencil icon at the right-end of that row to edit that user's permissions.
Notice that Username 2 currently has the Viewer role, which provides read access to all resources within the project.
Click ADD ANOTHER ROLE to add another dropdown selection for roles.
In the Select a role dropdown box, choose Kubernetes Engine > Kubernetes Engine Cluster Admin.
Click SAVE.
Click Check my progress to verify the objective.
You will now verify your work by using Username 2 to create a GKE cluster.
You should now see that the option to create a cluster is now enabled. You may need to refresh the web browser tab for Username 2 to see the changes.
Click Create to begin creating a GKE cluster.
Click Switch to Standard Cluster and confirm the same on next pop-up.
Set the name of the cluster to standard-cluster-1, if that is not the default.
Confirm that a zonal, rather than regional, cluster is selected.
Choose zone
Leave all other values at their defaults and click Create.
The cluster begins provisioning, but soon fails.
Username 2 still lacks some of the rights necessary to deploy a cluster. This is because GKE leverages Google Cloud Compute Engine instances for the nodes.
To deploy a GKE cluster, a user must also be assigned the iam.serviceAccountUser role on the Compute Engine default service account.
You will now use IAM to grant Username 2 the iam.serviceAccountUser role so that Username 2 may successfully deploy a GKE cluster.
On the Navigation menu (), click IAM & admin > Service accounts.
In the IAM console, click the row that corresponds to the Compute Engine default service account to select it.
Click on Permission to open the permissions information panel.
On the Permission page, click on Grant access.
The permissions information panel will open on the right side of the window.
Click Check my progress to verify the objective.
You will now verify your work by using Username 2 to create a GKE cluster.
While logged in as Username 2, on the Navigation menu (), click Kubernetes Engine > Clusters. You may need to refresh your web browser.
Click Create to begin creating a GKE cluster.
Click Switch to Standard Cluster and confirm the same on next pop-up.
Set the name of the cluster to standard-cluster-1, if that is not the default.
Confirm that a zonal, rather than regional, cluster is selected.
Choose zone
Leave all other values at their defaults and click Create.
The cluster will successfully deploy this time.
Click Check my progress to verify the objective.
PodSecurity is a Kubernetes admission controller that lets you apply Pod Security Standards to Pods running on your GKE clusters. Pod Security Standards are predefined security policies that cover the high-level needs of Pod security in Kubernetes. These policies range from being highly permissive to highly restrictive.
In this task, you create a pod security policy that allows the creation of unprivileged Pods in the default namespace of the cluster. Unprivileged Pods do not allow users to execute code as root, and have limited access to devices on the host.
You create a ClusterRole that can then be used in a role binding that ties the policy to accounts that require the ability to deploy pods with unprivileged access.
Users that require the ability to deploy privileged Pods can be granted access to the built in PSP that is provided to allow admin users to deploy pods after Pod Security Policies are enabled.
When you have the components configured you will enable the PodSecurityPolicy controller, which enforces these policies, and then test how they impact users with different privileges.
To use the PodSecurity admission controller, you must apply specific Pod Security Standards in specific modes to specific namespaces
Create namespaces in your cluster:
This command creates the following namespaces:
Apply the following Pod Security Standards:
These commands achieve the following result:
Verify that the labels were added:
The output is similar to the following:
Click Check my progress to verify the objective.
To verify that the PodSecurity admission controller works as intended, deploy a workload that violates the baseline and the restricted policy to both namespaces. The following example manifest deploys an nginx container that allows privilege escalation.
psa-workload.yaml
with nano using the following command:psa-workload.yaml
file:Press Ctrl+O, and then press Enter to save your edited file.
Press Ctrl+X to exit the nano text editor.
Apply the manifest to the baseline-ns namespace:
The output is similar to the following:
The baseline policy allows the Pod to deploy in the namespace.
The output is similar to the following:
The Pod won't deploy in the namespace. An audit entry is added to the log.
Click Check my progress to verify the objective.
Policy violations in the audit and enforce modes are recorded in the audit logs for your cluster. You can view these logs using the Logs Explorer in the Google Cloud console.
On the Google Cloud console title bar, type Logs Explorer in the Search field, then click Logs Explorer in the search results.
In the Query field, specify the following:
Click Run query.
In the Query results section, expand the Forbidden log entry. The details are similar to the following:
You perform IP and credential rotation on your cluster. It is a secure practice to do so regularly to reduce credential lifetimes. While there are separate commands to rotate the serving IP and credentials, rotating credentials additionally rotates the IP as well.
Y
to continue.After the command completes in the Cloud Shell the cluster will initiate the process to update each of the nodes. That process can take up to 15 minutes
for your cluster. The process also automatically updates the kubeconfig entry for the current user.
Note: You must update the kubeconfig file on any other system that uses kubectl or API to access the master before completing the rotation process to avoid losing access.
This finalizes the rotation processes and removes the original cluster ip-address.
Enter Y
to continue.
After the cluster has successfully upgraded, re-execute the following command:
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one