Skip to content

Commit

Permalink
SecurityHub Updates (#401)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit authored Jan 27, 2024
1 parent eab50c3 commit 288b411
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions charts/policy-reporter/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ securityHub:
secretAccessKey: {{ .Values.target.securityHub.secretAccessKey }}
secretRef: {{ .Values.target.securityHub.secretRef | quote }}
mountedSecret: {{ .Values.target.securityHub.mountedSecret | quote }}
productName: {{ .Values.target.securityHub.productName | quote }}
region: {{ .Values.target.securityHub.region }}
endpoint: {{ .Values.target.securityHub.endpoint }}
streamName: {{ .Values.target.securityHub.streamName }}
Expand Down
2 changes: 2 additions & 0 deletions charts/policy-reporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ target:
endpoint: ""
# AWS accountID
accountID: ""
# Used product name, defaults to "Polilcy Reporter"
productName: ""
# minimum priority "" < info < warning < critical < error
minimumPriority: ""
# list of sources which should send to S3
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type SecurityHub struct {
TargetBaseOptions `mapstructure:",squash"`
AWSConfig `mapstructure:",squash"`
AccountID string `mapstructure:"accountId"`
ProductName string `mapstructure:"productName"`
Channels []*SecurityHub `mapstructure:"channels"`
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/config/target_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (f *TargetFactory) createSecurityHub(config, parent *SecurityHub) target.Cl
}

setFallback(&config.AccountID, parent.AccountID)
if config.AccountID == "" {
if !hasAWSIdentity() && config.AccountID == "" {
return nil
}

Expand All @@ -723,12 +723,15 @@ func (f *TargetFactory) createSecurityHub(config, parent *SecurityHub) target.Cl

sugar.Infof("%s configured", config.Name)

setFallback(&config.ProductName, parent.ProductName, "Policy Reporter")

return securityhub.NewClient(securityhub.Options{
ClientOptions: config.ClientOptions(),
CustomFields: config.CustomFields,
Client: client,
AccountID: config.AccountID,
Region: config.Region,
ProductName: config.ProductName,
})
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/target/securityhub/securityhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Options struct {
Client *hub.Client
AccountID string
Region string
ProductName string
}

type client struct {
Expand All @@ -28,6 +29,7 @@ type client struct {
hub *hub.Client
accountID string
region string
productName string
}

func (c *client) Send(result v1alpha2.PolicyReportResult) {
Expand All @@ -43,11 +45,16 @@ func (c *client) Send(result v1alpha2.PolicyReportResult) {

t := time.Unix(result.Timestamp.Seconds, int64(result.Timestamp.Nanos))

var accID *string
if c.accountID != "" {
accID = toPointer(c.accountID)
}

res, err := c.hub.BatchImportFindings(context.TODO(), &hub.BatchImportFindingsInput{
Findings: []types.AwsSecurityFinding{
{
Id: &result.ID,
AwsAccountId: &c.accountID,
AwsAccountId: accID,
SchemaVersion: toPointer("2018-10-08"),
ProductArn: toPointer("arn:aws:securityhub:" + c.region + ":" + c.accountID + ":product/" + c.accountID + "/default"),
GeneratorId: toPointer(fmt.Sprintf("%s/%s", result.Source, generator)),
Expand All @@ -60,7 +67,7 @@ func (c *client) Send(result v1alpha2.PolicyReportResult) {
Title: &title,
Description: &result.Message,
ProductFields: map[string]string{
"Product Name": "Policy Reporter",
"Product Name": c.productName,
},
Resources: []types.Resource{
{
Expand Down Expand Up @@ -136,6 +143,7 @@ func NewClient(options Options) target.Client {
options.Client,
options.AccountID,
options.Region,
options.ProductName,
}
}

Expand Down

0 comments on commit 288b411

Please sign in to comment.