Skip to content

Commit 56c0a9f

Browse files
committed
sgx: set epc limits via NRI annotations
Signed-off-by: Mikko Ylinen <[email protected]>
1 parent 48fd7b8 commit 56c0a9f

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

deployments/sgx_plugin/base/intel-sgx-plugin.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ spec:
3232
- name: sgx-provision
3333
mountPath: /dev/sgx_provision
3434
readOnly: true
35+
- name: nri-sgx-epc
36+
image: ghcr.io/containers/nri-plugins/nri-sgx-epc:unstable
37+
securityContext:
38+
readOnlyRootFilesystem: true
39+
allowPrivilegeEscalation: false
40+
imagePullPolicy: IfNotPresent
41+
volumeMounts:
42+
- name: nrisockets
43+
mountPath: /var/run/nri
3544
volumes:
3645
- name: kubeletsockets
3746
hostPath:
3847
path: /var/lib/kubelet/device-plugins
48+
- name: nrisockets
49+
hostPath:
50+
path: /var/run/nri
3951
- name: sgx-enclave
4052
hostPath:
4153
path: /dev/sgx_enclave

pkg/controllers/sgx/controller_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
9494
},
9595
},
9696
},
97+
{
98+
Name: "nri-sgx-epc",
99+
Image: "ghcr.io/containers/nri-plugins/nri-sgx-epc:unstable",
100+
ImagePullPolicy: "IfNotPresent",
101+
SecurityContext: &v1.SecurityContext{
102+
ReadOnlyRootFilesystem: &yes,
103+
AllowPrivilegeEscalation: &no,
104+
},
105+
VolumeMounts: []v1.VolumeMount{
106+
{
107+
Name: "nrisockets",
108+
MountPath: "/var/run/nri",
109+
},
110+
},
111+
},
97112
},
98113
NodeSelector: map[string]string{"kubernetes.io/arch": "amd64"},
99114
Volumes: []v1.Volume{
@@ -105,6 +120,14 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
105120
},
106121
},
107122
},
123+
{
124+
Name: "nrisockets",
125+
VolumeSource: v1.VolumeSource{
126+
HostPath: &v1.HostPathVolumeSource{
127+
Path: "/var/run/nri",
128+
},
129+
},
130+
},
108131
{
109132
Name: "sgx-enclave",
110133
VolumeSource: v1.VolumeSource{

pkg/webhooks/sgx/sgx.go

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var ErrObjectType = errors.New("invalid runtime object type")
3535
type Mutator struct{}
3636

3737
const (
38+
epcLimitKey = "epc-limit.nri.io"
3839
namespace = "sgx.intel.com"
3940
encl = namespace + "/enclave"
4041
epc = namespace + "/epc"
@@ -148,6 +149,8 @@ func (s *Mutator) Default(ctx context.Context, obj runtime.Object) error {
148149
continue
149150
}
150151

152+
pod.Annotations[fmt.Sprintf("%s/container.%s", epcLimitKey, container.Name)] = fmt.Sprintf("%d", epcSize)
153+
151154
totalEpc += epcSize
152155

153156
// Quote Generation Modes:

test/e2e/sgxadmissionwebhook/sgxaadmissionwebhook.go

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func describe() {
6969

7070
ginkgo.By("checking the pod total EPC size annotation is correctly set")
7171
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
72+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1048576"))
7273
})
7374
ginkgo.It("mutates created pods when the container contains the quote generation libraries", func(ctx context.Context) {
7475
ginkgo.By("submitting the pod")
@@ -79,6 +80,7 @@ func describe() {
7980

8081
ginkgo.By("checking the pod total EPC size annotation is correctly set")
8182
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
83+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1048576"))
8284
})
8385
ginkgo.It("mutates created pods when the container uses aesmd from a side-car container to generate quotes", func(ctx context.Context) {
8486
ginkgo.By("submitting the pod")
@@ -93,6 +95,8 @@ func describe() {
9395
gomega.Expect(pod.Spec.Containers[0].Env[0].Value).To(gomega.Equal("1"))
9496
ginkgo.By("checking the pod total EPC size annotation is correctly set")
9597
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("2Mi"))
98+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1048576"))
99+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.aesmd"]).To(gomega.Equal("1048576"))
96100
})
97101
ginkgo.It("mutates created pods where one container uses host/daemonset aesmd to generate quotes", func(ctx context.Context) {
98102
ginkgo.By("submitting the pod")
@@ -106,6 +110,7 @@ func describe() {
106110
gomega.Expect(pod.Spec.Containers[0].Env[0].Value).To(gomega.Equal("1"))
107111
ginkgo.By("checking the pod total EPC size annotation is correctly set")
108112
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("1Mi"))
113+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test"]).To(gomega.Equal("1048576"))
109114
})
110115
ginkgo.It("mutates created pods where three containers use host/daemonset aesmd to generate quotes", func(ctx context.Context) {
111116
ginkgo.By("submitting the pod")
@@ -125,6 +130,9 @@ func describe() {
125130
gomega.Expect(pod.Spec.Containers[2].Env[0].Value).To(gomega.Equal("1"))
126131
ginkgo.By("checking the pod total EPC size annotation is correctly set")
127132
gomega.Expect(pod.Annotations["sgx.intel.com/epc"]).To(gomega.Equal("3Mi"))
133+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test1"]).To(gomega.Equal("1048576"))
134+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test2"]).To(gomega.Equal("1048576"))
135+
gomega.Expect(pod.Annotations["epc-limit.nri.io/container.test3"]).To(gomega.Equal("1048576"))
128136
})
129137
ginkgo.It("checks that Volumes and VolumeMounts are created only once", func(ctx context.Context) {
130138
ginkgo.By("submitting the pod")

0 commit comments

Comments
 (0)