VK Cloud logo

Security policies

A Kubernetes cluster is a complex system in which numerous resources can be deployed. Typical risks that arise when operating such a system:

  • granting overly broad access permissions;
  • deploying resources that are either vulnerable to attacks, consume too much capacity, or do not comply with corporate policies.

To mitigate these risks, the Managed Containers service, in addition to supporting access control to the cluster, implements security policies.

Kubernetes cluster capabilities for working with security policies:

Default security policies

Kubernetes clusters in the Managed Containers service have default security policies in effect that provide basic cluster protection against several common vulnerabilities:

Default security policy
Corresponding Gatekeeper resources
Constraint and constraint template: k8spsphostfilesystem
Constraint and constraint template: k8spsphostnamespace

These policies are implemented using preconfigured Gatekeeper templates and constraints. They are enabled by default in all clusters, but you can change or disable them via the personal dashboard.

Working with security policies via the personal dashboard

You can configure common security policies via the personal dashboard. The necessary set of Gatekeeper constraints and constraint templates will be automatically created in the cluster.

In this case, synchronization of security policies with the cluster will be enabled by default, and synchronization cannot be disabled. This affects the Gatekeeper resources in the cluster as follows:

  • If a constraint or template corresponding to a policy enabled in the personal dashboard is deleted from the cluster, it will be restored.
  • If the cluster contains manually created constraints that do not correspond to any policy enabled in the personal dashboard, they will be deleted.

For examples of working with third-party security policies, see the section Using Gatekeeper.

When working with policies via the personal dashboard, it is not recommended to modify individual constraints or templates corresponding to any policies configured in the personal dashboard: incorrect operation or absence of policies may reduce the security of the cluster.

Available security policies and their settings

Some policies have no settings; for them, you can only select a namespace.

Block NodePort

Prohibits the use of NodePort type services.

Using NodePort type services makes it possible to intercept traffic of other pods or nodes bypassing network security tools.

Block Wildcard Ingress

Checks whether the Ingress resource has the spec.rules.host parameter in the Ingress routing rule. Prohibits the following values for the parameter:

  • an empty string;
  • the * wildcard in the value.

Using Ingress resources with the specified spec.rules.host values makes it possible to intercept traffic of other services, even if there is no direct access to those services.

Block Service Account update

Prohibits updating the service account for a workload. The restriction does not apply to groups and users for which exceptions are configured.

An unrestricted ability to change the service account for a workload can lead to privilege escalation in the cluster.

Container resource requests

Makes it mandatory to request compute resources for containers: CPU in the requests.cpu parameter and memory in the requests.memory parameter. It checks that the values of these parameters do not exceed the configured thresholds.

The ability to create a container with excessively high requests can lead to resource exhaustion if limits are not set.

Container resource limits

Makes it mandatory to specify compute resource limits for containers: CPU in the limits.cpu parameter and memory in the limits.memory parameter. It checks that the values of these parameters do not exceed the configured thresholds.

Creating a container with inflated limits can exhaust compute resources.

Running images with a SHA hash

Prohibits the use of container images without specifying a SHA hash (digest).

If the SHA hash is not specified in the value of the image parameter, it is not guaranteed that the same image version will be used. When using tags instead of hashes, a situation may occur where some pods use an old image while others use a new one, even though the image tags are identical.

Allowed repositories

Prohibits the use of container images with repository prefixes that are not specified as trusted in the settings.

Using images from untrusted repositories can reduce the security of the cluster. For example, such images may contain embedded malicious code.

host-filesystem constraint

Prohibits the use of hostPath type volumes in containers. Mounting such volumes is equivalent to mounting a Kubernetes cluster node directory. The restriction does not apply to directories for which exceptions are configured.

Using hostPath without restrictions gives the container full access to the file system of the cluster node on which the pod is running. This can lead to disclosure of sensitive information about the cluster, privilege escalation, and other problems.

host-namespaces constraint

Prohibits accessing inter-process communication (IPC) tools and processes of a Kubernetes cluster node using the hostIPC: true and hostPID: true parameters.

A pod started with these parameters gets the following capabilities:

  • Viewing all processes running on the host.
  • Forcefully terminating any process on the host with the kill command sent from the pod.
  • Reading environment variables from the /proc/[PID]/environ file for each pod or process on the host.
  • Accessing the data of processes that use IPC for communication with each other.

These are very broad capabilities that are equivalent to vulnerabilities. They allow manipulating processes, disclosing sensitive environment variables, and exploiting other vulnerabilities.

Replica count constraint

Prohibits setting a number of replicas for Kubernetes deployments that does not fit within the configured range.

If there is no lower limit on the number of replicas, applications can be deployed without replication configured, which reduces fault tolerance. If there is no upper limit on the number of replicas, the cluster can be scaled excessively or its resources can be exhausted entirely. For example, a situation may occur where the cluster performs automatic scaling up to the specified limit to accommodate excessive replicas, but no available nodes remain to host a new workload.

Was this article helpful?