Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource_type to rule properties #4

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/policy/opa/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,12 @@ func (e *Engine) reportViolation(regoData *policy.RegoData, resource *output.Res
// reportPassed Adds a passed rule which wasn't violated by all the resources
func (e *Engine) reportPassed(regoData *policy.RegoData) {
passedRule := results.PassedRule{
RuleName: regoData.Metadata.Name,
Description: regoData.Metadata.Description,
RuleID: regoData.Metadata.ID,
Severity: regoData.Metadata.Severity,
Category: regoData.Metadata.Category,
RuleName: regoData.Metadata.Name,
Description: regoData.Metadata.Description,
RuleID: regoData.Metadata.ID,
Severity: regoData.Metadata.Severity,
Category: regoData.Metadata.Category,
ResourceType: regoData.Metadata.ResourceType,
}

e.results.ViolationStore.AddPassedRule(&passedRule)
Expand Down
11 changes: 6 additions & 5 deletions pkg/results/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ type Violation struct {

// PassedRule contains information of a passed rule
type PassedRule struct {
RuleName string `json:"rule_name" yaml:"rule_name" xml:"rule_name,attr"`
Description string `json:"description" yaml:"description" xml:"description,attr"`
RuleID string `json:"rule_id" yaml:"rule_id" xml:"rule_id,attr"`
Severity string `json:"severity" yaml:"severity" xml:"severity,attr"`
Category string `json:"category" yaml:"category" xml:"category,attr"`
RuleName string `json:"rule_name" yaml:"rule_name" xml:"rule_name,attr"`
Description string `json:"description" yaml:"description" xml:"description,attr"`
RuleID string `json:"rule_id" yaml:"rule_id" xml:"rule_id,attr"`
Severity string `json:"severity" yaml:"severity" xml:"severity,attr"`
Category string `json:"category" yaml:"category" xml:"category,attr"`
ResourceType string `json:"resource_type" yaml:"resource_type" xml:"resource_type,attr"`
}

// ViolationStore Storage area for violation data
Expand Down
1 change: 1 addition & 0 deletions pkg/writer/github_sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const violationTemplateForGH = `{
},
"properties": {
"category": "S3",
"resource_type": "aws_s3_bucket",
"severity": "HIGH"
}
}
Expand Down
22 changes: 12 additions & 10 deletions pkg/writer/human_readable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ var (
ViolationStore: &results.ViolationStore{
PassedRules: []*results.PassedRule{
{
RuleName: "s3EnforceUserACL",
Description: "S3 bucket Access is allowed to all AWS Account Users.",
RuleID: "AWS.S3Bucket.DS.High.1043",
Severity: "HIGH",
Category: "S3",
RuleName: "s3EnforceUserACL",
Description: "S3 bucket Access is allowed to all AWS Account Users.",
RuleID: "AWS.S3Bucket.DS.High.1043",
Severity: "HIGH",
Category: "S3",
ResourceType: "aws_s3_bucket",
},
},
Summary: summaryWithNoViolations,
Expand All @@ -53,11 +54,12 @@ var (
},
PassedRules: []*results.PassedRule{
{
RuleName: "s3EnforceUserACL",
Description: "S3 bucket Access is allowed to all AWS Account Users.",
RuleID: "AWS.S3Bucket.DS.High.1043",
Severity: "HIGH",
Category: "S3",
RuleName: "s3EnforceUserACL",
Description: "S3 bucket Access is allowed to all AWS Account Users.",
RuleID: "AWS.S3Bucket.DS.High.1043",
Severity: "HIGH",
Category: "S3",
ResourceType: "aws_s3_bucket",
},
},
Summary: summaryWithNoViolations,
Expand Down
2 changes: 2 additions & 0 deletions pkg/writer/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func writeSarif(data interface{}, writers []io.Writer, forGitHub bool) error {
for _, passedRule := range outputData.PassedRules {
m := sarif.NewPropertyBag()
m.Properties["category"] = passedRule.Category
m.Properties["resource_type"] = passedRule.ResourceType
m.Properties["severity"] = passedRule.Severity

run.AddRule(passedRule.RuleID).
Expand All @@ -67,6 +68,7 @@ func writeSarif(data interface{}, writers []io.Writer, forGitHub bool) error {
for _, violation := range outputData.Violations {
m := sarif.NewPropertyBag()
m.Properties["category"] = violation.Category
m.Properties["resource_type"] = violation.ResourceType
m.Properties["severity"] = violation.Severity

rule := run.AddRule(violation.RuleID).
Expand Down
5 changes: 4 additions & 1 deletion pkg/writer/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const violationTemplate = `{
},
"properties": {
"category": "S3",
"severity": "HIGH"
"severity": "HIGH",
"resource_type": "aws_s3_bucket"
}
}
],
Expand Down Expand Up @@ -113,6 +114,7 @@ var expectedSarifOutput3 = fmt.Sprintf(`{
},
"properties": {
"category": "S3",
"resource_type": "aws_s3_bucket",
"severity": "HIGH"
}
}
Expand Down Expand Up @@ -143,6 +145,7 @@ var expectedSarifOutput4 = fmt.Sprintf(`{
},
"properties": {
"category": "S3",
"resource_type": "aws_s3_bucket",
"severity": "HIGH"
}
}
Expand Down