conjur-asset-layer-api 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75c346bdbbbec93a6f0cf0e089bf17c8f21bc5a4
4
- data.tar.gz: e2f4155db409c0e607d8f7fe6a76136c3797f8bf
3
+ metadata.gz: e6ed26817bdc07935f87aa6fd739aeb23d334751
4
+ data.tar.gz: 853310d1208e67ebb1b3115a94f2934dda0293df
5
5
  SHA512:
6
- metadata.gz: b8a00cc6e4dd4140e7e83e1ab92ae98a8b76db8a5f4b9218b4a97827058387e764ce4bd01d1b852c3bf340c434629c30c00f487caf2ad35c0a1f260b6429f7e6
7
- data.tar.gz: 61b0dde9e21e3e97cd189407464da496ece39d8b644265529c5a89471dc6a359cfd140a81ab6f977ed71cfe93e9984b2311e8856914bb0a21a4598aa4a3d774b
6
+ metadata.gz: 0d3f6f126a4eb1c37fda76302681ce6fa9cac97580c9b1050b45a363dfd3b844ae2daf9cb710e1477aad42c39c1583efad8fd70db17364438116e5ccb71df068
7
+ data.tar.gz: feae14898a11262a406b2a8efede4dc20c9423011a9844183d2e76bf28b4d39642632e084d3d4cca049c6620eb338838e50b616255a818029d99e2100d95de20
@@ -57,5 +57,6 @@ Gem::Specification.new do |s|
57
57
  s.add_development_dependency "webmock"
58
58
  s.add_development_dependency "json_spec"
59
59
  s.add_development_dependency "ci_reporter"
60
+ s.add_development_dependency "aws-sdk"
60
61
  end
61
62
  end
@@ -13,7 +13,35 @@ class Conjur::Command::Layers < Conjur::Command
13
13
  hostid
14
14
  end
15
15
 
16
- desc "Add a host to an layer (note: host id should be provided in fully-qualified format, i.e. <conjur_account>:host:<id>)"
16
+ desc "Provision a layer by creating backing resources in an IaaS / PaaS system"
17
+ arg_name "layer"
18
+ command :provision do |c|
19
+ c.desc "Provisioner to use (aws)"
20
+ c.arg_name "provisioner"
21
+ c.flag [ :provisioner ]
22
+
23
+ c.desc "Variable holding a credential used to connect to the provisioner"
24
+ c.arg_name "variableid"
25
+ c.flag [ :credential ]
26
+
27
+ c.action do |global_options, options, args|
28
+ id = require_arg(args, 'layer')
29
+ provisioner = options[:provisioner] or exit_now!("Missing argument: provisioner")
30
+ credential = options[:credential] or exit_now!("Missing argument: credential")
31
+ raise "Supported provisioners: aws" unless provisioner == "aws"
32
+
33
+ require "conjur/provisioner/layer/aws"
34
+
35
+ layer = api.layer(id)
36
+ class << layer
37
+ include Conjur::Provisioner::Layer::AWS
38
+ end
39
+ layer.aws_credentialid = credential
40
+ layer.provision
41
+ end
42
+ end
43
+
44
+ desc "Add a host to an layer"
17
45
  arg_name "layer host"
18
46
  command :"hosts:add" do |c|
19
47
  c.action do |global_options, options, args|
