带你读《云原生机密计算最佳实践白皮书》——Intel SGX虚拟机最佳实践(5)

简介: 带你读《云原生机密计算最佳实践白皮书》——Intel SGX虚拟机最佳实践(5)

《云原生机密计算最佳实践白皮书》——06运行时底座——Intel vSGX:Intel SGX虚拟化——Intel SGX虚拟机最佳实践(4) https://developer.aliyun.com/article/1231118?groupCode=aliyun_linux




创建 SGX Guest xml 文件

以下是 SGX 虚拟机的参考 xml 文件 vsgx.xml, 在使用过程中,请根据实际需求,修改对应的配置字段。

说明:假设 guest image 的位置为/root/vsgx/AnolisOS-8.6-x86_64-ANCK.qcow2, 使用名为default

的 NAT 网络

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
 <name>vsgx</name>
 <memory unit='KiB'>16777216</memory>
 <currentMemory unit='KiB'>16777216</currentMemory>
 <vcpu placement='static'>8</vcpu>
 <os>
 <type arch='x86_64'>hvm</type>
 <boot dev='hd'/>
 </os>
 <features>
 <acpi/>
 <apic/>
 <pae/>
 </features>
 <clock offffset='localtime'/>
 <on_poweroffff>destroy</on_poweroffff>
 <on_reboot>restart</on_reboot>
 <on_crash>restart</on_crash>
 <pm>
 <suspend-to-mem enabled='no'/>
 <suspend-to-disk enabled='no'/>
 </pm>
 <qemu:commandline>
 <qemu:arg value='-cpu'/>
 <qemu:arg value='host,+sgx-provisionkey'/>
 <qemu:arg value='-object'/>
 <qemu:arg value='memory-backend-epc,id=mem1,size=64M,prealloc=on'/>
 <qemu:arg value='-M'/>
 <qemu:arg value='sgx-epc.0.memdev=mem1,sgx-epc.0.node=0'/>
 </qemu:commandline>
 <devices>
 <emulator>/usr/libexec/qemu-kvm</emulator>
 <disk type='fifile' device='disk'>
 <driver name='qemu' type='qcow2'/>
 <source fifile='/root/vsgx/AnolisOS-8.6-x86_64-ANCK.qcow2'/>
 <target dev='vda' bus='virtio'/>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
 </disk>
 <controller type='ide' index='0'>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
 </controller>
 <memballoon model='virtio'>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
 </memballoon>
 <console type='pty'>
 <target type='serial' port='0'/>
 </console>
 <interface type='network'>
 <source network='default'/>
 <model type='virtio'/>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
 </interface>
 </devices>
<feature>
 <sgx supported='yes'>
 <flflc>yes</flflc>
 <epc_size unit='KiB'>1048576</epc_size>
 </sgx>
</feature>
</domain>

启动虚拟机

# virsh create vsgx.xml
Domain 'vsgx' created from vsgx.xml

成功启动虚拟机之后,请输入一下命令列出虚拟机实例。

# virsh list
 Id 名称 状态
----------------------
 1 vsgx running

进入虚拟机控制台

# virsh console vsgx
Connected to domain 'vsgx'
Escape character is ^] (Ctrl + ])
# 这里要敲一下回车键
Anolis OS 8.6
Kernel 4.19.91-26.an8.x86_64 on an x86_64
Activate the web console with: systemctl enable --now cockpit.socket
localhost login:

请输入步骤二设置的用户名和密码,进入SGX guest。

localhost login: root
Password: 123456

检查 Guest 的 SGX 使能状态

不管是用 QEMU 命令行直接启动的 SGX Guest,还是使用 virsh 启动的 SGX Guest,在启动之后,都需要检查 Guest 中对 SGX 是否支持。

在 Guest 中使用 SGX 需要支持 SGX 的内核/操作系统。可以通过以下方式在 Guest 中确定支持:

检查 SGX 使能状态。

dmesg | grep -i sgx

以下输出表示 SGX 已经被正确使能。

[ 0.489460] sgx: EPC section 0x440000000-0x443ffffffffffff

