-
Notifications
You must be signed in to change notification settings - Fork 346
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
Support resource restrictions for rootless containers #499
Conversation
- Use systemd client to find systemd cgroup root - Add error context - Manager debug impl - Comments - Set default slice name for rootless and rootfull containers
a306996
to
9cff024
Compare
5d07e81
to
7e3bdcc
Compare
Codecov Report
@@ Coverage Diff @@
## main #499 +/- ##
==========================================
- Coverage 61.09% 60.55% -0.55%
==========================================
Files 85 86 +1
Lines 12417 12604 +187
==========================================
+ Hits 7586 7632 +46
- Misses 4831 4972 +141 |
7e3bdcc
to
f92b265
Compare
} else { | ||
let parts = cgroups_path | ||
.to_str() | ||
.ok_or_else(|| anyhow!("failed to parse cgroupsPath field"))? | ||
.ok_or_else(|| anyhow!("failed to parse cgroups path"))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the error is raised when the cgroup path is not in the format of [slice]:[scope_prefix]:[name]
, right?
I want to output the error message properly in case it fails.
print_feature_status(&content, "CONFIG_USER_NS", FeatureDisplay::new("user")); | ||
|
||
let user_display = match rootless::unprivileged_user_ns_enabled() { | ||
Ok(false) => FeatureDisplay::with_status("user", "enabled (root only)", "disabled"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// this needs to be done before we create the init process, so that the init | ||
// process will already be captured by the cgroup. It also needs to be done | ||
// before we enter the user namespace because if a privileged user starts a | ||
// rootless container on a cgroup v1 system we can still fullfill resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// rootless container on a cgroup v1 system we can still fullfill resource | |
// rootless container on a cgroup v1 system we can still fulfill resource |
// this needs to be done before we create the init process, so that the init | ||
// process will already be captured by the cgroup. It also needs to be done | ||
// before we enter the user namespace because if a privileged user starts a | ||
// rootless container on a cgroup v1 system we can still fullfill resource | ||
// restrictions through the cgroup fs support (delegation through systemd is | ||
// not supported for v1 by us). This only works if the user has not yet been | ||
// mapped to an unprivileged user by the user namespace however. | ||
// In addition this needs to be done before we enter the cgroup namespace as | ||
// the cgroup of the process will form the root of the cgroup hierarchy in | ||
// the cgroup namespace. | ||
apply_cgroups( | ||
args.cgroup_manager.as_ref(), | ||
linux.resources().as_ref(), | ||
args.init, | ||
) | ||
.context("failed to apply cgroups")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could I ask you to update the group part of the sequence diagram in README?
/// Root path of the cgroup hierarchy e.g. /sys/fs/cgroup | ||
root_path: PathBuf, | ||
/// Path relative to the root path e.g. /system.slice/youki-569d5ce3afe1074769f67.scope for rootfull containers | ||
/// and e.g. /user.slice/user-1000/user@1000.service/youki-569d5ce3afe1074769f67.scope for rootless containers | ||
cgroups_path: PathBuf, | ||
/// Combination of root path and cgroups path | ||
full_path: PathBuf, | ||
/// Destructured cgroups path as specified in the runtime spec e.g. system.slice:youki:569d5ce3afe1074769f67 | ||
destructured_path: CgroupsPath, | ||
/// Name of the container e.g. 569d5ce3afe1074769f67 | ||
container_name: String, | ||
/// Name of the systemd unit e.g. youki-569d5ce3afe1074769f67.scope | ||
unit_name: String, | ||
/// Client for communicating with systemd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
}) | ||
} | ||
|
||
fn destructure_cgroups_path(cgroups_path: PathBuf) -> Result<CgroupsPath> { | ||
log::debug!("CGROUPS PATH IS {:?}", cgroups_path); | ||
fn destructure_cgroups_path(cgroups_path: &Path) -> Result<CgroupsPath> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be implemented impl TryFrom<Path> for CgroupPath
. What do you think?
- Add cgroups path to error context - Correct spelling mistake - Update sequence diagram - Implement TryFrom for CgroupsPath
@utam0k PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
Resource restrictions can now be applied to rootless containers (using systemd).
Systemd places units started by unprivileged users under /user.slice/user-$(id -u).slice/user@$(id -u).service. In order for resource restrictions to be applied correctly, you have to enable delegation for this service unit. This describes how to do that.