logstash-mixin-aws 4.2.4 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bedbceb9fed81fbc39b3f594bc18f6cacde35aea4a00ebf90aa495612ee335f
4
- data.tar.gz: 7f14178a1db3ae963ac2fa4c6af0c37c42e888e30dd6ed32bdbfc0cc9fd3b007
3
+ metadata.gz: b584d410d71c4c32fc3b1cf34e9b4836f805cdf7c6f6eb5a1ea4be3e4d8c5d91
4
+ data.tar.gz: 5d772f5b89e35fef12781cb647cb7ceb1d0116304a53d81628897fcce94f2e05
5
5
  SHA512:
6
- metadata.gz: b6c7f25b4e78760eddf77e1b98a659110b5765a28b52699ba58eddc85e268c860efa1d520a944f43e911ed145326bffb26fb5ef9df47c283c8357e3188e8abe8
7
- data.tar.gz: 2bf224f332efe3e49a8767348425ec1da7a2ee3d5820ac078e058093090011d8f199e38d80c5974eb06a9e01426a6b9a96576dd1b2cae10f060b93902b182616
6
+ metadata.gz: 2cbad158d9eef2eafb325b4b8e3854ecd7c86e5a65e9d86042ee0979bb6644a49923f82c9bbe3b4e26e7fe664751074709fb261bc4572fa9fae3c8bef59c22c9
7
+ data.tar.gz: 54eff45517da99de84a296b882d3bfa37d455823b2ce3dd3d9a42cdb6f7d593de3fd416c7f9ad84f1d5b0e136ea30944a59871fe85de68e54b5dad8e954ac788
@@ -1,3 +1,9 @@
1
+ ## 4.3.0
2
+ - Drop strict value validation for region option #36
3
+ - Add endpoint option to customize the endpoint uri #32
4
+ - Allow user to provide a role to assume #27
5
+ - Update aws-sdk dependency to '~> 2'
6
+
1
7
  ## 4.2.4
2
8
  - Minor config validation fixes
3
9
 
@@ -9,11 +9,6 @@ module LogStash::PluginMixins::AwsConfig
9
9
  require "logstash/plugin_mixins/aws_config/v2"
10
10
 
11
11
  US_EAST_1 = "us-east-1"
12
- REGIONS_ENDPOINT = [US_EAST_1, "us-east-2", "us-west-1", "us-west-2",
13
- "eu-central-1", "eu-west-1", "eu-west-2",
14
- "ap-southeast-1", "ap-southeast-2", "ap-northeast-1",
15
- "ap-northeast-2", "sa-east-1", "us-gov-west-1",
16
- "cn-north-1", "ap-south-1", "ca-central-1"]
17
12
 
18
13
  def self.included(base)
19
14
  # Add these methods to the 'base' given.
@@ -6,11 +6,11 @@ module LogStash::PluginMixins::AwsConfig::Generic
6
6
 
7
7
  def generic_aws_config
8
8
  # The AWS Region
9
- config :region, :validate => LogStash::PluginMixins::AwsConfig::REGIONS_ENDPOINT, :default => LogStash::PluginMixins::AwsConfig::US_EAST_1
9
+ config :region, :validate => :string, :default => LogStash::PluginMixins::AwsConfig::US_EAST_1
10
10
 
11
11
  # This plugin uses the AWS SDK and supports several ways to get credentials, which will be tried in this order:
12
12
  #
13
- # 1. Static configuration, using `access_key_id` and `secret_access_key` params in logstash plugin config
13
+ # 1. Static configuration, using `access_key_id` and `secret_access_key` params or `role_arn` in the logstash plugin config
14
14
  # 2. External credentials file specified by `aws_credentials_file`
15
15
  # 3. Environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
16
16
  # 4. Environment variables `AMAZON_ACCESS_KEY_ID` and `AMAZON_SECRET_ACCESS_KEY`
@@ -26,6 +26,17 @@ module LogStash::PluginMixins::AwsConfig::Generic
26
26
  # URI to proxy server if required
27
27
  config :proxy_uri, :validate => :string
