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
Build for measured rootfs improvements #7231
Build for measured rootfs improvements #7231
Conversation
I set |
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.
The code looks good to me, but we don't currently have a way to test it in main
which makes me a little nervous, but then again we don't have a code path that activates it either, so it's probably ok to have code review only until it's merged into CCv0
, though I will need to update it to handle TDX root hashes then too.
Yeah, I was expecting it being partially tested by the new TDX job on GHB but it seems disabled? This is how I tested it:
|
hi @arronwy , could I have your review on this one? |
Hey Wainer, based on a conversation we had earlier, we have the following extra suggestions for measured rootfs that could go into this PR (or spun out separately). We might want to run it past the AC before we merge though to ensure that people have awareness:
\cc @fidencio |
b2b70e6
to
f2d78d7
Compare
Rebased and fixed the conflicts. Apparently the logic is still working even with the new cache mechanism. Leaving it WIP as I plan to address the last @stevenhorsman 's suggestions. |
0aa5291
to
e8f817a
Compare
A pod with following annotation should be failing the measurement as I am passing an incorrect hash, but it is not:
Am I passing the right annotation @stevenhorsman ? |
Just noticed that |
Yes - that looks like it matches the kata-deploy method that adds it when measured_rootfs is enabled at the moment:
Yeah, that's worth looking at more 😄 |
7ecc725
to
371c8a7
Compare
aad934c
to
3ea7dd8
Compare
The test that I am adding on this PR passed (https://github.com/kata-containers/kata-containers/actions/runs/6670016832/job/18130811556?pr=7231):
Removing the wip as it is ready to review. |
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.
Apart from a couple of minor issue this looks great. Thanks @wainersm!
@@ -538,7 +539,7 @@ install_kata() { | |||
} | |||
|
|||
main() { | |||
while getopts "a:b:c:deEfg:hH:k:p:t:u:v:x:" opt; do | |||
while getopts "a:b:c:deEfg:hH:mk:p:t:u:v:x:" opt; do |
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: Should this be k:mp:
to preserve the alphabetically ordering?
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.
Fixed!
tests/integration/kubernetes/lib.sh
Outdated
local datetime="$3" | ||
local message="$4" | ||
|
||
# Note: with image-rs we get more that the default 1000 lines of logs |
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: more that the
-> more than the
and apologies as I think that's my typo you've copied!
By convention the caller of tools/packaging/kernel/build-kernel.sh changes the script behavior by passing arguments, whereas, for measured rootfs it has used an environment variable (MEASURED_ROOTFS). This refactor the script so that the caller now must pass the "-m" argument to enable the build of the kernel with measured rootfs support. Fixes kata-containers#6674 Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Moved the measure rootfs logic from kata-deploy-binaries.sh to the kernel's builder script so that the former get less bloated with components's specific code. Fixes kata-containers#6674 Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Moved the measure rootfs logic from kata-deploy-binaries.sh to the shim-v2's builder script so that the former get less bloated with components's specific code. Fixes kata-containers#6674 Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
The KATA_BUILD_CC variable plus the existence (or not) of the initramfs were used to determine whether to build the kernel for measured rootfs or not. Currently the variable MEASURED_ROOTFS has been used to trigger the feature build and when it is activated it should expect the initramfs exist. In other words, this changed the kernel build so that if `MEASURED_ROOTFS=yes` then the initramf file must exist and be found. Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
When measured toofs is enabled then the shim-v2 build should find the guest rootfs hash file, otherwise might (silently) generate configuration files with empty hash. Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Re-wrote the logic of init.sh to follow the rules: * the root device MUST exist always because it will be either mounted or verified (then mounted) * if rootfs verifier is enabled then the hash device MUST exist. Avoid the case where dm-verity is set but the hash device does not exist and so the verification is silently skipped Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
The following functions were copied from CCv0's branch test's integration/kubernetes/confidential/lib.sh. I did just smalls refactorings (shortened their names and delinted shellcheck warnings): - k8s_delete_all_pods_if_any_exists() - k8s_wait_pod_be_ready() - k8s_create_pod() - assert_pod_fail() Co-authored-by: Fabiano Fidêncio <fabiano.fidencio@intel.com> Co-authored-by: Georgina Kinge <georgina.kinge@ibm.com> Co-authored-by: Jordan Jackson <jordan.jackson@ibm.com> Co-authored-by: Megan Wright <Megan.Wright@ibm.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Co-authored-by: Wang, Arron <arron.wang@intel.com>
Copied the new_pod_config() and pod-config.yaml.in from CCv0 branch tests' integration/kubernetes/confidential/tests_common.sh and fixtures. Unlike the original version, new_pod_config() now gets the runtimeclass by parameter as the RUNTIMECLASS environment variable seems not broadly used on main branch's CI. The pod-config.yaml.in was changed as the diff shows below. In particular the imagePullSecrets was removed to avoid it throwing a warning on the pod's log. ``` --- a/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in +++ b/tests/integration/kubernetes/runtimeclass_workloads/pod-config.yaml.in @@ -5,12 +5,10 @@ apiVersion: v1 kind: Pod metadata: - name: busybox-cc + name: test-e2e spec: runtimeClassName: $RUNTIMECLASS containers: - - name: nginx + - name: test_container image: $IMAGE - imagePullPolicy: Always - imagePullSecrets: - - name: cococred \ No newline at end of file + imagePullPolicy: Always \ No newline at end of file ``` Co-authored-by: Georgina Kinge <georgina.kinge@ibm.com> Co-authored-by: Megan Wright <Megan.Wright@ibm.com> Co-authored-by: stevenhorsman <steven@uk.ibm.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
The new clean-generated-files make target allows for removing the generated files (including the configuration.toml files). The tools/packaging/static-build/shim-v2/build.sh script now uses that target to always force the re-generation of those files. Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
This new function allow to the annotations to metadata section in a yaml configuration file. Co-authored-by: Ryan Savino <ryan.savino@amd.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Bring the assert_logs_contain() from CCv0 branch tests' integration/kubernetes/confidential/lib.sh. Introduced the print_node_journal() which uses `kubectl debug` to print the systemd's journal of a k8s's node. Fixes kata-containers#7590 Co-authored-by: stevenhorsman <steven@uk.ibm.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Bring the setup_common() from CCv0 branch test's integration/kubernetes/confidential/tests_common.sh. It should be used to reduce boilerplates on the setup() of the tests. Unlike the original code, this won't export the `test_start_time` variable as it wouldn't be accurate to grab logs from the worker nodes due date/time mismatch between the running tests machine and the worker node. The function export the `node` variable which holds the name of a random node which has kata installed. Apart from that, it exports the `node_start_time` which capture the date/time when the test started, relative to the `node`. Tests that should inspect the logs can schedule pods/resources to the `node` and use `node_start_time` as the value reference to grep the logs. Fixes kata-containers#7590 Co-authored-by: stevenhorsman <steven@uk.ibm.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Use this new function to set the node where the pod should be scheduled to. Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Implements the following test case: Scenario: Check incorrect hash fails **Given** I have a version of kata installed that has a kernel with the initramfs built and config with rootfs_verity.scheme=dm-verity rootfs_verity.hash=<incorrect hash of rootfs> set in the kernel_params **When** I try and create a container a basic pod **Then** The pod is doesn't run **And** Ideally we'd get a helpful message to indicate why Currently on CI only qemu-tdx is built with measured rootfs support in the kernel, so the test is restriced to that runtimeclass. Fixes kata-containers#7415 Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
3ea7dd8
to
48bdca4
Compare
Rebased this PR to solve a small conflict and addressed the last comments of @stevenhorsman |
Hi @arronwy @fidencio ! Can I ask you a special attention to this PR on the next days? I explain why. @ChengyuZhu6 's #8484 is pre-req to a lot of upcoming "merge to main" code. @stevenhorsman plans to pull some tests from CCv0 to test that basic pull mechanism and he will need to migrate some (if not all!) of the common test methods that I have on this PR. Steve's work will be based on this PR ,therefore, it will be important to merge it asap to avoid blocking him (Free Steve!) |
/test |
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, thanks @wainersm!
/test-s390x |
/retest-s390x |
While helping to solve kata-containers/tests#5701 I looked more carefully at the kernel, image and shim-v2 build scripts, and I found some opportunities of improvements. Apart from that, we've got some plans for measured rootfs on main branch as #7415.
This PR has the goals:
MEASURED_BOOTFS=yes
then the expected files are found or the build process die. This is to ensure we don't silently produce bad components