Web Hosting Journal

Kubernetes Best Configuration Practises

Kubernetes Configuration Practises

Kubernetes is defined as set of building blocks where-in they provide mechanisms that deploy maintain and scale applications based on CPU memory and it is coupled loosely to meet different workloads.

Kubernetes which was originally designed by Google is an open source container orchestration system which is used for automating application deployment management and scaling and is now maintained by the Cloud Native Computing Foundation. It was first introduced by Google in 2014.

Most organizations have an idea that containers and Kubernetes are like previous waves of infrastructure, where security starts with a securely configured infrastructure. In a recent survey of IT and security practitioners, respondents identified user-driven misconfigurations as major area of concern for container security and in addition to this role of human errors plays a major role in data breaching. Humans as well developers can make mistakes especially given that Kubernetes configuration options which are much complicated, by default security features are not enabled, and most of the community is learning how to effectively use components including Pod Security Policies & Security Context, Network Policies, RBAC, the API server.

So below are the best practices to build a strong and safe foundation:

1. Updating Kubernetes to the latest version

So right away update your Kubernetes to the latest version (1.16) . This version has all the new and exciting features and every new release is provided with a host of different security features.

2. Use Pod Security Policies to prevent risky containers/Pods from being used

Pod security policy is a cluster-level resources available in Kubernetes which is highly recommended and we must enable the PodSecurityPolicy admission controller to use it. Depending upon the nature of admission controllers, you should authorize at least one policy – otherwise no pods will be allowed to be created in the cluster.

Pod Security Policies address several critical security use cases, which are listed below:

3. Use Kubernetes namespaces to properly isolate your Kubernetes resources

Namespaces provides you the ability to create logical partitions & enforce separation of your resources as well as limit the scope of user permissions.

4. Use Network Policies to segment and limit container as well as pod communication

Network Policies are used to determine how pods are given access to communicate.

5. Create policies to govern image provenance using the Image Policy Webhook

We should Prevent unapproved images from being used with the admission controller to reject pods which use unapproved images including:

6. Securely configure the Kubernetes API server

The Kubernetes API server handles all the REST API calls between external users and Kubernetes components.

Run the below command on your master node:

ps -ef | grep kube-apiserver

In the output, check to ensure that the:

7. Securely configure the kube-scheduler

The default scheduler for Kubernetes, kube-scheduler selects the node that a newly created Pod should run on. Run the below command on your master node:

ps -ef | grep kube-scheduler

In the output, check to ensure that the:

8. Securely configure the kube-controller-manager

Run the below command on your master node:

ps -ef | grep kube-controller-manager

In the output, check to ensure that the:

Secure the configuration files on the master node

9. Secure the API server pod specification file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/manifests/kube-apiserver.yaml

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the API Server pod specification file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/manifests/kube-apiserver.yaml

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the controller manager pod specification file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/manifests/kube-controller-manager.yaml

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the controller manager pod specification file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/manifests/kube-controller-manager.yaml

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the scheduler pod specification file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/manifests/kube-scheduler.yaml

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the scheduler pod specification file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/manifests/kube-scheduler.yaml

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the etcd pod specification file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/manifests/etcd.yaml

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file. As a reminder on a topic already discussed, etcd is a key-value store, and protecting it is of the utmost importance, since it contains your REST API objects.

Secure the etcd pod specification file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/manifests/etcd.yaml

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the Container Network Interface file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a <path/to/cni/files>

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the Container Network Interface file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G <path/to/cni/files>

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the etcd data directory permissions.

First run the following command to the get etcd data directory:

ps -ef | grep etcd

Now run the following command based on the etcd data directory you found from the previous command:

stat -c %a /var/lib/etcd

In the output, check to ensure that permissions are 700 or more restrictive to ensure your etcd data directory is protected against unauthorized reads/writes.

Secure the etcd data directory ownership.

First run the following command to the get etcd data directory:

ps -ef | grep etcd

Now run the following command based on the etcd data directory you found from the previous command:

stat -c %U:%G /var/lib/etcd

In the output, check to ensure that ownership is etcd:etcd to ensure your etcd data directory is protected against unauthorized reads/writes.

Secure the admins.conf file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/admin.conf

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the admins.conf file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/admin.conf

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the scheduler.conf file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/scheduler.conf

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the scheduler.conf file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/scheduler.conf

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the controller-manager.conf file permissions.

Run the following command on the master node (specifying your file location on your system):