检查 SGX 驱动安装情况。

ls /dev/sgx_*

以下输出表示 SGX 已经被正确使能。

/dev/sgx_enclave /dev/sgx_provision


步骤四:构建 SGX 加密计算环境

为开发 SGX 程序,您需要在 SGX 虚拟机上安装 SGX SDK,PSW 和 DCAP 进而构建 SGX 加密计算环境。

安装 SGX SDK

mkdir -p $HOME/vsgx && \
 wget https://mirrors.openanolis.cn/inclavare-containers/bin/anolis8.6/sgx-2.17/sgx_linux_
 x64_sdk_2.17.100.3.bin && \
 chmod +x sgx_linux_x64_sdk_2.17.100.3.bin && \
echo -e 'n\n\/opt/intel\n' | ./sgx_linux_x64_sdk_*.bin && \
 rm -rf sgx_linux_x64_sdk_*.bin

安装 SGX PSW/DCAP

cd $HOME/vsgx && \
 wget https://mirrors.openanolis.cn/inclavare-containers/bin/anolis8.6/sgx-2.17/sgx_rpm
 _local_repo.tar.gz && \
 tar zxvf sgx_rpm_local_repo.tar.gz && \
 yum install -y yum-utils && \
 yum-confifig-manager --add-repo fifile://$HOME/vsgx/sgx_rpm_local_repo/ && \
 yum install --nogpgcheck -y sgx-aesm-service libsgx-launch libsgx-urts && \
 rm -rf sgx_rpm_local_repo.tar.gz



《云原生机密计算最佳实践白皮书》——06运行时底座——Intel vSGX:Intel SGX虚拟化——Intel SGX虚拟机最佳实践(6) https://developer.aliyun.com/article/1231116?groupCode=aliyun_linux

相关文章
|
2月前
|
Cloud Native 开发者
电子好书发您分享《云原生开发者洞察白皮书》
电子好书发您分享《云原生开发者洞察白皮书》
66 2
|
11月前
|
Ubuntu 安全 Linux
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
194 0
|
8月前
|
存储 人工智能 Cloud Native
耳朵经济快速增长背后,喜马拉雅数据价值如何释放 | 创新场景
喜马拉雅和阿里云的合作,正走在整个互联网行业的最前沿,在新的数据底座之上,喜马拉雅的AI、大数据应用也将大放光彩。本文摘自《云栖战略参考》
46606 5
耳朵经济快速增长背后,喜马拉雅数据价值如何释放 | 创新场景
|
2月前
|
Ubuntu 安全 虚拟化
vmware虚拟机运行ubuntu等卡慢的解决办法
vmware虚拟机运行ubuntu等卡慢的解决办法
591 0
|
12月前
|
Kubernetes Cloud Native Devops
为什么在Kubernetes上运行虚拟机?
为什么在Kubernetes上运行虚拟机?
78 0
|
2月前
|
存储 缓存 Java
JVM【带着问题去学习 02】数据结构栈+本地方法栈+虚拟机栈+JVM栈运行原理
JVM【带着问题去学习 02】数据结构栈+本地方法栈+虚拟机栈+JVM栈运行原理
40 0
|
2月前
|
Kubernetes Cloud Native 网络协议
云原生|kubernetes部署和运行维护中的错误汇总(不定时更新)
云原生|kubernetes部署和运行维护中的错误汇总(不定时更新)
590 0
|
2月前
|
安全 Cloud Native 算法
云原生安全-云计算发展白皮书(2020年)解读
云原生安全-云计算发展白皮书(2020年)解读
158 0
|
9月前
|
存储 Java
【面试题精讲】JVM-运行时数据区-虚拟机栈
【面试题精讲】JVM-运行时数据区-虚拟机栈
|
9月前
|
安全 虚拟化
VMWare 虚拟机 CPU 设置里针对 CPU 的 Intel VT-x 选项功能介绍
VMWare 虚拟机 CPU 设置里针对 CPU 的 Intel VT-x 选项功能介绍