-
Notifications
You must be signed in to change notification settings - Fork 521
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
containerd: add OCI default spec and settings #2697
Conversation
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.
remaining TODOs based on early feedback
98dc430
to
021d433
Compare
Force push: resolved remaining TODOs based on early feedback. |
7dad2fb
to
2a8101c
Compare
Force push: resolved merge conflict |
a3aed67
to
afbec9e
Compare
afbec9e
to
9c72669
Compare
Force push: removed panic in helper and reset default capabilities to 1.0.2-dev defaults. |
sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml
Outdated
Show resolved
Hide resolved
sources/api/migration/migrations/v1.12.0/oci-defaults-setting/Cargo.toml
Show resolved
Hide resolved
9c72669
to
e19d8eb
Compare
Force push: address some comments |
e19d8eb
to
c633a17
Compare
break out the migration to its own commit |
c633a17
to
46d0035
Compare
|
46d0035
to
9d7001a
Compare
9d7001a
to
bf2b51b
Compare
README.md
Outdated
|
||
The **default** capabilities that are set in Bottlerocket are: | ||
|
||
setting key | setting value |
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.
nit: maybe
setting key | setting value | |
setting | default value |
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.
I agree it's clearer - accepted suggestion
README.md
Outdated
setting key | corresponding linux process capability | ||
----- | ----- | ||
`settings.oci-defaults.capabilities.audit-control` | `CAP_AUDIT_CONTROL` | ||
`settings.oci-defaults.capabilities.audit-read` | `CAP_AUDIT_READ` | ||
`settings.oci-defaults.capabilities.audit-write` | `CAP_AUDIT_WRITE` | ||
`settings.oci-defaults.capabilities.block-suspend` | `CAP_BLOCK_SUSPEND` | ||
`settings.oci-defaults.capabilities.bpf` | `CAP_BPF` | ||
`settings.oci-defaults.capabilities.checkpoint-restore` | `CAP_CHECKPOINT_RESTORE` | ||
`settings.oci-defaults.capabilities.chown` | `CAP_CHOWN` |
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.
I'd prefer to organize this as:
capability | setting | default value
CAP_AUDIT_CONTROL | settings.oci-defaults.capabilities.audit-control | false
With all the default-true ones first, followed by the others. Then we wouldn't have the duplication, and the sorting would be similar to runc's list of capabilities.
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.
What would be preferable for default value
in the case of capabilities we do not configure with default values?
A: The semantically correct setting of false
B: The syntactically correct "setting" of (unset)
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.
Also, does this comment (reorganizing to capability | setting | default value
) also apply to rlimits
as well?
Meaning, reorganizing the rlimits
section to be resource limit | setting | default value
?
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.
I would prefer something like -
to indicate unset, so there's less visual noise.
Making the same change to the rlimits
section would be good too.
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.
##### OCI Defaults: Resource Limits | ||
|
||
Each of the `resource-limits` settings below contain two numeric fields: `hard-limit` and `soft-limit`, which are **32-bit unsigned integers**. | ||
|
||
Please see the [`getrlimit` linux manpage](https://man7.org/linux/man-pages/man7/capabilities.7.html) for meanings of `hard-limit` and `soft-limit`. |
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 is quite a lot of change to land in one commit. The functionality is great, no complaints there, but it makes it a bit harder for reviewers to digest.
As a suggestion for commit structure in the future, I'd recommend:
- one commit to add the scaffolding and base functionality
- one commit to add settings + template fields for rlimits (smaller)
- one commit to add settings + template fields for capabilities (larger)
- one commit for required migrations
It's fine for this PR though.
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.
Apologies for the monolithic PR structure and thank you for explaining a better way. I'll keep this comment in my notebook as a reminder for my next PR.
@@ -0,0 +1 @@ | |||
../../../shared-defaults/oci-defaults.toml |
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.
It's a minor thing, but I'd prefer to have these in the 75-79 or 85-89 range, together with ??-oci-hooks.toml
, rather than at the end of the 90 range. That way all the OCI related defaults share the same range.
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.
Symlinks renamed in latest force push
[settings.oci-defaults.resource-limits.max-open-files] | ||
hard-limit = 1048576 | ||
soft-limit = 65536 |
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.
In preparation for future Docker support, we should give these files a name to keep them distinct:
oci-defaults-containerd-cri.toml
oci-defaults-containerd-cri-resource-limits.toml
oci-defaults-containerd-cri-capabilities.toml
The capabilities will be the same but the resource limits and configuration files will be different.
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.
Accepted suggestion, thank you
migrate(common_migrations::AddPrefixesMigration(vec![ | ||
"settings.oci-defaults", | ||
])) |
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.
migrate(common_migrations::AddPrefixesMigration(vec![ | |
"settings.oci-defaults", | |
])) | |
migrate(common_migrations::AddPrefixesMigration(vec![ | |
"settings.oci-defaults", | |
"services.oci-defaults", | |
"configuration-files.oci-defaults", | |
])) |
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.
Thank you, accepted suggestion
[metadata.settings.oci-defaults] | ||
affected-services = ["oci-defaults", "containerd"] |
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.
Need a metadata migration for the affected services.
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.
/// OciDefaultsCapability specifies which process capabilities are | ||
/// allowed to be modified in Bottlerocket. The Linux process | ||
/// capabilities are defined in the Linux manpages (see the man7.org link below). | ||
/// Default values can be found in: sources/models/shared-defaults/oci-capabilities.toml | ||
/// OCI spec: /~https://github.com/opencontainers/runtime-spec/blob/c4ee7d12c742ffe806cd9350b6af3b4b19faed6f/config.md#linux-process | ||
/// Linux kernel capabilities: https://man7.org/linux/man-pages/man7/capabilities.7.html | ||
/// | ||
/// Default capabilities are specified in the following file: | ||
/// * sources/models/shared-defaults/oci-capabilities.toml |
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.
I'd probably clean up all of these links and just say:
/// OciDefaultsCapability specifies which process capabilities are | |
/// allowed to be modified in Bottlerocket. The Linux process | |
/// capabilities are defined in the Linux manpages (see the man7.org link below). | |
/// Default values can be found in: sources/models/shared-defaults/oci-capabilities.toml | |
/// OCI spec: /~https://github.com/opencontainers/runtime-spec/blob/c4ee7d12c742ffe806cd9350b6af3b4b19faed6f/config.md#linux-process | |
/// Linux kernel capabilities: https://man7.org/linux/man-pages/man7/capabilities.7.html | |
/// | |
/// Default capabilities are specified in the following file: | |
/// * sources/models/shared-defaults/oci-capabilities.toml | |
/// OciDefaultsCapability specifies which process capabilities are | |
/// allowed to be set in the default OCI spec. |
sources/models/shared-defaults/oci-capabilities.toml
is extremely likely to be renamed during a refactor, and this comment probably won't stay correct. The OCI spec link seems a little out-of-place here, and the man page is pretty easy to find by anyone who knows they're working with Linux capabilities.
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.
Agreed - wouldn't want stale references in comments. Accepted suggestion
/// OciDefaultsResourceLimitType specifies which resource limits are | ||
/// allowed to be modified in Bottlerocket. The full list of Linux resource limits can | ||
/// be found in the Linux manpages (for convenience at the man7.org link below.) | ||
/// Default values can be found in: sources/models/shared-defaults/oci-resource-limits.toml | ||
/// OCI spec: /~https://github.com/opencontainers/runtime-spec/blob/c4ee7d12c742ffe806cd9350b6af3b4b19faed6f/config.md#posix-process | ||
/// Linux resource limits: https://man7.org/linux/man-pages/man2/getrlimit.2.html#DESCRIPTION | ||
/// | ||
/// Default resource limits are specified in the following file: | ||
/// * sources/models/shared-defaults/oci-resource-limits.toml |
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.
/// OciDefaultsResourceLimitType specifies which resource limits are | |
/// allowed to be modified in Bottlerocket. The full list of Linux resource limits can | |
/// be found in the Linux manpages (for convenience at the man7.org link below.) | |
/// Default values can be found in: sources/models/shared-defaults/oci-resource-limits.toml | |
/// OCI spec: /~https://github.com/opencontainers/runtime-spec/blob/c4ee7d12c742ffe806cd9350b6af3b4b19faed6f/config.md#posix-process | |
/// Linux resource limits: https://man7.org/linux/man-pages/man2/getrlimit.2.html#DESCRIPTION | |
/// | |
/// Default resource limits are specified in the following file: | |
/// * sources/models/shared-defaults/oci-resource-limits.toml | |
/// OciDefaultsResourceLimitType specifies which resource limits are | |
/// allowed to be set in the default OCI spec. |
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.
Accepted suggestion
bf2b51b
to
ec2a9f4
Compare
Force push: address most PR comments |
migrate(common_migrations::AddPrefixesMigration(vec![ | ||
"settings.oci-defaults", | ||
"services.oci-defaults", | ||
"configuration-files.oci-defaults", | ||
])) |
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.
Since this is a feature for k8s only, you may want to exclude the execution of the migration for all the other variants.
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.
Done! Thanks :)
sources/api/migration/migrations/v1.12.0/oci-defaults-setting/src/main.rs
Outdated
Show resolved
Hide resolved
66c1115
to
e3d47c4
Compare
Force push: add metadata migration to Release.toml |
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.
🍕
LGTM assuming all the testing looks good.
e3d47c4
to
6a7d5a6
Compare
6a7d5a6
to
8be44e0
Compare
^ Attempt to fix metadata migration /~https://github.com/bottlerocket-os/bottlerocket/compare/6a7d5a626706cf74155089a75f89db8170157bc7..8be44e04b94087399ccd2a3d6c2957558f7711e5 |
8be44e0
to
8a04add
Compare
^ try even harder to fix the migrations /~https://github.com/bottlerocket-os/bottlerocket/compare/8be44e04b94087399ccd2a3d6c2957558f7711e5..8a04adde8601155ca1aa26389f7d522b94dde41a |
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.
Looks good to me, testing done looks good, and tests are passing. I'm not strong on the migrations, so definitely would be good to have someone that understands those better take a closer look.
sources/api/schnauzer/src/helpers.rs
Outdated
let mut is_first = true; | ||
for (rlimit_type, values) in &oci_default_rlimits { | ||
if !is_first { | ||
result_lines.push_str(",\n"); |
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.
Just to note - I don't think it makes that much difference - but you could have results_line
be an array, then use result_lines.join(",\n")
at the end to get the resulting comma separated final string.
Can you fix the co-authored-by tags in the commit messages?
Also, this description is not correct:
The changes here only affect |
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.
LGTM apart from a few style nits and the commit messages.
if cfg!(variant_runtime = "k8s") { | ||
migrate(AddMetadataMigration(&[SettingMetadata { | ||
metadata: &["affected-services"], | ||
setting: "settings.oci-defaults", | ||
}]))?; | ||
}; |
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.
If I understand correctly - conditionalizing this on the variant is just for defensive / documentation purposes, it isn't actually necessary for aws-ecs-1
which won't have this metadata.
fn run() -> Result<()> { | ||
if cfg!(variant_runtime = "k8s") { | ||
migrate(common_migrations::AddPrefixesMigration(vec![ | ||
"settings.oci-defaults", | ||
"services.oci-defaults", | ||
"configuration-files.oci-defaults", | ||
])) | ||
} else { | ||
Ok(()) | ||
} | ||
} |
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.
to avoid the "else" branch:
fn run() -> Result<()> { | |
if cfg!(variant_runtime = "k8s") { | |
migrate(common_migrations::AddPrefixesMigration(vec![ | |
"settings.oci-defaults", | |
"services.oci-defaults", | |
"configuration-files.oci-defaults", | |
])) | |
} else { | |
Ok(()) | |
} | |
} | |
fn run() -> Result<()> { | |
if cfg!(variant_runtime = "k8s") { | |
migrate(common_migrations::AddPrefixesMigration(vec![ | |
"settings.oci-defaults", | |
"services.oci-defaults", | |
"configuration-files.oci-defaults", | |
]))?; | |
} | |
Ok(()) | |
} |
if cfg!(variant_runtime = "k8s") { | ||
migrate(AddMetadataMigration(&[SettingMetadata { | ||
metadata: &["affected-services"], | ||
setting: "settings.oci-defaults", | ||
}]))?; | ||
}; |
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.
nit: I don't think that last semicolon is needed:
if cfg!(variant_runtime = "k8s") { | |
migrate(AddMetadataMigration(&[SettingMetadata { | |
metadata: &["affected-services"], | |
setting: "settings.oci-defaults", | |
}]))?; | |
}; | |
if cfg!(variant_runtime = "k8s") { | |
migrate(AddMetadataMigration(&[SettingMetadata { | |
metadata: &["affected-services"], | |
setting: "settings.oci-defaults", | |
}]))?; | |
} |
sources/api/schnauzer/src/helpers.rs
Outdated
let capabilities_section = format!( | ||
"\"bounding\": [ | ||
{capabilities_bounding} | ||
], | ||
\"effective\": [ | ||
{capabilities_effective} | ||
], | ||
\"permitted\": [ | ||
{capabilities_permitted} | ||
]", | ||
capabilities_bounding = capabilities_lines_joined, | ||
capabilities_effective = capabilities_lines_joined, | ||
capabilities_permitted = capabilities_lines_joined, | ||
); |
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.
You can use a combination of raw strings and concat!
to clean this up so the string literal isn't flush with the left margin:
let capabilities_section = format!( | |
"\"bounding\": [ | |
{capabilities_bounding} | |
], | |
\"effective\": [ | |
{capabilities_effective} | |
], | |
\"permitted\": [ | |
{capabilities_permitted} | |
]", | |
capabilities_bounding = capabilities_lines_joined, | |
capabilities_effective = capabilities_lines_joined, | |
capabilities_permitted = capabilities_lines_joined, | |
); | |
let capabilities_section = format!( | |
concat!( | |
r#""bounding": ["#, | |
"{capabilities_bounding}", | |
"]", | |
r#""effective": ["#, | |
"{capabilities_effective}", | |
"]", | |
r#""permitted": ["#, | |
"{capabilities_permitted}", | |
"]", | |
), | |
capabilities_bounding = capabilities_lines_joined, | |
capabilities_effective = capabilities_lines_joined, | |
capabilities_permitted = capabilities_lines_joined, | |
); |
(same for the rlimit function)
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 is much nicer, thank you!
8a04add
to
684e813
Compare
|
684e813
to
b0d09dc
Compare
This change adds support for setting default OCI spec values. The default OCI spec stored at `/etc/containerd/cri-base.json` is applied to all containers run by `containerd-cri`, unless otherwise configured (e.g. by Kubernetes pod specs). Co-authored-by: Mahdi Chaker <mmchaker@amazon.com> Co-authored-by: Matthew James Briggs <brigmatt@amazon.com>
Co-authored-by: Mahdi Chaker <mmchaker@amazon.com> Co-authored-by: Matthew James Briggs <brigmatt@amazon.com>
b0d09dc
to
352a0a1
Compare
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.
I performed upgrade/downgrade testing from v1.11.0 -> v1.12.0 -> v1.11.0
On v1.11 and v1.12 I ran an ngnix pod and checked its oci spec with a command like this:
ctr -n k8s.io c info --spec 5a724a53cf
The specs were the same on both versions of Bottlerocket (i.e. if a customer does not use these new settings, their pods will not be affected).
👍
Issue number:
Closes #1703
Description of changes:
This PR adds support for setting default OCI spec values. The default OCI spec stored at
/etc/containerd/cri-base.json
is applied to all containers run by containerd, unless otherwise configured (e.g. by Kubernetes).The OCI spec can be found in detail at /~https://github.com/opencontainers/runtime-spec/blob/main/config.md .
This PR also adds some default settings that we want Bottlerocket to ship with: namely, a specific set of process capabilities (
sources/models/shared-defaults/oci-capabilities.toml
) and resource limits (sources/models/shared-defaults/oci-resource-limits.toml
).Testing done:
OCI Defaults Test Plan
Manual Testing
Baseline
ami-09d516ec16c94c0e0
)
Test case: feature enabled and configured with default settings
Make sure there is no behavior change when not configuring the new settings.
oci-defaults.capabilities
,oci-defaults.resource-limits
in userdata
Test case: set capabilities
Test case: set resource-limits
Test case: set both capabilities and resource-limits
Combine both of the above: i.e. set capabilities and rlimit_nofile values
Test all variants
Repeat above Manual Testing steps for the following variants:
Run abridged Manual Testing steps for the following variants:
Run Sonobuoy Conformance
Test case: Upgrade Downgrade
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.