aws-rotate 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +3 -8
- data/lib/aws_rotate/key.rb +5 -0
- data/lib/aws_rotate/list.rb +30 -5
- data/lib/aws_rotate/version.rb +1 -1
- data/spec/lib/list_spec.rb +12 -0
- metadata +5 -4
- data/Gemfile.lock +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a8227dbc10aa515ededb79a5640969eac1315f8d2ff5e606d403bf03b82d402
|
4
|
+
data.tar.gz: d9422bf3540a31c35aae40aa856fd2686649bfeca4e05658616033f2c22b640b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d07348115dd82167e285edda3f314ec51315497bd12d61064aa74db87977e49a07da92bbad2d97be0e7aeb4f4f8a3da1178911c28538c9c8c5a74de3e398b1a
|
7
|
+
data.tar.gz: 7b2860846d492a8998b842002c15e8ae2cc8c25a5bce9ae4625733d774f7544e7e37616d041fb0f771873f909c7afb53b7e8545aabf6ea828e6ea1d7011a9e8a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +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.3.0]
|
7
|
+
- only rotate profiles with keys. skip profiles using assumed role.
|
8
|
+
|
6
9
|
## [0.2.0]
|
7
10
|
- continue rotating when hit max keys limit on a profile
|
8
11
|
- improve GetIamUserError message for key command
|
data/README.md
CHANGED
@@ -29,11 +29,6 @@ Example output:
|
|
29
29
|
Updating access key for AWS_PROFILE=default
|
30
30
|
Updated profile default in /home/ec2-user/.aws/credentials with new key: AKIAXZ6ODJLQWYW3575A
|
31
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
32
|
$
|
38
33
|
|
39
34
|
### select filter option
|
@@ -98,16 +93,16 @@ You can add something like this:
|
|
98
93
|
|
99
94
|
30 20 * * * bash -l -c 'aws-rotate keys --select dev-aws-profile test-aws-profile --no-backup >> /var/log/cron-aws-rotate.log 2>&1' # rotate AWS keys daily
|
100
95
|
|
101
|
-
Create a `/var/log/cron
|
96
|
+
Create a `/var/log/cron-aws-rotate.log` that is writable with your user:
|
102
97
|
|
103
98
|
sudo touch /var/log/cron-aws-rotate.log
|
104
99
|
sudo chown `whoami`:`whoami` /var/log/cron-aws-rotate.log
|
105
100
|
|
106
101
|
## Installation
|
107
102
|
|
108
|
-
|
103
|
+
You can install the tool with:
|
109
104
|
|
110
|
-
gem
|
105
|
+
gem install aws-rotate
|
111
106
|
|
112
107
|
## Requirements
|
113
108
|
|
data/lib/aws_rotate/key.rb
CHANGED
@@ -8,6 +8,7 @@ module AwsRotate
|
|
8
8
|
# and report errors early on. The noop check happens after this initial check.
|
9
9
|
# Also with this we can filter for only the keys thats that have associated users and will be updated.
|
10
10
|
# Only the profiles with IAM users will be shown as "Updating..."
|
11
|
+
puts "AWS_PROFILE=#{ENV['AWS_PROFILE']}"
|
11
12
|
@user = get_iam_user # will only rotate keys that belong to an actual IAM user
|
12
13
|
return unless @user
|
13
14
|
|
@@ -61,6 +62,10 @@ module AwsRotate
|
|
61
62
|
puts "The AWS_PROFILE=#{@profile} profile seems to have invalid secret keys. Please double check it.".color(:red)
|
62
63
|
puts "#{e.class} #{e.message}"
|
63
64
|
raise GetIamUserError
|
65
|
+
rescue Aws::Errors::NoSourceProfileError => e
|
66
|
+
puts "WARN: The AWS_PROFILE=#{@profile} profile does not have have access keys.".color(:yellow)
|
67
|
+
puts "#{e.class} #{e.message}"
|
68
|
+
raise GetIamUserError
|
64
69
|
end
|
65
70
|
|
66
71
|
# Check if there are 2 keys, cannot rotate if there are 2 keys already.
|
data/lib/aws_rotate/list.rb
CHANGED
@@ -1,20 +1,45 @@
|
|
1
1
|
module AwsRotate
|
2
2
|
class List < Base
|
3
|
+
def initialize(options={})
|
4
|
+
super
|
5
|
+
@lines = IO.readlines(@credentials_path)
|
6
|
+
end
|
7
|
+
|
3
8
|
def run
|
4
9
|
puts "AWS Profiles:"
|
5
10
|
puts profiles
|
11
|
+
profiles
|
6
12
|
end
|
7
13
|
|
14
|
+
# Only returns profiles that have aws_access_key_id associated
|
8
15
|
def profiles
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
has_key, within_profile, profiles = false, false, []
|
17
|
+
all_profiles.each do |profile|
|
18
|
+
@lines.each do |line|
|
19
|
+
line = line.strip
|
20
|
+
within_profile = false if line =~ /^\[/ # on the next profile section, reset flag
|
21
|
+
within_profile ||= line == "[#{profile}]" # enable checking
|
22
|
+
if within_profile
|
23
|
+
has_key = line =~ /^aws_access_key_id/
|
24
|
+
if has_key
|
25
|
+
profiles << profile
|
26
|
+
break
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
profiles
|
32
|
+
end
|
33
|
+
|
34
|
+
def all_profiles
|
35
|
+
all_profiles = []
|
36
|
+
@lines.each do |line|
|
12
37
|
next if line =~ /^\s*#/ # ignore comments
|
13
38
|
|
14
39
|
md = line.match(/\[(.*)\]/)
|
15
|
-
|
40
|
+
all_profiles << md[1] if md
|
16
41
|
end
|
17
|
-
|
42
|
+
all_profiles
|
18
43
|
end
|
19
44
|
end
|
20
45
|
end
|
data/lib/aws_rotate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-rotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -176,7 +176,6 @@ files:
|
|
176
176
|
- ".rspec"
|
177
177
|
- CHANGELOG.md
|
178
178
|
- Gemfile
|
179
|
-
- Gemfile.lock
|
180
179
|
- Guardfile
|
181
180
|
- LICENSE.txt
|
182
181
|
- README.md
|
@@ -210,6 +209,7 @@ files:
|
|
210
209
|
- spec/lib/cli_spec.rb
|
211
210
|
- spec/lib/key_spec.rb
|
212
211
|
- spec/lib/keys_spec.rb
|
212
|
+
- spec/lib/list_spec.rb
|
213
213
|
- spec/spec_helper.rb
|
214
214
|
homepage: https://github.com/tongueroo/aws-rotate
|
215
215
|
licenses:
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
- !ruby/object:Gem::Version
|
231
231
|
version: '0'
|
232
232
|
requirements: []
|
233
|
-
rubygems_version: 3.0.
|
233
|
+
rubygems_version: 3.0.6
|
234
234
|
signing_key:
|
235
235
|
specification_version: 4
|
236
236
|
summary: Easy way to rotate all your AWS keys in your ~/.aws/credentials
|
@@ -240,4 +240,5 @@ test_files:
|
|
240
240
|
- spec/lib/cli_spec.rb
|
241
241
|
- spec/lib/key_spec.rb
|
242
242
|
- spec/lib/keys_spec.rb
|
243
|
+
- spec/lib/list_spec.rb
|
243
244
|
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
aws-rotate (0.1.0)
|
5
|
-
activesupport
|
6
|
-
aws-sdk-core
|
7
|
-
aws-sdk-iam
|
8
|
-
rainbow
|
9
|
-
thor
|
10
|
-
zeitwerk
|
11
|
-
|
12
|
-
GEM
|
13
|
-
remote: https://rubygems.org/
|
14
|
-
specs:
|
15
|
-
activesupport (5.2.3)
|
16
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>= 0.7, < 2)
|
18
|
-
minitest (~> 5.1)
|
19
|
-
tzinfo (~> 1.1)
|
20
|
-
addressable (2.6.0)
|
21
|
-
public_suffix (>= 2.0.2, < 4.0)
|
22
|
-
aws-eventstream (1.0.3)
|
23
|
-
aws-partitions (1.201.0)
|
24
|
-
aws-sdk-core (3.62.0)
|
25
|
-
aws-eventstream (~> 1.0, >= 1.0.2)
|
26
|
-
aws-partitions (~> 1.0)
|
27
|
-
aws-sigv4 (~> 1.1)
|
28
|
-
jmespath (~> 1.0)
|
29
|
-
aws-sdk-iam (1.29.0)
|
30
|
-
aws-sdk-core (~> 3, >= 3.61.1)
|
31
|
-
aws-sigv4 (~> 1.1)
|
32
|
-
aws-sigv4 (1.1.0)
|
33
|
-
aws-eventstream (~> 1.0, >= 1.0.2)
|
34
|
-
byebug (11.0.1)
|
35
|
-
cli_markdown (0.1.0)
|
36
|
-
codeclimate-test-reporter (1.0.9)
|
37
|
-
simplecov (<= 0.13)
|
38
|
-
concurrent-ruby (1.1.5)
|
39
|
-
crack (0.4.3)
|
40
|
-
safe_yaml (~> 1.0.0)
|
41
|
-
diff-lcs (1.3)
|
42
|
-
docile (1.1.5)
|
43
|
-
hashdiff (1.0.0)
|
44
|
-
i18n (1.6.0)
|
45
|
-
concurrent-ruby (~> 1.0)
|
46
|
-
jmespath (1.4.0)
|
47
|
-
json (2.2.0)
|
48
|
-
minitest (5.11.3)
|
49
|
-
public_suffix (3.1.1)
|
50
|
-
rainbow (3.0.0)
|
51
|
-
rake (12.3.3)
|
52
|
-
rspec (3.8.0)
|
53
|
-
rspec-core (~> 3.8.0)
|
54
|
-
rspec-expectations (~> 3.8.0)
|
55
|
-
rspec-mocks (~> 3.8.0)
|
56
|
-
rspec-core (3.8.2)
|
57
|
-
rspec-support (~> 3.8.0)
|
58
|
-
rspec-expectations (3.8.4)
|
59
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.8.0)
|
61
|
-
rspec-mocks (3.8.1)
|
62
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
-
rspec-support (~> 3.8.0)
|
64
|
-
rspec-support (3.8.2)
|
65
|
-
safe_yaml (1.0.5)
|
66
|
-
simplecov (0.13.0)
|
67
|
-
docile (~> 1.1.0)
|
68
|
-
json (>= 1.8, < 3)
|
69
|
-
simplecov-html (~> 0.10.0)
|
70
|
-
simplecov-html (0.10.2)
|
71
|
-
thor (0.20.3)
|
72
|
-
thread_safe (0.3.6)
|
73
|
-
tzinfo (1.2.5)
|
74
|
-
thread_safe (~> 0.1)
|
75
|
-
webmock (3.6.2)
|
76
|
-
addressable (>= 2.3.6)
|
77
|
-
crack (>= 0.3.2)
|
78
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
79
|
-
zeitwerk (2.1.9)
|
80
|
-
|
81
|
-
PLATFORMS
|
82
|
-
ruby
|
83
|
-
|
84
|
-
DEPENDENCIES
|
85
|
-
aws-rotate!
|
86
|
-
bundler
|
87
|
-
byebug
|
88
|
-
cli_markdown
|
89
|
-
codeclimate-test-reporter
|
90
|
-
rake
|
91
|
-
rspec
|
92
|
-
webmock
|
93
|
-
|
94
|
-
BUNDLED WITH
|
95
|
-
2.0.2
|