stat -c %a /etc/kubernetes/controller-manager.conf

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the controller-manager.conf file ownership.

Run the following command on the master node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/controller-manager.conf

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the Kubernetes PKI directory and file ownership.

Run the following command on the master node (specifying your file location on your system):

ls -laR /etc/kubernetes/pki/

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the Kubernetes PKI directory and file permissions.

Run the following command on the master node (specifying your file location on your system):

ls -laR /etc/kubernetes/pki/*.crt

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the Kubernetes PKI key file permissions.

Run the following command on the master node (specifying your file location on your system):

ls -laR /etc/kubernetes/pki/*.key

In the output, check to ensure that permissions are 600 to maintain the integrity of the file.

10. Securely configure etcd

As mentioned in previous sections, etcd is a key-value store used by distributed systems such as Kubernetes for data access. etcd is considered the source of truth for Kubernetes, and you can read data from and write into etcd as needed. Securely configuring etcd and communications to its servers are of utmost criticality.

Run the following command on the etcd server node:

ps -ef | grep etcd

In the output, check to ensure that the:

11. Securely configure the Kubelet

The kubelet is the main “node agent” running on each node. Misconfiguring kubelet can expose you to a host of security risks. we can either use arguments on the running kubelet To find the kubelet config file, run the following command:

ps -ef | grep kubelet | grep config

Look for –config argument, which will give you the location of the kubelet config file.

Then run the following command on each node:

ps -ef | grep kubelet

In the output, make sure that the:

12. Secure the worker node configuration files

Secure the kubelet service file permissions.

Run the following command on each worker node (specifying your file location on your system):

stat -c %a /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the kubelet.conf file permissions.

Run the following command on each worker node (specifying your file location on your system):

stat -c %a /etc/kubernetes/kubelet.conf

In the output, check to ensure that permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the kubelet.conf file ownership.

Run the following command on each worker node (specifying your file location on your system):

stat -c %U:%G /etc/kubernetes/kubelet.conf

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the kublete service file ownership.

Run the following command on each worker node (specifying your file location on your system):

stat -c %U:%G /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

In the output, check to ensure that ownership is set as root:root to maintain the integrity of the file.

Secure the proxy kubeconfig file permissions.

Run the following command to first find the kubeconfig file being used:

ps -ef | grep kube-proxy

Get the kube-proxy file location (if it’s running) from –kubeconfig, then run the following command on each worker node (specifying your file location on your system).

stat -c %a <proxy kubeconfig file>

In the output, check to make sure permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the proxy kubeconfig file ownership.

Run the following command first to find the kubeconfig file being used:

ps -ef | grep kube-proxy

Get the kube-proxy file location (if it’s running) from –kubeconfig, then run the following command on each worker node (specifying your file location on your system):

stat -c %U:%G <proxy kubeconfig file>

In the output, check to make sure ownership is set as root:root to maintain the integrity of the file.

Secure the certificate authorities file permissions.

Run the following command first:

ps -ef | grep kubelet

Look for the file name that’s identified by –client-ca-file argument. Then run the following command, specifying the previous file name:

stat -c %a <filename>

In the output, check to make sure permissions are 644 or more restrictive to maintain the integrity of the file.

Secure the client certificate authorities file ownership.

Run the following command first:

ps -ef | grep kubelet

Look for the file name that’s identified by –client-ca-file argument. Then run the following command, specifying the previous file name:

stat -c %U:%G <filename>

In the output, check to make sure ownership is set asroot:root to maintain the integrity of the file.

Secure the kubelet configuration file permissions.

First locate the kubelet config file with following command:

ps -ef | grep kubelet | grep config

In the output, you may see the location of the config file if it exists. It would look something like /var/lib/kubelet/configuration.yaml.

Using the location of the file (we’ll use the file location from this previous example), run the following command to identify the file’s permissions:

stat -c %a /var/lib/kubelet/configuration.yaml

In the output, check to make sure permissions are set to 644 or more restrictive to ensure the integrity of the file.

Secure the kubelet configuration file ownership.

Run the following command:

ps -ef | grep kubelet | grep config

In the output, you may see the location of the config file if it exists – it would look something like /var/lib/kubelet/configuration.yaml.

Using the location of the file (we’ll use the file location from this previous example), run the following command to identify the file’s permissions:

stat -c %U:%G /var/lib/kubelet/configuration.yaml

In the output, check to make sure ownership is set to root:root to maintain the integrity of the file.

Exit mobile version