aws-creds 0.2.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17f66b03fff9750104d21819f6df7676bb8746d1
4
+ data.tar.gz: 002899a2d52f2840844bcf7dc4bbd856776b1d80
5
+ SHA512:
6
+ metadata.gz: c2eb68f8e7e8c38f1235fbedad7507418033426535842c4827cd204f5576a94a2f9161c98d44c33330c724d2b641169ebff8907985d7b32211545ada8a83db1b
7
+ data.tar.gz: 553e3648677f9a01855d650ecd6d61ff486626371a53eeaa81f6903c75d4239ef225670b4c969b0890d3c40996d4e93cb5685220554182c528a05d451103356b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Airbnb
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # AWS::Creds
2
+
3
+ AWS::Creds exposes your AWS credentials through a command line utility and a Ruby API.
4
+
5
+ ## Why?
6
+
7
+ There is plenty to get wrong when handling credentials:
8
+
9
+ - When storing them on disk, only your user should be able to read it. awscreds will raise an exception if its permissions are too broad.
10
+ - When passing it to programs, they shouldn't be passed through the command line, or other users can find them through ps.
11
+ - When manipulating credentials in a language like Ruby, it should be as hard as possible to leak secrets through logs or traces.
12
+
13
+ Using command-line AWS tools seemed to be painful as well:
14
+
15
+ - There seemed to be no simple way to maintain a set of AWS credentials for multiple identities, and pick one quickly.
16
+ - Different tools can use different environment variables, or offer different configuration file formats.
17
+
18
+ We wanted to address this problem with:
19
+
20
+ - A simple file format and well-known location, that could be easily reimplemented;
21
+ - A simple yet flexible Ruby API, so future tools do not need to reinvent the wheel;
22
+ - A command-line utility to easily pass the credentials of your choice to command line utilities.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'aws-creds'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install aws-creds
37
+
38
+ ## Usage
39
+
40
+ ### Storage
41
+
42
+ Put your AWS credentials in `~/.awscreds`, one line per credentials, with the following colon-separated fields:
43
+
44
+ - A name for your credentials (the magic name "default" will be picked unless specified otherwise)
45
+ - The Access Key ID (20 characters, alphanumeric)
46
+ - The Secret Access Key (40 characters)
47
+
48
+ For example:
49
+
50
+ default:AKIAIOSFODNNDEADBEEF:WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWp
51
+ admin:AKIAIOO432MG8BADF00D:T60q14wrbyxl3Ed13VOFA/2G+nvJR/jgHC42jIH1
52
+
53
+ ### Command-line utility
54
+
55
+ `awc --help` should guide you.
56
+
57
+ To list the available credentials, use `-l`:
58
+
59
+ $ awc -li admin
60
+ default
61
+ *admin
62
+
63
+ To call `myscript put` and provide it with credentials, use:
64
+
65
+ $ awc myscript put
66
+
67
+ Its effects can easily be inspected:
68
+
69
+ $ awc -i admin env | grep AWS
70
+ AWS_ACCESS_KEY=AKIAIOO432MG8BADF00D
71
+ AWSAccessKeyId=AKIAIOO432MG8BADF00D
72
+ AWS_ACCESS_KEY_ID=AKIAIOO432MG8BADF00D
73
+ AWS_SECRET_KEY=T60q14wrbyxl3Ed13VOFA/2G+nvJR/jgHC42jIH1
74
+ AWSSecretKey=T60q14wrbyxl3Ed13VOFA/2G+nvJR/jgHC42jIH1
75
+ AWS_SECRET_ACCESS_KEY=T60q14wrbyxl3Ed13VOFA/2G+nvJR/jgHC42jIH1
76
+
77
+ ### Ruby API
78
+
79
+ The Ruby gem should be easy to use (feedback is obviously welcome).
80
+
81
+ Documentation could be improved; in the meantime, here is a simple example:
82
+
83
+ require 'aws/creds'
84
+ require 'aws'
85
+ creds = AWS::Creds[:default]
86
+ STDERR.puts "Using access key #{creds.access_key_id}"
87
+ AWS.config creds.to_hash
88
+
89
+ ## Contributing
90
+
91
+ 1. Fork it
92
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
93
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
94
+ 4. Push to the branch (`git push origin my-new-feature`)
95
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs = %w[lib test]
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ end
8
+
9
+ desc 'Run tests'
10
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path '../lib', __FILE__
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
4
+
5
+ require 'aws/creds/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'aws-creds'
9
+ spec.version = AWS::Creds::VERSION
10
+ spec.authors = ['Pierre Carrier']
11
+ spec.email = ['pierre@gcarrier.fr']
12
+ spec.description = 'AWS credentials manager'
13
+ spec.summary = 'AWSCreds exposes your AWS credentials through the command line or Ruby API'
14
+ spec.homepage = 'https://github.com/airbnb/gem-aws-creds'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split $/
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename f }
19
+ spec.test_files = spec.files.grep %r{^(test|spec|features)/}
20
+ spec.require_paths = %w[lib]
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'aws-sdk'
25
+
26
+ spec.add_dependency 'trollop', '~> 2.0'
27
+ end
data/bin/awc ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'trollop'
4
+ require 'aws/creds'
5
+
6
+ parser = Trollop::Parser.new do
7
+ banner 'AWS credentials exposer for command-line utilities'
8
+ opt :list, 'List available credentials', :short => '-l'
9
+ opt :verbose, 'Verbose (exposes secrets)', :short => '-v'
10
+ opt :identity, 'Identity', :type => :string, :short => '-i'
11
+ stop_on_unknown
12
+ end
13
+
14
+ opts = Trollop::with_standard_exception_handling parser do
15
+ raise Trollop::HelpNeeded if ARGV.empty?
16
+ parser.parse ARGV
17
+ end
18
+
19
+ def no_keytab path
20
+ STDERR.puts <<-EOH
21
+ awc couldn't find a keytab at #{path}.
22
+
23
+ Please create one with something like:
24
+
25
+ default:AKIAIOSFODNNDEADBEEF:WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWp
26
+ admin:AKIAIOO432MG8BADF00D:T60q14wrbyxl3Ed13VOFA/2G+nvJR/jgHC42jIH1
27
+ EOH
28
+ exit false
29
+ end
30
+
31
+ def list_keys store, verbose=false
32
+ store.each do |name, creds|
33
+ prefix = store.default?(name) ? '*' : ' '
34
+ if verbose
35
+ puts "#{prefix}#{name}\t#{creds.access_key_id}\t#{creds.secret_access_key}"
36
+ else
37
+ puts "#{prefix}#{name}"
38
+ end
39
+ end
40
+ end
41
+
42
+ # set all the environment variables that various AWS tools expect
43
+ def update_env_for creds
44
+ %w[AWS_ACCESS_KEY AWSAccessKeyId AWS_ACCESS_KEY_ID].each do |var|
45
+ ENV[var] = creds.access_key_id
46
+ end
47
+
48
+ %w[AWS_SECRET_KEY AWSSecretKey AWS_SECRET_ACCESS_KEY].each do |var|
49
+ ENV[var] = creds.secret_access_key
50
+ end
51
+ end
52
+
53
+ begin
54
+ store = AWS::Creds::Store.new({:default => opts.identity})
55
+
56
+ if opts.list
57
+ list_keys store, opts.verbose
58
+ else
59
+ update_env_for store.default_keypair
60
+ exec(*ARGV)
61
+ end
62
+ rescue AWS::Creds::MissingKeyTab => e
63
+ no_keytab e.path
64
+ end
@@ -0,0 +1,14 @@
1
+ require 'aws/creds/version'
2
+ require 'aws/creds/store'
3
+ require 'aws/creds/keypair'
4
+
5
+ module AWS; module Creds
6
+ def self.method_missing name, *args, &block
7
+ @@root ||= Store.new
8
+ @@root.method(name).call(*args, &block)
9
+ end
10
+
11
+ def self.refresh
12
+ @@root = Store.new
13
+ end
14
+ end; end
@@ -0,0 +1,32 @@
1
+ module AWS; module Creds
2
+ class InvalidKeyPair < Exception; end
3
+ class InvalidAccessKeyId < InvalidKeyPair; end
4
+ class InvalidSecretAccessKey < InvalidKeyPair; end
5
+
6
+ class KeyPair
7
+ attr_reader :access_key_id, :secret_access_key
8
+
9
+ def initialize access_key_id, secret_access_key
10
+ @access_key_id, @secret_access_key = access_key_id, secret_access_key
11
+ validate
12
+ end
13
+
14
+ # For AWS-SDK compatibility
15
+ def to_hash
16
+ {:access_key_id => access_key_id, :secret_access_key => secret_access_key}
17
+ end
18
+
19
+ # Make it harder to leak secrets by accident
20
+ def to_s
21
+ "<#{self.class}: #{access_key_id[0..9]}...>"
22
+ end
23
+ alias_method :inspect, :to_s
24
+
25
+ private
26
+ def validate
27
+ raise InvalidAccessKeyId.new 'Incorrect length for Access Key ID' unless access_key_id.length == 20
28
+ raise InvalidAccessKeyId.new 'Access Key ID contains invalid characters' unless access_key_id =~ /^[A-Z0-9]{20}$/
29
+ raise InvalidSecretAccessKey.new 'Incorrect length for Secret Access Key' unless secret_access_key.length == 40
30
+ end
31
+ end
32
+ end; end
@@ -0,0 +1,72 @@
1
+ require 'aws/creds/keypair'
2
+
3
+ module AWS; module Creds
4
+ class InvalidKeyTab < Exception
5
+ attr_accessor :path, :msg
6
+ def initialize path, msg=nil
7
+ @path, @msg = path, msg
8
+
9
+ def to_s
10
+ "#{path}: #{msg}"
11
+ end
12
+ end
13
+ end
14
+
15
+ class MissingKeyTab < InvalidKeyTab; end
16
+ class UnsafePerms < InvalidKeyTab; end
17
+
18
+ class Store < Hash
19
+ def initialize opts={}
20
+ # :keytab => false to disable autoloading
21
+ keytab = opts[:keytab] || '~/.awscreds'
22
+ import_keytab keytab if keytab
23
+
24
+ @default = opts[:default]
25
+ @default ||= ENV['AWS_IDENTITY'] unless opts[:ignore_environment]
26
+ @default ||= 'default'
27
+ end
28
+
29
+ def identities
30
+ keys
31
+ end
32
+
33
+ def credentials
34
+ values
35
+ end
36
+
37
+ def [] name
38
+ super name.to_s
39
+ end
40
+
41
+ def default_keypair
42
+ self[@default]
43
+ end
44
+
45
+ def default? name
46
+ name == @default
47
+ end
48
+
49
+ def import_keytab path
50
+ read_config(path).lines.each do |line, idx|
51
+ fields = line.chomp.split ':'
52
+ raise InvalidKeyTab.new path, "missing fields line #{idx}" unless fields.length >= 3
53
+ self[fields[0]] = KeyPair.new fields[1], fields[2]
54
+ end
55
+ self
56
+ end
57
+
58
+ def read_config path
59
+ path = File.expand_path path
60
+
61
+ raise MissingKeyTab.new path, 'does not exist' unless File.exists? path
62
+
63
+ mode = File.stat(path).mode & 07777
64
+
65
+ unless mode & 07077 == 0
66
+ raise UnsafePerms.new path, "unsafe permissions (#{sprintf '%#04o', mode}); please chmod go= #{File.expand_path path}"
67
+ end
68
+
69
+ File.read path
70
+ end
71
+ end
72
+ end; end
@@ -0,0 +1,3 @@
1
+ module AWS; module Creds
2
+ VERSION = '0.2.2'
3
+ end; end
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'aws/creds/keypair'
3
+ require 'aws-sdk'
4
+
5
+ class TestKeyPairs < Test::Unit::TestCase
6
+ INVALID_CASES = {
7
+ AWS::Creds::InvalidAccessKeyId => [
8
+ %w[AKIAIOSFODNNDEADBEE WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWp],
9
+ %w[AKIAIOSFODNNDEADBEEFF WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWp],
10
+ %w[AKIAIOSFODNNDEADBEE$ WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWp],
11
+ ],
12
+ AWS::Creds::InvalidSecretAccessKey => [
13
+ %w[AKIAIOSFODNNDEADBEEF WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcW],
14
+ %w[AKIAIOSFODNNDEADBEEF WT8ftNba7siVx5UOoGzJSyd82uNCZAC8LCllzcWpp],
15
+ ]
16
+ }
17
+
18
+ EXAMPLE = AWS::Creds::KeyPair.new 'F'*10 + '0'*10, '0'*40
19
+
20
+ def test_accessors
21
+ assert_instance_of String, EXAMPLE.access_key_id
22
+ assert_instance_of String, EXAMPLE.secret_access_key
23
+ end
24
+
25
+ def test_validation
26
+ INVALID_CASES.each do |e, list|
27
+ list.each do |pair|
28
+ assert_raise(e) {AWS::Creds::KeyPair.new(*pair)}
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_leaks
34
+ reprs = [EXAMPLE.to_s, EXAMPLE.inspect]
35
+ assert_empty reprs.grep(/0/)
36
+ end
37
+
38
+ def test_aws_sdk
39
+ AWS.config EXAMPLE.to_hash
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-creds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Pierre Carrier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-25 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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
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: trollop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: AWS credentials manager
70
+ email:
71
+ - pierre@gcarrier.fr
72
+ executables:
73
+ - awc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - aws-creds.gemspec
83
+ - bin/awc
84
+ - lib/aws/creds.rb
85
+ - lib/aws/creds/keypair.rb
86
+ - lib/aws/creds/store.rb
87
+ - lib/aws/creds/version.rb
88
+ - test/test_keypairs.rb
89
+ homepage: https://github.com/airbnb/gem-aws-creds
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.0.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: AWSCreds exposes your AWS credentials through the command line or Ruby API
113
+ test_files:
114
+ - test/test_keypairs.rb
115
+ has_rdoc: