Skip to content

Commit 6189118

Browse files
authored
Merge pull request #5 from kailun-qin/dev-aesm
[Feature] Add AESM socket attachment support
2 parents 63f7f62 + 1bdb4bd commit 6189118

5 files changed

Lines changed: 103 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ spec:
143143
alibabacloud.com/sgx_epc_MiB: 20
144144
```
145145
146-
If you want a remote attestation, you should mount `/var/run/aesmd/aesm.socket` in your container, maybe like this:
146+
If you want a remote attestation, aesm.socket MUST BE mounted inside application containers. There are two ways to achieve it:
147+
148+
Way 1: Mount aesm.socket (i.e. /var/run/aesmd/aesm.socket) inside your application containers manually, maybe like this:
147149
148150
```yaml
149151
apiVersion: v1
@@ -172,6 +174,8 @@ spec:
172174

173175
```
174176

177+
Way 2: Enable AESM socket attachment of sgx-device-plugin (via --enable-aesm-socket-attach=true) which will help you mount ASEM socket inside your application containers automatically. See deploy/sgx-device-plugin-enable-aesm.yml.
178+
175179
## FAQ
176180

177181
* **Can I deploy this SGX device plugin in my own self-hosting Kubernetes?**

cmd/sgx-device-plugin/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"syscall"
56

67
"github.com/fsnotify/fsnotify"
@@ -12,7 +13,13 @@ import (
1213
"github.com/AliyunContainerService/sgx-device-plugin/pkg/utils"
1314
)
1415

16+
func init() {
17+
flag.BoolVar(&sgx.EnableAESMSocketAttach, "enable-aesm-socket-attach", false, "Enables attachment of AESM service socket")
18+
}
19+
1520
func main() {
21+
flag.Parse()
22+
1623
klog.Infof("Detecting SGX devices ...")
1724
if len(sgx.GetDevices()) == 0 {
1825
panic("No Device Found.")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: sgx-device-plugin-ds
5+
namespace: kube-system
6+
spec:
7+
selector:
8+
matchLabels:
9+
k8s-app: sgx-device-plugin
10+
template:
11+
metadata:
12+
annotations:
13+
scheduler.alpha.kubernetes.io/critical-pod: ""
14+
labels:
15+
k8s-app: sgx-device-plugin
16+
spec:
17+
containers:
18+
- image: registry.cn-hangzhou.aliyuncs.com/acs/sgx-device-plugin:v1.0.0-fb467e2-aliyun
19+
imagePullPolicy: IfNotPresent
20+
name: sgx-device-plugin
21+
args: ["--enable-aesm-socket-attach"]
22+
securityContext:
23+
allowPrivilegeEscalation: false
24+
capabilities:
25+
drop:
26+
- ALL
27+
volumeMounts:
28+
- mountPath: /var/lib/kubelet/device-plugins
29+
name: device-plugin
30+
- mountPath: /var/run/aesmd
31+
name: aesm
32+
- mountPath: /dev
33+
name: dev
34+
tolerations:
35+
- effect: NoSchedule
36+
key: alibabacloud.com/sgx_epc_MiB
37+
operator: Exists
38+
volumes:
39+
- hostPath:
40+
path: /var/lib/kubelet/device-plugins
41+
type: DirectoryOrCreate
42+
name: device-plugin
43+
- hostPath:
44+
path: /var/run/aesmd
45+
type: Directory
46+
name: aesm
47+
- hostPath:
48+
path: /dev
49+
type: Directory
50+
name: dev

pkg/device_plugin/device_plugin.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,26 @@ func (m *SGXDevicePlugin) ListAndWatch(e *devicepluginapi.Empty, s deviceplugina
5353
// Allocate which return list of devices.
5454
// Allocate implements DevicePluginServer interface.
5555
func (m *SGXDevicePlugin) Allocate(ctx context.Context, reqs *devicepluginapi.AllocateRequest) (*devicepluginapi.AllocateResponse, error) {
56+
var mounts []*devicepluginapi.Mount
5657
var devices []*devicepluginapi.DeviceSpec
5758

59+
if sgx.EnableAESMSocketAttach {
60+
for path, exist := range sgx.AllMountPoints() {
61+
if path != sgx.AESMSocketDir {
62+
continue
63+
}
64+
if exist {
65+
mounts = append(mounts, &devicepluginapi.Mount{
66+
ContainerPath: path,
67+
HostPath: path,
68+
ReadOnly: true,
69+
})
70+
} else {
71+
klog.Warningf("WARNING: Mount point %s not found", path)
72+
}
73+
}
74+
}
75+
5876
for dev, exist := range sgx.AllDeviceDrivers() {
5977
if exist {
6078
devices = append(devices, &devicepluginapi.DeviceSpec{
@@ -74,6 +92,7 @@ func (m *SGXDevicePlugin) Allocate(ctx context.Context, reqs *devicepluginapi.Al
7492
"SGX_VISIBLE_DEVICES": strings.Join(req.DevicesIDs, ","),
7593
},
7694
Devices: devices,
95+
Mounts: mounts,
7796
}
7897

7998
klog.Infof("[Allocate] %s", req.String())

pkg/sgx/sgx.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,24 @@ import (
1010
devicepluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
1111
)
1212

13+
var EnableAESMSocketAttach bool
14+
var AESMSocketDir string = "/var/run/aesmd"
15+
1316
var initOnce = &sync.Once{}
1417

18+
var allMountPoints = map[string]bool{
19+
AESMSocketDir: false, // optional
20+
}
21+
22+
// AllMountPoints lists all mount points.
23+
func AllMountPoints() map[string]bool {
24+
ret := make(map[string]bool)
25+
for k, v := range allMountPoints {
26+
ret[k] = v
27+
}
28+
return ret
29+
}
30+
1531
var allDeviceDrivers = map[string]bool{
1632
"/dev/isgx": false, // required
1733
"/dev/gsgx": false, // optional
@@ -28,6 +44,12 @@ func AllDeviceDrivers() map[string]bool {
2844

2945
func init() {
3046
initOnce.Do(func() {
47+
// Detecting mount points.
48+
for mp := range allMountPoints {
49+
if fi, err := os.Stat(mp); err == nil && fi.IsDir() {
50+
allMountPoints[mp] = true
51+
}
52+
}
3153
// Detecting device drivers.
3254
for driver := range allDeviceDrivers {
3355
if fi, err := os.Stat(driver); err == nil && !fi.IsDir() {

0 commit comments

Comments
 (0)