Skip to content

Commit

Permalink
kubernetes-retired#397 [WIP] added block other tenant resources
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixking25 committed Mar 11, 2020
1 parent d49fbcd commit 6fef519
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package test

import (
"fmt"
"os"
"strings"
"time"

"github.com/onsi/ginkgo"
configutil "github.com/realshuting/multi-tenancy/benchmarks/e2e/config"
"k8s.io/kubernetes/test/e2e/framework"
)

const (
expectedVal = "Error from server (Forbidden)"
)

var _ = framework.KubeDescribe("test cross tenants permission", func() {
var config *configutil.BenchmarkConfig
var resourceList string
var err error
var tenantA, tenantB string
namespaceFlag := fmt.Sprintf("-n")

ginkgo.BeforeEach(func() {
ginkgo.By("get namespace wide api-resources")

config, err = configutil.ReadConfig(configutil.ConfigPath)
framework.ExpectNoError(err)

os.Setenv("KUBECONFIG", config.TenantA.Kubeconfig)
tenantA = configutil.GetContextFromKubeconfig(config.TenantA.Kubeconfig)
outputFlag := fmt.Sprintf("-o=name")

resourceList, err = framework.RunKubectl(namespaceFlag, config.TenantA.Namespace, "api-resources", outputFlag)
framework.ExpectNoError(err)
})

framework.KubeDescribe("tenant cannot access other tenant namespaced resources", func() {

ginkgo.BeforeEach(func() {
os.Setenv("KUBECONFIG", config.TenantB.Kubeconfig)
tenantB = configutil.GetContextFromKubeconfig(config.TenantB.Kubeconfig)
})

ginkgo.It("get namespaced resources", func() {
ginkgo.By(fmt.Sprintf("tenant %s cannot get tenant %s namespaced resources", tenantB, tenantA))
resources := strings.Fields(resourceList)
for _, resource := range resources {
_, errNew := framework.LookForString(expectedVal, time.Minute, func() string {
_, err := framework.RunKubectl(namespaceFlag, config.TenantA.Namespace, "get", resource)
return err.Error()
})

framework.ExpectNoError(errNew)
}
})
})
})
1 change: 1 addition & 0 deletions benchmarks/e2e/tests/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ginkgowrapper "k8s.io/kubernetes/test/e2e/framework/ginkgowrapper"

// test sources
_ "github.com/realshuting/multi-tenancy/benchmarks/e2e/tests/block_other_tenant_resources"
_ "github.com/realshuting/multi-tenancy/benchmarks/e2e/tests/block_cluster_resources"
_ "github.com/realshuting/multi-tenancy/benchmarks/e2e/tests/configure_ns_quotas"
)
Expand Down

0 comments on commit 6fef519

Please sign in to comment.