VK Cloud logo

Security policies

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

  • granting overly broad access rights;
  • 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 that provide basic cluster protection against several common vulnerabilities:

Default security policy

Corresponding Gatekeeper resources

host-filesystem constraint

Constraint and constraint template: k8spsphostfilesystem

host-namespaces constraint

Constraint and constraint template: k8spsphostnamespace

These policies are implemented using preconfigured Gatekeeper templates and constraints. Default security policies are enabled by default in all clusters, but you can change or disable them via the management console.

Working with security policies via the management console

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

At the same time, synchronization of security policies with the cluster is enabled by default and 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 management console 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 management console, they will be deleted.

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

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

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 (services).

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

Block Wildcard Ingress

Checks the Ingress resource for the presence of the spec.rules.host parameter in the Ingress routing rule. Prohibits using the following as 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 (workload). The restriction does not apply to groups and users for whom 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 a compute resource request mandatory for containers: CPU in the requests.cpu parameter and memory in the requests.memory parameter. 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 specifying compute resource limits mandatory for containers: CPU in the limits.cpu parameter and memory in the limits.memory parameter. 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 SHA hash

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

If a 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 the old image while others use the new image, 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 cluster security. 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 directory of a Kubernetes cluster node. 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 runs. This can lead to disclosure of sensitive information about the cluster, privilege escalation, and other problems.

host-namespaces constraint

Prohibits access to 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 gains the following capabilities:

  • Viewing all processes running on the host.
  • Forcibly terminating any process on the host with a kill command sent from the pod.
  • Reading environment variables from the /proc/[PID]/environ file for each pod or process on the host.
  • Access to 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 specifying 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 configured replication, 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 completely exhausted. For example, a situation may occur where the cluster performs automatic scaling up to the specified limit to accommodate excess replicas, while no available nodes remain to host a new workload.

Was this article helpful?