Skip to content

Commit

Permalink
fix acount>account typo in department label/tag and add test cases (#6)
Browse files Browse the repository at this point in the history
* fix acount>account typo in department label/tag and add test cases

* bump version
  • Loading branch information
chrisns authored May 12, 2022
1 parent 28dbfe3 commit e590728
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 15 deletions.
20 changes: 20 additions & 0 deletions infra/checkov/require-known-department-label/pass2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "aws_s3_bucket" "b" {
bucket = "my-tf-test-bucket"
tags = {
mycompany.com.department = "accounts"
}
}

resource "aws_ami" "example" {
name = "terraform-example"
virtualization_type = "hvm"
root_device_name = "/dev/xvda"
tags = {
mycompany.com.department = "accounts"
}
ebs_block_device {
device_name = "/dev/xvda"
snapshot_id = "snap-xxxxxxxx"
volume_size = 8
}
}
2 changes: 1 addition & 1 deletion infra/checkov/require-known-department-label/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ definition:
resource_types: "all"
attribute: 'tags.mycompany.com.department'
operator: "equals"
value: acounts
value: accounts
- cond_type: "attribute"
resource_types: "all"
attribute: 'tags.mycompany.com.department'
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/kyverno/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

nameSuffix: "-2.0.0"
nameSuffix: "-2.1.0"

commonLabels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"

resources:
- require-department-label/policy.yaml
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/kyverno/require-department-label/fail0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Pod
metadata:
name: require-department-label-fail0
labels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/kyverno/require-department-label/pass0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-department-label-pass0
labels:
mycompany.com/department: finance
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/kyverno/require-department-label/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
- "*"
selector:
matchLabels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
validate:
message: "The label `mycompany.com/department` is required."
pattern:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/kyverno/require-department-label/skip0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-department-label-skip0
labels:
mycompany.com/require-department-label: exempt
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/kyverno/require-department-label/skip1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-department-label-skip1
namespace: kube-system
labels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-known-department-label-fail0
labels:
mycompany.com/department: nothr
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-known-department-label-pass0
labels:
mycompany.com/department: hr
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
11 changes: 11 additions & 0 deletions kubernetes/kyverno/require-known-department-label/pass1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: require-known-department-label-pass1
labels:
mycompany.com/department: accounts
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
image: nginx
6 changes: 3 additions & 3 deletions kubernetes/kyverno/require-known-department-label/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ spec:
- "*"
selector:
matchLabels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
validate:
message: "The label `mycompany.com/department` is required to be one of [tech|acounts|servicedesk|hr]"
message: "The label `mycompany.com/department` is required to be one of [tech|accounts|servicedesk|hr]"
pattern:
metadata:
labels:
"mycompany.com/department": "tech|acounts|servicedesk|hr"
"mycompany.com/department": "tech|accounts|servicedesk|hr"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-known-department-label-skip0
labels:
mycompany.com/require-known-department-label: exempt
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: require-known-department-label-skip1
namespace: kube-system
labels:
mycompany.com/policy-version: "2.0.0"
mycompany.com/policy-version: "2.1.0"
spec:
containers:
- name: nginx
Expand Down
6 changes: 6 additions & 0 deletions kubernetes/kyverno/require-known-department-label/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ policies:
resources:
- fail0.yaml
- pass0.yaml
- pass1.yaml
- skip0.yaml
- skip1.yaml

Expand All @@ -20,6 +21,11 @@ results:
resource: require-known-department-label-pass0
kind: Pod
result: pass
- policy: require-known-department-label
rule: require-known-department-label
resource: require-known-department-label-pass1
kind: Pod
result: pass
- policy: require-known-department-label
rule: require-known-department-label
resource: require-known-department-label-skip0
Expand Down

0 comments on commit e590728

Please sign in to comment.