28
28
 
29
+ # Custom endpoint to connect to s3
30
+ config :endpoint, :validate => :string
31
+
32
+ # The AWS IAM Role to assume, if any.
33
+ # This is used to generate temporary credentials typically for cross-account access.
34
+ # See https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html for more information.
35
+ config :role_arn, :validate => :string
36
+
37
+ # Session name to use when assuming an IAM role
38
+ config :role_session_name, :validate => :string, :default => "logstash"
39
+
29
40
  # Path to YAML file containing a hash of AWS credentials.
30
41
  # This file will only be loaded if `access_key_id` and
31
42
  # `secret_access_key` aren't set. The contents of the
@@ -22,6 +22,10 @@ module LogStash::PluginMixins::AwsConfig::V1
22
22
  def aws_options_hash
23
23
  opts = {}
24
24
 
25
+ if @role_arn || @role_session_name
26
+ @logger.warn("role_arn and role_session_name settings are not supported in the v1 plugin")
27
+ end
28
+
25
29
  if @access_key_id.is_a?(NilClass) ^ @secret_access_key.is_a?(NilClass)
26
30
  @logger.warn("Likely config error: Only one of access_key_id or secret_access_key was provided but not both.")
27
31
  end
@@ -51,6 +55,10 @@ module LogStash::PluginMixins::AwsConfig::V1
51
55
  # For a list, see https://github.com/aws/aws-sdk-ruby/blob/master/lib/aws/core/configuration.rb
52
56
  opts.merge!(self.aws_service_endpoint(@region))
53
57
 
58
+ if !@endpoint.is_a?(NilClass)
59
+ opts[:endpoint] = @endpoint
60
+ end
61
+
54
62
  return opts
55
63
  end # def aws_options_hash
56
64
  end
@@ -34,6 +34,10 @@ module LogStash::PluginMixins::AwsConfig::V2
34
34
  opts.merge!({ :region => @region })
35
35
  end
36
36
 
37
+ if !@endpoint.is_a?(NilClass)
38
+ opts[:endpoint] = @endpoint
39
+ end
40
+
37
41
  return opts
38
42
  end
39
43
 
@@ -47,15 +51,25 @@ module LogStash::PluginMixins::AwsConfig::V2
47
51
  }
48
52
 
49
53
  credentials_opts[:session_token] = @session_token.value if @session_token
54
+ Aws::Credentials.new(credentials_opts[:access_key_id],
55
+ credentials_opts[:secret_access_key],
56
+ credentials_opts[:session_token])
50
57
  elsif @aws_credentials_file
51
58
  credentials_opts = YAML.load_file(@aws_credentials_file)
52
- end
53
-
54
- if credentials_opts
55
59
  Aws::Credentials.new(credentials_opts[:access_key_id],
56
60
  credentials_opts[:secret_access_key],
57
61
  credentials_opts[:session_token])
62
+ elsif @role_arn
63
+ assume_role
58
64
  end
59
65
  end
60
66
  end
67
+
68
+ def assume_role
69
+ Aws::AssumeRoleCredentials.new(
70
+ :client => Aws::STS::Client.new(:region => @region),
71
+ :role_arn => @role_arn,
72
+ :role_session_name => @role_session_name
73
+ )
74
+ end
61
75
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-mixin-aws'
3
- s.version = '4.2.4'
3
+ s.version = '4.3.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "AWS mixins to provide a unified interface for Amazon Webservice"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
20
20
  s.add_runtime_dependency 'logstash-codec-plain'
21
21
  s.add_runtime_dependency 'aws-sdk-v1', '>= 1.61.0'
22
- s.add_runtime_dependency 'aws-sdk', '~> 2.3.0'
22
+ s.add_runtime_dependency 'aws-sdk', '~> 2'
23
23
  s.add_development_dependency 'logstash-devutils'
24
+ s.add_development_dependency 'timecop'
24
25
  end
25
26
 
@@ -2,6 +2,7 @@
2
2
  require "logstash/devutils/rspec/spec_helper"
3
3
  require "logstash/plugin_mixins/aws_config"
