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

allow using AWS role or EC2 Instance role for Elasticsearch Auth #306

Merged
merged 1 commit into from
Jul 2, 2020
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
9 changes: 5 additions & 4 deletions comm_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ communications:
elasticsearch:
enabled: false
awsSigning:
enabled: false # enable awsSigning using IAM for Elastisearch hosted on AWS, if true make sure AWS environment variables are set. Refer https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
awsRegion: "us-east-1" # AWS region where Elasticsearch is deployed
server: 'ELASTICSEARCH_ADDRESS' # e.g https://example.com:9243
username: 'ELASTICSEARCH_USERNAME' # Basic Auth
enabled: false # enable awsSigning using IAM for Elastisearch hosted on AWS, if true make sure AWS environment variables are set. Refer https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
awsRegion: 'us-east-1' # AWS region where Elasticsearch is deployed
roleArn: '' # AWS IAM Role arn to assume for credentials, use this only if you dont want to use the EC2 instance role or not running on AWS instance
server: 'ELASTICSEARCH_ADDRESS' # e.g https://example.com:9243
username: 'ELASTICSEARCH_USERNAME' # Basic Auth
password: 'ELASTICSEARCH_PASSWORD'
# ELS index settings
index:
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type ElasticSearch struct {
type AWSSigning struct {
Enabled bool
AWSRegion string `yaml:"awsRegion"`
RoleArn string `yaml:"roleArn"`
}

// Index settings for ELS
Expand Down
13 changes: 12 additions & 1 deletion pkg/notify/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws/signer/v4"
"github.com/infracloudio/botkube/pkg/config"
"github.com/infracloudio/botkube/pkg/events"
Expand Down Expand Up @@ -55,11 +58,19 @@ type ElasticSearch struct {
func NewElasticSearch(c *config.Config) (Notifier, error) {
var elsClient *elastic.Client
var err error
var creds *credentials.Credentials
if c.Communications.ElasticSearch.AWSSigning.Enabled {
// Get credentials from environment variables and create the AWS Signature Version 4 signer
creds := credentials.NewEnvCredentials()
sess := session.Must(session.NewSession())
if c.Communications.ElasticSearch.AWSSigning.RoleArn != "" {
creds = stscreds.NewCredentials(sess, c.Communications.ElasticSearch.AWSSigning.RoleArn)
} else {
creds = ec2rolecreds.NewCredentials(sess)
}

signer := v4.NewSigner(creds)
awsClient, err := aws_signing_client.New(signer, nil, awsService, c.Communications.ElasticSearch.AWSSigning.AWSRegion)

if err != nil {
return nil, err
}
Expand Down