From 785c9dcab219f31407e6ec46aa3b03fbed6304dd Mon Sep 17 00:00:00 2001 From: Allen Sanabria Date: Sat, 28 Sep 2019 07:55:09 -0400 Subject: [PATCH 1/2] Update how veneur handles aws credentials. * If aws creds are set in config file, try and load those up. * If no creds are set, follow the aws sdk golang loading order. --- CHANGELOG.md | 1 + plugins/s3/README.md | 21 +++++++++++++++++++++ server.go | 36 ++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8951b2183..3f3bc5852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * Updated the vendored version of DataDog/datadog-go which adds support for sending metrics to Unix Domain socket. Thanks, [prudhvi](https://github.com/prudhvi)! * Splunk sink: Downgraded Splunk HEC errors to be logged at warning level, rather than error level. Added a note to clarify that Splunk cluster restarts can cause temporary errors, which are not necessarily problematic. Thanks, [aditya](https://github.com/chimeracoder)! * Updated the vendored version of github.com/gogo/protobuf which fixes Gopkg.toml conflicts for users of veneur. Thanks, [dtbartle](http://github.com/dtbartle)! +* Updated server.go to use the aws sdk (https://docs.aws.amazon.com/sdk-for-go/api/aws/session/) when the creds are not set in the config.yaml. Thanks, [linuxdynasty](https://github.com/linuxdynasty)! ## Bugfixes * veneur-prometheus now reports incremental counters instead of cumulative counters. This may cause dramatic differences in the statistics reported by veneur-prometheus. Thanks, [kklipsch-stripe](https://github.com/kklipsch-stripe)! diff --git a/plugins/s3/README.md b/plugins/s3/README.md index 2f769c5f5..a28755601 100644 --- a/plugins/s3/README.md +++ b/plugins/s3/README.md @@ -4,3 +4,24 @@ S3 Plugin The S3 plugin archives every flush to S3 as a separate S3 object. This plugin is still in an experimental state. + + + +# Config Options to connect to S3 + +Mandatory parameters below. + +* aws_s3_bucket: `string` +* aws_region: `string` + +Optional parameters below. + +* aws_access_key_id `string` +* aws_secret_access_key `string` + +The Golang AWS SDK will load up Credentials in the following order. https://docs.aws.amazon.com/sdk-for-go/api/aws/session/ + +1. Environment Variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_PROFILE`, `AWS_REGION` +2. Shared Credentials file `~/.aws/credentials` +3. Shared Configuration file (if SharedConfig is enabled) `export AWS_SDK_LOAD_CONFIG=1` +4. EC2 Instance Metadata (credentials only). diff --git a/server.go b/server.go index 6426057ff..a5e5aa9f1 100644 --- a/server.go +++ b/server.go @@ -677,28 +677,32 @@ func NewFromConfig(logger *logrus.Logger, conf Config) (*Server, error) { awsID := conf.AwsAccessKeyID awsSecret := conf.AwsSecretAccessKey if conf.AwsS3Bucket != "" { + var sess *session.Session + var err error if len(awsID) > 0 && len(awsSecret) > 0 { - sess, err := session.NewSession(&aws.Config{ + sess, err = session.NewSession(&aws.Config{ Region: aws.String(conf.AwsRegion), Credentials: credentials.NewStaticCredentials(awsID, awsSecret, ""), }) + } else { + sess, err = session.NewSession(&aws.Config{ + Region: aws.String(conf.AwsRegion), + }) + } - if err != nil { - logger.Infof("error getting AWS session: %s", err) - svc = nil - } else { - logger.Info("Successfully created AWS session") - svc = s3.New(sess) - plugin := &s3p.S3Plugin{ - Logger: log, - Svc: svc, - S3Bucket: conf.AwsS3Bucket, - Hostname: ret.Hostname, - } - ret.registerPlugin(plugin) - } + if err != nil { + logger.Infof("error getting AWS session: %s", err) + svc = nil } else { - logger.Info("AWS S3 credentials not found. S3 plugin is disabled.") + logger.Info("Successfully created AWS session") + svc = s3.New(sess) + plugin := &s3p.S3Plugin{ + Logger: log, + Svc: svc, + S3Bucket: conf.AwsS3Bucket, + Hostname: ret.Hostname, + } + ret.registerPlugin(plugin) } } else { logger.Info("AWS S3 bucket not set. Skipping S3 Plugin initialization.") From b186e1535c0480a17682224df356ac8c3a5fdf95 Mon Sep 17 00:00:00 2001 From: Aditya Mukerjee Date: Tue, 21 Apr 2020 17:48:14 -0400 Subject: [PATCH 2/2] =?UTF-8?q?golang=E2=86=92go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/s3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/s3/README.md b/plugins/s3/README.md index a28755601..8063d6ccc 100644 --- a/plugins/s3/README.md +++ b/plugins/s3/README.md @@ -19,7 +19,7 @@ Optional parameters below. * aws_access_key_id `string` * aws_secret_access_key `string` -The Golang AWS SDK will load up Credentials in the following order. https://docs.aws.amazon.com/sdk-for-go/api/aws/session/ +The Go AWS SDK will load up Credentials in the following order. https://docs.aws.amazon.com/sdk-for-go/api/aws/session/ 1. Environment Variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_PROFILE`, `AWS_REGION` 2. Shared Credentials file `~/.aws/credentials`