Skip to content

Commit

Permalink
add related object
Browse files Browse the repository at this point in the history
Signed-off-by: YiscahLevySilas1 <[email protected]>
  • Loading branch information
YiscahLevySilas1 committed Jul 17, 2023
1 parent 266d8ec commit 3782b3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 56 deletions.
5 changes: 4 additions & 1 deletion rules/workload-mounted-configmap/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ deny[msga] {
"fixPaths":[],
"alertObject": {
"k8sApiObjects": [resource]
}
},
"relatedObjects": [{
"object": configMap
}]
}
}

Expand Down
5 changes: 4 additions & 1 deletion rules/workload-mounted-pvc/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ deny[msga] {
"fixPaths":[],
"alertObject": {
"k8sApiObjects": [resource]
}
},
"relatedObjects": [{
"object": PVC
}]
}
}

Expand Down
12 changes: 5 additions & 7 deletions rules/workload-mounted-secrets/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ deny[msga] {
secret.metadata.name == volume.secret.secretName
is_same_namespace(secret.metadata, resource.metadata)

# add related ressource
resource_vector := json.patch(resource, [{"op": "add", "path": "relatedObjects", "value": [secret]}])


containers_path := get_containers_path(resource)
containers := object.get(resource, containers_path, [])
container := containers[j]
Expand All @@ -32,9 +28,11 @@ deny[msga] {
"failedPaths": [failedPaths],
"fixPaths":[],
"alertObject": {
"k8sApiObjects": [resource],
"externalObjects": resource_vector
}
"k8sApiObjects": [resource]
},
"relatedObjects": [{
"object": secret
}]
}
}

Expand Down
48 changes: 1 addition & 47 deletions rules/workload-mounted-secrets/test/failed/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,7 @@
"name": "mypod"
}
}
],
"externalObjects": {
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "mypod",
"namespace": "default"
},
"relatedObjects": [
{
"apiVersion": "v1",
"data": {
"password": "MWYyZDFlMmU2N2Rm",
"username": "YWRtaW4="
},
"kind": "Secret",
"metadata": {
"name": "mysecret"
},
"type": "Opaque"
}
],
"spec": {
"containers": [
{
"image": "redis",
"name": "mypod",
"volumeMounts": [
{
"mountPath": "/etc/foo",
"name": "foo",
"readOnly": true
}
]
}
],
"volumes": [
{
"name": "foo",
"secret": {
"optional": true,
"secretName": "mysecret"
}
}
]
}
}
]
}
}
]

0 comments on commit 3782b3d

Please sign in to comment.