This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more support for the parser and the rendering of results
- Loading branch information
1 parent
a8f4f93
commit 91f9e68
Showing
373 changed files
with
191,812 additions
and
46 deletions.
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
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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
Parameters: | ||
BucketName: | ||
Type: String | ||
Default: naughty | ||
BucketKeyEnabled: | ||
Type: Boolean | ||
Default: false | ||
|
||
Resources: | ||
S3Bucket: | ||
Type: 'AWS::S3::Bucket' | ||
DeletionPolicy: Retain | ||
Properties: | ||
BucketName: bad-example | ||
BucketName: | ||
Ref: BucketName | ||
BucketEncryption: | ||
ServerSideEncryptionConfiguration: | ||
- BucketKeyEnabled: | ||
Ref: BucketKeyEnabled |
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
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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package formatters | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/result" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/severity" | ||
"github.com/liamg/clinch/terminal" | ||
"github.com/liamg/tml" | ||
) | ||
|
||
var severityFormat = map[severity.Severity]string{ | ||
severity.Low: tml.Sprintf("<white>%s</white>", severity.Low), | ||
severity.Medium: tml.Sprintf("<yellow>%s</yellow>", severity.Medium), | ||
severity.High: tml.Sprintf("<red>%s</red>", severity.High), | ||
severity.Critical: tml.Sprintf("<bold><red>%s</red></bold>", severity.Critical), | ||
} | ||
|
||
func FormatDefault(_ io.Writer, results []result.Result, _ string) error { | ||
|
||
fmt.Println("") | ||
for i, res := range results { | ||
printResult(res, i, false) | ||
} | ||
|
||
terminal.PrintErrorf("\n %d potential problems detected.\n\n", len(results)) | ||
|
||
return nil | ||
|
||
} | ||
|
||
func printResult(res result.Result, i int, includePassedChecks bool) { | ||
resultHeader := fmt.Sprintf(" <underline>Result %d</underline>\n", i+1) | ||
var severity string | ||
if includePassedChecks && res.Status == result.Passed { | ||
terminal.PrintSuccessf(resultHeader) | ||
severity = tml.Sprintf("<green>PASSED</green>") | ||
} else { | ||
terminal.PrintErrorf(resultHeader) | ||
severity = severityFormat[res.Severity] | ||
} | ||
|
||
_ = tml.Printf(` | ||
<blue>[</blue>%s<blue>]</blue><blue>[</blue>%s<blue>]</blue> %s | ||
<blue>%s</blue> | ||
`, res.RuleID, severity, res.Description, res.Location) | ||
|
||
render, err := res.Resource().Render() | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err.Error()) | ||
} | ||
|
||
highlightRender(render, res.Attribute) | ||
|
||
if res.LegacyRuleID != "" { | ||
_ = tml.Printf(" <white>Legacy ID: </white><blue>%s</blue>\n", res.LegacyRuleID) | ||
} | ||
if res.Impact != "" { | ||
_ = tml.Printf(" <white>Impact: </white><blue>%s</blue>\n", res.Impact) | ||
} | ||
if res.Resolution != "" { | ||
_ = tml.Printf(" <white>Resolution: </white><blue>%s</blue>\n", res.Resolution) | ||
} | ||
if len(res.Links) > 0 { | ||
_ = tml.Printf("\n <white>More Info:</white>") | ||
} | ||
for _, link := range res.Links { | ||
_ = tml.Printf("\n <blue>- %s </blue>", link) | ||
} | ||
|
||
fmt.Printf("\n\n") | ||
} | ||
|
||
func highlightRender(renderText string, attributeOfInterest string) { | ||
if attributeOfInterest == "" { | ||
tml.Println(renderText) | ||
} else { | ||
var newLines []string | ||
|
||
lines := strings.Split(renderText, "\n") | ||
for _, line := range lines { | ||
if strings.Contains(line, attributeOfInterest) { | ||
newLines = append(newLines, fmt.Sprintf(" <red>%s</red>", line)) | ||
} else { | ||
newLines = append(newLines, fmt.Sprintf(" %s", line)) | ||
} | ||
} | ||
|
||
tml.Printf(strings.Join(newLines, "\n")) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package parser | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/resource" | ||
"github.com/awslabs/goformation/v5" | ||
) | ||
|
||
type Parser struct{} | ||
|
||
func New(filepaths ...string) (resource.Resources, error) { | ||
|
||
var resources resource.Resources | ||
for _, filepath := range filepaths { | ||
template, err := goformation.Open(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sourceFormat := resource.DefaultFormat | ||
if strings.HasSuffix(strings.ToLower(filepath), ".json") { | ||
sourceFormat = resource.JsonFormat | ||
} | ||
|
||
for name, r := range template.Resources { | ||
formationType := r.AWSCloudFormationType() | ||
resources = append(resources, resource.NewCFResource(&r, formationType, string(name), sourceFormat, filepath)) | ||
} | ||
} | ||
|
||
return resources, nil | ||
} |
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
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
Oops, something went wrong.