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
[MTB] added block other tenant resources benchmark #1318
Merged
k8s-ci-robot
merged 7 commits into
kubernetes-retired:master
from
phoenixking25:block-other-tenant-resources
Jan 19, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be6e2fb
added test
phoenixking25 a606f7a
removed extra code
phoenixking25 e1dbabe
renamed variable
phoenixking25 b6b4129
Merge branch 'master' of github.com:kubernetes-sigs/multi-tenancy int…
phoenixking25 05f8796
Merge branch 'master' of github.com:kubernetes-sigs/multi-tenancy int…
phoenixking25 ca7681d
made changes
phoenixking25 bb174d9
corrected nodeport benchmark
phoenixking25 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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
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
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
40 changes: 40 additions & 0 deletions
40
benchmarks/kubectl-mtb/test/benchmarks/block_other_tenant_resources/README.md
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,40 @@ | ||
# Block access to other tenant resources <small>[MTB-PL1-CC-TI-2] </small> | ||
|
||
**Profile Applicability:** | ||
|
||
2 | ||
|
||
**Type:** | ||
|
||
Configuration | ||
|
||
**Category:** | ||
|
||
Tenant Protection | ||
|
||
**Description:** | ||
|
||
Access controls should be configured so that a tenant cannot view, edit, create, or delete namespaced resources belonging to another tenant. | ||
|
||
**Rationale:** | ||
|
||
Tenant resources should be isolated from other tenants. | ||
|
||
|
||
**Audit:** | ||
|
||
Run the following commands to retrieve the list of namespaced resources available in Tenant B | ||
```bash | ||
kubectl --kubeconfig tenant-b api-resources --namespaced=true | ||
``` | ||
For each namespaced resource, and each verb (get, list, create, update, patch, watch, delete, and deletecollection) issue the following command | ||
```bash | ||
kubectl --kubeconfig tenant-a -n b1 <verb> <resource> | ||
``` | ||
Each command must return 'no' | ||
|
||
|
||
**namespaceRequired:** | ||
|
||
2 | ||
|
73 changes: 73 additions & 0 deletions
73
.../kubectl-mtb/test/benchmarks/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,73 @@ | ||
package blockothertenantresources | ||
|
||
import ( | ||
"fmt" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/test/utils" | ||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/types" | ||
|
||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/bundle/box" | ||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/pkg/benchmark" | ||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/test" | ||
) | ||
|
||
var verbs = []string{"get", "update"} | ||
|
||
var b = &benchmark.Benchmark{ | ||
|
||
PreRun: func(options types.RunOptions) error { | ||
|
||
return nil | ||
}, | ||
|
||
Run: func(options types.RunOptions) error { | ||
var resources []utils.GroupResource | ||
|
||
lists, err := options.ClusterAdminClient.Discovery().ServerPreferredResources() | ||
if err != nil { | ||
options.Logger.Debug(err.Error()) | ||
return err | ||
} | ||
|
||
for _, list := range lists { | ||
if len(list.APIResources) == 0 { | ||
continue | ||
} | ||
gv, err := schema.ParseGroupVersion(list.GroupVersion) | ||
if err != nil { | ||
continue | ||
} | ||
for _, resource := range list.APIResources { | ||
if len(resource.Verbs) == 0 || !resource.Namespaced { | ||
continue | ||
} | ||
|
||
resources = append(resources, utils.GroupResource{ | ||
APIGroup: gv.Group, | ||
APIResource: resource, | ||
}) | ||
} | ||
} | ||
|
||
err = utils.CheckAccessOnResourcesInNamespace(options.Tenant2Client, options.TenantNamespace, resources, verbs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = utils.CheckAccessOnResourcesInNamespace(options.Tenant1Client, options.OtherNamespace, resources, verbs) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
// Get the []byte representation of a file, or an error if it doesn't exist: | ||
err := b.ReadConfig(box.Get("block_other_tenant_resources/config.yaml")) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
test.BenchmarkSuite.Add(b); | ||
} |
1 change: 1 addition & 0 deletions
1
...ctl-mtb/test/benchmarks/block_other_tenant_resources/block_other_tenant_resources_test.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 @@ | ||
package blockothertenantresources |
19 changes: 19 additions & 0 deletions
19
benchmarks/kubectl-mtb/test/benchmarks/block_other_tenant_resources/config.yaml
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,19 @@ | ||
id: MTB-PL1-CC-TI-2 | ||
title: Block access to other tenant resources | ||
benchmarkType: Configuration | ||
category: Tenant Protection | ||
description: Access controls should be configured so that a tenant cannot view, edit, create, or delete namespaced resources belonging to another tenant. | ||
remediation: | ||
profileLevel: 2 | ||
namespaceRequired: 2 | ||
rationale: Tenant resources should be isolated from other tenants. | ||
Audit: | | ||
Run the following commands to retrieve the list of namespaced resources available in Tenant B | ||
```bash | ||
kubectl --kubeconfig tenant-b api-resources --namespaced=true | ||
``` | ||
For each namespaced resource, and each verb (get, list, create, update, patch, watch, delete, and deletecollection) issue the following command | ||
```bash | ||
kubectl --kubeconfig tenant-a -n b1 <verb> <resource> | ||
``` | ||
Each command must return 'no' |
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
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
Oops, something went wrong.
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.
Maybe we can add the arguments in a list itself like
-n test test2 --as bob-k8s-access bob2-k8s-access
?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.
That's a great idea! @phoenixking25 what do you think?
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.
Looks like the Cobra CLI package allows this:
spf13/cobra#661