⎈ k8s knowledge compiler

Restrict a Container's Syscalls with seccomp [page]deterministic

tutorials

Seccomp stands for secure computing mode and has been a feature of the Linux kernel since version 2.6.12. It can be used to sandbox the privileges of a process, restricting the calls it is able to make from userspace into the kernel. Kubernetes lets you automatically apply seccomp profiles loaded onto a [node](#gloss:node) to your Pods and containers.

Identifying the privileges required for your workloads can be difficult. In this tutorial, you will go through how to load seccomp profiles into a local Kubernetes cluster, how to apply them to a Pod, and how you can begin to craft profiles that give only the necessary privileges to your container processes.

##

* Learn how to load seccomp profiles on a node * Learn how to apply a seccomp profile to a container * Observe auditing of syscalls made by a container process * Observe behavior when a missing profile is specified * Observe a violation of a seccomp profile * Learn how to create fine-grained seccomp profiles * Learn how to apply a container runtime default seccomp profile

##

In order to complete all steps in this tutorial, you must install [kind](/docs/tasks/tools/#kind) and [kubectl](/docs/tasks/tools/#kubectl).

The commands used in the tutorial assume that you are using [Docker](https://www.docker.com/) as your container runtime. (The cluster that `kind` creates may use a different container runtime internally). You could also use [Podman](https://podman.io/) but in that case, you would have to follow specific [instructions](https://kind.sigs.k8s.io/docs/user/rootless/) in order to complete the tasks successfully.

This tutorial shows some examples that are still beta (since v1.25) and others that use only generally available seccomp functionality. You should make sure that your cluster is [configured correctly](https://kind.sigs.k8s.io/docs/user/quick-start/#setting-kubernetes-version) for the version you are using.

The tutorial also uses the `curl` tool for downloading examples to your computer. You can adapt the steps to use a different tool if you prefer.

It is not possible to apply a seccomp profile to a container running with `privileged: true` set in the container's `securityContext`. Privileged containers always run as `Unconfined`.

## Download example seccomp profiles {#download-profiles}

The contents of these profiles will be explored later on, but for now go ahead and download them into a directory named `profiles/` so that they can be loaded into the cluster.

Run these commands:

```shell mkdir ./profiles curl -L -o profiles/audit.json https://k8s.io/examples/pods/security/seccomp/profiles/audit.json curl -L -o profiles/violation.json https://k8s.io/examples/pods/security/seccomp/profiles/violation.json curl -L -o profiles/fine-grained.json https://k8s.io/examples/pods/security/seccomp/profiles/fine-grained.json ls profiles ```

You should see three profiles listed at the end of the final step: ``` audit.json fine-grained.json violation.json ```

## Create a local Kubernetes cluster with kind

For simplicity, [kind](https://kind.sigs.k8s.io/) can be used to create a single node cluster with the seccomp profiles loaded. Kind runs Kubernetes in Docker, so each node of the cluster is a container. This allows for files to be mounted in the filesystem of each container similar to loading files onto a node.

Download that example kind configuration, and save it to a file named `kind.yaml`: ```shell curl -L -O https://k8s.io/examples/pods/security/seccomp/kind.yaml ```

You can set a specific Kubernetes version by setting the node's container image. See [Nodes](https://kind.sigs.k8s.io/docs/user/configuration/#nodes) within the kind documentation about configuration for more details on this. This tutorial assumes you are using Kubernetes .

As a beta feature, you can configure Kubernetes to use the profile that the [container runtime](#gloss:container-runtime) prefers by default, rather than falling back to `Unconfined`. If you w …(trimmed)

Sources

tutorials/security/seccomp.md · docRestrict a Container's Syscalls with seccomp

Related (14)

references Nodenode conf=1
references Container Runtimecontainer runtime conf=1
references ServiceService conf=1
part_of {{% heading "objectives" %}}describes conf=1
part_of {{% heading "prerequisites" %}}describes conf=1
part_of Create a local Kubernetes cluster with kinddescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
api_for Containerdocuments API object conf=1

← all Docs