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 175
#397 added block other tenant resources test #515
Merged
k8s-ci-robot
merged 7 commits into
kubernetes-retired:master
from
phoenixking25:block_other_tenants
Apr 21, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6fef519
#397 [WIP] added block other tenant resources
phoenixking25 f03b3b2
added namespaced resources annotation test
phoenixking25 cace94f
resolved path conflicts
phoenixking25 7bd4f60
changed path and added tenantvalidate function
phoenixking25 35169c0
resolved conflict
phoenixking25 23b5ce3
reordered imports
phoenixking25 d70ba71
Merge branch 'master' into block_other_tenants
phoenixking25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 83 additions & 0 deletions
83
benchmarks/e2e/tests/block_other_tenant_resources/block_other_tenant_resources.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,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) | ||
} | ||
}) | ||
}) | ||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 removenot !
from front of it and fill the Tenant A and comment out the Tenant B inconfig.yaml
then it shows error.