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

resolve gosec issues or add nosec annotations #179

Merged
merged 1 commit into from
Feb 4, 2021
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
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ func getConfig() *types.Configuration {
v.GetStringMapString("customfields")
v.GetStringMapString("Webhook.CustomHeaders")
v.GetStringMapString("CloudEvents.Extensions")
v.Unmarshal(c)
if err := v.Unmarshal(c); err != nil {
log.Printf("[ERROR] : Error unmarshalling config : %s", err)
}

if value, present := os.LookupEnv("CUSTOMFIELDS"); present {
customfields := strings.Split(value, ",")
Expand Down
58 changes: 30 additions & 28 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/falcosecurity/falcosidekick/types"
)

const TestRule string = "Test rule"
const testRule string = "Test rule"

// mainHandler is Falco Sidekick main handler (default).
func mainHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -55,13 +55,15 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {

// pingHandler is a simple handler to test if daemon is UP.
func pingHandler(w http.ResponseWriter, r *http.Request) {
// #nosec G104 nothing to be done if the following fails
w.Write([]byte("pong\n"))
}

// healthHandler is a simple handler to test if daemon is UP.
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
w.Write([]byte("{\"status\": \"ok\"}"))
// #nosec G104 nothing to be done if the following fails
w.Write([]byte(`{"status": "ok"}`))
}

// testHandler sends a test event to all enabled outputs.
Expand Down Expand Up @@ -114,107 +116,107 @@ func newFalcoPayload(payload io.Reader) (types.FalcoPayload, error) {
}

func forwardEvent(falcopayload types.FalcoPayload) {
if config.Slack.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Slack.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Slack.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Slack.MinimumPriority) || falcopayload.Rule == testRule) {
go slackClient.SlackPost(falcopayload)
}

if config.Rocketchat.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Rocketchat.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Rocketchat.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Rocketchat.MinimumPriority) || falcopayload.Rule == testRule) {
go rocketchatClient.RocketchatPost(falcopayload)
}

if config.Mattermost.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Mattermost.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Mattermost.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Mattermost.MinimumPriority) || falcopayload.Rule == testRule) {
go mattermostClient.MattermostPost(falcopayload)
}

if config.Teams.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Teams.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Teams.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Teams.MinimumPriority) || falcopayload.Rule == testRule) {
go teamsClient.TeamsPost(falcopayload)
}

if config.Datadog.APIKey != "" && (falcopayload.Priority >= types.Priority(config.Datadog.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Datadog.APIKey != "" && (falcopayload.Priority >= types.Priority(config.Datadog.MinimumPriority) || falcopayload.Rule == testRule) {
go datadogClient.DatadogPost(falcopayload)
}

if config.Discord.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Discord.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Discord.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Discord.MinimumPriority) || falcopayload.Rule == testRule) {
go discordClient.DiscordPost(falcopayload)
}

if config.Alertmanager.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Alertmanager.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Alertmanager.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Alertmanager.MinimumPriority) || falcopayload.Rule == testRule) {
go alertmanagerClient.AlertmanagerPost(falcopayload)
}

if config.Elasticsearch.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Elasticsearch.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Elasticsearch.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Elasticsearch.MinimumPriority) || falcopayload.Rule == testRule) {
go elasticsearchClient.ElasticsearchPost(falcopayload)
}

if config.Influxdb.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Influxdb.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Influxdb.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Influxdb.MinimumPriority) || falcopayload.Rule == testRule) {
go influxdbClient.InfluxdbPost(falcopayload)
}

if config.Loki.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Loki.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Loki.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Loki.MinimumPriority) || falcopayload.Rule == testRule) {
go lokiClient.LokiPost(falcopayload)
}

if config.Nats.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Nats.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Nats.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Nats.MinimumPriority) || falcopayload.Rule == testRule) {
go natsClient.NatsPublish(falcopayload)
}

