aws-rotate 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adf6a451f691065bc62e8feb7b43704bc603a438b05b9a3f092bc336ea8e3288
4
- data.tar.gz: fa9607d7253c854924f471fec41e6526239a7c1b0e1609590b6d07691fcc6e25
3
+ metadata.gz: 207cf2ce3e4f6e03f138a2757ba3d64cad3dc825793db640cb90505a0890b077
4
+ data.tar.gz: f5990b39c5d8ffc3c1a53a93b91e8fd0dfe194dfdaadd7080fc32b8ba3c61770
5
5
  SHA512:
6
- metadata.gz: c981cc84a81b3efe9e7901a2942f155f36723f51afd4996e55285839127cc4865283844cf6e16987afe305e08b3d9d208fe1ccb7d2a31827652a4f767afa4623
7
- data.tar.gz: 2be376dcc9cb074db6b214c83c6e74b794185b50bb144dcd58e5607360a78f67bbb59c5d17497c32fc0b33282fbc8e39f300ee6c5f4c1d48806c78ee56698416
6
+ metadata.gz: c0b8b7ccbc346a5453af992b8134cf35038cda8bf996d936b73255c2af46dd9ddf29b1ddaf0b940d2cc98ae3919311a2d88b1c5c79545565855548381118a583
7
+ data.tar.gz: 7a9df313347d41310662b9c7896f962d42dd7992c4fa443710b363e211f33c2fe6942c2daf444ce0648da561d8c075162767d6d99b39e794f3caaca9e5b756f6
@@ -3,5 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.2.0]
7
+ - continue rotating when hit max keys limit on a profile
8
+ - improve GetIamUserError message for key command
9
+
6
10
  ## [0.1.0]
7
11
  - Initial release.
data/README.md CHANGED
@@ -17,6 +17,25 @@ IMPORTANT: The `aws-rotate keys` command will update **all** the profiles found
17
17
 
18
18
  aws-rotate keys --noop
19
19
 
20
+ Example output:
21
+
22
+ $ aws-rotate keys
23
+ Backed up credentials file at: /home/ec2-user/.aws/credentials.bak-2019-08-14-16:45:36
24
+ Updating access key for AWS_PROFILE=profile1
25
+ Created new access key: AKIAXZ6ODJLQWYW3575A
26
+ Updated profile profile1 in /home/ec2-user/.aws/credentials with new key: AKIAXZ6ODJLQWYW3575A
27
+ Old access key deleted: AKIAXZ6ODJLQ3Q5TJUHN
28
+ Please note, it sometimes take a few seconds or even minutes before the new IAM access key is usable.
29
+ Updating access key for AWS_PROFILE=default
30
+ Updated profile default in /home/ec2-user/.aws/credentials with new key: AKIAXZ6ODJLQWYW3575A
31
+ Please note, it sometimes take a few seconds or even minutes before the new IAM access key is usable.
32
+ Updating access key for AWS_PROFILE=profile2
33
+ Created new access key: AKIAXCGZM5KIS35XPH5R
34
+ Updated profile profile2 in /home/ec2-user/.aws/credentials with new key: AKIAXCGZM5KIS35XPH5R
35
+ Old access key deleted: AKIAXCGZM5KI63JFCKFD
36
+ Please note, it sometimes take a few seconds or even minutes before the new IAM access key is usable.
37
+ $
38
+
20
39
  ### select filter option
21
40
 
22
41
  If you would like to selectively update profiles, you can use the `--select` option. The `-s` option is also shorthand for the `--select` option. Example:
@@ -14,7 +14,7 @@ module AwsRotate
14
14
  if ENV['AWS_PROFILE'].nil?
15
15
  lines = IO.readlines(@credentials_path)
16
16
  default_found = lines.detect { |l| l =~ /\[default\]/ }
17
- 'default'
17
+ 'default' if default_found
18
18
  else
19
19
  abort("AWS_PROFILE must be set")
20
20
  end
@@ -11,7 +11,9 @@ module AwsRotate
11
11
  @user = get_iam_user # will only rotate keys that belong to an actual IAM user
12
12
  return unless @user
13
13
 
14
- check_max_keys_limit
14
+ at_max = check_max_keys_limit
15
+ return false if at_max
16
+
15
17
  message = "Updating access key for AWS_PROFILE=#{@profile}"
16
18
  message = "NOOP: #{message}" if @options[:noop]
17
19
  puts message.color(:green)
@@ -25,10 +27,18 @@ module AwsRotate
25
27
  true
26
28
  end
27
29
 
30
+ def get_iam_user
31
+ get_iam_user!
32
+ rescue GetIamUserError
33
+ message = @options[:noop] ? "Will not be able to update key" : "Unable to update key"
34
+ puts "WARN: #{message} for AWS_PROFILE=#{@profile}".color(:yellow)
35
+ return false
36
+ end
37
+
28
38
  # Returns IAM username.