@@ -0,0 +1,143 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'aws'
22
+
23
+ module Conjur
24
+ module Provisioner
25
+ module Layer
26
+ module AWS
27
+ def self.included(base)
28
+ base.instance_eval do
29
+ attr_accessor :aws_credentialid
30
+ end
31
+ end
32
+
33
+ def aws_role
34
+ aws_iam.role[self.id.parameterize]
35
+ end
36
+
37
+ # Creates an AWS IAM Role corresponding to the Layer. The Role can be assumed by EC2 instances.
38
+ # Creates a system user (deputy) and adds it to the layer.
39
+ # In S3, a file is created with the identity of the system user, along with other
40
+ # information needed by Conjur chef-solo. The file is in chef-solo JSON format.
41
+ # It will be used by the [conjur-client Upstart job](https://github.com/conjur-cookbooks/conjur-client/blob/master/templates/default/conjur-bootstrap.conf.erb)
42
+ # to finish the server configuration.
43
+ def provision
44
+ aws_create_role
45
+ aws_create_s3_bootstrap_file
46
+ end
47
+
48
+ protected
49
+
50
+ def aws_bucket_name
51
+ "conjur-#{Conjur.account}-bootstrap"
52
+ end
53
+
54
+ def aws_role_name
55
+ self.id.parameterize
56
+ end
57
+
58
+ def aws_bootstrap_file_name
59
+ [ aws_role_name, ".json" ].join
60
+ end
61
+
62
+ def aws_create_s3_bootstrap_file
63
+ bucket = aws_s3.buckets[aws_bucket_name]
64
+ bucket = aws_s3.buckets.create(aws_bucket_name) unless bucket.exists?
65
+
66
+ host = begin
67
+ conjur_api.create_host id: [ id, "ec2_instance" ].join('/')
68
+ rescue
69
+ conjur_api.host [ id, "ec2_instance" ].join('/')
70
+ end
71
+ add_host host.roleid
72
+
73
+ solo_json = {
74
+ "conjur" => {
75
+ "host_identity" => {
76
+ "id" => host.id,
77
+ "api_key" => host.api_key
78
+ }
79
+ },
80
+ "run_list" => [
81
+ "terminal-login::configure"
82
+ ]
83
+ }
84
+
85
+ bucket.objects[aws_bootstrap_file_name].write JSON.pretty_generate(solo_json)
86
+ end
87
+
88
+ def aws_credentials
89
+ raise "No aws credentialid provided" unless aws_credentialid
90
+ require 'json'
91
+ @aws_credentials ||= JSON.parse(conjur_api.variable(aws_credentialid).value).symbolize_keys
92
+ end
93
+
94
+ def aws_iam
95
+ @aws_iam ||= ::AWS::IAM.new aws_credentials
96
+ end
97
+
98
+ def aws_s3
99
+ @aws_s3 ||= ::AWS::S3.new aws_credentials
100
+ end
101
+
102
+ def aws_create_role
103
+ path = self.id.split('/')[0...-1].join('/')
104
+ policy = {
105
+ "Version" => "2012-10-17",
106
+ "Statement" => [
107
+ {
108
+ "Effect" => "Allow",
109
+ "Principal" => {
110
+ "Service" => "ec2.amazonaws.com"
111
+ },
112
+ "Action" => "sts:AssumeRole"
113
+ }
114
+ ]
115
+ }
116
+ role_params = {
117
+ role_name: aws_role_name,
118
+ assume_role_policy_document: JSON.pretty_generate(policy)
119
+ }
120
+ instance_profile_params = {
121
+ instance_profile_name: aws_role_name
122
+ }
123
+
124
+ # keg: I don't really get the purpose of 'path'
125
+ # instance_profile_params[:path] = role_params[:path] = [ '/', path, '/' ].join unless path.blank?
126
+
127
+ role = aws_iam.client.create_role role_params
128
+ instance_profile = aws_iam.client.create_instance_profile instance_profile_params
129
+ aws_iam.client.add_role_to_instance_profile role_name: aws_role_name, instance_profile_name: aws_role_name
130
+
131
+ aws_iam.client.put_role_policy role_name: aws_role_name, policy_name: 'read-bootstrap-file', policy_document: JSON.pretty_generate({
132
+ "Statement" => [{
133
+ "Effect" => "Allow",
134
+ "Action" => "s3:GetObject",
135
+ "Resource" => ["arn:aws:s3:::#{aws_bucket_name}/#{aws_bootstrap_file_name}"]
136
+ }
137
+ ]
138
+ })
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,7 +1,7 @@
1
1
  module Conjur
2
2
  module Asset
3
3
  module Layer
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-asset-layer-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-09 00:00:00.000000000 Z
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: conjur-api
@@ -71,6 +71,7 @@ files:
71
71
  - lib/conjur/command/layers.rb
72
72
  - lib/conjur/layer-api.rb
73
73
  - lib/conjur/layer.rb
74
+ - lib/conjur/provisioner/layer/aws.rb
74
75
  homepage: http://conjur.net
75
76
  licenses: []
76
77
  metadata: {}