Skip to content

Commit

Permalink
I did reverse commit
Browse files Browse the repository at this point in the history
1) S3 endpoint is under s3 config
2) Yandex s3 uses credential library instead of file
3) Small error fixes

Signed-off-by: Narek Tatevosyan <nrkk@yandex-team.ru>
  • Loading branch information
nrk-simple committed Aug 5, 2021
1 parent b1fd23e commit 9e06d07
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,11 @@ webui:
yandex:
# accesskeyid: "" # yandex access key
# secretaccesskey: "" # yandex secret access key
# region : "" # yandex region (default: ru-central-1)
# region: "" # yandex storage region (default: ru-central-1)
s3:
# bucket: "falcosidekick" # Yandex S3, bucket name
# prefix : "" # name of prefix, keys will have format: s3://<bucket>/<prefix>/YYYY-MM-DD/YYYY-MM-DDTHH:mm:ss.s+01:00.json
# endpoint: "" yandex storage endpoint (default: https://storage.yandexcloud.net)
# bucket: "falcosidekick" # Yandex storage, bucket name
# prefix: "" # name of prefix, keys will have format: s3://<bucket>/<prefix>/YYYY-MM-DD/YYYY-MM-DDTHH:mm:ss.s+01:00.json
# minimumpriority: "" # minimum priority of event for using this output, order is emergency|alert|critical|erro
```

Expand Down Expand Up @@ -765,6 +766,14 @@ care of lower/uppercases**) : `yaml: a.b --> envvar: A_B` :
- **GRAFANA_CHECKCERT**: check if ssl certificate of the output is valid (default: true)
- **GRAFANA_MINIMUMPRIORITY**: minimum priority of event for using this output, order is
`emergency|alert|critical|error|warning|notice|informational|debug or "" (default)`
- **YANDEX_ACCESSKEYID** : Yandex Access Key Id
- **YANDEX_SECRETACCESSKEY** : AWS Secret Access Key
- **YANDEX_REGION**: Yandex region (default: ru-central-1)
- **YANDEX_S3_ENDPOINT**: yandex storage endpoint (default: https://storage.yandexcloud.net)
- **YANDEX_S3_BUCKET**: Yandex storage, bucket name
- **YANDEX_S3_PREFIX**: name of prefix, keys will have format: s3://<bucket>/<prefix>/YYYY-MM-DD/YYYY-MM-DDTHH:mm:ss.s+01:00.json
- **YANDEX_S3_MINIMUMPRIORITY**: # minimum priority of event for using this output, order is emergency|alert|critical|erro


#### Slack/Rocketchat/Mattermost/Googlechat Message Formatting

Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func getConfig() *types.Configuration {

v.SetDefault("Yandex.AccessKeyID", "")
v.SetDefault("Yandex.SecretAccessKey", "")
v.SetDefault("Yandex.Endpoint", "https://storage.yandexcloud.net")
v.SetDefault("Yandex.Region", "ru-central1")
v.SetDefault("Yandex.S3.Endpoint", "https://storage.yandexcloud.net")
v.SetDefault("Yandex.S3.Bucket", "")
v.SetDefault("Yandex.S3.Prefix", "falco")
v.SetDefault("Yamdex.S3.MinimumPriority", "")
Expand Down Expand Up @@ -366,7 +366,7 @@ func getConfig() *types.Configuration {
c.Fission.MinimumPriority = checkPriority(c.Fission.MinimumPriority)
c.Rabbitmq.MinimumPriority = checkPriority(c.Rabbitmq.MinimumPriority)
c.Wavefront.MinimumPriority = checkPriority(c.Wavefront.MinimumPriority)
c.Yandex.S3.MinimumPriority = checkPriority(c.Wavefront.MinimumPriority)
c.Yandex.S3.MinimumPriority = checkPriority(c.Yandex.S3.MinimumPriority)

c.Slack.MessageFormatTemplate = getMessageFormatTemplate("Slack", c.Slack.MessageFormat)
c.Rocketchat.MessageFormatTemplate = getMessageFormatTemplate("Rocketchat", c.Rocketchat.MessageFormat)
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ func forwardEvent(falcopayload types.FalcoPayload) {
}

if config.Yandex.S3.Bucket != "" && (falcopayload.Priority >= types.Priority(config.Yandex.S3.MinimumPriority) || falcopayload.Rule == testRule) {
go yandexS3Client.UploadYandexS3(falcopayload)
go yandexClient.UploadYandexS3(falcopayload)
}
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
wavefrontClient *outputs.Client
fissionClient *outputs.Client
grafanaClient *outputs.Client
yandexClient *outputs.Client
yandexClient *outputs.Client

statsdClient, dogstatsdClient *statsd.Client
config *types.Configuration
Expand Down Expand Up @@ -456,14 +456,14 @@ func init() {
var err error
yandexClient, err = outputs.NewYandexClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Yandex.S3.Bucket = ""
config.Yandex.S3.Bucket = ""
log.Printf("[ERROR] : Yandex - %v\n", err)
} else {
if config.Yandex.S3.Bucket != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "YandexS3")
}
}
}
}
log.Printf("[INFO] : Enabled Outputs : %s\n", outputs.EnabledOutputs)

}
Expand Down
20 changes: 7 additions & 13 deletions outputs/yandex.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,30 @@ import (
"errors"
"fmt"
"log"
"os"
"time"

"github.com/DataDog/datadog-go/statsd"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/falcosecurity/falcosidekick/types"
)

// NewYandexClient returns a new output.Client for accessing the Yandex API.
func NewYandexClient(config *types.Configuration, stats *types.Statistics, promStats *types.PromStatistics, statsdClient, dogstatsdClient *statsd.Client) (*Client, error) {

if config.Yandex.AccessKeyID != "" && config.Yandex.SecretAccessKey != "" {
err1 := os.Setenv("AWS_ACCESS_KEY_ID", config.Yandex.AccessKeyID)
err2 := os.Setenv("AWS_SECRET_ACCESS_KEY", config.Yandex.SecretAccessKey)
if err1 != nil || err2 != nil {
log.Printf("[ERROR] : Yandex - Error setting Yandex env vars")
return nil, errors.New("Error setting Yandex env vars")
}
}
sess, err := session.NewSession(&aws.Config{
Region: aws.String(config.Yandex.Region),
Endpoint: aws.String(config.Yandex.Endpoint)})
Region: aws.String(config.Yandex.Region),
Endpoint: aws.String(config.Yandex.S3.Endpoint),
Credentials: credentials.NewStaticCredentials(config.Yandex.AccessKeyID, config.Yandex.SecretAccessKey, ""),
})
if err != nil {
log.Printf("[ERROR] : AWS - %v\n", "Error while creating Yandex Session")
log.Printf("[ERROR] : Yandex - %v\n", "Error while creating Yandex Session")
return nil, errors.New("Error while creating Yandex Session")
}

log.Printf("[INFO] : Yandex Session has been configured successfully")

return &Client{
OutputType: "Yandex",
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ type grafanaOutputConfig struct {
type YandexOutputConfig struct {
AccessKeyID string
SecretAccessKey string
Endpoint string
Region string
S3 YandexS3Config
}
type YandexS3Config struct {
Endpoint string
Prefix string
Bucket string
MinimumPriority string
Expand Down

0 comments on commit 9e06d07

Please sign in to comment.