Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Harden the nodes and access to the API server

By updated

Improve this page

Logo Kubernetes

This challenge checks that you can, on your own, harden a worker node and close the API server to anonymous clients without breaking the cluster: unneeded services removed, SSH restricted to a group, contractor account stripped of its rights, kubelet closed, a firewall that survives a reboot. It is meant for people who have just followed the module on identities, access and nodes, starting with the lesson Hardening the nodes of a Kubernetes cluster. It runs in a dsoxlab virtual machine, on a kubeadm cluster with Kubernetes 1.37, and takes about 60 minutes. It gives no hints and teaches nothing new: it checks what the lessons of the module and their guided labs have already let you practice.

What you will learn

The lab opens real SSH sessions, queries the kubelet and the API server without credentials, opens connections from another node and reboots the worker at the end. It checks that you can:

  • Remove from a worker the services it does not use.
  • Restrict SSH access to a group, by key, with no root login.
  • Keep an account while stripping it of all its sudo rights.
  • Close the kubelet to anonymous clients and to an account with no rights, and close its read-only port.
  • Set a firewall with a drop policy that lets SSH, the kubelet, Pod traffic and the Calico network through.
  • Restrict the API server, for anonymous clients, to the health paths and kubeadm join.
  • Get the node back Ready and protected after a reboot.

What should you be able to do before you start?

No step-by-step procedure goes with the challenge, and finding what to remove, what to close and what to leave open is part of what it checks. Everything it asks for is taught in two lessons:

If one of these points feels unclear, reread the lesson before you start.

What does the statement ask for?

The second worker, k8s-w2.lab, has just joined the cluster. It was installed from an old server template that left many things on it that Kubernetes does not need, and a contractor whose contract has ended had an account on it. The API server still answers clients that present no credentials, and those clients are allowed to read the cluster. You are on the control plane, with kubectl and sudo, and you open a session on the worker over SSH.

During and after your work, SSH from the administration workstation and from the control plane, the kubelet, the Calico network, the health probes of the API server and kubeadm join must keep working.

The statement says what must be true at the end, never how to get there:

  1. The apache2 web server is purged from k8s-w2.lab, and the inventory service that listens on a port is stopped and disabled.
  2. Only the members of the ops-noeuds group, which holds ansible and student, open an SSH session on the worker, by key, and never as root.
  3. The contractor's account stays on the node with its files, with no sudo right at all.
  4. The kubelet answers 401 to an anonymous client, delegates its authorization decisions to the API server and has closed its read-only port.
  5. An input chain with a drop policy closes the worker: a node that is not an administration workstation no longer reaches SSH or port 10256 of kube-proxy, and the flows that are needed go through.
  6. An anonymous client reaches only the health paths and what kubeadm join needs, and gets 401 everywhere else, with no extra RBAC binding. This requirement is blocking.
  7. All of this survives a reboot of the worker, which comes back Ready. This requirement is blocking.

How do you start the challenge and get graded?

The lab sets up the cluster and the worker in the state described above, then reads the real state when you ask for the grade. You start it with dsoxlab run k8s-challenge-durcir-les-noeuds-et-l-acces-api. Two commands are then used: dsoxlab check k8s-challenge-durcir-les-noeuds-et-l-acces-api lists the criteria that are not met and gives the grade, as many times as you like, and dsoxlab submit k8s-challenge-durcir-les-noeuds-et-l-acces-api returns the final result. The lab never looks at the commands you typed: it reads the listening ports, opens fresh sessions and connections, places a Pod on the worker to reach it from the other node, then reboots the worker.

Put it into practice

This lab is the challenge itself. It puts you in front of the situation described above and it is graded on the state of the cluster, as a colleague taking over your work would do.

How is the challenge graded?

The pass mark is 70 points out of 100. Seven requirements of equal weight make up the grade, in the order of the statement. Requirements 6 and 7 are blocking: if one of the two is not met, the challenge fails, whatever the total.

If a requirement resists, dsoxlab check gives its label without saying how to fix it. Reread the lesson that covers its subject, Hardening the nodes of a Kubernetes cluster or Restricting access to the Kubernetes API server, fix it, then run dsoxlab check again.

Key points

  • The challenge is a final exercise to do alone and without hints: it explains nothing and grades the state of the cluster, not your commands.
  • Requirements 6 and 7 are blocking: anonymous access to the API server limited to the health paths and kubeadm join, and a worker that comes back Ready and protected after a reboot.
  • A hardening that cuts SSH, the kubelet or the Calico network breaks the cluster: the lab detects it.
  • dsoxlab check lists the criteria that are not met; dsoxlab submit returns the result.