yle_tf-aws_assume_role 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/lib/yle_tf-aws_assume_role/action.rb +55 -0
- data/lib/yle_tf-aws_assume_role/config.rb +20 -0
- data/lib/yle_tf-aws_assume_role/plugin.rb +34 -0
- data/lib/yle_tf-aws_assume_role/version.rb +5 -0
- data/lib/yle_tf-aws_assume_role.rb +2 -0
- data/yle_tf-aws_assume_role.gemspec +36 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8243e470b21490c1d852211c02b252c95756337f
|
4
|
+
data.tar.gz: 50d007465e09724098c48851426882ff9b0c031c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2fdd41417831719b12b767570335b256b8f023cca756214ec8693ac4ce57cac594d700849ac79b1b7b1961b87e54de62eb9198bd061588eb20ae206f75051104
|
7
|
+
data.tar.gz: ca73e5700e3667a269379c53a887a34aa787d9eaa60784ae481ca2227b065dd3635630dfb57e39a32ca8900b6f8378cff60efe302b6ffa88e435182be3625d9e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Metrics/BlockLength:
|
2
|
+
Exclude:
|
3
|
+
- '*.gemspec'
|
4
|
+
- 'spec/**/*'
|
5
|
+
|
6
|
+
Metrics/ClassLength:
|
7
|
+
Severity: warning
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 100
|
11
|
+
Severity: warning
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 12
|
15
|
+
Severity: warning
|
16
|
+
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/FileName:
|
21
|
+
Exclude:
|
22
|
+
- 'lib/yle_tf-*.rb'
|
23
|
+
- 'spec/yle_tf-*_spec.rb'
|
24
|
+
|
25
|
+
Style/GuardClause:
|
26
|
+
MinBodyLength: 3
|
27
|
+
|
28
|
+
Style/NegatedIf:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/TrailingCommaInLiteral:
|
32
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at teemu.matilainen@reaktor.fi. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016-2017 Yleisradio Oy
|
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,59 @@
|
|
1
|
+
# YleTf Plugin for Assuming AWS IAM Roles
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yle_tf-aws_assume_role.svg)](https://badge.fury.io/rb/yle_tf-aws_assume_role)
|
4
|
+
[![Build Status](https://travis-ci.org/Yleisradio/yle_tf-aws_assume_role.svg?branch=master)](https://travis-ci.org/Yleisradio/yle_tf-aws_assume_role)
|
5
|
+
|
6
|
+
A plugin for [yle_tf](https://github.com/Yleisradio/yle_tf) for assuming AWS IAM roles using [yle-aws-role](https://github.com/Yleisradio/yle-aws-role).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
If you are running `tf` standalone, install the plugin with:
|
11
|
+
|
12
|
+
```sh
|
13
|
+
gem install yle_tf-aws_assume_role
|
14
|
+
```
|
15
|
+
|
16
|
+
and configure it for YleTf by listing it in the `TF_PLUGINS` environment variable. For example in Posix shells:
|
17
|
+
```sh
|
18
|
+
export TF_PLUGINS='yle_tf-aws_assume_role'
|
19
|
+
```
|
20
|
+
|
21
|
+
If you install and use YleTf from your own software or wrappers, add this line to your application's Gemfile for automatic plugin loading:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
group :tf_plugins do
|
25
|
+
gem 'yle_tf-aws_assume_role'
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
You can also add it without group definition, and load it in the code:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'yle_tf-aws_assume_role'
|
33
|
+
```
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
Example `tf.yaml` configuration:
|
38
|
+
|
39
|
+
```yaml
|
40
|
+
aws:
|
41
|
+
assume_role: true
|
42
|
+
account: 98765432100
|
43
|
+
role: dev
|
44
|
+
duration: 1800
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bundle update` to install and update the dependencies. Then, run `bundle exec rake spec` to run the tests.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Yleisradio/yle_tf-aws_assume_role. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'yle-aws-role'
|
2
|
+
require 'yle_tf/error'
|
3
|
+
require 'yle_tf/logger'
|
4
|
+
|
5
|
+
require_relative 'config'
|
6
|
+
|
7
|
+
module YleTfPlugins
|
8
|
+
module AWSAssumeRole
|
9
|
+
class Action
|
10
|
+
def initialize(app, **config)
|
11
|
+
@app = app
|
12
|
+
@action_config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
config = Config.new(@action_config, env[:config])
|
17
|
+
|
18
|
+
if !assume_role?(config, env)
|
19
|
+
@app.call(env)
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
assume_role(config) do |role|
|
24
|
+
env[:aws_role_assumed] = role
|
25
|
+
@app.call(env)
|
26
|
+
env[:aws_role_assumed] = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def assume_role?(config, env)
|
31
|
+
reason = if env[:aws_role_assumed]
|
32
|
+
'AWS IAM role already assumed'
|
33
|
+
elsif !config.assume_role?
|
34
|
+
'Not assuming AWS IAM role'
|
35
|
+
end
|
36
|
+
|
37
|
+
return true if !reason
|
38
|
+
|
39
|
+
YleTf::Logger.debug(reason)
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
def assume_role(config, &block)
|
44
|
+
account = config[:account]
|
45
|
+
role = config[:role]
|
46
|
+
duration = config[:duration]
|
47
|
+
|
48
|
+
YleTf::Logger.debug("Assuming AWS IAM role '#{account}:#{role}'")
|
49
|
+
::Yle::AWS::Role.assume_role(account, role, duration, &block)
|
50
|
+
rescue ::Yle::AWS::Role::Errors::AssumeRoleError => e
|
51
|
+
raise YleTf::Error, e, e.backtrace
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module YleTfPlugins
|
2
|
+
module AWSAssumeRole
|
3
|
+
class Config
|
4
|
+
attr_reader :action_config, :tf_config
|
5
|
+
|
6
|
+
def initialize(action_config, tf_config)
|
7
|
+
@action_config = action_config
|
8
|
+
@tf_config = tf_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def assume_role?
|
12
|
+
self[:assume_role]
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
@action_config.fetch(key.to_sym) { tf_config.fetch('aws', key.to_s) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yle_tf'
|
2
|
+
|
3
|
+
module YleTfPlugins
|
4
|
+
module AWSAssumeRole
|
5
|
+
class Plugin < YleTf::Plugin
|
6
|
+
register
|
7
|
+
|
8
|
+
default_config(
|
9
|
+
'aws' => {
|
10
|
+
'assume_role' => false,
|
11
|
+
'account' => nil,
|
12
|
+
'role' => nil,
|
13
|
+
'duration' => 3600,
|
14
|
+
}
|
15
|
+
)
|
16
|
+
|
17
|
+
action_hook do |hook|
|
18
|
+
require_relative 'action'
|
19
|
+
hook.before(YleTf::Action::TfHooks, Action)
|
20
|
+
end
|
21
|
+
|
22
|
+
command('_asu', 'Executes shell with the assumed role without Terraform env') do
|
23
|
+
require_relative 'action'
|
24
|
+
require 'yle_tf_plugins/commands/_shell/command'
|
25
|
+
|
26
|
+
YleTf::Action::Builder.new do
|
27
|
+
use YleTf::Action::LoadConfig
|
28
|
+
use Action
|
29
|
+
use YleTf::Action::Command, YleTfPlugins::CommandShell::Command
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'yle_tf-aws_assume_role/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'yle_tf-aws_assume_role'
|
9
|
+
spec.version = YleTfPlugins::AWSAssumeRole::VERSION
|
10
|
+
spec.summary = 'A plugin for yle_tf for assuming AWS IAM roles'
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/Yleisradio/yle_tf-aws_assume_role'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.authors = [
|
16
|
+
'Yleisradio',
|
17
|
+
'Teemu Matilainen',
|
18
|
+
]
|
19
|
+
spec.email = [
|
20
|
+
'devops@yle.fi',
|
21
|
+
'teemu.matilainen@reaktor.com',
|
22
|
+
]
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'yle_tf', '~> 0.1'
|
31
|
+
spec.add_dependency 'yle-aws-role', '~> 1.1'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
34
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yle_tf-aws_assume_role
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yleisradio
|
8
|
+
- Teemu Matilainen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yle_tf
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: yle-aws-role
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.13'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.13'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '12.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '12.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.5'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.5'
|
84
|
+
description: A plugin for yle_tf for assuming AWS IAM roles
|
85
|
+
email:
|
86
|
+
- devops@yle.fi
|
87
|
+
- teemu.matilainen@reaktor.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".rubocop.yml"
|
95
|
+
- ".travis.yml"
|
96
|
+
- CHANGELOG.md
|
97
|
+
- CODE_OF_CONDUCT.md
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- lib/yle_tf-aws_assume_role.rb
|
103
|
+
- lib/yle_tf-aws_assume_role/action.rb
|
104
|
+
- lib/yle_tf-aws_assume_role/config.rb
|
105
|
+
- lib/yle_tf-aws_assume_role/plugin.rb
|
106
|
+
- lib/yle_tf-aws_assume_role/version.rb
|
107
|
+
- yle_tf-aws_assume_role.gemspec
|
108
|
+
homepage: https://github.com/Yleisradio/yle_tf-aws_assume_role
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.13
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: A plugin for yle_tf for assuming AWS IAM roles
|
132
|
+
test_files: []
|