awssume 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/awssume.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/awssume +4 -0
- data/lib/awssume.rb +22 -0
- data/lib/awssume/adapter/aws_client.rb +31 -0
- data/lib/awssume/command_decorator.rb +15 -0
- data/lib/awssume/configuration.rb +49 -0
- data/lib/awssume/version.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ca101e4a43eaaf9f72e5a037a5e82543863999f
|
4
|
+
data.tar.gz: a354b71f596d90fbd6d3aebd89478d948789a36e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 855e8bfd2e439072cfcae7a07df02ae4d30c98b3bb4256304f70a3cd4abfb19e9b11e7e719e8489105ece3436b9243156d2f212da395cbdb07c2d9d37a50c5d8
|
7
|
+
data.tar.gz: 98600f682087d09e543194fbf70fdbbb98337922e78b882596a1193de57b6c4ba0869aaa868343a10b39dac9737a765d20549e2977cebca510bce1553f55d5ab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 reppard
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Awssume
|
2
|
+
|
3
|
+
Assume a role, do a thing.
|
4
|
+
|
5
|
+
This is a gem for assuming an AWS IAM role and using the returned temporary
|
6
|
+
credentials to do something such as run a deploy script or execute an aws cli
|
7
|
+
command. This gem was created because of the need to assume a role using
|
8
|
+
an instance profile on an EC2 instance and use the resulting credentials to
|
9
|
+
do some work. This functionality doesn't currently exist in some often used
|
10
|
+
community tools.
|
11
|
+
|
12
|
+
References:
|
13
|
+
[AWS Cli Issue](https://github.com/aws/aws-cli/issues/1390)
|
14
|
+
[Terraform Issue](https://github.com/hashicorp/terraform/issues/1275)
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'awssume'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install awssume
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
This gem has the potential to be used as a library in a project using Ruby.
|
35
|
+
After a few things are implemented(such as a global configuration block) usage
|
36
|
+
instructions for using as a library will be added.
|
37
|
+
|
38
|
+
Currently the focus has been to use this gem as a command line tool.
|
39
|
+
|
40
|
+
You can configure env vars to authenticate with AWS:
|
41
|
+
|
42
|
+
```
|
43
|
+
$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
44
|
+
$ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
45
|
+
$ export AWS_DEFAULT_REGION=us-west-2
|
46
|
+
```
|
47
|
+
|
48
|
+
If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY aren't set then other
|
49
|
+
authentication options are checked(such as instance profiles). This is
|
50
|
+
functionality provided by the aws-sdk.
|
51
|
+
|
52
|
+
```
|
53
|
+
$ AWS_ROLE_ARN=arn::aws::iam::123456789012:role/RoletoAssume \
|
54
|
+
awssume <command to execute>
|
55
|
+
```
|
56
|
+
```
|
57
|
+
$ AWS_ROLE_ARN=arn::aws::iam::123456789012:role/RoletoAssume \
|
58
|
+
awssume bundle exec rake component:deploy
|
59
|
+
```
|
60
|
+
```
|
61
|
+
$ AWS_ROLE_ARN=arn::aws::iam::123456789012:role/RoletoAssume \
|
62
|
+
awssume aws iam list-roles
|
63
|
+
```
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
68
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
69
|
+
prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
72
|
+
To release a new version, update the version number in `version.rb`, and then
|
73
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
74
|
+
push git commits and tags, and push the `.gem` file to
|
75
|
+
[rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on
|
80
|
+
GitHub at https://github.com/Manheim/awssume.
|
81
|
+
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the
|
86
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/awssume.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'awssume/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'awssume'
|
8
|
+
spec.version = Awssume::VERSION
|
9
|
+
spec.authors = ['reppard']
|
10
|
+
spec.email = ['reppardwalker@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Assume a role, do a thing.'
|
13
|
+
spec.description = [
|
14
|
+
'This is a gem for assuming an AWS IAM role and using the returned',
|
15
|
+
'temporary credentials to do something such as run a deploy script',
|
16
|
+
'or execute an aws cli command.'
|
17
|
+
].join(' ')
|
18
|
+
spec.homepage = 'https://github.com/Manheim/awssume'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'aws-sdk'
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "awssume"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/awssume
ADDED
data/lib/awssume.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'awssume/version'
|
3
|
+
require 'awssume/command_decorator'
|
4
|
+
require 'awssume/configuration'
|
5
|
+
require 'awssume/adapter/aws_client'
|
6
|
+
|
7
|
+
module Awssume
|
8
|
+
def self.run
|
9
|
+
config = Awssume::Configuration.new
|
10
|
+
adapter = Awssume::Adapter::AwsClient.new(
|
11
|
+
region: config.region,
|
12
|
+
role_arn: config.role_arn,
|
13
|
+
role_session_name: config.role_session_name
|
14
|
+
)
|
15
|
+
aws_env = {
|
16
|
+
'AWS_REGION' => config.region,
|
17
|
+
'AWS_DEFAULT_REGION' => config.region
|
18
|
+
}
|
19
|
+
creds_hash = adapter.assume
|
20
|
+
system(aws_env, Awssume::CommandDecorator.format_cmd(ARGV[0..-1], creds_hash))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Awssume
|
4
|
+
module Adapter
|
5
|
+
# This is aws sts client wrapper class
|
6
|
+
class AwsClient
|
7
|
+
attr_reader :config
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def assume
|
14
|
+
sts_client.assume_role(
|
15
|
+
role_arn: config[:role_arn],
|
16
|
+
role_session_name: role_session_name
|
17
|
+
).credentials.to_h
|
18
|
+
end
|
19
|
+
|
20
|
+
def role_session_name
|
21
|
+
config[:role_session_name]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def sts_client
|
27
|
+
Aws::STS::Client.new(region: config[:region])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Awssume
|
2
|
+
class CommandDecorator
|
3
|
+
class << self
|
4
|
+
def generate_var_string(var_hash)
|
5
|
+
var_hash.collect { |k,v| "AWS_#{k.upcase}='#{v}'" }.sort.join(' ')
|
6
|
+
end
|
7
|
+
|
8
|
+
def format_cmd(cmd, var_hash)
|
9
|
+
cmd = cmd.join(' ') if cmd.kind_of?(Array)
|
10
|
+
|
11
|
+
"#{generate_var_string(var_hash)} #{cmd}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Awssume
|
2
|
+
# A class for managing the properties needed for assuming a role
|
3
|
+
class Configuration
|
4
|
+
def self.default_session_name
|
5
|
+
"AwssumedSession#{Time.new.to_i}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.defaults
|
9
|
+
{
|
10
|
+
region: ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'],
|
11
|
+
role_arn: ENV['AWS_ROLE_ARN'],
|
12
|
+
role_session_name: ENV['AWS_ROLE_SESSION_NAME'] || default_session_name
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor(*defaults.keys)
|
17
|
+
|
18
|
+
def initialize(opts = {})
|
19
|
+
attrs.each do |k, _|
|
20
|
+
attr_val = validate_attrs(attrs.merge(opts), k)
|
21
|
+
instance_variable_set("@#{k}", attr_val)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validate_attrs(attrs, attr_key)
|
28
|
+
throwout_nils(attrs).fetch(attr_key) do
|
29
|
+
raise ArgumentError, missing_attr_error_msg(attr_key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def missing_attr_error_msg(key)
|
34
|
+
[
|
35
|
+
"Missing '#{key}'",
|
36
|
+
'Args should be passed in or set in the env:',
|
37
|
+
"AWS_#{key.upcase}=value awssume"
|
38
|
+
].join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def throwout_nils(attrs)
|
42
|
+
attrs.reject { |_, v| v.nil? }
|
43
|
+
end
|
44
|
+
|
45
|
+
def attrs
|
46
|
+
self.class.defaults
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awssume
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- reppard
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This is a gem for assuming an AWS IAM role and using the returned temporary
|
70
|
+
credentials to do something such as run a deploy script or execute an aws cli command.
|
71
|
+
email:
|
72
|
+
- reppardwalker@gmail.com
|
73
|
+
executables:
|
74
|
+
- awssume
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- awssume.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- exe/awssume
|
88
|
+
- lib/awssume.rb
|
89
|
+
- lib/awssume/adapter/aws_client.rb
|
90
|
+
- lib/awssume/command_decorator.rb
|
91
|
+
- lib/awssume/configuration.rb
|
92
|
+
- lib/awssume/version.rb
|
93
|
+
homepage: https://github.com/Manheim/awssume
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Assume a role, do a thing.
|
117
|
+
test_files: []
|