Skip to content

Conversation

@vadorovsky
Copy link
Member

This change adds the runc wrapper which has a purpose of applying
policies set through Kubernetes namespaces. For now, it uses the
namespace labels proposed in the PSP Replacement KEP[0].

The runc wrapper checks whether the container which is about to be
started was scheduled by kubelet (by checking runc annotations set by
kubelet / runtime servers). If some non-default policy is set, that
policy is written for the particilar container to the BPF map, so then
BPF programs can be aware of that policy.

For now, there is no way of proving that those annotations really come
from Kubernetes. Coming up with some sane way of securely proving that
will be something to implement in a follow up work.

[0] kubernetes/enhancements#2582

Fixes: #3
Signed-off-by: Michal Rostecki [email protected]

@vadorovsky vadorovsky force-pushed the policies branch 2 times, most recently from b1f21c1 to 8b7e091 Compare June 30, 2021 10:07
@vadorovsky vadorovsky force-pushed the policies branch 2 times, most recently from 59cbe28 to df53f9e Compare July 7, 2021 16:07
@vadorovsky vadorovsky marked this pull request as ready for review July 7, 2021 16:07
@nickgerace
Copy link
Collaborator

Overall PR question: will runc always be available?

Copy link
Collaborator

@nickgerace nickgerace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few questions! Mainly looked at Rust code.

@vadorovsky
Copy link
Member Author

@nickgerace

Overall PR question: will runc always be available?

Usually yes, runc is the default runtime used by the most of CRI servers (containerd-cri, cri-o etc.). So far I would focus on it. There are some other OCI-compatible runtimes, but usually made just as an experiment (i.e. crun).

@nickgerace
Copy link
Collaborator

Usually yes, runc is the default runtime used by the most of CRI servers (containerd-cri, cri-o etc.). So far I would focus on it. There are some other OCI-compatible runtimes, but usually made just as an experiment (i.e. crun).

Thanks for the explanation! Resolved and replied to some conversations. Awaiting for re-review on ones left open.

This change adds the runc wrapper which has a purpose of applying
policies set through Kubernetes namespaces. For now, it uses the
namespace labels proposed in the PSP Replacement KEP[0].

The runc wrapper checks whether the container which is about to be
started was scheduled by kubelet (by checking runc annotations set by
kubelet / runtime servers). If some non-default policy is set, that
policy is written for the particilar container to the BPF map, so then
BPF programs can be aware of that policy.

For now, there is no way of proving that those annotations really come
from Kubernetes. Coming up with some sane way of securely proving that
will be something to implement in a follow up work.

[0] kubernetes/enhancements#2582

Fixes: #3
Signed-off-by: Michal Rostecki <[email protected]>
Since the runc wrapper got introduced, it's more convenient to register
new containers through it, instead of detecting then through BPF
programs.

This change also fixes the way how PID is determined for each process.

Another change is denying to launch any runc processes which are not
children of the runc wrapper.

Signed-off-by: Michal Rostecki <[email protected]>
@vadorovsky
Copy link
Member Author

@nickgerace Your comments should be addressed now, PTAL

This commit brings the following changes to the Vagrant ecosystem:

- memory increased to 8GB
- no restart after provisioning the control plane components
- using upstream kubeadm and upstream containerd runtime
- adding several useful packages

Signed-off-by: Michal Rostecki <[email protected]>
Starting from now, registering containers is handled by the runc
wrapper and the role of the BPF runtime map becomes rather to find the
unwrapped runc processes and deny them.

Signed-off-by: Michal Rostecki <[email protected]>
Copy link
Collaborator

@nickgerace nickgerace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Rust changes as well as general syntax and flow for Bash/C

Dockerfile Outdated
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/local/src
# Build libbpf and bpftool from the newest stable kernel sources.
ENV KERNEL_TAG v5.13.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that could be overridden at build? If so, would it make sense to make it an ARG?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, ARG can be overriden at build, ENV can't. Will change to ARG then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I also added a possibility to override the tag in Makefile, so you can do:

make KERNEL_TAG=v5.12.15

or use any tag from https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/

@vadorovsky vadorovsky merged commit 852f178 into main Jul 8, 2021
@vadorovsky vadorovsky deleted the policies branch July 8, 2021 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply policy levels on containers

3 participants