Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cgroup v2 support #3

Merged
merged 3 commits into from
Mar 5, 2024
Merged

Add cgroup v2 support #3

merged 3 commits into from
Mar 5, 2024

Conversation

nbdd0121
Copy link
Contributor

@nbdd0121 nbdd0121 commented Mar 4, 2024

cgroup v1 uses two special files to determine access, where cgroup v2 uses eBPF programs to control access. The code will attach a custom eBPF program which allows run-time reconfiguration and detach docker's default.

eBPF programs will be detached when the attaching program dies, which can be dangerous if container-hotplug exits unexpectedly while the program is running, so we instead pin it (so it stays when the program exits) and unpin it after the docker container is down. In this case we might have garbage eBPF programs pinned when container-hotplug exits unexpectedly but it is safe.

@nbdd0121 nbdd0121 requested review from pamaury and jwnrt March 4, 2024 16:21
@nbdd0121
Copy link
Contributor Author

nbdd0121 commented Mar 4, 2024

@jprendes just in case that you're interested

Cargo.toml Outdated
@@ -30,6 +30,7 @@ bollard = "0.16"
futures = "0.3"
rustix = { version = "0.38", features = ["fs", "stdio", "termios"] }
bitflags = "2"
aya = { git = "https://github.com/nbdd0121/aya.git" }
Copy link

Choose a reason for hiding this comment

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

We should either merge changes upstream or fork the repo under lowRISC I think. Seems like your changes could be upstreamed?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was actually upstreamed one hour ago! Good timing :)

Copy link

@pamaury pamaury left a comment

Choose a reason for hiding this comment

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

This looks good to me, I have never really used eBPF programs so I might have missed something.

nbdd0121 added 2 commits March 5, 2024 11:28
This is a simple program which allows mknod, a standard list of devices
to be allowed inside the container, and a hashmap mapping a list of devices
to allwoed accesses. This allows runtime update on whether a device is
allowed inside a container.

It is automatically compiled with build.rs.
cgroup v1 uses two special files to determine access, where cgroup v2
uses eBPF programs to control access. The code will attach a custom eBPF
program which allows run-time reconfiguration and detach docker's default.

eBPF programs will be detached when the attaching program dies, which
can be dangerous if container-hotplug exits unexpectedly while the program
is running, so we instead pin it (so it stays when the program exits) and
unpin it after the docker container is down. In this case we might have
garbage eBPF programs pinned when container-hotplug exits unexpectedly but
it is safe.
@nbdd0121 nbdd0121 merged commit 0045fe8 into main Mar 5, 2024
1 check passed
@nbdd0121 nbdd0121 deleted the cgroupv2 branch March 5, 2024 11:34
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.

3 participants