QingTian Enclave 如何调试
问题
因为QingTian Enclave本身是一个机密计算环境,无法支持ssh的登录,所以导致开发过程中调测是一个大问题。针对调测问题,我们可以参考ssh的方式,在开发阶段,往QingTian Enclave镜像中打入vsock_server,然后在primary VM中以vsock_client的方式登录
准备工作
-
8U32G c7t实例,并勾选enclave支持
-
HCE操作系统
-
下载必要外围组件 (如果您使用ubuntu镜像的话,按照[ubuntu镜像必要包安装])(https://bbs.huaweicloud.com/blogs/451439))
yum install qingtian-tool virtio-qtbox qt-enclave-bootstrap -y
-
配置enclave隔离资源,并进行资源隔离
vim /etc/qingtian/enclave/qt-enclave-env.conf
建议一次性隔离出较大内存资源预留给Enclave使用,避免反复隔离,造成系统内存碎片化,隔离服务重启失败
启动资源隔离服务:
systemctl start qt-enclave-env
如果出现隔离服务失败,无法申请到足够内存,可能存在内存碎片,推荐重启虚拟机,再执行隔离服务
-
安装必要python包
pip3 install docker knack
-
安装docker和git
yum install docker git -y
Note: 如果您使用ubuntu: apt-get install docker git -y
操作步骤
- 获取
vsock_server
源码:
#!/bin/bash
cd /home
git clone https://gitee.com/heathjay/huawei-qingtian.git
cd /home/huawei-qingtian
git checkout newjay-java-sdk
cd /home/huawei-qingtian/enclave/qtsm-sdk-c/tests/vsock_shell
- 编写一个调测DockerfileTest:
FROM ubuntu:22.04 AS base-img
# COPY debug tool source code
COPY ./vsock_shell.c /root/vsock_shell.c
RUN apt-get update -y && \
apt-get install gcc -y
RUN cd /root && \
gcc vsock_shell.c -o directShell && \
chmod 777 /root/directShell
# COPY your enclave app
# eg. hello_world.sh
#COPY ./hello_world.sh /root/
RUN echo "#!/bin/bash" >> hello_world.sh && \
echo "echo hello" >> hello_world.sh
# Let launch the debug tool firstly
CMD ["/root/directShell"]
该directShell
默认监听9999端口;
3. 生成docker image并转换为Enclave的镜像:
docker build -f DockerfileTest -t test .; qt enclave make-img --docker-uri test --eif test.eif
4. 获取并编译vsock_client:
#!/bin/bash
git clone https://github.com/stefanha/nc-vsock.git
cd /home/nc-vsock && make
- 启动Enclave,并使用vsock_client登录
启动Enclave:
qt enclave start --cpus 2 --mem 8192 --eif test.eif --cid 4
使用vsock_client登录
/home/nc-vsock/nc-vsock 4 9999
这里的4 和Enclave 的Cid一致
这种方式仅仅推荐使用在调测阶段,不要在生产环境中使用
在使用normal方式启动Enclave时,往串口或者终端打印都不推荐;推荐将要往串口或者终端打印的内容往文件中打印,然后使用https://support.huaweicloud.com/usermanual-ecs/ecs_03_1426.html 导出到primary VM进行运维
- 点赞
- 收藏
- 关注作者
评论(0)