Skip to content

Commit

Permalink
add policy to check that event.name is not referenced on events, jinj…
Browse files Browse the repository at this point in the history
…a cleanup
  • Loading branch information
lmolkova committed Oct 17, 2024
1 parent 3029273 commit 42a2e88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion model/azure/logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ groups:
- ref: cloud.resource_id
brief: The [Fully Qualified Azure Resource ID](https://docs.microsoft.com/rest/api/resources/resources/get-by-id) the log is emitted for.
note: ""
- ref: event.name
body:
id: az.resource.log
requirement_level: recommended
Expand Down
1 change: 1 addition & 0 deletions model/event/common.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
groups:
- id: event
type: attribute_group
stability: experimental
brief: >
This document defines attributes for Events represented using Log Records.
attributes:
Expand Down
12 changes: 12 additions & 0 deletions policies/yaml_schema.rego
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ deny[yaml_schema_violation(description, group.id, name)] {
description := sprintf("Event name '%s' is invalid. Event name %s'", [name, invalid_name_helper])
}

# checks event.name is not referenced in event attributes
deny[yaml_schema_violation(description, group.id, name)] {
group := input.groups[_]
group.type == "event"
name := group.name

attr := group.attributes[_]
attr.ref == "event.name"

description := sprintf("Attribute 'event.name' is referenced on event group '%s'. Event name must be provided in 'name' property on the group", [name])
}

# require resources have names
deny[yaml_schema_violation(description, group.id, "")] {
group := input.groups[_]
Expand Down
8 changes: 8 additions & 0 deletions policies/yaml_schema_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ test_fails_on_invalid_event_name if {
}
}

test_fails_on_referenced_event_name_on_event if {
event := [{ "id": "yaml_schema.test",
"type": "event",
"name": "foo",
"attributes": [{"ref": "event.name"}]}]
count(deny) == 1 with input as {"groups": event}
}

test_fails_on_invalid_resource_name if {
every name in invalid_names {
count(deny) >= 1 with input as {"groups": create_resource(name)}
Expand Down

0 comments on commit 42a2e88

Please sign in to comment.