Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

#397 added block other tenant resources test #515

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions benchmarks/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ func (c *BenchmarkConfig) GetValidTenant() (TenantSpec, error) {

return c.TenantB, nil
}

func (c *BenchmarkConfig) ValidateTenant(t TenantSpec) (error) {
if c == nil {
return errors.New("Please fill in a valid/non-empty config.yaml")
}

if !reflect.DeepEqual(t, TenantSpec{}) {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was confusing to me so i tested it and it was working well, no problem i will run again the test and get back to you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am agreed that it should give error but its working according to required behavior only when we compliment it by not ! in front of it. Actually if we see https://github.com/kubernetes-sigs/multi-tenancy/blob/a99b6dbd22693bf23f119226184df87301549f32/benchmarks/e2e/config/config.go#L26 this is also behaving exact like this! Lets say i remove not ! from front of it and fill the Tenant A and comment out the Tenant B in config.yaml then it shows error.

}

return errors.New("Given tenant does not match with TenantSpec")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package test

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

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

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

var _ = framework.KubeDescribe("test across tenants permission", func() {
var config *configutil.BenchmarkConfig
var resourceList string
var err error
var tenantA, tenantB string
var namespaceFlag = "-n"
var dryrun = "--dry-run=true"
var all = "--all=true"

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

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

err = config.ValidateTenant(config.TenantA)
framework.ExpectNoError(err)

os.Setenv("KUBECONFIG", config.TenantA.Kubeconfig)
tenantA = configutil.GetContextFromKubeconfig(config.TenantA.Kubeconfig)

outputFlag := fmt.Sprintf("-o=name")
nsdFlag := fmt.Sprintf("--namespaced=true")

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

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

ginkgo.BeforeEach(func() {
err = config.ValidateTenant(config.TenantB)
framework.ExpectNoError(err)

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

ginkgo.It("get tenant 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)
}
})

ginkgo.It("edit other tenant namespaced resources", func() {
ginkgo.By(fmt.Sprintf("tenant %s cannot edit tenant %s namespaced resources", tenantB, tenantA))
resources := strings.Fields(resourceList)
annotation := "test=multi-tenancy"
for _, resource := range resources {
_, errNew := framework.LookForString(expectedVal, time.Minute, func() string {
_, err := framework.RunKubectl(namespaceFlag, config.TenantA.Namespace, "annotate", resource, annotation, dryrun, all)
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 @@ -13,6 +13,7 @@ import (
_ "sigs.k8s.io/multi-tenancy/benchmarks/e2e/tests/block_cluster_resources"
_ "sigs.k8s.io/multi-tenancy/benchmarks/e2e/tests/configure_ns_quotas"
_ "sigs.k8s.io/multi-tenancy/benchmarks/e2e/tests/block_privileged_containers"
_ "sigs.k8s.io/multi-tenancy/benchmarks/e2e/tests/block_other_tenant_resources"
)

// RunE2ETests runs the multi-tenancy benchmark tests
Expand Down