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

Cherry-pick #10265 to 6.x: Fix permissions issues for SQS #10411

Merged
merged 1 commit into from
Jan 30, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ https://github.com/elastic/beats/compare/v6.6.0...6.x[Check the HEAD diff]
*Functionbeat*

- Ensure that functionbeat is logging at info level not debug. {issue}10262[10262]
- Add the required permissions to the role when deployment SQS functions. {issue}9152[9152]

==== Added

Expand Down
50 changes: 45 additions & 5 deletions x-pack/functionbeat/provider/aws/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package aws
import (
"context"
"errors"
"sort"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
Expand Down Expand Up @@ -101,12 +102,51 @@ func (s *SQS) Template() *cloudformation.Template {
return template
}

// Policies returns a slice of policies to add to the lambda role.
func (s *SQS) Policies() []cloudformation.AWSIAMRole_Policy {
resources := make([]string, len(s.config.Triggers))
for idx, trigger := range s.config.Triggers {
resources[idx] = trigger.EventSourceArn
}

// Give us a chance to generate the same document indenpendant of the changes,
// to help with updates.
sort.Strings(resources)

// SQS Roles permissions:
// - lambda:CreateEventSourceMapping
// - lambda:ListEventSourceMappings
// - lambda:ListFunctions
//
// Lambda Role permission
// - sqs:ChangeMessageVisibility
// - sqs:DeleteMessage
// - sqs:GetQueueAttributes
// - sqs:ReceiveMessage
policies := []cloudformation.AWSIAMRole_Policy{
cloudformation.AWSIAMRole_Policy{
PolicyName: cloudformation.Join("-", []string{"fnb", "sqs", s.config.Name}),
PolicyDocument: map[string]interface{}{
"Statement": []map[string]interface{}{
map[string]interface{}{
"Action": []string{
"sqs:ChangeMessageVisibility",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:ReceiveMessage",
},
"Effect": "Allow",
"Resource": resources,
},
},
},
},
}

return policies
}

// LambdaConfig returns the configuration to use when creating the lambda.
func (s *SQS) LambdaConfig() *lambdaConfig {
return s.config.LambdaConfig
}

// Policies returns a slice of policy to add to the lambda.
func (s *SQS) Policies() []cloudformation.AWSIAMRole_Policy {
return []cloudformation.AWSIAMRole_Policy{}
}