{"id":13641775,"url":"https://github.com/AliyunContainerService/sgx-device-plugin","last_synced_at":"2025-04-20T11:32:13.215Z","repository":{"id":52675459,"uuid":"224789740","full_name":"AliyunContainerService/sgx-device-plugin","owner":"AliyunContainerService","description":"Kubernetes Device Plugin for Intel SGX","archived":false,"fork":false,"pushed_at":"2023-09-20T06:28:45.000Z","size":3075,"stargazers_count":67,"open_issues_count":0,"forks_count":22,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-08-03T01:24:43.669Z","etag":null,"topics":["device-plugin","intel-sgx","kubernetes"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AliyunContainerService.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-29T06:20:58.000Z","updated_at":"2024-06-26T06:16:43.000Z","dependencies_parsed_at":"2023-10-20T16:40:46.984Z","dependency_job_id":null,"html_url":"https://github.com/AliyunContainerService/sgx-device-plugin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fsgx-device-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fsgx-device-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fsgx-device-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliyunContainerService%2Fsgx-device-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AliyunContainerService","download_url":"https://codeload.github.com/AliyunContainerService/sgx-device-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223827684,"owners_count":17209827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["device-plugin","intel-sgx","kubernetes"],"created_at":"2024-08-02T01:01:24.300Z","updated_at":"2025-04-20T11:32:13.200Z","avatar_url":"https://github.com/AliyunContainerService.png","language":"Go","funding_links":[],"categories":["Distributed Systems"],"sub_categories":["Library OSes and SDKs"],"readme":"# sgx-device-plugin\n\n支持 Intel SGX2/SGX1 的 Kubernetes 设备插件\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/AliyunContainerService/sgx-device-plugin)](https://goreportcard.com/report/github.com/AliyunContainerService/sgx-device-plugin)\n[English](./README.md) | 简体中文\n\n## 介绍\n\nsgx-device-plugin 由阿里云容器服务团队和蚂蚁金服安全计算团队针对 Intel SGX 联合开发的 Kubernetes Device Plugin，可以帮助用户更容易的在容器中使用 SGX2/SGX1。\n\nIntel(R) Software Guard Extensions (Intel(R) SGX) 是 Intel 为软件开发者提供的安全技术，用于防止指定的代码和数据的窃取和恶意篡改。详情可参考[官方链接](https://software.intel.com/en-us/sgx) 。\n\n## 功能\n\n* 无需开启容器特权模式即可使用 SGX；\n* 支持 EPC 内存大小自动获取；\n* 支持容器声明式 EPC 内存分配；\n* 支持 SGX2 驱动（/dev/sgx_enclave、/dev/sgx_provision、/dev/sgx/enclave、/dev/sgx/provision）自动透传和挂载到容器；\n* 支持 SGX1 驱动（/dev/isgx、/dev/sgx）自动透传和挂载到容器；\n\n## 依赖\n\n* 对于 SGX1\n  * [Intel SGX Drivers](https://github.com/intel/linux-sgx-driver)\n  * [Intel SGX PSW(Platform Software)](https://github.com/intel/linux-sgx) (如果你需要 AESM 服务)\n* Kubernetes 版本 \u003e= 1.10\n* Go 版本 \u003e= 1.13\n\n## ACK-TEE 简介\n\nTEE (Trusted Execution Environment) ，中文名：可信执行环境，是把用户应用程序代码和数据运行在一个通过硬件孤岛和内存加密技术（Hardware Isolation and memory encryption Technology）创建的特殊执行上线文环境 Enclave 中，任何其他应用、OS Kernel、BIOS、甚至 CPU 之外的其他硬件均无法访问，主要用于防止用户的机密数据、隐私数据被恶意修改、窥探和窃取。\n\n在 [阿里云ACK (Alibaba Cloud Container Service for Kubernetes)](https://aliyun.com/product/kubernetes) 上可以创建一个基于 Intel\u0026reg; SGX 的机密计算托管 Kubernetes 集群，节点型号是支持 Intel\u0026reg; SGX 的裸金属服务器 `ecs.ebmhfg5.2xlarge`, 相对于 VM，裸金属的 Overhead 开销更小，性能更优，性能抖动更小。每个节点上默认都会自动安装 containerd、SGX Driver、SGX PSW(Platform Software) 以及 SGX-Device-Plugin。\n\n## 编译\u0026打包镜像（可选）\n\nStep 1: 下载源码并编译。\n\n```bash\nmkdir -p $GOPATH/src/github.com/AliyunContainerService\ngit clone https://github.com/AliyunContainerService/sgx-device-plugin.git $GOPATH/src/github.com/AliyunContainerService/sgx-device-plugin\ncd $GOPATH/src/github.com/AliyunContainerService/sgx-device-plugin/\nmake\nls -l _output/sgx-device-plugin\n```\n\nStep 2： 镜像打包\n\n```bash\ndocker build -t {SGX_DEVICE_PLUGIN_IMAGE} . -f Dockerfile\ndocker push {SGX_DEVICE_PLUGIN_IMAGE}\n```\n\n## 部署 sgx-device-plugin\n\n在创建ACK机密计算托管集群时，默认会自动安装 sgx-device-plugin DaemonSet。当然你也可以在你自己支持 SGX 的 Kubernetes 中选择手动安装:\n\n```bash\n$ cat \u003c\u003cEOF | kubectl create -f -\napiVersion: apps/v1\nkind: DaemonSet\nmetadata:\n  name: sgx-device-plugin-ds\n  namespace: kube-system\nspec:\n  selector:\n    matchLabels:\n      k8s-app: sgx-device-plugin\n  template:\n    metadata:\n      annotations:\n        scheduler.alpha.kubernetes.io/critical-pod: \"\"\n      labels:\n        k8s-app: sgx-device-plugin\n    spec:\n      containers:\n      - image: registry.cn-hangzhou.aliyuncs.com/acs/sgx-device-plugin:v1.0.0-fb467e2-aliyun\n        imagePullPolicy: IfNotPresent\n        name: sgx-device-plugin\n        securityContext:\n          allowPrivilegeEscalation: false\n          capabilities:\n            drop:\n            - ALL\n        volumeMounts:\n        - mountPath: /var/lib/kubelet/device-plugins\n          name: device-plugin\n        - mountPath: /dev\n          name: dev\n      tolerations:\n      - effect: NoSchedule\n        key: alibabacloud.com/sgx_epc_MiB\n        operator: Exists\n      volumes:\n      - hostPath:\n          path: /var/lib/kubelet/device-plugins\n          type: DirectoryOrCreate\n        name: device-plugin\n      - hostPath:\n          path: /dev\n          type: Directory\n        name: dev\nEOF\n$ kubectl -n kube-system -l k8s-app=sgx-device-plugin\nNAME                         READY   STATUS        RESTARTS   AGE\nsgx-device-plugin-ds-5brgs   1/1     Running       0          5d5h\nsgx-device-plugin-ds-b467q   1/1     Running       0          5d5h\nsgx-device-plugin-ds-vl7sm   1/1     Running       0          5d5h\n$\n```\n\n插件成功运行后，会发现 Node 的 `.status.capacity` 或 `.status.allocatable` 多了一种新资源 **`alibabacloud.com/sgx_epc_MiB`**:\n\n```bash\n$ kubectl get node {NODE_NAME} -o yaml\n...\n  allocatable:\n    alibabacloud.com/sgx_epc_MiB: \"93\"\n    cpu: \"8\"\n...\n$\n```\n\n## 运行 SGX 应用容器\n\n首先你的应用须通过 Intel SGX SDK 或 SGX LibOS 进行编译、签名和镜像打包。\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: {POD_NAME}\n  namespace: default\nspec:\n  containers:\n  - image: {CONTAINER_IMAGE}\n    imagePullPolicy: IfNotPresent\n    name: {CONTAINER_NAME}\n    resources:\n      requests:\n        alibabacloud.com/sgx_epc_MiB: 20\n      limits:\n        alibabacloud.com/sgx_epc_MiB: 20\n```\n\n如果你的应用需要 Remote Attestation，那么必须将 aesm.socket 挂载到你的容器中，有两种方法:\n\n方法一：手动挂载 `/var/run/aesmd/aesm.socket` 到你的容器中，例如：\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: {POD_NAME}\n  namespace: default\nspec:\n  containers:\n  - image: {CONTAINER_IMAGE}\n    imagePullPolicy: IfNotPresent\n    name: {CONTAINER_NAME}\n    resources:\n      requests:\n        alibabacloud.com/sgx_epc_MiB: 20\n      limits:\n        alibabacloud.com/sgx_epc_MiB: 20\n    volumeMounts:\n    - mountPath: /var/run/aesmd/aesm.socket\n      name: aesmsocket\n  volumes:\n  - hostPath:\n      path: /var/run/aesmd/aesmd/aesm.socket\n      type: Socket\n    name: aesmsocket\n\n```\n\n方法二：启用 sgx-device-plugin 的 AESM socket 自动挂载功能（通过 `--enable-aesm-socket-attach=true` 选项），详情可参考 [deploy/sgx-device-plugin-enable-aesm-socket-attach.yaml](deploy/sgx-device-plugin-enable-aesm-socket-attach.yaml)。\n\n## FAQ\n\n* **我可以把这个插件部署到自己的私有 Kubernetes 集群中吗 ?**\n当然可以，这个插件是云原生、云平台无关的，你可以把它部署在任何 Kubernetes 上，但它只能运行在 SGX 的节点上。\n\n* **这个插件是否可以真的帮助应用限制 EPC 大小 ？**\n不可以，`alibabacloud.com/sgx_epc_MiB` 里指定的 EPC 大小限制仅用于 K8s 的调度, 因为 SGX 驱动目前还不支持 EPC 大小限制。\n\n## 许可证\n\n本软件许可证为 [Apache 2.0](./LICENSE)。\n\n## Contributing\n\n详情请参考 [CONTRIBUTING.md](./docs/en/CONTRIBUTING.md)。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAliyunContainerService%2Fsgx-device-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAliyunContainerService%2Fsgx-device-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAliyunContainerService%2Fsgx-device-plugin/lists"}