aws_runas 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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +16 -8
- data/README.md +1 -0
- data/lib/aws_runas/cli.rb +2 -1
- data/lib/aws_runas/config.rb +1 -1
- data/lib/aws_runas/main.rb +19 -9
- data/lib/aws_runas/version.rb +1 -1
- data/spec/aws_runas/config_spec.rb +6 -0
- data/spec/aws_runas/main_spec.rb +33 -0
- data/spec/helpers/config_spec.rb +1 -0
- data/spec/helpers/files/aws_config_nomfa +7 -0
- data.tar.gz.sig +2 -3
- metadata +5 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1725b31ac831ab9d03534988e9503c9531933be
|
4
|
+
data.tar.gz: 77d0509bb39c0d274bedb21152c8de1c340ed9d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d5095da3b865dc73abf72abf2492f12641d1ddef9b772f82ce6f68427354dcc10da2f1e4f81ec2766ee59133911f3a85a83239aca40f9b937eabc8c6b16122
|
7
|
+
data.tar.gz: 660afcfda580390e17abe2cf36e0dc1c91980121953209ffe5baf4bba83ebd08480a3304673e8987fc0120b675a3771ca29618303bccbcd576c5f068eaf62b9c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
|
2
|
-
====================
|
1
|
+
## v0.3.0
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
Add session only features:
|
4
|
+
|
5
|
+
* Add the `--no-role` command to load a profile and just get a
|
6
|
+
session token, instead of assuming a role.
|
7
|
+
* Changed default behaviour so that if `AWS_SESSION_TOKEN` exists, no MFA
|
8
|
+
is loaded - this allows the assumption of multiple roles from within
|
9
|
+
the same session.
|
10
|
+
* `--no-role` will fail if a MFA serial is not present (it's pretty much
|
11
|
+
useless - you will just be getting a session for the same access
|
12
|
+
key/secret key with the same level of privilege that you did before).
|
13
|
+
|
14
|
+
|
15
|
+
## v0.2.0
|
6
16
|
|
7
17
|
* `$SHELL` is now supported - if this environment variable exists, the shell
|
8
18
|
in it will be launched.
|
@@ -11,14 +21,12 @@ aws_runas CHANGELOG
|
|
11
21
|
* Fixes to support mingw32 such as IO flushing and detection of a lack of
|
12
22
|
`noecho` support.
|
13
23
|
|
14
|
-
|
15
|
-
-------------------------------------
|
24
|
+
## v0.1.3
|
16
25
|
|
17
26
|
* Fixed #3 (better handling of invalid profile name).
|
18
27
|
* Added guard for invalid file as well.
|
19
28
|
|
20
|
-
|
21
|
-
-------------------------------------
|
29
|
+
## v0.1.2
|
22
30
|
|
23
31
|
* Fixed #1 and #2 (default credentials fallback bug and overzealous version
|
24
32
|
restrictions).
|
data/README.md
CHANGED
@@ -40,6 +40,7 @@ If COMMAND is omitted, the default shell ($SHELL, /bin/sh, or cmd.exe,
|
|
40
40
|
depending on your system) will launch.
|
41
41
|
|
42
42
|
[options] are:
|
43
|
+
-n, --no-role Get a session token only, do not assume a role
|
43
44
|
-p, --path=<s> Path to the AWS config file
|
44
45
|
-r, --profile=<s> The AWS profile to load (default: default)
|
45
46
|
-h, --help Show this message
|
data/lib/aws_runas/cli.rb
CHANGED
@@ -36,6 +36,7 @@ module AwsRunAs
|
|
36
36
|
[options] are:
|
37
37
|
EOS
|
38
38
|
|
39
|
+
opt :no_role, 'Get a session token only, do not assume a role', type: TrueClass, default: nil
|
39
40
|
opt :path, 'Path to the AWS config file', type: String
|
40
41
|
opt :profile, 'The AWS profile to load', type: String, default: 'default'
|
41
42
|
stop_on_unknown
|
@@ -47,7 +48,7 @@ module AwsRunAs
|
|
47
48
|
def start
|
48
49
|
opts = load_opts
|
49
50
|
mfa_code = read_mfa_if_needed(path: opts[:path], profile: opts[:profile])
|
50
|
-
@main = AwsRunAs::Main.new(path: opts[:path], profile: opts[:profile], mfa_code: mfa_code)
|
51
|
+
@main = AwsRunAs::Main.new(path: opts[:path], profile: opts[:profile], mfa_code: mfa_code, no_role: opts[:no_role])
|
51
52
|
@main.assume_role
|
52
53
|
command = ARGV.shift
|
53
54
|
@main.handoff(command: command, argv: ARGV)
|
data/lib/aws_runas/config.rb
CHANGED
@@ -46,7 +46,7 @@ module AwsRunAs
|
|
46
46
|
|
47
47
|
# Checks to see if MFA is required for a specific profile.
|
48
48
|
def mfa_required?
|
49
|
-
return true if load_config_value(key: 'mfa_serial')
|
49
|
+
return true if load_config_value(key: 'mfa_serial') && !ENV.include?('AWS_SESSION_TOKEN')
|
50
50
|
false
|
51
51
|
end
|
52
52
|
|
data/lib/aws_runas/main.rb
CHANGED
@@ -21,7 +21,7 @@ module AwsRunAs
|
|
21
21
|
# and hands off environment to called process.
|
22
22
|
class Main
|
23
23
|
# Instantiate the object and set up the path, profile, and populate MFA
|
24
|
-
def initialize(path: nil, profile: default, mfa_code: nil)
|
24
|
+
def initialize(path: nil, profile: default, mfa_code: nil, no_role: nil)
|
25
25
|
cfg_path = if path
|
26
26
|
path
|
27
27
|
else
|
@@ -29,6 +29,7 @@ module AwsRunAs
|
|
29
29
|
end
|
30
30
|
@cfg = AwsRunAs::Config.new(path: cfg_path, profile: profile)
|
31
31
|
@mfa_code = mfa_code
|
32
|
+
@no_role = no_role
|
32
33
|
end
|
33
34
|
|
34
35
|
def sts_client
|
@@ -43,14 +44,23 @@ module AwsRunAs
|
|
43
44
|
def assume_role
|
44
45
|
session_id = "aws-runas-session_#{Time.now.to_i}"
|
45
46
|
role_arn = @cfg.load_config_value(key: 'role_arn')
|
46
|
-
mfa_serial = @cfg.load_config_value(key: 'mfa_serial')
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
mfa_serial = @cfg.load_config_value(key: 'mfa_serial') unless ENV.include?('AWS_SESSION_TOKEN')
|
48
|
+
if @no_role
|
49
|
+
raise 'No mfa_serial in selected profile, session will be useless' if mfa_serial.nil?
|
50
|
+
@role_credentials = sts_client.get_session_token(
|
51
|
+
duration_seconds: 3600,
|
52
|
+
serial_number: mfa_serial,
|
53
|
+
token_code: @mfa_code
|
54
|
+
).credentials
|
55
|
+
else
|
56
|
+
@role_credentials = Aws::AssumeRoleCredentials.new(
|
57
|
+
client: sts_client,
|
58
|
+
role_arn: role_arn,
|
59
|
+
serial_number: mfa_serial,
|
60
|
+
token_code: @mfa_code,
|
61
|
+
role_session_name: session_id
|
62
|
+
).credentials
|
63
|
+
end
|
54
64
|
end
|
55
65
|
|
56
66
|
def credentials_env
|
data/lib/aws_runas/version.rb
CHANGED
@@ -73,6 +73,12 @@ describe AwsRunAs::Config do
|
|
73
73
|
expect(@cfg.instance_variable_get('@profile')).to eq('test-profile')
|
74
74
|
expect(@cfg.mfa_required?).to be true
|
75
75
|
end
|
76
|
+
|
77
|
+
it 'confirms MFA is not required if AWS_SESSION_TOKEN is set' do
|
78
|
+
expect(@cfg.instance_variable_get('@profile')).to eq('test-profile')
|
79
|
+
expect(@cfg.mfa_required?).to be true
|
80
|
+
ENV.store('AWS_SESSION_TOKEN', 'foo')
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
84
|
describe '#load_source_profile' do
|
data/spec/aws_runas/main_spec.rb
CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
require 'spec_helper'
|
16
16
|
require 'aws_runas/main'
|
17
17
|
|
18
|
+
MFA_ERROR = 'No mfa_serial in selected profile, session will be useless'.freeze
|
19
|
+
|
18
20
|
describe AwsRunAs::Main do
|
19
21
|
before(:context) do
|
20
22
|
@main = AwsRunAs::Main.new(
|
@@ -35,6 +37,37 @@ describe AwsRunAs::Main do
|
|
35
37
|
expect(Aws::AssumeRoleCredentials).to receive(:new).and_call_original
|
36
38
|
@main.assume_role
|
37
39
|
end
|
40
|
+
|
41
|
+
it 'calls out to Aws::STS::Client.get_session_token when no_role is set' do
|
42
|
+
expect_any_instance_of(Aws::STS::Client).to receive(:get_session_token).and_call_original
|
43
|
+
ENV.delete('AWS_SESSION_TOKEN')
|
44
|
+
@main = AwsRunAs::Main.new(
|
45
|
+
path: MOCK_AWS_CONFIGPATH,
|
46
|
+
profile: 'test-profile',
|
47
|
+
mfa_code: '123456',
|
48
|
+
no_role: true
|
49
|
+
)
|
50
|
+
@main.assume_role
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises exception when no_role is set and there is no mfa_serial' do
|
54
|
+
expect do
|
55
|
+
ENV.delete('AWS_SESSION_TOKEN')
|
56
|
+
@main = AwsRunAs::Main.new(
|
57
|
+
path: MOCK_AWS_NO_MFA_PATH,
|
58
|
+
profile: 'test-profile',
|
59
|
+
mfa_code: '123456',
|
60
|
+
no_role: true
|
61
|
+
)
|
62
|
+
@main.assume_role
|
63
|
+
end.to raise_error(MFA_ERROR)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'calls out to Aws::AssumeRoleCredentials.new with no MFA when AWS_SESSION_TOKEN is set' do
|
67
|
+
expect(Aws::AssumeRoleCredentials).to receive(:new).with(hash_including(serial_number: nil)).and_call_original
|
68
|
+
ENV.store('AWS_SESSION_TOKEN', 'foo')
|
69
|
+
@main.assume_role
|
70
|
+
end
|
38
71
|
end
|
39
72
|
|
40
73
|
describe '#credentials_env' do
|
data/spec/helpers/config_spec.rb
CHANGED
data.tar.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Q-\3da�Zs4�g�N�*ö2�.��a��\Fz�
|
1
|
+
;h�&���m��Nޭ��v}����5��}�[a\L/SX���u�,X��k,
|
2
|
+
{(�T�f�cTT����fx3��&��8����B�*��+���[��4��a�m(�*�R�.zl�N-� �f8&t�A0W78^m��&/�gҊ�M��)^���Do�N
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_runas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Marchesi
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
reriQxVYXGlD8ZDuaKlDyVqUbF026ZHIlHKIgg90O037qFPxCBACTtxtYTP2hwug
|
32
32
|
Yis=
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-
|
34
|
+
date: 2016-06-11 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: aws-sdk
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- spec/aws_runas/utils_spec.rb
|
163
163
|
- spec/helpers/config_spec.rb
|
164
164
|
- spec/helpers/files/aws_config
|
165
|
+
- spec/helpers/files/aws_config_nomfa
|
165
166
|
- spec/spec_helper.rb
|
166
167
|
homepage: https://github.com/vancluever/aws-runas
|
167
168
|
licenses:
|
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
184
|
version: '0'
|
184
185
|
requirements: []
|
185
186
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.5.1
|
187
188
|
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: Run a command or shell under an assumed AWS IAM role
|
@@ -194,4 +195,5 @@ test_files:
|
|
194
195
|
- spec/aws_runas/utils_spec.rb
|
195
196
|
- spec/helpers/config_spec.rb
|
196
197
|
- spec/helpers/files/aws_config
|
198
|
+
- spec/helpers/files/aws_config_nomfa
|
197
199
|
- spec/spec_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|