Commit Graph

1194 Commits

Author SHA1 Message Date
Matthew Arnold
7fc822896c policy: fix setting the policy path from agent config
Fix setting the image service policy path when there
is a policy path in the agent config.

Fixes #8049

Signed-off-by: Matthew Arnold <mattarno@uk.ibm.com>
2023-09-25 17:00:13 +01:00
Fabiano Fidêncio
b588c1128c Merge pull request #7676 from ChengyuZhu6/pull_image_in_guest
CC | image pulling in the guest without forked containerd
2023-09-20 21:11:24 +02:00
ChengyuZhu6
53ea36d3f5 agent: Introduce ImagePullHandler to support IMAGE_GUEST_PULL volume
As we do not employ a forked containerd, we utilize the KataVirtualVolume
which storing the image url supplied by snapshotter as an integral part of `CreateContainer`.
Within this process, we store the image information in rootfs.storage and pass this image url through `CreateContainerRequest`.
This approach distinguishes itself from the use of `PullImageRequest`, as rootfs.storage is already set and initialized at this stage.
To maintain clarity and avoid any need for modification to the `OverlayfsHandler`,we introduce the `ImagePullHandler`.
This dedicated handler is responsible for orchestrating the image-pulling logic within the guest environment.
This logic encompasses tasks such as calling the image-rs to download and unpack the image into `/run/kata-containers/{container_id}/images`,
followed by a bind mount to `/run/kata-containers/{container_id}`.

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
2023-09-18 21:05:11 +02:00
ChengyuZhu6
d0ac25f5c5 agent: redefine functions of pulling image in the guest
Without using forked containerd, the kata-agent wouldn't receive the `PullImageRequest`.
To using nydus-snapshotter, kata-agent can pass the image url and container id to image-rs
to handle pulling image.So we need to redefine functions of pulling image in the guest to support
both PullImageRequest and remote snapshotter.
1) Extract codes for setting proxy environment variables into a separate function `set_proxy_env_vars`.
2) Create a separate function `handle_attestation_agent` to handle attestation agent
   initialization.
3) Create a separate function `common_image_pull` for image pull logic.
4) Extract codes for unpacking pause image into a separate function `unpack_pause_image` and pass the necessary parameters to customize the behavior.

Fixes #7790

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
Co-authored-by: Jiang Liu <gerry@linux.alibaba.com>
Co-authored-by: Wang, Arron <arron.wang@intel.com>
Co-authored-by: wllenyj <wllenyj@linux.alibaba.com>
Co-authored-by: jordan9500 <jordan.jackson@ibm.com>
Co-authored-by: stevenhorsman <steven@uk.ibm.com>
2023-09-18 21:05:11 +02:00
stevenhorsman
0ffc9c02a2 agent: bump image-rs version
- Bump image-rs to stay aligned with guest-components version

Fixes: #7947
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2023-09-18 11:01:10 +01:00
Fabiano Fidêncio
ee15a389de Merge pull request #7688 from ChengyuZhu6/image_sharing_dmverity
CC | support dm-verity tarfs disk image in CoCo
2023-09-13 20:52:01 +02:00
ChengyuZhu6
a533c974f9 agent: enable verity feature in image-rs
update image-rs to support verity feature

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
2023-09-13 18:38:51 +08:00
Fabiano Fidêncio
d0b69651ce Merge pull request #7917 from stevenhorsman/cherry-pick-cgroups-fixes
agent: optimize the code of systemd cgroup manager
2023-09-13 09:53:46 +02:00
ChengyuZhu6
622bd4e370 agent: create directories to mount filesystem by overlay
When creating a container with a raw disk image using virtio-blk,
the guest does not have the upper directory and worker directory present.
Therefore, it is necessary to create these directories before mounting the filesystem with overlay.

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
2023-09-13 10:01:12 +08:00
ChengyuZhu6
72c9f62b70 agent: introduce DmVerityHandler to support dm-verity volume
We utilize the KataVirtualVolume which storing the dm-verity info
and the path of disk image on the host supplied by snapshotter as an integral part of `CreateContainer`.
Within this process, we copy the verity info and the disk image path to mount slice to create a block device by virtio-blk.
Then storing the `lowerdir` in rootfs.storage which is the mountpoint of the verity path through `CreateContainerRequest`.
To maintain clarity and avoid any need for modification to the `VirtioBlkPciHandler`,we introduce the `DmVerityHandler`.
This dedicated handler is responsible for calling image-rs to create verity device and mount the device to the `lowerdir` within the guest environment.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
2023-09-13 10:01:11 +08:00
stevenhorsman
d1d49675a0 agent: config: Allow clippy lint
- Allow `clippy::redundant-closure-call` in `from_cmdline`
which has issues with the guard function passed into
the `parse_cmdline_param` macro

Fixes: #7902
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2023-09-12 15:16:50 +01:00
stevenhorsman
3416e104b8 agent: config: Fix useles-vec warning
Fix clippy::useless-vec warning