29
39
  # Returns nil unless this profile is actually associated with an user.
30
40
  # Skips assume role profiles.
31
- def get_iam_user
41
+ def get_iam_user!
32
42
  resp = sts.get_caller_identity
33
43
  arn = resp.arn
34
44
  # Example arns:
@@ -55,15 +65,18 @@ module AwsRotate
55
65
 
56
66
  # Check if there are 2 keys, cannot rotate if there are 2 keys already.
57
67
  # Raise error if there are 2 keys.
68
+ # Returns false if not at max limit
58
69
  MAX_KEYS = 2
59
70
  def check_max_keys_limit!
60
71
  resp = iam.list_access_keys(user_name: @user)
61
- return if resp.access_key_metadata.size < MAX_KEYS
72
+ return false if resp.access_key_metadata.size < MAX_KEYS # not at max limit
62
73
  raise MaxKeysError
63
74
  end
64
75
 
65
76
  # Check if there are 2 keys, cannot rotate if there are 2 keys already.
66
77
  # Display info message for user to reduce it to 1 key.
78
+ # Returns false if not at max limit
79
+ # Returns true if at max limit
67
80
  def check_max_keys_limit
68
81
  check_max_keys_limit!
69
82
  rescue MaxKeysError
@@ -71,7 +84,7 @@ module AwsRotate
71
84
  This user #{@user} in the AWS_PROFILE=#{@profile} has 2 access keys. This is the max number of keys allowed.
72
85
  Please remove at least one of the keys so aws-rotate can rotate the key.
73
86
  EOL
74
- exit 1
87
+ true # at max limit
75
88
  end
76
89
 
77
90
  @@cache = {}
@@ -96,7 +109,7 @@ module AwsRotate
96
109
 
97
110
  # store in cache to help with multiple profiles using the same aws access key
98
111
  old_key_id = aws_configure_get(:aws_access_key_id)
99
- @@cache[old_key_id] = CacheKey.new(old_key_id, key.access_key_id, key.secret_access_key)
112
+ @@cache[old_key_id] = OldKey.new(old_key_id, key.access_key_id, key.secret_access_key)
100
113
 
101
114
  puts "Created new access key: #{key.access_key_id}"
102
115
  key
@@ -6,7 +6,7 @@ module AwsRotate
6
6
  next unless filter_match?(profile)
7
7
 
8
8
  ENV['AWS_PROFILE'] = profile
9
- update_key
9
+ Key.new(@options).run
10
10
  end
11
11
  end
12
12
 
@@ -31,12 +31,5 @@ module AwsRotate
31
31
  end
32
32
  selected
33
33
  end
34
-
35
- def update_key
36
- Key.new(@options).run
37
- rescue Key::GetIamUserError
38
- message = @options[:noop] ? "Will not be able to update key" : "Unable to update key"
39
- puts "WARN: #{message} for AWS_PROFILE=#{@profile}".color(:yellow)
40
- end
41
34
  end
42
35
  end
@@ -0,0 +1,3 @@
1
+ module AwsRotate
2
+ OldKey = Struct.new(:old_key_id, :access_key_id, :secret_access_key)
3
+ end
@@ -1,3 +1,3 @@
1
1
  module AwsRotate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,7 +3,7 @@ describe AwsRotate::Key do
3
3
  rotater = AwsRotate::Key.new
4
4
  # The methods that are commented out have stubs at lower-levels.
5
5
  # allow(rotater).to receive(:get_iam_user).and_return('tung')
6
- allow(rotater).to receive(:check_max_keys_limit).and_return(null)
6
+ allow(rotater).to receive(:check_max_keys_limit).and_return(false)
7
7
  allow(rotater).to receive(:cache_access_key).and_return(cache_access_key)
8
8
  # allow(rotater).to receive(:create_access_key).and_return(create_access_key)
9
9
  allow(rotater).to receive(:update_aws_credentials_file).and_return(null)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-rotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -189,7 +189,6 @@ files:
189
189
  - lib/aws_rotate/aws_services.rb
190
190
  - lib/aws_rotate/backup.rb
191
191
  - lib/aws_rotate/base.rb
192
- - lib/aws_rotate/cache_key.rb
193
192
  - lib/aws_rotate/cli.rb
194
193
  - lib/aws_rotate/command.rb
195
194
  - lib/aws_rotate/completer.rb
@@ -204,6 +203,7 @@ files:
204
203
  - lib/aws_rotate/key.rb
205
204
  - lib/aws_rotate/keys.rb
206
205
  - lib/aws_rotate/list.rb
206
+ - lib/aws_rotate/old_key.rb
207
207
  - lib/aws_rotate/version.rb
208
208
  - spec/fixtures/home/.aws/config
209
209
  - spec/fixtures/home/.aws/credentials
@@ -1,3 +0,0 @@
1
- module AwsRotate
2
- CacheKey = Struct.new(:old_key_id, :access_key_id, :secret_access_key)
3
- end