if config.Stan.HostPort != "" && config.Stan.ClusterID != "" && config.Stan.ClientID != "" && (falcopayload.Priority >= types.Priority(config.Stan.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Stan.HostPort != "" && config.Stan.ClusterID != "" && config.Stan.ClientID != "" && (falcopayload.Priority >= types.Priority(config.Stan.MinimumPriority) || falcopayload.Rule == testRule) {
go stanClient.StanPublish(falcopayload)
}

if config.AWS.Lambda.FunctionName != "" && (falcopayload.Priority >= types.Priority(config.AWS.Lambda.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.AWS.Lambda.FunctionName != "" && (falcopayload.Priority >= types.Priority(config.AWS.Lambda.MinimumPriority) || falcopayload.Rule == testRule) {
go awsClient.InvokeLambda(falcopayload)
}

if config.AWS.SQS.URL != "" && (falcopayload.Priority >= types.Priority(config.AWS.SQS.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.AWS.SQS.URL != "" && (falcopayload.Priority >= types.Priority(config.AWS.SQS.MinimumPriority) || falcopayload.Rule == testRule) {
go awsClient.SendMessage(falcopayload)
}

if config.AWS.SNS.TopicArn != "" && (falcopayload.Priority >= types.Priority(config.AWS.SNS.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.AWS.SNS.TopicArn != "" && (falcopayload.Priority >= types.Priority(config.AWS.SNS.MinimumPriority) || falcopayload.Rule == testRule) {
go awsClient.PublishTopic(falcopayload)
}

if config.AWS.CloudWatchLogs.LogGroup != "" && (falcopayload.Priority >= types.Priority(config.AWS.CloudWatchLogs.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.AWS.CloudWatchLogs.LogGroup != "" && (falcopayload.Priority >= types.Priority(config.AWS.CloudWatchLogs.MinimumPriority) || falcopayload.Rule == testRule) {
go awsClient.SendCloudWatchLog(falcopayload)
}

if config.SMTP.HostPort != "" && (falcopayload.Priority >= types.Priority(config.SMTP.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.SMTP.HostPort != "" && (falcopayload.Priority >= types.Priority(config.SMTP.MinimumPriority) || falcopayload.Rule == testRule) {
go smtpClient.SendMail(falcopayload)
}

if config.Opsgenie.APIKey != "" && (falcopayload.Priority >= types.Priority(config.Opsgenie.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Opsgenie.APIKey != "" && (falcopayload.Priority >= types.Priority(config.Opsgenie.MinimumPriority) || falcopayload.Rule == testRule) {
go opsgenieClient.OpsgeniePost(falcopayload)
}

if config.Webhook.Address != "" && (falcopayload.Priority >= types.Priority(config.Webhook.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Webhook.Address != "" && (falcopayload.Priority >= types.Priority(config.Webhook.MinimumPriority) || falcopayload.Rule == testRule) {
go webhookClient.WebhookPost(falcopayload)
}

if config.CloudEvents.Address != "" && (falcopayload.Priority >= types.Priority(config.CloudEvents.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.CloudEvents.Address != "" && (falcopayload.Priority >= types.Priority(config.CloudEvents.MinimumPriority) || falcopayload.Rule == testRule) {
go cloudeventsClient.CloudEventsSend(falcopayload)
}

if config.Azure.EventHub.Name != "" && (falcopayload.Priority >= types.Priority(config.Azure.EventHub.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Azure.EventHub.Name != "" && (falcopayload.Priority >= types.Priority(config.Azure.EventHub.MinimumPriority) || falcopayload.Rule == testRule) {
go azureClient.EventHubPost(falcopayload)
}

if config.GCP.PubSub.ProjectID != "" && config.GCP.PubSub.Topic != "" && (falcopayload.Priority >= types.Priority(config.GCP.PubSub.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.GCP.PubSub.ProjectID != "" && config.GCP.PubSub.Topic != "" && (falcopayload.Priority >= types.Priority(config.GCP.PubSub.MinimumPriority) || falcopayload.Rule == testRule) {
go gcpClient.GCPPublishTopic(falcopayload)
}

if config.Googlechat.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Googlechat.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Googlechat.WebhookURL != "" && (falcopayload.Priority >= types.Priority(config.Googlechat.MinimumPriority) || falcopayload.Rule == testRule) {
go googleChatClient.GooglechatPost(falcopayload)
}

if config.Kafka.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Kafka.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Kafka.HostPort != "" && (falcopayload.Priority >= types.Priority(config.Kafka.MinimumPriority) || falcopayload.Rule == testRule) {
go kafkaClient.KafkaProduce(falcopayload)
}

if config.Pagerduty.APIKey != "" && config.Pagerduty.Service != "" && (falcopayload.Priority >= types.Priority(config.Pagerduty.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Pagerduty.APIKey != "" && config.Pagerduty.Service != "" && (falcopayload.Priority >= types.Priority(config.Pagerduty.MinimumPriority) || falcopayload.Rule == testRule) {
go pagerdutyClient.PagerdutyCreateIncident(falcopayload)
}

if config.Kubeless.Namespace != "" && config.Kubeless.Function != "" && (falcopayload.Priority >= types.Priority(config.Kubeless.MinimumPriority) || falcopayload.Rule == TestRule) {
if config.Kubeless.Namespace != "" && config.Kubeless.Function != "" && (falcopayload.Priority >= types.Priority(config.Kubeless.MinimumPriority) || falcopayload.Rule == testRule) {
go kubelessClient.KubelessCall(falcopayload)
}
}
10 changes: 7 additions & 3 deletions outputs/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import (
func NewAWSClient(config *types.Configuration, stats *types.Statistics, promStats *types.PromStatistics, statsdClient, dogstatsdClient *statsd.Client) (*Client, error) {

if config.AWS.AccessKeyID != "" && config.AWS.SecretAccessKey != "" && config.AWS.Region != "" {
os.Setenv("AWS_ACCESS_KEY_ID", config.AWS.AccessKeyID)
os.Setenv("AWS_SECRET_ACCESS_KEY", config.AWS.SecretAccessKey)
os.Setenv("AWS_DEFAULT_REGION", config.AWS.Region)
err1 := os.Setenv("AWS_ACCESS_KEY_ID", config.AWS.AccessKeyID)
err2 := os.Setenv("AWS_SECRET_ACCESS_KEY", config.AWS.SecretAccessKey)
err3 := os.Setenv("AWS_DEFAULT_REGION", config.AWS.Region)
if err1 != nil || err2 != nil || err3 != nil {
log.Printf("[ERROR] : AWS - Error setting AWS env vars")
return nil, errors.New("Error setting AWS env vars")
}
}

sess, err := session.NewSession(&aws.Config{
Expand Down
6 changes: 4 additions & 2 deletions outputs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (c *Client) Post(payload interface{}) error {
case influxdbPayload:
fmt.Fprintf(body, "%v", payload)
default:
json.NewEncoder(body).Encode(payload)
if err := json.NewEncoder(body).Encode(payload); err != nil {
log.Printf("[ERROR] : %v - %s", c.OutputType, err)
}
}

if c.Config.Debug == true {
Expand All @@ -105,8 +107,8 @@ func (c *Client) Post(payload interface{}) error {
customTransport := http.DefaultTransport.(*http.Transport).Clone()

if c.Config.CheckCert == false {
// #nosec G402 This is only set as a result of explicit configuration
customTransport.TLSClientConfig = &tls.Config{
// nolint: gosec
InsecureSkipVerify: true,
}
}
Expand Down
6 changes: 5 additions & 1 deletion outputs/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (c *Client) KafkaProduce(falcopayload types.FalcoPayload) {
Value: falcoMsg,
}

c.KafkaProducer.SetWriteDeadline(time.Now().Add(10 * time.Second))
if err := c.KafkaProducer.SetWriteDeadline(time.Now().Add(10 * time.Second)); err != nil {
c.setKafkaErrorMetrics()
log.Printf("[ERROR] : Kafka - %v\n", err)
return
}
_, err = c.KafkaProducer.WriteMessages(kafkaMsg)
if err != nil {
c.setKafkaErrorMetrics()
Expand Down