Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@littlejawa
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

For confidential container, we want to have the ability to pull the image on the guest side, and not rely on the host's repository.

To achieve this, an extension to the kata shim's mount options for CreateContainer was added. Provided the right information through these options, the kata agent in the remote VM will proceed with the PullImage before handling the actual CreateContainer.

This commit adds support for this method.

As part of this, I am adding an option to the runtime configuration, making it possible to select whether or not the additional data should be sent.
We need it to be configurable, because there are use cases for confidential containers where pull-in-guest is not desired (like: sharing a volume from the host to the VM, containing the container images).

Additionally: with this feature enabled, cri-o will still comply with kubernetes' "PullImageRequest", even though the resulting container image is not used.
This can be an issue, not only in terms of resource usage: if the workload is encrypted and cri-o can't access it, cri-o will fail the PullImageRequest, and kubernetes will never send CreateContainer.
I'm looking for a way to avoid this situation, maybe making cri-o skip PullImage for a specific runtime. This will be a separate PR - suggestions are welcome.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Here is how I've been testing it:

Prerequisite: build/install kata from the CCv0 branch (https://github.com/kata-containers/kata-containers/tree/CCv0).
Build/install cloud-api-adaptor and related podvm image, using libvirt as the cloud provider (and have a libvirt server available that you can talk to).
(https://github.com/confidential-containers/cloud-api-adaptor/)

Add the following configuration to crio, to define new runtime classes:

  • kata: regular kata container
  • kata-remote: peer-pod container - in this scenario, cloud-api-adapator makes a PullImage request to the kata-agent as part of processing the CreateContainer request. This method is considered a hack, and is bound to be deprecated.
  • kata-cc: confidential container - in this scenario, the changes in this PR are exercised: cri-o provides the needed information to the agent as part of the CreateContainer request, cloud-api-adaptor forwards it without doing anything more, and the agent performs the PullImage on its own.

/etc/crio/crio.conf.d/50-kata-runtimes

[crio.runtime.runtimes.kata]
  runtime_path = "/usr/local/bin/containerd-shim-kata-v2"
  runtime_root = "/run/vc"
  runtime_type = "vm"
  privileged_without_host_devices = true
  runtime_config_path = "/usr/share/defaults/kata-containers/configuration.toml"

[crio.runtime.runtimes.kata-remote]
  runtime_path = "/usr/local/bin/containerd-shim-kata-v2"
  runtime_root = "/run/vc"
  runtime_type = "vm"
  privileged_without_host_devices = true
  runtime_config_path = "/usr/share/defaults/kata-containers/configuration-remote.toml"

[crio.runtime.runtimes.kata-cc]
  runtime_path = "/usr/local/bin/containerd-shim-kata-v2"
  runtime_root = "/run/vc"
  runtime_type = "vm"
  privileged_without_host_devices = true
  runtime_config_path = "/usr/share/defaults/kata-containers/configuration-remote.toml"
  runtime_pull_image = true

The kata configuration files configuration.toml and configuration-remote.toml are the default, built and installed as part of kata-container.

  • start crio
  • start cloud-api-adaptor in a terminal:
    ./cloud-api-adaptor libvirt -uri="qemu+ssh://[libvirt server address]/system?no_verify=1"

Then try to load the same container, using the different runtime classes.
I'm using the following script:

runtest.sh

#!/bin/bash
set -e

RUNTIMECLASS=$1
if [ "$RUNTIMECLASS" == "" ]; then
    exit 1
fi
echo RUNNING WITH RUNTIMECLASS=$RUNTIMECLASS

PODID=$(crictl runp --runtime="$RUNTIMECLASS" sandbox.json)
CTRID=$(crictl create $PODID ctr.json sandbox.json)
crictl start $CTRID

The logs from cloud-api-adaptor show the difference of behaviour.

$ ./runtest.sh kata-remote
=> cloud-api-adaptor logs:
[...]
2023/11/09 11:14:52 [adaptor/proxy] getImageName: got image from annotations: docker.io/bitnami/nginx:latest
2023/11/09 11:14:52 [adaptor/proxy] CreateContainer: calling PullImage for "docker.io/bitnami/nginx:latest" before CreateContainer (cid: "194ef1718624d13f59f5031d1fa836a66764c0ab37b5cddfeeb76834457c12b9")
2023/11/09 11:14:55 [adaptor/proxy] CreateContainer: successfully pulled image "docker.io/bitnami/nginx:latest"
2023/11/09 11:14:55 [adaptor/proxy] StartContainer: containerID:194ef1718624d13f59f5031d1fa836a66764c0ab37b5cddfeeb76834457c12b9
$ ./runtest.sh kata-cc
=> cloud-api-adaptor logs:
[...]
2023/11/09 11:18:59 [adaptor/proxy] CreateContainer: Ignoring PullImage before CreateContainer (cid: "401347cc2cdfa5d26a3b75825163417ff08795e26c6c597f242e0485e6325484")
2023/11/09 11:19:02 [adaptor/proxy] StartContainer: containerID:401347cc2cdfa5d26a3b75825163417ff08795e26c6c597f242e0485e6325484

In addition, logging into the pod VM, I can check the kata-agent's logs in journalctl and confirm that it actually pulled the image on its own, without receiving the PullImage request

Does this PR introduce a user-facing change?

Confidential Containers: add support for pull-in-guest method

@openshift-ci openshift-ci bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Nov 9, 2023
@codecov
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #7471 (fff6493) into main (869aa6e) will decrease coverage by 0.10%.
Report is 23 commits behind head on main.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7471      +/-   ##
==========================================
- Coverage   48.38%   48.29%   -0.10%     
==========================================
  Files         145      145              
  Lines       16055    16087      +32     
==========================================
+ Hits         7768     7769       +1     
- Misses       7350     7381      +31     
  Partials      937      937              

@littlejawa littlejawa force-pushed the coco_pullimage_in_guest branch 3 times, most recently from 83b084d to cf2ddc1 Compare November 9, 2023 13:55
@haircommander haircommander added this to the 1.29 milestone Nov 16, 2023
@kwilczynski
Copy link
Contributor

/retest

@littlejawa littlejawa force-pushed the coco_pullimage_in_guest branch from cf2ddc1 to 73af464 Compare November 29, 2023 17:48
@littlejawa
Copy link
Contributor Author

/retest

Copy link
Member

@sohankunkerkar sohankunkerkar left a comment

Choose a reason for hiding this comment

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

/lgtm
Looks sane to me!

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 4, 2023
@haircommander
Copy link
Member

is the content in https://github.com/kata-containers/kata-containers/tree/CCv0 going to be merged into the main branch? If we implement this feature here, is there any risk to kata that is unpatched?

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 5, 2023
@littlejawa
Copy link
Contributor Author

is the content in https://github.com/kata-containers/kata-containers/tree/CCv0 going to be merged into the main branch? If we implement this feature here, is there any risk to kata that is unpatched?

This content is in the process of being merged to main (there are several ongoing PRs for that).
When the merge is complete, we can change the source of the vendoring, but the behaviour won't change.

Additional features will be added to that - sharing container images in a volume from the host typically. But what I have in this PR will stay: Both pull-in-guest and volume sharing need to be supported in the end.

@littlejawa littlejawa force-pushed the coco_pullimage_in_guest branch from 73af464 to 3d1e31b Compare December 8, 2023 15:04
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 8, 2023
@littlejawa
Copy link
Contributor Author

/retest

@haircommander haircommander removed this from the 1.29 milestone Dec 14, 2023
@haircommander
Copy link
Member

I chatted with @littlejawa at today's cri-o meeting, and we agreed to unset the milestone for this. We will still aim to backport it to 1.28, but will wait to do so until the CCv0 changes are merged into upstream kata

…uest

For confidential container, we want to have the ability to pull the image
on the guest side, and not rely on the host's repository.

To achieve this, an extension to the kata shim's options for CreateContainer
was added. Provided the right information through these options,
the kata agent in the remote VM will proceed with the PullImage before
handling the actual CreateContainer.

This commit adds support for this method.

Signed-off-by: Julien Ropé <[email protected]>
@littlejawa littlejawa force-pushed the coco_pullimage_in_guest branch from 3d1e31b to fff6493 Compare December 18, 2023 08:37
@littlejawa
Copy link
Contributor Author

Modified the vendoring to point to kata/main branch.
I have tested this in the same way as described above, with no issue.

The only thing this PR requires is the code for the KataVirtualVolume object.
This is already on kata/main, even if not used yet on the kata side. The code that will use it is in the process of being merged.
The type definition and associated code is identical to the CCv0 branch in kata and there is no plan to modify it further, which makes me confident that this PR can support both existing binaries made out of the CCv0 branch, and future builds of kata based on main, after the merge is done.

The vendoring is not done on a tag, because that code was not released in kata yet.
There is no plan to release it for now, as we wait for merging the CCv0 branch first.
I don't think we should wait for a proper release though, as this may not happen before several months, and we need to support CCv0 builds in the meantime.

@littlejawa
Copy link
Contributor Author

/retest

@haircommander
Copy link
Member

/approve

LGTM, @cri-o/cri-o-maintainers PTAL

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 18, 2023
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 19, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 19, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haircommander, littlejawa, saschagrunert, sohankunkerkar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [haircommander,saschagrunert,sohankunkerkar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@saschagrunert
Copy link
Member

/retest

1 similar comment
@littlejawa
Copy link
Contributor Author

/retest

@openshift-merge-bot openshift-merge-bot bot merged commit 755e84e into cri-o:main Dec 19, 2023
@haircommander
Copy link
Member

/cherry-pick release-1.28

@openshift-cherrypick-robot

@haircommander: #7471 failed to apply on top of branch "release-1.28":

Applying: kata: support confidential container's api for pulling image in the guest
Using index info to reconstruct a base tree...
M	go.mod
M	go.sum
M	internal/oci/runtime_vm.go
M	pkg/config/config.go
M	vendor/modules.txt
Falling back to patching base and 3-way merge...
Auto-merging vendor/modules.txt
Auto-merging pkg/config/config.go
Auto-merging internal/oci/runtime_vm.go
Auto-merging go.sum
CONFLICT (content): Merge conflict in go.sum
Auto-merging go.mod
CONFLICT (content): Merge conflict in go.mod
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 kata: support confidential container's api for pulling image in the guest
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Details

In response to this:

/cherry-pick release-1.28

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants