oneaws 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2eafc4ba671ad4dc11df4fade663322d6b4ed6d7f7c89f8b2490c2c9eab63b08
4
+ data.tar.gz: f1fec019a30a413da02a4d05cb7f4f25aeea959999f46027b2969209dc2319d3
5
+ SHA512:
6
+ metadata.gz: f0cc8de11530ae39439165ddeb7efab54ab1bf0a14542e2724464e8073ae5f5bf75caf650b39a89f06663f0fe36a9d4cac0396a04309dd293aa745fb7800d3c3
7
+ data.tar.gz: 833d79033134bf4bfe4728aca62b7b10c3eeeeb2fe7b17c7573f87bd7c4a8b6d9a9de468a51457a6c14bde1aedf9a6803e10ec26c64a877abc4063432a203a05
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -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 ykky@pepabo.com. 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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oneaws.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # oneaws
2
+
3
+ OneLoginとAWS STSを使って、一時的なセキュリティ情報を取得します。
4
+
5
+ ## Usage
6
+
7
+ 事前に環境変数を設定します。
8
+
9
+ ```
10
+ # bash
11
+ export ONELOGIN_CLIENT_ID=<your onelogin client id>
12
+ export ONELOGIN_CLIENT_SECRET=<your onelogin client secret>
13
+ export ONELOGIN_USERNAME=<your onelogin username>
14
+ export ONELOGIN_PASSWORD=<your onelogin password>
15
+ export ONELOGIN_APP_ID=<your onelogin app_id>
16
+ export ONELOGIN_SUBDOMAIN=<your onelogin subdomain>
17
+ export AWS_ROLE_ARN=<your aws role arn>
18
+ export AWS_PRINCIPAL_ARN=<your aws idp arn>
19
+
20
+ # fish
21
+ set -x ONELOGIN_CLIENT_ID <your onelogin client id>
22
+ set -x ONELOGIN_CLIENT_SECRET <your onelogin client secret>
23
+ set -x ONELOGIN_USERNAME <your onelogin username>
24
+ set -x ONELOGIN_PASSWORD <your onelogin password>
25
+ set -x ONELOGIN_APP_ID <your onelogin app_id>
26
+ set -x ONELOGIN_SUBDOMAIN <your onelogin subdomain>
27
+ set -x AWS_ROLE_ARN <your aws role arn>
28
+ set -x AWS_PRINCIPAL_ARN <your aws idp arn>
29
+ ```
30
+
31
+ 環境変数を設定したら実行します。
32
+
33
+ ```
34
+ oneaws
35
+ ```
36
+
37
+ `-u` オプションをつけていると `~/.aws/credentials` に追記されます(default: true)。
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oneaws"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/oneaws ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'oneaws'
5
+
6
+ Oneaws::Cli.start
data/lib/oneaws.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "oneaws/cli"
2
+ require "oneaws/version"
3
+
4
+ module Oneaws
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
data/lib/oneaws/cli.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'thor'
2
+ require 'oneaws/client'
3
+ require 'inifile'
4
+
5
+ module Oneaws
6
+ class Cli < Thor
7
+ default_command :getkey
8
+
9
+ desc 'getkey', 'getkey'
10
+ option :update_aws_credentials, aliases: "-u", type: :boolean, default: true
11
+ option :profile, aliases: "-p", type: :string, default: "oneaws"
12
+ option :eval, type: :string, enum: ["bash", "fish"]
13
+ def getkey
14
+ client = Client.new
15
+
16
+ params = {
17
+ username: ENV['ONELOGIN_USERNAME'],
18
+ password: ENV['ONELOGIN_PASSWORD'],
19
+ app_id: ENV['ONELOGIN_APP_ID'],
20
+ subdomain: ENV['ONELOGIN_SUBDOMAIN'],
21
+ }
22
+ credential = client.issue_credential(params)
23
+
24
+ if options["update_aws_credentials"]
25
+ credential_file = File.expand_path("~/.aws/credentials")
26
+ unless inifile = IniFile.load(credential_file)
27
+ inifile = IniFile.new
28
+ end
29
+
30
+ profile = options["profile"]
31
+
32
+ inifile[profile]["aws_access_key_id"] = credential.access_key_id
33
+ inifile[profile]["aws_secret_access_key"] = credential.secret_access_key
34
+ inifile[profile]["aws_session_token"] = credential.session_token
35
+ inifile.write(filename: credential_file)
36
+ end
37
+
38
+ case options["eval"]
39
+ when "bash"
40
+ puts <<~EOS
41
+ export AWS_ACCESS_KEY_ID='#{credential.access_key_id}'
42
+ export AWS_SECRET_ACCESS_KEY='#{credential.secret_access_key}'
43
+ export AWS_SESSION_TOKEN='#{credential.session_token}'
44
+ EOS
45
+ when 'fish'
46
+ puts <<~EOS
47
+ set -x AWS_ACCESS_KEY_ID '#{credential.access_key_id}'
48
+ set -x AWS_SECRET_ACCESS_KEY '#{credential.secret_access_key}'
49
+ set -x AWS_SESSION_TOKEN '#{credential.session_token}'
50
+ EOS
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,58 @@
1
+ require 'onelogin'
2
+ require 'aws-sdk-core'
3
+
4
+ module Oneaws
5
+ class Client
6
+ class SamlRequestError < StandardError; end
7
+
8
+ def initialize
9
+ @onelogin = OneLogin::Api::Client.new({
10
+ client_id: ENV['ONELOGIN_CLIENT_ID'],
11
+ client_secret: ENV['ONELOGIN_CLIENT_SECRET'],
12
+ region: ENV['ONELOGIN_REGION'] || 'us',
13
+ })
14
+
15
+ @aws = Aws::STS::Client.new(
16
+ credentials: Aws::AssumeRoleCredentials,
17
+ region: ENV['AWS_REGION'] || 'ap-northeast-1',
18
+ )
19
+ end
20
+
21
+ def issue_credential(options)
22
+ username = options[:username]
23
+ password = options[:password]
24
+ app_id = options[:app_id]
25
+ subdomain = options[:subdomain]
26
+ response = @onelogin.get_saml_assertion(username, password, app_id, subdomain)
27
+ if response.nil?
28
+ raise SamlRequestError.new("#{@onelogin.error} #{@onelogin.error_description}")
29
+ end
30
+
31
+ mfa = response.mfa
32
+
33
+ # sent push notification to OneLogin Protect
34
+ response = @onelogin.get_saml_assertion_verifying(app_id, mfa.devices[0].id, mfa.state_token, nil, nil, false)
35
+ if response.nil?
36
+ raise SamlRequestError.new("#{@onelogin.error} #{@onelogin.error_description}")
37
+ end
38
+
39
+ while response.type != "success" do
40
+ sleep 1
41
+ response = @onelogin.get_saml_assertion_verifying(app_id, mfa.devices[0].id, mfa.state_token, nil, nil, true)
42
+ if response.nil?
43
+ raise SamlRequestError.new("#{@onelogin.error} #{@onelogin.error_description}")
44
+ end
45
+ end
46
+
47
+ saml_assertion = response.saml_response
48
+
49
+ params = {
50
+ duration_seconds: 3600,
51
+ principal_arn: ENV['AWS_PRINCIPAL_ARN'],
52
+ role_arn: ENV['AWS_ROLE_ARN'],
53
+ saml_assertion: saml_assertion,
54
+ }
55
+ @aws.assume_role_with_saml(params)[:credentials]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Oneaws
2
+ VERSION = "0.1.0"
3
+ end
data/oneaws.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/oneaws/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "oneaws"
5
+ spec.version = Oneaws::VERSION
6
+ spec.authors = ["Yuki Koya"]
7
+ spec.email = ["ykky@pepabo.com"]
8
+
9
+ spec.summary = %q{Issue temporary credentials using OneLogin and AWS STS.}
10
+ spec.description = %q{Issue temporary credentials using OneLogin and AWS STS.}
11
+ spec.homepage = "https://github.com/pepabo/oneaws"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/pepabo/oneaws"
16
+ spec.metadata["changelog_uri"] = "https://github.com/pepabo/oneaws"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency 'thor'
28
+ spec.add_dependency 'onelogin'
29
+ spec.add_dependency 'aws-sdk-core'
30
+ spec.add_dependency 'inifile'
31
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oneaws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Koya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: onelogin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: inifile
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: Issue temporary credentials using OneLogin and AWS STS.
70
+ email:
71
+ - ykky@pepabo.com
72
+ executables:
73
+ - oneaws
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - exe/oneaws
85
+ - lib/oneaws.rb
86
+ - lib/oneaws/cli.rb
87
+ - lib/oneaws/client.rb
88
+ - lib/oneaws/version.rb
89
+ - oneaws.gemspec
90
+ homepage: https://github.com/pepabo/oneaws
91
+ licenses: []
92
+ metadata:
93
+ homepage_uri: https://github.com/pepabo/oneaws
94
+ source_code_uri: https://github.com/pepabo/oneaws
95
+ changelog_uri: https://github.com/pepabo/oneaws
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.3.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.1.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Issue temporary credentials using OneLogin and AWS STS.
115
+ test_files: []