@@ -344,6 +344,53 @@ func TestDeploymentForMCPServerWithEnvVars(t *testing.T) {
344
344
assert .True (t , debugModeArgFound , "DEBUG_MODE should be passed as --env flag" )
345
345
}
346
346
347
+ func TestProxyRunnerSecurityContext (t * testing.T ) {
348
+ t .Parallel ()
349
+
350
+ // Create a test MCPServer
351
+ mcpServer := & mcpv1alpha1.MCPServer {
352
+ ObjectMeta : metav1.ObjectMeta {
353
+ Name : "test-mcp-server-env" ,
354
+ Namespace : "default" ,
355
+ },
356
+ Spec : mcpv1alpha1.MCPServerSpec {
357
+ Image : "test-image:latest" ,
358
+ Transport : "stdio" ,
359
+ Port : 8080 ,
360
+ },
361
+ }
362
+
363
+ // Register the scheme
364
+ s := scheme .Scheme
365
+ s .AddKnownTypes (mcpv1alpha1 .GroupVersion , & mcpv1alpha1.MCPServer {})
366
+ s .AddKnownTypes (mcpv1alpha1 .GroupVersion , & mcpv1alpha1.MCPServerList {})
367
+
368
+ // Create a reconciler with the scheme
369
+ r := & MCPServerReconciler {
370
+ Scheme : s ,
371
+ }
372
+
373
+ // Generate the deployment
374
+ deployment := r .deploymentForMCPServer (mcpServer )
375
+ require .NotNil (t , deployment , "Deployment should not be nil" )
376
+
377
+ // Check that the ProxyRunner's pod and container security context are set
378
+ proxyRunnerPodSecurityContext := deployment .Spec .Template .Spec .SecurityContext
379
+ require .NotNil (t , proxyRunnerPodSecurityContext , "ProxyRunner pod security context should not be nil" )
380
+ assert .True (t , * proxyRunnerPodSecurityContext .RunAsNonRoot , "ProxyRunner pod RunAsNonRoot should be true" )
381
+ assert .Equal (t , int64 (1000 ), * proxyRunnerPodSecurityContext .RunAsUser , "ProxyRunner pod RunAsUser should be 1000" )
382
+ assert .Equal (t , int64 (1000 ), * proxyRunnerPodSecurityContext .RunAsGroup , "ProxyRunner pod RunAsGroup should be 1000" )
383
+ assert .Equal (t , int64 (1000 ), * proxyRunnerPodSecurityContext .FSGroup , "ProxyRunner pod FSGroup should be 1000" )
384
+
385
+ proxyRunnerContainerSecurityContext := deployment .Spec .Template .Spec .Containers [0 ].SecurityContext
386
+ require .NotNil (t , proxyRunnerContainerSecurityContext , "ProxyRunner container security context should not be nil" )
387
+ assert .False (t , * proxyRunnerContainerSecurityContext .Privileged , "ProxyRunner container Privileged should be false" )
388
+ assert .True (t , * proxyRunnerContainerSecurityContext .RunAsNonRoot , "ProxyRunner container RunAsNonRoot should be true" )
389
+ assert .Equal (t , int64 (1000 ), * proxyRunnerContainerSecurityContext .RunAsUser , "ProxyRunner container RunAsUser should be 1000" )
390
+ assert .Equal (t , int64 (1000 ), * proxyRunnerContainerSecurityContext .RunAsGroup , "ProxyRunner container RunAsGroup should be 1000" )
391
+ assert .False (t , * proxyRunnerContainerSecurityContext .AllowPrivilegeEscalation , "ProxyRunner container AllowPrivilegeEscalation should be false" )
392
+ }
393
+
347
394
// Helper functions
348
395
func boolPtr (b bool ) * bool {
349
396
return & b
0 commit comments