-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(report): handle [email protected] schema for misconfigs in sarif report #8399
Open
rperez-fo
wants to merge
1
commit into
aquasecurity:main
Choose a base branch
from
rperez-fo:fix-sarif/bitbucket-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -357,6 +357,13 @@ func clearURI(s string) string { | |
s = strings.ReplaceAll(s, "[email protected]:", "github.com/") | ||
s = strings.ReplaceAll(s, ".git", "") | ||
s = strings.ReplaceAll(s, "?ref=", "/tree/") | ||
case strings.HasPrefix(s, "[email protected]:"): | ||
// build bitbucket url format | ||
// e.g. `[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.2.0/main.tf` -> `bitbucket.org/terraform-aws-modules/terraform-aws-s3-bucket/src/v4.2.0/main.tf` | ||
// cf. https://github.com/aquasecurity/trivy/issues/8154 | ||
s = strings.ReplaceAll(s, "[email protected]:", "bitbucket.org/") | ||
s = strings.ReplaceAll(s, ".git", "") | ||
s = strings.ReplaceAll(s, "?ref=", "/src/") | ||
case strings.HasPrefix(s, "git::https:/") && !strings.HasPrefix(s, "git::https://"): | ||
s = strings.TrimPrefix(s, "git::https:/") | ||
s = strings.ReplaceAll(s, ".git", "") | ||
|
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 |
---|---|---|
|
@@ -22,6 +22,11 @@ func Test_clearURI(t *testing.T) { | |
uri: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.2.0/main.tf", | ||
want: "github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/v4.2.0/main.tf", | ||
}, | ||
{ | ||
name: "bitbucket", | ||
uri: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.2.0/main.tf", | ||
want: "bitbucket.org/terraform-aws-modules/terraform-aws-s3-bucket/src/v4.2.0/main.tf", | ||
}, | ||
{ | ||
name: "git", | ||
uri: "git::https://example.com/storage.git?ref=51d462976d84fdea54b47d80dcabbf680badcdb8", | ||
|
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 |
---|---|---|
|
@@ -730,6 +730,190 @@ func TestReportWriter_Sarif(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
name: "ref to bitbucket", | ||
input: types.Report{ | ||
Results: types.Results{ | ||
{ | ||
Target: "git::https:/bitbucket.org/terraform-google-modules/terraform-google-kubernetes-engine?ref=c4809044b52b91505bfba5ef9f25526aa0361788/modules/workload-identity/main.tf", | ||
Class: types.ClassConfig, | ||
Type: ftypes.Terraform, | ||
Misconfigurations: []types.DetectedMisconfiguration{ | ||
{ | ||
Type: "Terraform Security Check", | ||
ID: "AVD-GCP-0007", | ||
AVDID: "AVD-GCP-0007", | ||
Title: "Service accounts should not have roles assigned with excessive privileges", | ||
Description: "Service accounts should have a minimal set of permissions assigned in order to do their job. They should never have excessive access as if compromised, an attacker can escalate privileges and take over the entire account.", | ||
Message: "Service account is granted a privileged role.", | ||
Query: "data..", | ||
Resolution: "Limit service account access to minimal required set", | ||
Severity: "HIGH", | ||
PrimaryURL: "https://avd.aquasec.com/misconfig/avd-gcp-0007", | ||
References: []string{ | ||
"https://cloud.google.com/iam/docs/understanding-roles", | ||
"https://avd.aquasec.com/misconfig/avd-gcp-0007", | ||
}, | ||
Status: "Fail", | ||
CauseMetadata: ftypes.CauseMetadata{ | ||
StartLine: 91, | ||
EndLine: 91, | ||
Occurrences: []ftypes.Occurrence{ | ||
{ | ||
Resource: "google_project_iam_member.workload_identity_sa_bindings[\"roles/storage.admin\"]", | ||
Filename: "git::https:/bitbucket.org/terraform-google-modules/terraform-google-kubernetes-engine?ref=c4809044b52b91505bfba5ef9f25526aa0361788/modules/workload-identity/main.tf", | ||
Location: ftypes.Location{ | ||
StartLine: 87, | ||
EndLine: 93, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Target: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.2.0/main.tf", | ||
Class: types.ClassConfig, | ||
Type: ftypes.Terraform, | ||
Misconfigurations: []types.DetectedMisconfiguration{ | ||
{ | ||
Type: "Terraform Security Check", | ||
ID: "AVD-GCP-0007", | ||
AVDID: "AVD-GCP-0007", | ||
Title: "Service accounts should not have roles assigned with excessive privileges", | ||
Description: "Service accounts should have a minimal set of permissions assigned in order to do their job. They should never have excessive access as if compromised, an attacker can escalate privileges and take over the entire account.", | ||
Message: "Service account is granted a privileged role.", | ||
Query: "data..", | ||
Resolution: "Limit service account access to minimal required set", | ||
Severity: "HIGH", | ||
PrimaryURL: "https://avd.aquasec.com/misconfig/avd-gcp-0007", | ||
References: []string{ | ||
"https://cloud.google.com/iam/docs/understanding-roles", | ||
"https://avd.aquasec.com/misconfig/avd-gcp-0007", | ||
}, | ||
Status: "Fail", | ||
CauseMetadata: ftypes.CauseMetadata{ | ||
StartLine: 91, | ||
EndLine: 91, | ||
Occurrences: []ftypes.Occurrence{ | ||
{ | ||
Resource: "google_project_iam_member.workload_identity_sa_bindings[\"roles/storage.admin\"]", | ||
Filename: "[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.2.0/main.tf", | ||
Location: ftypes.Location{ | ||
StartLine: 87, | ||
EndLine: 93, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: &sarif.Report{ | ||
Version: "2.1.0", | ||
Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json", | ||
Runs: []*sarif.Run{ | ||
{ | ||
Tool: *sarif.NewTool( | ||
&sarif.ToolComponent{ | ||
FullName: lo.ToPtr("Trivy Vulnerability Scanner"), | ||
Name: "Trivy", | ||
Version: lo.ToPtr(""), | ||
InformationURI: lo.ToPtr("https://github.com/aquasecurity/trivy"), | ||
Rules: []*sarif.ReportingDescriptor{ | ||
{ | ||
ID: "AVD-GCP-0007", | ||
Name: lo.ToPtr("Misconfiguration"), | ||
ShortDescription: sarif.NewMultiformatMessageString("Service accounts should not have roles assigned with excessive privileges"), | ||
FullDescription: sarif.NewMultiformatMessageString("Service accounts should have a minimal set of permissions assigned in order to do their job. They should never have excessive access as if compromised, an attacker can escalate privileges and take over the entire account."), | ||
DefaultConfiguration: &sarif.ReportingConfiguration{ | ||
Level: "error", | ||
}, | ||
HelpURI: lo.ToPtr("https://avd.aquasec.com/misconfig/avd-gcp-0007"), | ||
Help: &sarif.MultiformatMessageString{ | ||
Text: lo.ToPtr("Misconfiguration AVD-GCP-0007\nType: Terraform Security Check\nSeverity: HIGH\nCheck: Service accounts should not have roles assigned with excessive privileges\nMessage: Service account is granted a privileged role.\nLink: [AVD-GCP-0007](https://avd.aquasec.com/misconfig/avd-gcp-0007)\nService accounts should have a minimal set of permissions assigned in order to do their job. They should never have excessive access as if compromised, an attacker can escalate privileges and take over the entire account."), | ||
Markdown: lo.ToPtr("**Misconfiguration AVD-GCP-0007**\n| Type | Severity | Check | Message | Link |\n| --- | --- | --- | --- | --- |\n|Terraform Security Check|HIGH|Service accounts should not have roles assigned with excessive privileges|Service account is granted a privileged role.|[AVD-GCP-0007](https://avd.aquasec.com/misconfig/avd-gcp-0007)|\n\nService accounts should have a minimal set of permissions assigned in order to do their job. They should never have excessive access as if compromised, an attacker can escalate privileges and take over the entire account."), | ||
}, | ||
Properties: sarif.Properties{ | ||
"tags": []any{ | ||
"misconfiguration", | ||
"security", | ||
"HIGH", | ||
}, | ||
"precision": "very-high", | ||
"security-severity": "8.0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
), | ||
Results: []*sarif.Result{ | ||
{ | ||
RuleID: lo.ToPtr("AVD-GCP-0007"), | ||
RuleIndex: lo.ToPtr(uint(0)), | ||
Level: lo.ToPtr("error"), | ||
Message: *sarif.NewTextMessage("Artifact: bitbucket.org/terraform-google-modules/terraform-google-kubernetes-engine?ref=c4809044b52b91505bfba5ef9f25526aa0361788/modules/workload-identity/main.tf\nType: terraform\nVulnerability AVD-GCP-0007\nSeverity: HIGH\nMessage: Service account is granted a privileged role.\nLink: [AVD-GCP-0007](https://avd.aquasec.com/misconfig/avd-gcp-0007)"), | ||
Locations: []*sarif.Location{ | ||
{ | ||
PhysicalLocation: sarif.NewPhysicalLocation(). | ||
WithArtifactLocation( | ||
&sarif.ArtifactLocation{ | ||
URI: lo.ToPtr("bitbucket.org/terraform-google-modules/terraform-google-kubernetes-engine?ref=c4809044b52b91505bfba5ef9f25526aa0361788/modules/workload-identity/main.tf"), | ||
URIBaseId: lo.ToPtr("ROOTPATH"), | ||
}, | ||
). | ||
WithRegion( | ||
&sarif.Region{ | ||
StartLine: lo.ToPtr(91), | ||
StartColumn: lo.ToPtr(1), | ||
EndLine: lo.ToPtr(91), | ||
EndColumn: lo.ToPtr(1), | ||
}, | ||
), | ||
Message: sarif.NewTextMessage("bitbucket.org/terraform-google-modules/terraform-google-kubernetes-engine?ref=c4809044b52b91505bfba5ef9f25526aa0361788/modules/workload-identity/main.tf"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
RuleID: lo.ToPtr("AVD-GCP-0007"), | ||
RuleIndex: lo.ToPtr(uint(0)), | ||
Level: lo.ToPtr("error"), | ||
Message: *sarif.NewTextMessage("Artifact: bitbucket.org/terraform-aws-modules/terraform-aws-s3-bucket/src/v4.2.0/main.tf\nType: terraform\nVulnerability AVD-GCP-0007\nSeverity: HIGH\nMessage: Service account is granted a privileged role.\nLink: [AVD-GCP-0007](https://avd.aquasec.com/misconfig/avd-gcp-0007)"), | ||
Locations: []*sarif.Location{ | ||
{ | ||
PhysicalLocation: sarif.NewPhysicalLocation(). | ||
WithArtifactLocation( | ||
&sarif.ArtifactLocation{ | ||
URI: lo.ToPtr("bitbucket.org/terraform-aws-modules/terraform-aws-s3-bucket/src/v4.2.0/main.tf"), | ||
URIBaseId: lo.ToPtr("ROOTPATH"), | ||
}, | ||
). | ||
WithRegion( | ||
&sarif.Region{ | ||
StartLine: lo.ToPtr(91), | ||
StartColumn: lo.ToPtr(1), | ||
EndLine: lo.ToPtr(91), | ||
EndColumn: lo.ToPtr(1), | ||
}, | ||
), | ||
Message: sarif.NewTextMessage("bitbucket.org/terraform-aws-modules/terraform-aws-s3-bucket/src/v4.2.0/main.tf"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
ColumnKind: "utf16CodeUnits", | ||
OriginalUriBaseIDs: map[string]*sarif.ArtifactLocation{ | ||
"ROOTPATH": { | ||
URI: lo.ToPtr("file:///"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can refactor this logic out into a function as it's also repeated with GitHub?