aws-mfa-secure 0.3.7 → 0.4.3

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: 66ffdf370150a2faa8dd385f187822633ba16bea532b359bc219443ec2b34ded
4
- data.tar.gz: 1a2f3e0d2632fbc3ddd650ee9dd04677ccea305fe30d1b8e99b85a301337e911
3
+ metadata.gz: 402fd832cf07be964b75d2a30a96600b65956e11979d02595d8e74725970a232
4
+ data.tar.gz: edc70a0647f6f73de89d02e83e788fc922f4c189a29c47b94a7efad33410fe25
5
5
  SHA512:
6
- metadata.gz: 7ddd72b31ee4374e113c711333217dc07e385850ce641bf94d636689c788e1b93e73527d9c89194364846131f8d504ed3b4a88d9038963894e9c937a66bf2ad8
7
- data.tar.gz: 4cc98c88e78e3e43c54ee2458cc3d79eda0b18794adf644e727d6fa4de270b7c1b2874360b7ef6c481ce9689aa742bc0c10c593b0ea19d26c4554a22ed28f3cd
6
+ metadata.gz: 51f145fe9a979d65cd54086e84e98c66050cb148fd45e39bbf766ade2d7d4175472580946761517a32d5749e2ab0dee37866e542450b428847b1c4c91d91d013
7
+ data.tar.gz: 8b471f3641a3d92f7b0f507fe6049c6f3c70b1e6bfb5ec451d114c74c257896191a1bd6ef944701bf02ba14db3e520895dba801a6e0c673962f099648a6d3665
@@ -3,6 +3,21 @@
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.4.3] - 2020-12-10
7
+ - [#4](https://github.com/tongueroo/aws-mfa-secure/pull/4) require singleton
8
+
9
+ ## [0.4.2]
10
+ - add helpful message
11
+
12
+ ## [0.4.1]
13
+ - #3 no-mfa option for exports
14
+
15
+ ## [0.4.0]
16
+ - #2 do not eager load ext/aws.rb
17
+
18
+ ## [0.3.8]
19
+ - fix edge case when aws profile not found
20
+
6
21
  ## [0.3.7]
7
22
  - check aws cli is fully setup
8
23
 
data/README.md CHANGED
@@ -4,8 +4,12 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/aws-mfa-secure.png)](http://badge.fury.io/rb/aws-mfa-secure)
6
6
 
7
+ [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
8
+
7
9
  Surprisingly, the [aws cli](https://docs.aws.amazon.com/cli/latest/reference/) does not yet support MFA for normal IAM users. See: [boto/botocore/pull/1399](https://github.com/boto/botocore/pull/1399) The aws-mfa-secure tool decorates the AWS CLI or API to handle MFA authentication. The MFA prompt only activates if `mfa_serial` is configured.
8
10
 
11
+ An advantage of the aws-mfa-secure is that it caches the temporary credentials `~/.aws/aws-mfa-secure-sessions` and reuses them until they expire. The expiration is 8 hours by default. This means that when you open a new terminal tab, you won’t have to re-enter the MFA code.
12
+
9
13
  ## Installation
10
14
 
11
15
  gem install aws-mfa-secure
@@ -13,7 +17,7 @@ Surprisingly, the [aws cli](https://docs.aws.amazon.com/cli/latest/reference/) d
13
17
  Prerequisite: The [AWS CLI](https://docs.aws.amazon.com/cli/latest/reference/) is required. You can install the AWS CLI via pip.
14
18
 
15
19
  pip install awscli --upgrade --user
16
-
20
+
17
21
  ## Usage
18
22
 
19
23
  **Summary**:
@@ -39,7 +43,7 @@ Note: AWS already supports `mfa_serial` for assumed roles: [AWS Configuration an
39
43
 
40
44
  alias aws="aws-mfa-secure session"
41
45
 
42
- You may want to add the alias to your `~/.bash_profile`
46
+ The alias allows us to intercept the normal aws cli command and decorate it. The `aws-mfa-secure session` only activates if `mfa_serial` is configured in your `~/.aws/credentials` file. Otherwise, it will pass the command through to the normal aws cli. You may want to add the alias to your `~/.bash_profile` do you don't have to alias it every time you open a new terminal.
43
47
 
44
48
  Autocompletion still works with the alias.
45
49
 
@@ -13,8 +13,10 @@ module AwsMfaSecure
13
13
  def setup
14
14
  loader = Zeitwerk::Loader.new
15
15
  loader.inflector = Inflector.new
16
- loader.push_dir(File.dirname(__dir__)) # lib
17
- loader.ignore("#{File.dirname(__dir__)}/aws-mfa-secure.rb")
16
+ lib = File.dirname(__dir__) # lib
17
+ loader.push_dir(lib)
18
+ loader.ignore("#{lib}/aws-mfa-secure.rb")
19
+ loader.do_not_eager_load("#{lib}/aws_mfa_secure/ext/aws.rb")
18
20
  loader.setup
19
21
  end
20
22
  end
@@ -132,7 +132,9 @@ module AwsMfaSecure
132
132
  memoize :sts
133
133
 
134
134
  def aws_config(prop)
135
- v = AWSConfig[aws_profile][prop.to_s]
135
+ profile_data = AWSConfig[aws_profile]
136
+ return unless profile_data
137
+ v = profile_data[prop.to_s]
136
138
  v unless v.blank?
137
139
  end
138
140
  memoize :aws_config
@@ -8,6 +8,7 @@ module AwsMfaSecure
8
8
 
9
9
  desc "exports", "Generate export statements that can be eval"
10
10
  long_desc Help.text(:exports)
11
+ option :mfa, type: :boolean, desc: "Use --no-mfa to bypass the mfa_profile check for a normal get session token call"
11
12
  def exports
12
13
  Exports.new(options).run
13
14
  end
@@ -1,3 +1,5 @@
1
+ require "singleton"
2
+
1
3
  # Useful for Ruby interfacing
2
4
  module AwsMfaSecure
3
5
  class Credentials < Base
@@ -6,8 +6,18 @@ module AwsMfaSecure
6
6
  end
7
7
 
8
8
  def run
9
+ # Allow use `aws-mfa-secure exports --no-mfa`
10
+ # This bypasses the check for mfa_serial being configured in the ~/.aws/credentials profile
11
+ # Useful if we want to grab temporary AWS_xxx credentials for testing.
12
+ if @options[:mfa] == false
13
+ resp = sts.get_session_token
14
+ puts script(resp.credentials)
15
+ return
16
+ end
17
+
9
18
  unless iam_mfa?
10
19
  $stderr.puts "WARN: mfa_serial is not configured for this AWS_PROFILE=#{@aws_profile}"
20
+ $stderr.puts "If you want to use exports without this mfa_serial check. Use the --no-mfa option."
11
21
  return
12
22
  end
13
23
 
@@ -16,14 +26,14 @@ module AwsMfaSecure
16
26
  save_creds(resp.credentials.to_h)
17
27
  end
18
28
 
19
- puts script
29
+ puts script(credentials)
20
30
  end
21
31
 
22
- def script
32
+ def script(creds)
23
33
  <<~EOL
24
- export AWS_ACCESS_KEY_ID=#{credentials["access_key_id"]}
25
- export AWS_SECRET_ACCESS_KEY=#{credentials["secret_access_key"]}
26
- export AWS_SESSION_TOKEN=#{credentials["session_token"]}
34
+ export AWS_ACCESS_KEY_ID=#{creds["access_key_id"]}
35
+ export AWS_SECRET_ACCESS_KEY=#{creds["secret_access_key"]}
36
+ export AWS_SESSION_TOKEN=#{creds["session_token"]}
27
37
  EOL
28
38
  end
29
39
  end
@@ -1,3 +1,3 @@
1
1
  module AwsMfaSecure
2
- VERSION = "0.3.7"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-mfa-secure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.3
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-14 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  - !ruby/object:Gem::Version
244
244
  version: '0'
245
245
  requirements: []
246
- rubygems_version: 3.0.6
246
+ rubygems_version: 3.1.4
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: Adds MFA Support to AWS CLI and Ruby SDKs for normal IAM user