QingTian Enclave:docker 容器中管理Enclave的生命周期

举报
heathjay 发表于 2025/06/21 18:20:55 2025/06/21
【摘要】 背景当前项目需要在容器里对QingTian Enclave的生命周期进行管理。 准备工作参考: https://bbs.huaweicloud.com/blogs/451408 购买c7t虚拟机,在虚拟机上安装必要的外围包组件,以HCE操作系统为例:yum install qingtian-tool virtio-qtbox qt-enclave-bootstrap -y 执行隔离服务隔离...

背景

当前项目需要在容器里对QingTian Enclave的生命周期进行管理。

准备工作

参考: https://bbs.huaweicloud.com/blogs/451408 购买c7t虚拟机,在虚拟机上安装必要的外围包组件,以HCE操作系统为例:

yum install qingtian-tool virtio-qtbox qt-enclave-bootstrap -y

执行隔离服务

隔离必要资源预留给QingTian Enclave使用,当前只能在父虚拟机上操作,以配置4 vCPU、8G资源预留为例子:

vim  /etc/qingtian/enclave/qt-enclave-env.conf 

配置文件为:


# qingtian enclave configuration file.

# Which hugepage size to reserve for qingtian enclave
# can only configure it by 2 (2MB hugepage size) or 1024 (1GB hugepage size)
hugepage_size:1024

# How much memory to allocate for qingtian enclave (in MiB).
memory_mib:8192

# User can use cpu_count to set how many CPUs need to be reserved.
# Or cpu_list to set which CPUs need to be reserved.
#
# cpu_count and cpu_list conflict with each other. Only use exactly one of them.
#
# How many CPUs to reserve for qingtian enclave.
#cpu_count:4

# Which CPUs to reserve for qingtian enclave. You can configure it like below:
# 2,3 means reserving CPUs 2, 3, and you can also use 2-5 to reserve 2 through 5.
cpu_list:2,3,6,7

启动隔离服务:

systemctl start qt-enclave-env

Note:如果隔离失败,可能原因有:

  1. 确认是否开启Enclave服务
  2. 确认虚拟机规格是否满足要求,最少预留2 vCPU给父虚拟机
  3. 可能是系统长时间运行,无法隔离连续内存,需要在console页面重启虚拟机

制作业务EIF镜像

这里制作的是需要在enclav中运行的业务程序,以循环打印helloworld为例,在/home/test目录下:

mkdir -p /home/test
cd /home/test

写一个helloworld.sh脚本:

#!/bin/bash

while true
do
    echo "hello world"
    sleep 5
done

修改其权限:chmod 777 helloworld
写一个简单的Dockerfile_eif:

FROM ubuntu:22.04

COPY helloworld.sh /root/helloworld.sh

CMD "/root/helloworld.sh"

制作Docker image

docker build -f Dockerfile_eif -t helloworld .

制作EIF镜像:

qt enclave make-img --docker-uri helloworld --eif helloworld.eif

制作管理enclave的容器镜像

在这个容器镜像中,会安装管理QingTian Enclave生命周期的包:qingtian-tool,以及他的相关依赖glib2.0pythoncjson,以及python的模块dockerknack
并且会把上一步的业务Enclave镜像(helloworld.eif)放在容器镜像中。

  1. 先下载qingtian-tool的rpm包
yum download qingtian-tool

在写这篇博客的时候,qingtian-tool版本为1.0-54;所以会在/home/test目录下看到这样一个rpm包:
qingtian-tool-1.0-54.hce2.x86_64.rpm

  1. 编写一个Dockerfile
FROM ubuntu:22.04
# 将下载的qingtian-tool rpm包拷贝到容器镜像中
COPY ./qingtian-tool-1.0-54.hce2.x86_64.rpm /root/qingtian-tool-1.0-54.hce2.x86_64.rpm
# 拷贝业务EIF镜像
COPY ./helloworld.eif /root/helloworld.eif

# 安装必要依赖
RUN apt-get update -y && \
    apt-get install python3 pip alien  libglib2.0-dev libcjson-dev -y

RUN cd /root/ && \
    alien -d qingtian-tool-1.0-54.hce2.x86_64.rpm && \
    dpkg -i *.deb && \
    pip install docker knack &&\
    ln -s /usr/bin/python3 /usr/bin/python # ubuntu中需要建立软连接

制作容器镜像:

docker build -f Dockerfile_eif -t container-qt .

启动容器,并对QingTian Enclave的生命周期进行管理

QingTian Enclave的生命周期管理依赖宿主机上的一个设备/dev/qtbox_service0,所以在启动容器的时候,需要将该设备映射到容器中。

方法一:使用–device参数

通过--device参数将必要设备/dev/qtbox_service0映射到容器中

docker run --device=/dev/qtbox_service0:/dev/qtbox_service0 --rm -it container-qt /bin/bash

在容器中检查是否设备已映射:
ls /dev/ | grep qt
可以看到:
image.png

测试管理Enclave生命周期命令

  1. 启动
    qt enclave start --cpus 2 --mem 1024 --eif /root/helloworld.eif --cid 4
    可以看到enclave启动成功:
    image.png

  2. 查询Enclave
    qt enclave query
    image.png

  3. 停止Enclave
    qt enclave stop --enclave-id 0
    image.png

Note: 在这种方式下,qt enclave console命令会失效,也就是无法通过console获取以debug-mode启动的Enclave中内部打印,用于开发调测。为了解决这个问题,可以参考方案二。

方案二:使用–privileged方式启动容器,并通过-v /dev:/dev挂载/dev目录

使用privileged方式启动容器,会让容器具备访问宿主机上所有设备的权限,在安全上不推荐使用,只可用于非生产环境的调测工作。
docker run --privileged -v /dev:/dev -it container-qt /bin/bash

容器内检查设备:
ls /dev | grep qt
image.png

测试enclave生命周期

  1. 启动QingTian Enclave
    qt enclave start --cpus 2 --mem 1024 --eif /root/helloworld.eif --cid 4
    image.png

  2. 查询QingTian Enclave
    qt enclave query
    image.png

  3. 停止QingTian Enclave
    qt enclave stop --enclave-id 0
    image.png

  4. 以debug-mode启动QingTian Enclave,并使用console命令获取Enclave内部打印
    qt enclave start --cpus 2 --mem 1024 --eif /root/helloworld.eif --cid 4 --debug-mode
    image.png

使用console查询:
qt enclave console --enclave-id 0
image.png

Note: 这里的主要原因是debug模式下,会挂载一个/dev/sandbox-log-0设备到父虚拟机内,而console命令依赖这个设备

总结

从容器内管理Enclave的生命周期可行,但需要注意挂载必要设备,与aws nitro enclave一致:

  • 需要在容器镜像中安装必要依赖包
  • 隔离服务需要提前在父虚拟机内启动
  • 在容器里拉起的enclave,宿主机中无法通过qt enclave query的命令查询到
  • debug模式启动的enclave需要更新容器内的/dev设备目录,才能通过console命令获取enclave内部打印
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。