This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #655 from SomtochiAma/block_add_capabilities
Block add capabilities
- Loading branch information
Showing
4 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# # path to cluster administrator's kubeconfig file | ||
# adminKubeconfig: | ||
# adminKubeconfig: | ||
|
||
# # path to the tenant's kubeconfig and its namespace | ||
# tenantA: | ||
# kubeconfig: | ||
# namespace: | ||
# kubeconfig: | ||
# namespace: | ||
|
||
# # path to the tenant's kubeconfig and its namespace | ||
# tenantB: | ||
# kubeconfig: | ||
# namespace: | ||
# kubeconfig: | ||
# namespace: | ||
|
||
# # label is used to identify the resources | ||
# # label is used to identify the resources | ||
# # managed by the cluster administrator | ||
# label: |
69 changes: 69 additions & 0 deletions
69
benchmarks/e2e/tests/block_add_capabilities/block_add_capabilities.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package tenantaccess | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"strings" | ||
"github.com/onsi/ginkgo" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
configutil "sigs.k8s.io/multi-tenancy/benchmarks/e2e/config" | ||
imageutils "k8s.io/kubernetes/test/utils/image" | ||
|
||
) | ||
|
||
const ( | ||
expectedVal = "capability may not be added" | ||
) | ||
|
||
var _ = framework.KubeDescribe("Tenants should unable to add linux capabilities for pods", func() { | ||
var config *configutil.BenchmarkConfig | ||
var tenantA configutil.TenantSpec | ||
var user string | ||
var err error | ||
|
||
ginkgo.BeforeEach(func() { | ||
config, err = configutil.ReadConfig(configutil.ConfigPath) | ||
framework.ExpectNoError(err) | ||
|
||
tenantA, err = config.GetValidTenant() | ||
framework.ExpectNoError(err) | ||
user = configutil.GetContextFromKubeconfig(tenantA.Kubeconfig) | ||
}) | ||
|
||
ginkgo.It("validate tenants can't create containers with add capabilities", func() { | ||
kclient := configutil.NewKubeClientWithKubeconfig(tenantA.Kubeconfig) | ||
BusyBoxImage := imageutils.GetE2EImage(imageutils.BusyBox) | ||
podSpec := &v1.Pod{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Pod", | ||
APIVersion: "v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "multitenant-tester", | ||
Namespace: tenantA.Namespace, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "write-pod", | ||
Image: BusyBoxImage, | ||
Command: []string{"/bin/sh"}, | ||
Args: []string{"-c", "trap exit TERM; while true; do sleep 1; done"}, | ||
SecurityContext: &v1.SecurityContext{ | ||
Capabilities: &v1.Capabilities{ | ||
Add: []v1.Capability{ | ||
"SETPCAP", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
_, err = kclient.CoreV1().Pods(tenantA.Namespace).Create(podSpec) | ||
if !strings.Contains(err.Error(),expectedVal) { | ||
framework.Failf("%s must be unable to create pod with add capabilities", user) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters