Skip to content

Support IAM Roles for Service Accounts in EKS #60

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

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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ You'll need to ensure that the environment in which the fluentd plugin runs has
}
```

### EKS
If you want to use IAM roles for service accounts on Amazon EKS clusters, please refer to the official documentation and specify a Service Account for your fluentd Pod.

Then, the endpoint configuration looks like:

```ruby
<endpoint>
url https://CLUSTER_ENDPOINT_URL
region eu-west-1
assume_role_arn "#{ENV['AWS_ROLE_ARN']}"
assume_role_web_identity_token_file "#{ENV['AWS_WEB_IDENTITY_TOKEN_FILE']}"
</endpoint>
```

## Troubleshooting

* "Elasticsearch::Transport::Transport::Errors::Forbidden" error="[403]" even after verifying the access keys/roles/policies.
Expand Down
24 changes: 19 additions & 5 deletions lib/fluent/plugin/out_aws-elasticsearch-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AwsElasticsearchServiceOutput < ElasticsearchOutput
config_param :assume_role_arn, :string, :default => nil
config_param :ecs_container_credentials_relative_uri, :string, :default => nil #Set with AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variable value
config_param :assume_role_session_name, :string, :default => "fluentd"
config_param :assume_role_web_identity_token_file, :string, :default => nil
end

# here overrides default value of reload_connections to false because
Expand Down Expand Up @@ -84,11 +85,19 @@ def credentials(opts)
}).credentials
end
else
credentials = sts_credential_provider({
role_arn: opts[:assume_role_arn],
role_session_name: opts[:assume_role_session_name],
region: opts[:region]
}).credentials
if opts[:assume_role_web_identity_token_file].nil?
credentials = sts_credential_provider({
role_arn: opts[:assume_role_arn],
role_session_name: opts[:assume_role_session_name],
region: opts[:region]
}).credentials
else
credentials = sts_web_identity_credential_provider({
role_arn: opts[:assume_role_arn],
web_identity_token_file: opts[:assume_role_web_identity_token_file],
region: opts[:region]
}).credentials
end
end
end
raise "No valid AWS credentials found." unless credentials.set?
Expand All @@ -106,6 +115,11 @@ def sts_credential_provider(opts)
@sts ||= Aws::AssumeRoleCredentials.new(opts)
end

def sts_web_identity_credential_provider(opts)
# AssumeRoleWebIdentityCredentials is an auto-refreshing credential provider
@sts ||= Aws::AssumeRoleWebIdentityCredentials.new(opts)
end

end


Expand Down