Skip to content

Commit

Permalink
feat(output): add reviewdog output format for security report (#1028)
Browse files Browse the repository at this point in the history
* feat(output): add reviewdog output format for security report

* chore: update snapshots

* fix(output): add leading newline to message
  • Loading branch information
gotbadger committed Jun 5, 2023
1 parent b612a19 commit 3d28318
Show file tree
Hide file tree
Showing 13 changed files with 2,498 additions and 11 deletions.
6 changes: 5 additions & 1 deletion docs/_data/bearer_scan.yaml
Expand Up @@ -43,7 +43,8 @@ options:
usage: Disable the cache and runs the detections again
- name: format
shorthand: f
usage: Specify report format (json, yaml, sarif, gitlab-sast)
usage: |
Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
- name: help
shorthand: h
default_value: "false"
Expand All @@ -64,6 +65,9 @@ options:
Specify the comma-separated ids of the rules you would like to run. Skips all other rules.
- name: output
usage: Specify the output path for the report.
- name: parallel
default_value: "4"
usage: Specify the amount of parallelism to use during the scan
- name: quiet
default_value: "false"
usage: Suppress non-essential messages
Expand Down
2 changes: 1 addition & 1 deletion e2e/flags/.snapshots/TestMetadataFlags-help-scan
Expand Up @@ -11,7 +11,7 @@ Examples:

Report Flags
--exclude-fingerprint strings Specify the comma-separated fingerprints of the findings you would like to exclude from the report.
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast)
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
--output string Specify the output path for the report.
--report string Specify the type of report (security, privacy, dataflow). (default "security")
--severity string Specify which severities are included in the report. (default "critical,high,medium,low,warning")
Expand Down
2 changes: 1 addition & 1 deletion e2e/flags/.snapshots/TestMetadataFlags-scan-help
Expand Up @@ -11,7 +11,7 @@ Examples:

Report Flags
--exclude-fingerprint strings Specify the comma-separated fingerprints of the findings you would like to exclude from the report.
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast)
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
--output string Specify the output path for the report.
--report string Specify the type of report (security, privacy, dataflow). (default "security")
--severity string Specify which severities are included in the report. (default "critical,high,medium,low,warning")
Expand Down
Expand Up @@ -12,7 +12,7 @@ Examples:

Report Flags
--exclude-fingerprint strings Specify the comma-separated fingerprints of the findings you would like to exclude from the report.
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast)
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
--output string Specify the output path for the report.
--report string Specify the type of report (security, privacy, dataflow). (default "security")
--severity string Specify which severities are included in the report. (default "critical,high,medium,low,warning")
Expand Down
@@ -1,6 +1,6 @@

--
Error: flag error: report flags error: invalid format argument; supported values: json, yaml, sarif, gitlab-sast
Error: flag error: report flags error: invalid format argument; supported values: json, yaml, sarif, gitlab-sast, rdjson
Usage:
scan [flags] <path>
Aliases:
Expand All @@ -12,7 +12,7 @@ Examples:

Report Flags
--exclude-fingerprint strings Specify the comma-separated fingerprints of the findings you would like to exclude from the report.
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast)
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
--output string Specify the output path for the report.
--report string Specify the type of report (security, privacy, dataflow). (default "security")
--severity string Specify which severities are included in the report. (default "critical,high,medium,low,warning")
Expand Down Expand Up @@ -42,5 +42,5 @@ General Flags
--no-color Disable color in output


flag error: report flags error: invalid format argument; supported values: json, yaml, sarif, gitlab-sast
flag error: report flags error: invalid format argument; supported values: json, yaml, sarif, gitlab-sast, rdjson

Expand Up @@ -12,7 +12,7 @@ Examples:

Report Flags
--exclude-fingerprint strings Specify the comma-separated fingerprints of the findings you would like to exclude from the report.
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast)
-f, --format string Specify report format (json, yaml, sarif, gitlab-sast, rdjson)
--output string Specify the output path for the report.
--report string Specify the type of report (security, privacy, dataflow). (default "security")
--severity string Specify which severities are included in the report. (default "critical,high,medium,low,warning")
Expand Down
12 changes: 12 additions & 0 deletions pkg/commands/artifact/run.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/bearer/bearer/pkg/github_api"
reportoutput "github.com/bearer/bearer/pkg/report/output"
"github.com/bearer/bearer/pkg/report/output/gitlab"
rdo "github.com/bearer/bearer/pkg/report/output/reviewdog"
"github.com/bearer/bearer/pkg/report/output/sarif"
"github.com/bearer/bearer/pkg/report/output/security"
"github.com/bearer/bearer/pkg/report/output/stats"
Expand Down Expand Up @@ -365,6 +366,17 @@ func (r *runner) Report(config settings.Config, report types.Report) (bool, erro
return false, fmt.Errorf("error generating JSON report %s", err)
}

logger.Msg(*content)
case flag.FormatReviewDog:
sastContent, err := rdo.ReportReviewdog(detections.(*map[string][]security.Result))
if err != nil {
return false, fmt.Errorf("error generating reviewdog report %s", err)
}
content, err := reportoutput.ReportJSON(sastContent)

Check failure on line 375 in pkg/commands/artifact/run.go

View workflow job for this annotation

GitHub Actions / build

undefined: output.ReportJSON

Check failure on line 375 in pkg/commands/artifact/run.go

View workflow job for this annotation

GitHub Actions / build

undefined: output.ReportJSON

Check failure on line 375 in pkg/commands/artifact/run.go

View workflow job for this annotation

GitHub Actions / build-darwin

undefined: output.ReportJSON
if err != nil {
return false, fmt.Errorf("error generating JSON report %s", err)
}

logger.Msg(*content)
case flag.FormatGitLabSast:

Expand Down
7 changes: 4 additions & 3 deletions pkg/flag/report_flags.go
Expand Up @@ -7,6 +7,7 @@ import (
)

var (
FormatReviewDog = "rdjson"
FormatGitLabSast = "gitlab-sast"
FormatSarif = "sarif"
FormatJSON = "json"
Expand All @@ -23,7 +24,7 @@ var (
DefaultSeverity = "critical,high,medium,low,warning"
)

var ErrInvalidFormat = errors.New("invalid format argument; supported values: json, yaml, sarif, gitlab-sast")
var ErrInvalidFormat = errors.New("invalid format argument; supported values: json, yaml, sarif, gitlab-sast, rdjson")
var ErrInvalidReport = errors.New("invalid report argument; supported values: security, privacy")
var ErrInvalidSeverity = errors.New("invalid severity argument; supported values: critical, high, medium, low, warning")

Expand All @@ -33,7 +34,7 @@ var (
ConfigName: "report.format",
Shorthand: "f",
Value: FormatEmpty,
Usage: "Specify report format (json, yaml, sarif, gitlab-sast)",
Usage: "Specify report format (json, yaml, sarif, gitlab-sast, rdjson)",
}
ReportFlag = Flag{
Name: "report",
Expand Down Expand Up @@ -120,7 +121,7 @@ func (f *ReportFlagGroup) ToOptions() (ReportOptions, error) {
case FormatYAML:
case FormatJSON:
case FormatEmpty:
case FormatSarif, FormatGitLabSast:
case FormatSarif, FormatGitLabSast, FormatReviewDog:
if report != ReportSecurity {
return ReportOptions{}, ErrInvalidFormat
}
Expand Down

0 comments on commit 3d28318

Please sign in to comment.