4
4
  require 'aws-sdk'
5
+ require 'timecop'
5
6
 
6
7
  class DummyInputAwsConfigV2 < LogStash::Inputs::Base
7
8
  include LogStash::PluginMixins::AwsConfig::V2
@@ -81,6 +82,16 @@ describe LogStash::PluginMixins::AwsConfig do
81
82
  end
82
83
  end
83
84
 
85
+ describe 'config endpoint' do
86
+ context "endpoint provided" do
87
+ let(:settings) { { 'access_key_id' => '1234', 'secret_access_key' => 'secret', 'endpoint' => 'http://localhost'} }
88
+
89
+ it 'should use specified endpoint' do
90
+ expect(subject[:endpoint]).to eq("http://localhost")
91
+ end
92
+ end
93
+ end
94
+
84
95
  context 'when we arent providing credentials' do
85
96
  let(:settings) { {} }
86
97
  it 'should always return a hash' do
@@ -125,6 +136,60 @@ describe LogStash::PluginMixins::AwsConfig::V2 do
125
136
  expect(subject.secret_access_key).to eq(settings['secret_access_key'])
126
137
  end
127
138
  end
139
+
140
+ context 'role arn is provided' do
141
+ let(:settings) { { 'role_arn' => 'arn:aws:iam::012345678910:role/foo', 'region' => 'us-west-2' } }
142
+ let(:sts_double) { instance_double(Aws::STS::Client) }
143
+ let(:now) { Time.now }
144
+ let(:expiration) { Time.at(now.to_i + 3600) }
145
+ let(:temp_credentials) {
146
+ double(credentials:
147
+ double(
148
+ access_key_id: '1234',
149
+ secret_access_key: 'secret',
150
+ session_token: 'session_token',
151
+ expiration: expiration.to_s,
152
+ )
153
+ )
154
+ }
155
+ let(:new_temp_credentials) {
156
+ double(credentials:
157
+ double(
158
+ access_key_id: '5678',
159
+ secret_access_key: 'secret1',
160
+ session_token: 'session_token1',
161
+ expiration: expiration.to_s,
162
+ )
163
+ )
164
+ }
165
+
166
+ before do
167
+ allow(Aws::STS::Client).to receive(:new).and_return(sts_double)
168
+ allow(sts_double).to receive(:assume_role) {
169
+ if Time.now < expiration
170
+ temp_credentials
171
+ else
172
+ new_temp_credentials
173
+ end
174
+ }
175
+ end
176
+
177
+ it 'supports passing role_arn' do
178
+ Timecop.freeze(now) do
179
+ expect(subject.credentials.access_key_id).to eq('1234')
180
+ expect(subject.credentials.secret_access_key).to eq('secret')
181
+ expect(subject.credentials.session_token).to eq('session_token')
182
+ end
183
+ end
184
+
185
+ it 'rotates the keys once they expire' do
186
+ Timecop.freeze(Time.at(expiration.to_i + 100)) do
187
+ expect(subject.credentials.access_key_id).to eq('5678')
188
+ expect(subject.credentials.secret_access_key).to eq('secret1')
189
+ expect(subject.credentials.session_token).to eq('session_token1')
190
+ end
191
+ end
192
+ end
128
193
  end
129
194
  end
130
195
 
@@ -187,4 +252,5 @@ describe LogStash::PluginMixins::AwsConfig::V2 do
187
252
  expect(subject).to eq({ :dummy_input_aws_config_region => "us-east-1.awswebservice.local" })
188
253
  end
189
254
  end
255
+
190
256
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-mixin-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.4
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-27 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: 2.3.0
66
+ version: '2'
67
67
  name: aws-sdk
68
68
  prerelease: false
69
69
  type: :runtime
@@ -71,7 +71,7 @@ dependencies:
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 2.3.0
74
+ version: '2'
75
75
  - !ruby/object:Gem::Dependency
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ name: timecop
96
+ prerelease: false
97
+ type: :development
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  description: This gem is a Logstash plugin required to be installed on top of the
90
104
  Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
91
105
  gem is not a stand-alone program