-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: policy, chainsaw test, kyverno test
- Loading branch information
Showing
8 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
multitenancy-benchmarks/require-resource-quota/.chainsaw-test/chainsaw-step-01-assert-1.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,6 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: require-resource-quota | ||
status: | ||
ready: true |
30 changes: 30 additions & 0 deletions
30
multitenancy-benchmarks/require-resource-quota/.chainsaw-test/chainsaw-test.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,30 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: require-resource-quota | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- apply: | ||
file: ns-good.yaml | ||
- script: | ||
content: | | ||
sed 's/validationFailureAction: audit/validationFailureAction: Audit/' ../require-resource-quota.yaml | kubectl create -f - | ||
- assert: | ||
file: chainsaw-step-01-assert-1.yaml | ||
- name: step-02 | ||
try: | ||
- apply: | ||
expect: | ||
- check: | ||
($error != null): true | ||
file: ns-bad.yaml | ||
- name: step-99 | ||
try: | ||
- delete: | ||
ref: | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
name: require-resource-quota |
5 changes: 5 additions & 0 deletions
5
multitenancy-benchmarks/require-resource-quota/.chainsaw-test/ns-bad.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,5 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: bad-ns | ||
spec: {} |
24 changes: 24 additions & 0 deletions
24
multitenancy-benchmarks/require-resource-quota/.chainsaw-test/ns-good.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,24 @@ | ||
|
||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: good-ns | ||
spec: {} | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: ResourceQuota | ||
metadata: | ||
name: foo-resource-quota | ||
namespace: good-ns | ||
spec: | ||
hard: | ||
cpu: "1000" | ||
memory: 200Gi | ||
pods: "10" | ||
scopeSelector: | ||
matchExpressions: | ||
- operator : In | ||
scopeName: PriorityClass | ||
values: ["high"] |
16 changes: 16 additions & 0 deletions
16
multitenancy-benchmarks/require-resource-quota/.kyverno-test/kyverno-test.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,16 @@ | ||
apiVersion: cli.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: require-resource-quota | ||
policies: | ||
- ../require-resource-quota.yaml | ||
resources: | ||
- resource.yaml | ||
results: | ||
- kind: Namespace | ||
policy: require-resource-quota | ||
resources: | ||
- ns-resource-quota | ||
result: fail | ||
rule: require-resource-quota | ||
variables: values.yaml |
5 changes: 5 additions & 0 deletions
5
multitenancy-benchmarks/require-resource-quota/.kyverno-test/resource.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,5 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: ns-resource-quota | ||
spec: {} |
8 changes: 8 additions & 0 deletions
8
multitenancy-benchmarks/require-resource-quota/.kyverno-test/values.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,8 @@ | ||
apiVersion: cli.kyverno.io/v1alpha1 | ||
kind: Values | ||
policies: | ||
- name: require-resource-quota | ||
rules: | ||
- name: require-resource-quota | ||
values: | ||
policies_count: "0" |
51 changes: 51 additions & 0 deletions
51
multitenancy-benchmarks/require-resource-quota/require-resource-quota.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,51 @@ | ||
apiVersion: kyverno.io/v2beta1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: require-resource-quota | ||
annotations: | ||
policies.kyverno.io/title: Require Resource Quota | ||
policies.kyverno.io/category: Multitenancy Benchmarks | ||
policies.kyverno.io/severity: medium | ||
policies.kyverno.io/subject: Namespace | ||
policies.kyverno.io/description: >- | ||
In cases such as multi-tenancy where new Namespaces must be fully | ||
provisioned before they can be used, it may not be easy to declare and | ||
understand if/when the Namespace is ready. Having a policy which defines | ||
all the resources which are required for each Namespace can assist in determining | ||
compliance. This policy, expected to be run in background mode only, performs a Namespace | ||
check to ensure that all Namespaces have a ResourceQuota. | ||
Additional rules may be written to extend the check for your needs. By default, background | ||
scans occur every one hour which may be changed with an additional container flag. Please | ||
see the installation documentation for details. | ||
spec: | ||
background: true | ||
validationFailureAction: Audit | ||
rules: | ||
- name: resourcequotas | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Namespace | ||
exclude: | ||
any: | ||
- resources: | ||
namespaces: | ||
- kube-system | ||
- kube-public | ||
- kube-node-lease | ||
- kyverno | ||
context: | ||
- name: resourcequotas | ||
apiCall: | ||
urlPath: "/api/v1/namespaces/{{request.object.metadata.name}}/resourcequotas" | ||
jmesPath: "items[] | length(@)" | ||
validate: | ||
message: "Every Namespace must have at least one ResourceQuota." | ||
deny: | ||
conditions: | ||
all: | ||
- key: "{{ resourcequotas }}" | ||
operator: Equals | ||
value: 0 | ||
|