Files
admin 783761cb26 feat(tee): 框架直接调度 AMD SEV-SNP / 海光 CSV,真机端到端跑通
mpc-tee 新增 platform/session/schedule(no_std) 与 guest(std):平台能力表、会话绑定证明、fail-closed 准入、qemu LaunchSpec、guest 内 Tee 实现。CLI 加 tee paths / tee plan,catalog 与 domain 同步清单与常量(非 breaking)。deploy/tee 提供宿主预检与直接启动脚本,docs/TEE_DIRECT_LAUNCH.md 记录分层与真机真值。真机校正:confidential-guest-support、kernel-hashes=on + pflash 固件(CSV)、cbitpos 51/47、console=ttyS0。影响:TEE 调度不经容器编排层;SNP/CSV guest 跨物理机密文会话已实测通过。
2026-11-06 18:42:27 +08:00

85 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# 宿主预检:产出 `mpc tee plan --node` 需要的节点描述(只读,不启动任何进程)。
#
# 用法:
# deploy/tee/preflight.sh --platform sev-snp --site alice --host 192.168.1.7 \
# --tcb 5 --measurement <64hex> > alice.node
#
# 路径用 MPC_TEE_QEMU / MPC_TEE_FIRMWARE / MPC_TEE_KERNEL / MPC_TEE_INITRD 覆盖。
# 不给 --measurement 时写全零,`mpc tee plan` 会 fail-closed 拒绝 —— 这是刻意的,
# 不允许「不知道镜像是哪一份也照跑」。
#
set -euo pipefail
platform=""
site="site-a"
host="127.0.0.1"
tcb="0"
measurement=""
kbs_url="http://127.0.0.1:8080"
while [ "$#" -gt 0 ]; do
case "$1" in
--platform) platform="${2:-}"; shift 2 ;;
--site) site="${2:-}"; shift 2 ;;
--host) host="${2:-}"; shift 2 ;;
--tcb) tcb="${2:-}"; shift 2 ;;
--measurement) measurement="${2:-}"; shift 2 ;;
--kbs-url) kbs_url="${2:-}"; shift 2 ;;
-h|--help) sed -n '2,13p' "$0"; exit 0 ;;
*) echo "不认识的参数: $1" >&2; exit 2 ;;
esac
done
case "$platform" in
sev-snp) kbc="online" ;;
hygon-csv) kbc="offline" ;;
*) echo "--platform 只认 sev-snp / hygon-csv" >&2; exit 2 ;;
esac
qemu="${MPC_TEE_QEMU:-$(command -v qemu-system-x86_64 || true)}"
firmware="${MPC_TEE_FIRMWARE:-/srv/tee/firmware.fd}"
kernel="${MPC_TEE_KERNEL:-/srv/tee/vmlinuz}"
initrd="${MPC_TEE_INITRD:-/srv/tee/initrd.img}"
exists() { if [ -e "$1" ]; then echo true; else echo false; fi; }
device_present="$(exists /dev/sev)"
qemu_present="$(exists "$qemu")"
firmware_present="$(exists "$firmware")"
if [ -e "$kernel" ] && [ -e "$initrd" ]; then
image_present=true
else
image_present=false
fi
kbs_reachable=false
if [ "$kbc" = "online" ] && command -v curl >/dev/null 2>&1; then
code="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 "$kbs_url" 2>/dev/null || true)"
if [ -n "$code" ] && [ "$code" != "000" ]; then
kbs_reachable=true
fi
fi
if [ -z "$measurement" ]; then
measurement="$(printf '%064d' 0)"
fi
printf '# 由 preflight.sh 生成:所有 present 位都是宿主实测结果\n'
printf 'site=%s\n' "$site"
printf 'host=%s\n' "$host"
printf 'kind=%s\n' "$platform"
printf 'tcb=%s\n' "$tcb"
printf 'device_present=%s\n' "$device_present"
printf 'qemu_present=%s\n' "$qemu_present"
printf 'firmware_present=%s\n' "$firmware_present"
printf 'image_present=%s\n' "$image_present"
printf 'kbc=%s\n' "$kbc"
printf 'kbs_reachable=%s\n' "$kbs_reachable"
printf 'measurement=%s\n' "$measurement"
printf 'qemu=%s\n' "$qemu"
printf 'firmware=%s\n' "$firmware"
printf 'kernel=%s\n' "$kernel"
printf 'initrd=%s\n' "$initrd"