Fixes: #7902
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2023-09-12 15:16:50 +01:00
stevenhorsman
da8d4a4584 agent: Vendor
run make vendor on agent to update

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2023-09-12 12:54:54 +01:00
Yuan-Zhuo
03aceccb1b agent: optimize the code of systemd cgroup manager
1. Directly support CgroupManager::freeze through systemd API.
2. Avoid always passing unit_name by storing it into DBusClient.
3. Realize CgroupManager::destroy more accurately by killing systemd unit rather than stop it.
4. Ignore no such unit error when destroying systemd unit.
5. Update zbus version and corresponding interface file.

Acknowledgement: error handling for no such systemd unit error refers to

Fixes: #7080, #7142, #7143, #7166

Signed-off-by: Yuan-Zhuo <yuanzhuo0118@outlook.com>
Signed-off-by: Yohei Ueda <yohei@jp.ibm.com>
(cherry picked from commit 470d065415)
2023-09-12 12:01:40 +01:00
Biao Lu
13943fb81b agent: launch api-server-rest
If 'rest_api' is configured, start api-server-rest after
attestation-agent and confidential-data-hub.

Fixes: #7555

Signed-off-by: Biao Lu <biao.lu@intel.com>
2023-09-07 09:55:46 +08:00
Biao lu
47c28923d7 agent: Add config for api-server-rest
Add configuration for 'rest api server'.
Optional configurations are
  'agent.rest_api=attestation' will enable attestation api
  'agent.rest_api=resource' will enable resource api
  'agent.rest_api=all' will enable all (attestation and resource) api

Fixes: #7555

Signed-off-by: Biao lu <biao.lu@intel.com>
2023-09-07 09:55:46 +08:00
Linda Yu
f1573b4747 agent: unittest for sealed secret as file in kata
Fixes: #7555

Signed-off-by: Linda Yu <linda.yu@intel.com>
2023-09-07 09:55:46 +08:00
Linda Yu
d7873e5251 agent: support sealed secret as file in kata
Fixes: #7555

Signed-off-by: Linda Yu <linda.yu@intel.com>
2023-09-07 09:55:40 +08:00
Linda Yu
c60adedf99 agent: add feature for confidential data hub (cdh)
Fixes: #7555

Signed-off-by: Linda Yu <linda.yu@intel.com>
2023-09-07 09:00:25 +08:00
Linda Yu
9c02722d46 agent: unittest for sealed secret as env in kata
Fixes: #7555

Signed-off-by: Linda Yu <linda.yu@intel.com>
2023-09-07 09:00:25 +08:00
Linda Yu
75def881e5 agent: support sealed secret as env in kata
Fixes: #7555

Signed-off-by: Linda Yu <linda.yu@intel.com>
2023-09-07 09:00:25 +08:00
Biao Lu
5316839165 agent: launch confidential-data-hub
confidential-data-hub depends attestation-agent, and
confidential-data-hab need to start before rpc server, so move the
function 'init_attestation_agent' from image_rpc.rs to main.rs and
launch confidential-data-hub after 'init_attestation_agent'.

Fixes: #7544

Signed-off-by: Biao Lu <biao.lu@intel.com>
2023-09-07 08:59:31 +08:00
Biao Lu
acd0a75efd agent: rootfs: add sealed-secret in Makefile
When set SEALED_SECRET to "yes", the kata-agent is built with
sealed-secret capability, default value is "no".

Fixes: #7544

Signed-off-by: Biao Lu <biao.lu@intel.com>
2023-09-06 10:57:34 +08:00
Jiang Liu
f45ee1fe1d agent: refine StorageDeviceGeneric::cleanup()
Refine StorageDeviceGeneric::cleanup() to improve safety.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-09-02 17:05:29 +08:00
Jiang Liu
1f4facdfe9 agent: implement StorageDeviceGeneric::cleanup()
Refactor cleanup_sandbox_storage as StorageDeviceGeneric::cleanup().

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-09-02 17:05:16 +08:00
Jiang Liu
d955f9dcf8 types: make StorageDevice::cleanup() return possible error code
Make StorageDevice::cleanup() return possible error code.

Fixes: #7818

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-09-02 17:04:55 +08:00
Jiang Liu
039fde2b66 agent: move StorageDeviceGeneric from kata-types into agent
Move StorageDeviceGeneric from kata-types into agent, so we can
refactor code later.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-09-02 17:04:36 +08:00
Jiang Liu
eac38d1a05 agent: avoid possible leakage of storage device
When a storage device is used by more than one container, the second
and forth instances will cause storage device reference count leakage,
thus cause storage device leakage. The reason is:
add_storages() will increase reference count of existing storage device,
but forget to add the device to the `mount_list` array, thus leak the
reference count.

