wdi_runas 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc34fccab31d8c247bf560b56f53c05e9b0cbe2e
4
+ data.tar.gz: e9fd612410995e972f2ad670a045ae16e0408c77
5
+ SHA512:
6
+ metadata.gz: d99d51e732876b3d8038e24b4166454b38158e42e41484c4eb620c2735746a0e3dfb6d141e9d9cd70f809caf8462a80586e806cddb9246a224ea0463134d9003
7
+ data.tar.gz: bb1651aaa016d43aaf3822352671fdf93d278a2c04103e64a07becfc688eba2712f5878ac7d7f8bfa1c567df644a1e18669dc3aabc1faca062594b8648c2fdfd
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Adding bin and vendor as this should never be vendored in production
12
+ /bin/
13
+ /vendor/
14
+
15
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Style/HashSyntax:
4
+ Exclude:
5
+ - Rakefile
6
+ AllCops:
7
+ TargetRubyVersion: 2.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ dist: trusty
2
+ langauge: ruby
3
+ rvm:
4
+ - "2.4.0"
5
+ - "2.3.3"
6
+ - "2.2.6"
data/CHANGELOG.md ADDED
@@ -0,0 +1,107 @@
1
+ ## v0.5.0
2
+
3
+ ### Zsh Support
4
+
5
+ `zsh` is now supported for the fancy prompt. When using the shell, your
6
+ existing profile data from `.zshrc` will be copied over into the temporary
7
+ configuration.
8
+
9
+ ### Additional Functionality for Bash and Zsh
10
+
11
+ 2 additional functions are available for `bash` and `zsh` as well:
12
+
13
+ * `aws_session_expired`, which reads `AWS_SESSION_EXPIRATION_UNIX` (see below)
14
+ and compares this with the current Unix timestamp supplied by `date`. It
15
+ returns 0 on true and 1 on false, which can be used semantically in shell
16
+ scripts.
17
+ * `aws_session_status_color`, which works off of `aws_session_expired` to
18
+ render an ANSI numeric color code - red when `aws_session_expired` is `true`,
19
+ yellow otherwise.
20
+
21
+ The prompts for `bash` and `zsh` now work off of these functions to render the
22
+ right color. The prompt will go red when the session has expired.
23
+
24
+ ### Skip Fancy Interactive Prompt
25
+
26
+ The default interactive prompt that you get when you run `aws-runas` with no
27
+ command supplied can now by skipped by adding `--skip-prompt` to the CLI
28
+ arguments. The profile functions mentioned above are still passed in. This
29
+ allows you to leverage their functionality inside your own scripts and custom
30
+ prompts if you want in other ways.
31
+
32
+ ### Additional Variables
33
+
34
+ Several environment variables have been added for more quality-of-life when
35
+ working in the shell or aware tools:
36
+
37
+ * `AWS_REGION` and `AWS_DEFAULT_REGION`, which pass through the region
38
+ configured in the profile, if present
39
+ * `AWS_SESSION_EXPIRATION` and `AWS_SESSION_EXPIRATION_UNIX` to supply the
40
+ session expiration time, in both human and UNIX timestamps, respectively
41
+ named.
42
+
43
+ ## v0.4.2
44
+
45
+ The role that aws-runas assumed and the profile it used are now exposed as
46
+ `AWS_RUNAS_ASSUMED_ROLE_ARN` and `AWS_RUNAS_PROFILE`, respectively. These can be
47
+ used in scripts to track the profile being used or the role ARN used, in case
48
+ this data is needed later, or for troubleshooting purposes.
49
+
50
+ ## v0.4.1
51
+
52
+ Fixed the escape sequence in the bash shell prompt indicator so that it has the
53
+ `\[` and `\]` enclosures - this fixes issues that the prompt was having with
54
+ line wrapping.
55
+
56
+ ## v0.4.0
57
+
58
+ * Dropping support for Ruby 2.1. You will need at least Ruby 2.2.6 to be using
59
+ this gem now. If you have a version below this, please use a v0.3.x version.
60
+ * MFA entry is no longer hidden from the terminal - you will see the digits you
61
+ enter now.
62
+ * Added a special indicator to `bash` prompts when running interactively. This
63
+ prompt displays your running profile, like so: `(AWS:default)`. When running
64
+ via --no-role, the indicator is just `(AWS)`. This should help to distinguish
65
+ any AWS shells you may be running from regular ones.
66
+
67
+ ## v0.3.1
68
+
69
+ This update sets `AWS_SDK_CONFIG_OPT_OUT` before the `aws-sdk` Ruby gem is
70
+ loaded to start assuming roles, to disable newer AWS Ruby SDK functionality that
71
+ allows the assumption of roles from `~/.aws/config` directly through the
72
+ toolchain. This conflicts with `aws-runas`'s own config file handling and breaks
73
+ in scenarios where one may want a default `~/.aws/config` file but no
74
+ credentials (ie: instance profiles).
75
+
76
+ ## v0.3.0
77
+
78
+ Add session only features:
79
+
80
+ * Add the `--no-role` command to load a profile and just get a
81
+ session token, instead of assuming a role.
82
+ * Changed default behaviour so that if `AWS_SESSION_TOKEN` exists, no MFA
83
+ is loaded - this allows the assumption of multiple roles from within
84
+ the same session.
85
+ * `--no-role` will fail if a MFA serial is not present (it's pretty much
86
+ useless - you will just be getting a session for the same access
87
+ key/secret key with the same level of privilege that you did before).
88
+
89
+
90
+ ## v0.2.0
91
+
92
+ * `$SHELL` is now supported - if this environment variable exists, the shell
93
+ in it will be launched.
94
+ * Windows support:
95
+ * `cmd.exe` is set as the default shell on non-Cygwin Windows systems.
96
+ * Fixes to support mingw32 such as IO flushing and detection of a lack of
97
+ `noecho` support.
98
+
99
+ ## v0.1.3
100
+
101
+ * Fixed #3 (better handling of invalid profile name).
102
+ * Added guard for invalid file as well.
103
+
104
+ ## v0.1.2
105
+
106
+ * Fixed #1 and #2 (default credentials fallback bug and overzealous version
107
+ restrictions).
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # Copyright 2015 Chris Marchesi
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ source 'https://rubygems.org'
16
+
17
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2015-2017 Chris Marchesi
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ [![Build Status](https://img.shields.io/travis/vancluever/aws-runas.svg)](https://travis-ci.org/vancluever/aws-runas)
2
+ [![Gem Version](https://img.shields.io/gem/v/aws_runas.svg)](https://rubygems.org/gems/aws_runas)
3
+ [![Codecov](https://img.shields.io/codecov/c/github/vancluever/aws-runas.svg)](https://codecov.io/github/vancluever/aws-runas)
4
+
5
+ aws-runas
6
+ ==========
7
+
8
+ [![asciicast](https://asciinema.org/a/107502.png)](https://asciinema.org/a/107502)
9
+
10
+ **The problem:** You manage AWS across several different roles and need to use
11
+ tools outside of the regular `aws-cli` toolchain.
12
+
13
+ **The solution:** Use `aws-runas` :)
14
+
15
+ Features
16
+ ---------
17
+
18
+ There are a few other tools and shell scripts out there that do the same
19
+ thing, but there are some differentiators in this gem:
20
+
21
+ * Support for your roles already laid out in `~/.aws/config`.
22
+ * These roles can also be copied to a local `aws_config` file and pushed
23
+ to source control to ensure your deployment targets live with source.
24
+ * Support for single-run commands (supplied on the command line) or
25
+ interactive shell sessions (by supplying no commands).
26
+ * MFA will be auto-detected and only prompted for if necessary (allowing one
27
+ to assume a role that does not have a MFA serial supplied).
28
+ * Session tokens can be acquired without assuming a role by adding the
29
+ appropriate `mfa_serial` into the `[default]` profile and running `aws-runas`
30
+ with `--no-role`. Subsequent uses of `aws-runas` after this will not prompt
31
+ you for MFA (useful for tooling that needs to assume multiple roles off the
32
+ same session token).
33
+
34
+ How it Works
35
+ -------------
36
+
37
+ Roles are assumed, or session tokens are simply acquired (if `--no-role` is
38
+ specified) via the `AssumeRole` or the `GetSessionToken` AWS STS API calls.
39
+ After this, your command or shell is launched with the standard AWS credential
40
+ chain environment variables set:
41
+
42
+ * `AWS_ACCESS_KEY_ID`
43
+ * `AWS_SECRET_ACCESS_KEY`
44
+ * `AWS_SESSION_TOKEN`
45
+
46
+ ### Additional Variables
47
+
48
+ In addition to the above, two toolchain-local environment variables are set to
49
+ help you determine what credentials are in use locally:
50
+
51
+ * `AWS_RUNAS_ASSUMED_ROLE_ARN` - set when a role is assumed (not set if
52
+ `--no-role` is used)
53
+ * `AWS_RUNAS_PROFILE` - set with the profile used when `aws-runas` was run
54
+ * `AWS_REGION` and `AWS_DEFAULT_REGION` - set with the region name defined in
55
+ the profile being used
56
+ * `AWS_SESSION_EXPIRATION` - set with the expiry timestamp in UTC
57
+ * `AWS_SESSION_EXPIRATION_UNIX` - set with the expiry timestamp in Unix time,
58
+ useful for scripting
59
+
60
+ ### Fancy Bash/Zsh Prompt
61
+
62
+ If you use `aws-runas` without any options and your default shell is Bash or
63
+ Zsh, a colorized prompt will appear with the profile that is in use if a role is
64
+ assumed, or a simple `(AWS)` indicator added to the prompt if a session token is
65
+ only obtained. See the video at the start of the doc for a demo!
66
+
67
+ #### Shell Integration Functions
68
+
69
+ 2 functions currently get exported when you run under one of the two supported
70
+ shells:
71
+
72
+ * `aws_session_expired`, which reads `AWS_SESSION_EXPIRATION_UNIX` (see above)
73
+ and compares this with the current Unix timestamp supplied by `date`. It
74
+ returns 0 on true and 1 on false, which can be used semantically in shell
75
+ scripts.
76
+ * `aws_session_status_color`, which works off of `aws_session_expired` to
77
+ render an ANSI numeric color code - red when `aws_session_expired` is `true`,
78
+ yellow otherwise.
79
+
80
+ #### Skipping the Fancy Prompt
81
+
82
+ If you are doing your own prompt customization based on aws-runas data and don't
83
+ want the prompt modified, you can supply `--skip-prompt` to skip the prompt
84
+ modification. The aforementioned integration functions will still be available
85
+ to you however, which you can use in your own scripts.
86
+
87
+ Usage
88
+ ------
89
+
90
+ Install the gem (`gem install aws_runas`), and the command can be run via
91
+ `aws-runas` via your regular `$PATH`.
92
+
93
+ ```
94
+ aws-runas: Run commands under AWS IAM roles
95
+
96
+ Usage:
97
+ aws-runas [options] COMMAND ARGS
98
+
99
+ If COMMAND is omitted, the default shell ($SHELL, /bin/sh, or cmd.exe,
100
+ depending on your system) will launch.
101
+
102
+ [options] are:
103
+ -n, --no-role Get a session token only, do not assume a role
104
+ -s, --skip-prompt Do not launch interactive sessions with the fancy prompt
105
+ -p, --path=<s> Path to the AWS config file
106
+ -r, --profile=<s> The AWS profile to load (default: default)
107
+ -h, --help Show this message
108
+ ```
109
+
110
+ `--path` is optional, and if omitted will default to the files in the
111
+ following order:
112
+
113
+ * `aws_config`, in the current working directory
114
+ * `~/.aws/config`, in your user directory.
115
+
116
+
117
+ Usage on Windows
118
+ -----------------
119
+
120
+ `aws_runas` works on Windows platforms, but YMMV. The gem has been tested
121
+ lightly on Cygwin and MSYS. Cygwin works great if you use the self-contained
122
+ Ruby ecosystem. Operating on MSYS or bare Windows will probably work as well as
123
+ any other Ruby gem. Running on WSL has not been tested, but as long as you can
124
+ get the minimum required Ruby version on it (currently >= 2.2.6), it should
125
+ generally work.
126
+
127
+ ### OpenSSL Cert Bundle for Windows
128
+
129
+ Running `aws-runas` on native Windows may require the installation of a CA
130
+ certificate bundle. To do this, you will need to get the certificate bundle from
131
+ somewhere like [here](http://curl.haxx.se/docs/caextract.html) and set your
132
+ `SSL_CERT_FILE` environment variable to go to the file.
133
+
134
+
135
+ Author
136
+ -------
137
+
138
+ Chris Marchesi <chrism@vancluevertech.com>
139
+
140
+ License
141
+ --------
142
+
143
+ ```
144
+ Copyright 2015-2017 Chris Marchesi
145
+
146
+ Licensed under the Apache License, Version 2.0 (the "License");
147
+ you may not use this file except in compliance with the License.
148
+ You may obtain a copy of the License at
149
+
150
+ http://www.apache.org/licenses/LICENSE-2.0
151
+
152
+ Unless required by applicable law or agreed to in writing, software
153
+ distributed under the License is distributed on an "AS IS" BASIS,
154
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155
+ See the License for the specific language governing permissions and
156
+ limitations under the License.
157
+ ```
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # Copyright 2015 Chris Marchesi
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'bundler/gem_tasks'
16
+ require 'rspec/core/rake_task'
17
+ RSpec::Core::RakeTask.new(:spec)
18
+
19
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDjjCCAnagAwIBAgIBATANBgkqhkiG9w0BAQUFADBGMQ8wDQYDVQQDDAZjaHJp
3
+ c20xHjAcBgoJkiaJk/IsZAEZFg52YW5jbHVldmVydGVjaDETMBEGCgmSJomT8ixk
4
+ ARkWA2NvbTAeFw0xNzAzMTYxNjM0MTZaFw0xODAzMTYxNjM0MTZaMEYxDzANBgNV
5
+ BAMMBmNocmlzbTEeMBwGCgmSJomT8ixkARkWDnZhbmNsdWV2ZXJ0ZWNoMRMwEQYK
6
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
7
+ 3i76LgHtAqSINqsk+1joj4bx4Mwk2Dgc5HMSe2MUAUzBxCXMDdlSSSJMBB8ZTXbf
8
+ uKreoDESTVLQlPm+RnsTDZpMMurznYGq15RrstD8pkxCre6QiGY1Ujwh/qdQQ65G
9
+ xULqYRSpikriJl8mHyUOxz2A56os/sTIzvfdNdC0y3wMUmPOQZMzsLxcxBT9rvtm
10
+ ME3IS5nR9u35X9O0CtNtvP+9VhJ/8mpSaYh2t0FigWJggvB9pRyT7D2YI0y1NpuW
11
+ w3FQeGwDZkvpI6dQxgQKuwNMIZVs39QSu5ltzlrjkFhm4mJKf5Zf1hVjMfKKWJSM
12
+ BDYULea2Iv+fpGU2SkhrSwIDAQABo4GGMIGDMAkGA1UdEwQCMAAwCwYDVR0PBAQD
13
+ AgSwMB0GA1UdDgQWBBRJbzaO73nDGmYlgYL+7tEDhL6+FjAkBgNVHREEHTAbgRlj
14
+ aHJpc21AdmFuY2x1ZXZlcnRlY2guY29tMCQGA1UdEgQdMBuBGWNocmlzbUB2YW5j
15
+ bHVldmVydGVjaC5jb20wDQYJKoZIhvcNAQEFBQADggEBALVY07yDy4um9cYp0ku9
16
+ WMZLWUwsxXsqmhnKcKa552NWhrdnjy/jCdc1fWcsyF60X5FZ4OEIHB2WubTa8/Ty
17
+ fWW/FNQMxAYNUzO8XBZGuE/5m8V3dJL8AlUiuiDLfZoeQAVe6zeaeBWYJenxNBRS
18
+ 8oLbWQukwSlOP62gMme5mVXM0NKc/MeO2wQSRJXjYoGdDCfqgaIImPg7ExME6Fw+
19
+ g09hCEeualN7su6OZYCUknxeGDmCvfO5fQlGmTzAVewWgGApG7XUvM0gJXV8ks0+
20
+ 80WBA6xKwX0zwURD8J7WNieL2iY5AhBg26cHuFLMQGTCyNEeZHZHnJhCwuBcnV1w
21
+ 2zQ=
22
+ -----END CERTIFICATE-----
data/exe/wdi-runas ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2015 Chris Marchesi
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'aws_runas/cli'
18
+
19
+ AwsRunAs::Cli.start
@@ -0,0 +1,67 @@
1
+ # Copyright 2015 Chris Marchesi
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'trollop'
16
+ require 'aws_runas/config'
17
+ require 'aws_runas/main'
18
+ require 'io/console'
19
+
20
+ module AwsRunAs
21
+ module Cli
22
+ module_function
23
+
24
+ # loads the command-line options.
25
+ def load_opts(args: ARGV)
26
+ Trollop.options(args) do
27
+ banner <<-EOS.gsub(/^ {10}/, '')
28
+ aws-runas: Run commands under AWS IAM roles
29
+
30
+ Usage:
31
+ aws-runas [options] COMMAND ARGS
32
+
33
+ If COMMAND is omitted, the default shell ($SHELL, /bin/sh, or cmd.exe,
34
+ depending on your system) will launch.
35
+
36
+ [options] are:
37
+ EOS
38
+
39
+ opt :no_role, 'Get a session token only, do not assume a role', type: TrueClass, default: nil
40
+ opt :skip_prompt, 'Do not launch interactive sessions with the fancy prompt', type: TrueClass, default: nil
41
+ opt :path, 'Path to the AWS config file', type: String
42
+ opt :profile, 'The AWS profile to load', type: String, default: 'default'
43
+ stop_on_unknown
44
+ end
45
+ end
46
+
47
+ # Start the CLI. Load options (profile, specific config path), and run
48
+ # main.
49
+ def start
50
+ opts = load_opts
51
+ mfa_code = read_mfa_if_needed(path: opts[:path], profile: opts[:profile])
52
+ @main = AwsRunAs::Main.new(path: opts[:path], profile: opts[:profile], mfa_code: mfa_code, no_role: opts[:no_role])
53
+ @main.assume_role
54
+ command = ARGV.shift
55
+ @main.handoff(command: command, argv: ARGV, skip_prompt: opts[:skip_prompt])
56
+ end
57
+
58
+ # Reads the MFA code from standard input.
59
+ def read_mfa_if_needed(path: nil, profile: 'default')
60
+ @cfg = AwsRunAs::Config.new(path: path, profile: profile)
61
+ return nil unless @cfg.mfa_required?
62
+ STDOUT.print 'Enter MFA code: '
63
+ STDOUT.flush
64
+ STDIN.gets.chomp
65
+ end
66
+ end
67
+ end