fluent-plugin-aws-elasticsearch-service-hotfix 0.1.6.pre.f1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae990e26139301babae0a4700d214f9e9008ff15
4
+ data.tar.gz: 3b9e08a75d5578768a9901298bf5ba9442f07bc6
5
+ SHA512:
6
+ metadata.gz: 3b702cb67b94163e593cd568e10edbb6cc35778e64d9e3b9132e8b269ea1609ea86ded04b66d09f7403715ff7b3aef731871cb80ef2cdfc08abacc55fffd5a3d
7
+ data.tar.gz: 4dd29ac5f6f6e3bae3600f7a41d678aaf6f3f22beadf2aa8c1be9e21b3555286db09148386dd4d7cc3846eeb81561fcdba89c90e7c2d1ee5b0d80f8de89addb9
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-aws-elasticsearch-service.gemspec
4
+ gemspec
5
+
6
+ gem 'fluent-plugin-elasticsearch', '~> 1.0', require: false
7
+ gem 'aws-sdk', '~> 2', require: false
8
+ gem 'faraday_middleware-aws-signers-v4', '>= 0.1.0', '< 0.1.2', require: false
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 @
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,143 @@
1
+ # Fluent::AwsElasticsearchServiceOutput
2
+
3
+ This output plugin to post to "Amazon Elasticsearch Service".
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fluent-plugin-aws-elasticsearch-service'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ In your fluentd configration, use `type aws-elasticsearch-service`.
16
+
17
+ example:
18
+
19
+ ```ruby
20
+ <source>
21
+ type tail
22
+ format apache
23
+ time_format "%d/%b/%Y:%T %z"
24
+ path "/var/log/nginx/access.log"
25
+ pos_file "/var/log/td-agent/nginx.access.pos"
26
+ tag "es.nginx.access"
27
+ </source>
28
+
29
+ <match es.**>
30
+ type "aws-elasticsearch-service"
31
+ type_name "access_log"
32
+ logstash_format true
33
+ include_tag_key true
34
+ tag_key "@log_name"
35
+ flush_interval 1s
36
+
37
+ <endpoint>
38
+ url https://CLUSTER_ENDPOINT_URL
39
+ region eu-west-1
40
+ # access_key_id "secret"
41
+ # secret_access_key "seekret"
42
+ </endpoint>
43
+ </match>
44
+ ```
45
+
46
+ ## IAM
47
+ If you do not wish to use credentials in your configuration via the `access_key_id` and `secret_access_key` options you should use IAM policies.
48
+
49
+ The first step is to assign an IAM instance role `ROLE` to your EC2 instances. Name it appropriately. The role should contain no policy: we're using the possession of the role as the authenticating factor and placing the policy against the ES cluster.
50
+
51
+ You should then configure a policy for the ES cluster policy thus, with appropriate substitutions for the capitalized terms:
52
+
53
+ ```json
54
+ {
55
+ "Version": "2012-10-17",
56
+ "Statement": [
57
+ {
58
+ "Effect": "Allow",
59
+ "Principal": {
60
+ "AWS": "arn:aws:iam::ACCOUNT:role/ROLE"
61
+ },
62
+ "Action": "es:*",
63
+ "Resource": "arn:aws:es:eu-west-1:ACCOUNT:domain/ES_DOMAIN/*"
64
+ },
65
+ {
66
+ "Effect": "Allow",
67
+ "Principal": {
68
+ "AWS": "*"
69
+ },
70
+ "Action": "es:*",
71
+ "Resource": "arn:aws:es:eu-west-1:ACCOUNT:domain/ES_DOMAIN/*",
72
+ "Condition": {
73
+ "IpAddress": {
74
+ "aws:SourceIp": [
75
+ "1.2.3.4/32",
76
+ "5.6.7.8/32"
77
+ ]
78
+ }
79
+ }
80
+ }
81
+ ]
82
+ }
83
+ ```
84
+
85
+ This will allow your fluentd hosts (by virtue of the possession of the role) and any traffic coming from the specified IP addresses (you querying Kibana) to access the various endpoints. Whilst not ideally secure (both the fluentd and Kibana boxes should ideally be restricted to the verbs they require) it should allow you to get up and ingesting logs without anything getting in your way, before you tighten down the policy.
86
+
87
+ Additionally, you can use an STS assumed role as the authenticating factor and instruct the plugin to assume this role. This is useful for cross-account access and when assigning a standard role is not possible. The endpoint configuration looks like:
88
+
89
+ ```ruby
90
+ <endpoint>
91
+ url https://CLUSTER_ENDPOINT_URL
92
+ region eu-west-1
93
+ assume_role_arn arn:aws:sts::ACCOUNT:assumed-role/ROLE
94
+ assume_role_session_name SESSION_ID # Defaults to fluentd if omitted
95
+ </endpoint>
96
+ ```
97
+
98
+ The policy attached to your AWS Elasticsearch cluster then becomes something like:
99
+
100
+ ```json
101
+ {
102
+ "Version": "2012-10-17",
103
+ "Statement": [
104
+ {
105
+ "Effect": "Allow",
106
+ "Principal": {
107
+ "AWS": "arn:aws:sts::ACCOUNT:assumed-role/ROLE/SESSION_ID"
108
+ },
109
+ "Action": "es:*",
110
+ "Resource": "arn:aws:es:eu-west-1:ACCOUNT:domain/ES_DOMAIN/*"
111
+ }
112
+ ]
113
+ }
114
+ ```
115
+
116
+ You'll need to ensure that the environment in which the fluentd plugin runs has the capability to assume this role, by attaching a policy something like this to the instance profile:
117
+
118
+ ```json
119
+ {
120
+ "Version": "2012-10-17",
121
+ "Statement": {
122
+ "Effect": "Allow",
123
+ "Action": "sts:AssumeRole",
124
+ "Resource": "arn:aws:iam::ACCOUNT:role/ROLE"
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## Development
130
+
131
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
132
+
133
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
134
+
135
+ ## Contributing
136
+
137
+ Bug reports and pull requests are welcome on GitHub at https://github.com/atomita/fluent-plugin-aws-elasticsearch-service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
138
+
139
+
140
+ ## License
141
+
142
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
143
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-aws-elasticsearch-service-hotfix"
8
+ spec.version = "0.1.6-f1"
9
+ spec.authors = ["tanaka_733"]
10
+ spec.email = ["tanaka.takayoshi+gh@gmail.com"]
11
+
12
+ spec.summary = %q{Output plugin to post to "Amazon Elasticsearch Service" with hotfix.}
13
+ spec.description = %q{this is a Output plugin. Post to "Amazon Elasticsearch Service".}
14
+ spec.homepage = "https://github.com/tanaka-takayoshi/fluent-plugin-aws-elasticsearch-service"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_runtime_dependency "fluentd", "~> 0"
27
+ spec.add_runtime_dependency "fluent-plugin-elasticsearch", "~> 1.0"
28
+ spec.add_runtime_dependency "aws-sdk", "~> 2"
29
+ spec.add_runtime_dependency "faraday_middleware-aws-signers-v4", ">= 0.1.0", "< 0.1.2"
30
+ end
@@ -0,0 +1,192 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'fluent/plugin/out_elasticsearch'
5
+ require 'aws-sdk'
6
+ require 'faraday_middleware/aws_signers_v4'
7
+
8
+
9
+ module Fluent
10
+ class AwsElasticsearchServiceOutput < ElasticsearchOutput
11
+
12
+ Plugin.register_output('aws-elasticsearch-service', self)
13
+
14
+ config_section :endpoint do
15
+ config_param :region, :string
16
+ config_param :url, :string
17
+ config_param :access_key_id, :string, :default => ""
18
+ config_param :secret_access_key, :string, :default => ""
19
+ config_param :assume_role_arn, :string, :default => nil
20
+ config_param :assume_role_session_name, :string, :default => "fluentd"
21
+ end
22
+
23
+
24
+ #
25
+ # @override
26
+ #
27
+ def get_connection_options
28
+ raise "`endpoint` require." if @endpoint.empty?
29
+
30
+ hosts =
31
+ begin
32
+ @endpoint.map do |ep|
33
+ uri = URI(ep[:url])
34
+ host = %w(user password path).inject(host: uri.host, port: uri.port, scheme: uri.scheme) do |hash, key|
35
+ hash[key.to_sym] = uri.public_send(key) unless uri.public_send(key).nil? || uri.public_send(key) == ''
36
+ hash
37
+ end
38
+
39
+ host[:aws_elasticsearch_service] = {
40
+ :credentials => credentials(ep),
41
+ :region => ep[:region]
42
+ }
43
+
44
+ host
45
+ end
46
+ end
47
+
48
+ {
49
+ hosts: hosts
50
+ }
51
+ end
52
+
53
+
54
+ private
55
+
56
+ #
57
+ # get AWS Credentials
58
+ #
59
+ def credentials(opts)
60
+ calback = lambda do
61
+ credentials = nil
62
+ unless opts[:access_key_id].empty? or opts[:secret_access_key].empty?
63
+ credentials = Aws::Credentials.new opts[:access_key_id], opts[:secret_access_key]
64
+ else
65
+ if opts[:assume_role_arn].nil?
66
+ credentials = Aws::SharedCredentials.new({
67
+ retries: 2
68
+ }).credentials
69
+ credentials ||= Aws::InstanceProfileCredentials.new.credentials
70
+ else
71
+ credentials = sts_credential_provider({
72
+ role_arn: opts[:assume_role_arn],
73
+ role_session_name: opts[:assume_role_session_name],
74
+ region: opts[:region]
75
+ }).credentials
76
+ end
77
+ end
78
+ raise "No valid AWS credentials found." unless credentials.set?
79
+ credentials
80
+ end
81
+ def calback.inspect
82
+ credentials = self.call
83
+ "#<#{credentials.class.name} access_key_id=#{credentials.access_key_id.inspect}>"
84
+ end
85
+ calback
86
+ end
87
+
88
+ def sts_credential_provider(opts)
89
+ # AssumeRoleCredentials is an auto-refreshing credential provider
90
+ @sts ||= Aws::AssumeRoleCredentials.new(opts)
91
+ end
92
+
93
+ end
94
+
95
+
96
+ #
97
+ # monkey patch
98
+ #
99
+ class ElasticsearchOutput
100
+ module Elasticsearch
101
+
102
+ module Client
103
+ include ::Elasticsearch::Client
104
+ extend self
105
+ end
106
+
107
+ module Transport
108
+ module Transport
109
+ module HTTP
110
+ class Faraday < ::Elasticsearch::Transport::Transport::HTTP::Faraday
111
+
112
+ alias :__build_connections_origin_from_aws_elasticsearch_service_output :__build_connections
113
+
114
+ # Builds and returns a collection of connections.
115
+ #
116
+ # @return [Connections::Collection]
117
+ # @override
118
+ #
119
+ def __build_connections
120
+ ::Elasticsearch::Transport::Transport::Connections::Collection.new(
121
+ :connections => hosts.map { |host|
122
+ host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
123
+ host[:port] ||= DEFAULT_PORT
124
+ url = __full_url(host)
125
+
126
+ ::Elasticsearch::Transport::Transport::Connections::Connection.new(
127
+ :host => host,
128
+ :connection => ::Faraday::Connection.new(
129
+ url,
130
+ (options[:transport_options] || {}),
131
+ &__aws_elasticsearch_service_setting(host, &@block)
132
+ ),
133
+ :options => host[:connection_options]
134
+ )
135
+ },
136
+ :selector_class => options[:selector_class],
137
+ :selector => options[:selector]
138
+ )
139
+ end
140
+
141
+ def __aws_elasticsearch_service_setting(host, &block)
142
+ lambda do |faraday|
143
+ if host[:aws_elasticsearch_service]
144
+ faraday.request :aws_signers_v4,
145
+ credentials: host[:aws_elasticsearch_service][:credentials],
146
+ service_name: 'es',
147
+ region: host[:aws_elasticsearch_service][:region]
148
+ end
149
+ block.call faraday
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ end
159
+ end
160
+
161
+
162
+ #
163
+ # monkey patch
164
+ #
165
+ class FaradayMiddleware::AwsSignersV4
166
+
167
+ alias :initialize_origin_from_aws_elasticsearch_service_output :initialize
168
+
169
+ def initialize(app, options = nil)
170
+ super(app)
171
+
172
+ credentials = options.fetch(:credentials)
173
+ service_name = options.fetch(:service_name)
174
+ region = options.fetch(:region)
175
+ @signer =
176
+ begin
177
+ if credentials.is_a?(Proc)
178
+ signer = lambda do
179
+ Aws::Signers::V4.new(credentials.call, service_name, region)
180
+ end
181
+ def signer.sign(req)
182
+ self.call.sign(req)
183
+ end
184
+ signer
185
+ else
186
+ Aws::Signers::V4.new(credentials, service_name, region)
187
+ end
188
+ end
189
+
190
+ @net_http = app.is_a?(Faraday::Adapter::NetHttp)
191
+ end
192
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-aws-elasticsearch-service-hotfix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6.pre.f1
5
+ platform: ruby
6
+ authors:
7
+ - tanaka_733
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fluent-plugin-elasticsearch
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware-aws-signers-v4
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.0
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: 0.1.2
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 0.1.0
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.1.2
117
+ description: this is a Output plugin. Post to "Amazon Elasticsearch Service".
118
+ email:
119
+ - tanaka.takayoshi+gh@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - Gemfile
126
+ - LICENSE
127
+ - README.md
128
+ - Rakefile
129
+ - fluent-plugin-aws-elasticsearch-service.gemspec
130
+ - lib/fluent/plugin/out_aws-elasticsearch-service.rb
131
+ homepage: https://github.com/tanaka-takayoshi/fluent-plugin-aws-elasticsearch-service
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">"
147
+ - !ruby/object:Gem::Version
148
+ version: 1.3.1
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Output plugin to post to "Amazon Elasticsearch Service" with hotfix.
155
+ test_files: []