Fixes: #7820

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-09-02 17:04:16 +08:00
stevenhorsman
c888facd24 versions: Bump guest-components
Bump image-rs and attestation-agent to use the latest guest-components
with the rust clap version fix

Fixes: #7580
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
2023-08-30 14:33:35 +01:00
Jiang Liu
412e8554f3 agent: simplify storage device by removing StorageDeviceObject
Simplify storage device implementation by removing StorageDeviceObject.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:20 +08:00
Jiang Liu
d5483aaf7c agent: move storage device related code into dedicated files
Move storage device related code into dedicated files.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:20 +08:00
Jiang Liu
3b1af40b16 agent: refine storage related code a bit
Refine storage related code by:
- remove the STORAGE_HANDLER_LIST
- define type alias
- move code near to its caller

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
331e35bc1a agent: switch to new storage subsystem
Switch to new storage subsystem to create a StorageDevice for each
storage object.

Fixes: #7614

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
aee71b16f1 kata-types: introduce StorageDevice and StorageHandlerManager
Introduce StorageDevice and StorageHandlerManager, which will be used
to refine storage device management for kata-agent.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
0d5a9eaeff agent: simplify the way to manage storage object
Simplify the way to manage storage objects, and introduce
StorageStateCommon structures for coming extensions.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
6dcd164c4e sys-util: support more mount flags in parse_mount_options()
Support more mount flags in parse_mount_options().

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
cf15777edd agent: use create_mount_destination() from kata-sys-util
Use create_mount_destination() from kata-sys-util crate to reduce
redundant code.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
7f12e27a68 types: add more mount related constants
Add more mount related constants.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-28 09:53:19 +08:00
Jiang Liu
b6218beef6 agent: use function from kata-sys-utils to reduce code
Use function get_linux_mount_info() from kata-sys-util crate to share
common code.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-25 22:23:03 +08:00
Fabiano Fidêncio
aef93c7aaf Merge pull request #7576 from surajssd/update-aa-imagers-tdshim
Update AA, image-rs td-shim
2023-08-24 08:38:29 +02:00
Suraj Deshmukh
d8953498c6 CCv0: Update image-rs, AA and td-shim
- image-rs & AA: 3d8192f8d3efab041916ea4d60e32248ac6ec43d
- td-shim: 35c8ec33311877f0711412fd34cee929ae57e80e

Fixes: #7580

Signed-off-by: Suraj Deshmukh <suraj.deshmukh@microsoft.com>
2023-08-23 14:34:07 +00:00
Jiang Liu
f218a3104e agent/image: move image service related code into image-rpc.rs
Move image service related code into image-rpc.rs, to simplify
maintenance.

Fixes: #7633

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
Co-authored-by: wllenyj <wllenyj@linux.alibaba.com>
Co-authored-by: jordan9500 <jordan.jackson@ibm.com>
Co-authored-by: stevenhorsman <steven@uk.ibm.com>
2023-08-21 19:29:09 +08:00
Jiang Liu
81980388d4 agent/image: export the image service singleton instance
Export the image service singleton instance.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-21 19:28:44 +08:00
Jiang Liu
624d3c063a agent/image: syntax only change to image service implementation
Syntax only change to image service implementation.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-21 19:28:32 +08:00
Fabiano Fidêncio
516468815e cc: Merge from main to CCv0 - Aug 14th
Conflicts:
	src/agent/src/rpc.rs

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
2023-08-14 09:22:03 +02:00
Chao Wu
7031b5db07 Merge pull request #7535 from ManaSugi/fix/allow-redundant-clone
agent: Allow clippy::redundant_clone in the unit tests
2023-08-11 14:17:56 +08:00
Wedson Almeida Filho
729b2dd611 agent: avoid creating new Vec instances when easily avoidable
There are many places where the code currently creates new `Vec`
instances when it's not really needed. The result is a perf hit because
it allocates memory, copies all elements, then frees the memory; in some
cases, copying elements also involves extra allocations (e.g., when
elements are strings, or structs containing strings).

This patch addresses a number of these cases.

Fixes: #7203

Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
2023-08-09 02:38:36 -03:00
Jiang Liu
baabfa9f1f agent: refine implementation of mount related code
Refine implementation of mount by:
- log message with `path.display()` instead of `{:?}`
- add prefix "_" to unused variables
- pass by reference instead of by value to avoid creating redundant
  array
- exactly matching prefix "fsgid=" instead of "fsgid"
- avoid redundant clone() operations

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-08 18:03:03 +08:00
Jiang Liu
98ba211a34 agent: fix a bug in update_ephemeral_mounts()
There's a bug in function update_ephemeral_mounts() which only handles
the first storage object and ignores all other storage objects.

Fixes: #7551

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-08 18:03:02 +08:00
Jiang Liu
5333618d70 agent: make add_storage() take &[Storage] instead of Vec<Storage>
Simplify add_storage() by taking &[Storage] instead of Vec<Storage>.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
2023-08-08 18:03:01 +08:00