conjur-api 4.31.0 → 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +1 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +22 -3
- data/Dockerfile +12 -3
- data/Gemfile +3 -3
- data/Jenkinsfile +69 -0
- data/LICENSE.md +195 -0
- data/README.md +16 -0
- data/Rakefile +34 -18
- data/ci/wait_for_server.sh +10 -0
- data/conjur-api.gemspec +6 -14
- data/dev/docker-compose.yml +23 -0
- data/dev/empty.yml +2 -0
- data/dev/start.sh +15 -0
- data/dev/stop.sh +6 -0
- data/docker-compose.yml +27 -0
- data/features/exists.feature +37 -0
- data/features/group.feature +11 -0
- data/features/host.feature +20 -0
- data/features/host_factory_create_host.feature +28 -0
- data/features/host_factory_token.feature +63 -0
- data/features/load_policy.feature +61 -0
- data/features/members.feature +51 -0
- data/features/new_api.feature +36 -0
- data/features/permitted.feature +43 -0
- data/features/permitted_roles.feature +30 -0
- data/features/public_keys.feature +11 -0
- data/features/resource_fields.feature +53 -0
- data/features/role_fields.feature +15 -0
- data/features/rotate_api_key.feature +13 -0
- data/features/step_definitions/api_steps.rb +4 -54
- data/features/step_definitions/policy_steps.rb +35 -0
- data/features/step_definitions/result_steps.rb +7 -0
- data/features/support/env.rb +14 -5
- data/features/support/hooks.rb +3 -0
- data/features/support/world.rb +5 -6
- data/features/update_password.feature +14 -0
- data/features/user.feature +17 -0
- data/features/variable_fields.feature +20 -0
- data/features/variable_value.feature +67 -0
- data/lib/conjur/acts_as_resource.rb +95 -65
- data/lib/conjur/acts_as_role.rb +102 -51
- data/lib/conjur/{audit-api.rb → acts_as_rolsource.rb} +10 -14
- data/lib/conjur/acts_as_user.rb +13 -22
- data/lib/conjur/api/authn.rb +37 -72
- data/lib/conjur/api/host_factories.rb +35 -55
- data/lib/conjur/api/policies.rb +56 -0
- data/lib/conjur/api/pubkeys.rb +36 -160
- data/lib/conjur/api/resources.rb +32 -116
- data/lib/conjur/api/roles.rb +28 -105
- data/lib/conjur/api/variables.rb +22 -91
- data/lib/conjur/api.rb +19 -46
- data/lib/conjur/base.rb +21 -132
- data/lib/conjur/base_object.rb +57 -0
- data/lib/conjur/{authn-api.rb → build_object.rb} +23 -11
- data/lib/conjur/cast.rb +12 -17
- data/lib/conjur/cert_utils.rb +1 -1
- data/lib/conjur/cidr.rb +1 -1
- data/lib/conjur/configuration.rb +13 -91
- data/lib/conjur/escape.rb +1 -2
- data/lib/conjur/group.rb +9 -65
- data/lib/conjur/has_attributes.rb +22 -59
- data/lib/conjur/host.rb +5 -35
- data/lib/conjur/host_factory.rb +40 -40
- data/lib/conjur/host_factory_token.rb +38 -23
- data/lib/conjur/id.rb +63 -0
- data/lib/conjur/layer.rb +5 -80
- data/lib/conjur/log.rb +1 -1
- data/lib/conjur/log_source.rb +1 -1
- data/lib/conjur/{secret.rb → policy.rb} +11 -14
- data/lib/conjur/{api/secrets.rb → policy_load_result.rb} +35 -22
- data/lib/conjur/query_string.rb +2 -1
- data/lib/conjur/resource.rb +5 -299
- data/lib/conjur/role.rb +5 -317
- data/lib/conjur/role_grant.rb +20 -28
- data/lib/conjur/user.rb +5 -63
- data/lib/conjur/variable.rb +31 -76
- data/lib/conjur/{authz-api.rb → webservice.rb} +8 -16
- data/lib/conjur-api/version.rb +2 -2
- data/publish.sh +7 -0
- data/spec/api_spec.rb +208 -0
- data/spec/cast_spec.rb +21 -0
- data/spec/{lib/cert_utils_spec.rb → cert_utils_spec.rb} +0 -0
- data/spec/{lib/cidr_spec.rb → cidr_spec.rb} +0 -0
- data/spec/{lib/configuration_spec.rb → configuration_spec.rb} +40 -140
- data/spec/{lib/has_attributes_spec.rb → has_attributes_spec.rb} +6 -2
- data/spec/{lib/log_source_spec.rb → log_source_spec.rb} +0 -0
- data/spec/{lib/log_spec.rb → log_spec.rb} +0 -0
- data/spec/roles_spec.rb +24 -0
- data/spec/spec_helper.rb +63 -78
- data/spec/ssl_spec.rb +3 -5
- data/spec/vendor/rest_client_spec.rb +0 -54
- data/test.sh +40 -0
- metadata +122 -281
- data/.kateproject +0 -5
- data/LICENSE +0 -22
- data/ci/test.sh +0 -9
- data/features/audit_resources.feature +0 -15
- data/features/audit_roles.feature +0 -15
- data/features/bootstrap.feature +0 -31
- data/features/step_definitions/cli_steps.rb +0 -5
- data/jenkins.sh +0 -27
- data/lib/conjur/acts_as_asset.rb +0 -88
- data/lib/conjur/annotations.rb +0 -186
- data/lib/conjur/api/audit.rb +0 -138
- data/lib/conjur/api/deputies.rb +0 -57
- data/lib/conjur/api/groups.rb +0 -111
- data/lib/conjur/api/hosts.rb +0 -109
- data/lib/conjur/api/info.rb +0 -126
- data/lib/conjur/api/layers.rb +0 -62
- data/lib/conjur/api/ldapsync.rb +0 -115
- data/lib/conjur/api/users.rb +0 -106
- data/lib/conjur/bootstrap.rb +0 -161
- data/lib/conjur/build_from_response.rb +0 -49
- data/lib/conjur/core-api.rb +0 -74
- data/lib/conjur/deputy.rb +0 -55
- data/lib/conjur/env.rb +0 -54
- data/lib/conjur/event_source.rb +0 -101
- data/lib/conjur/exists.rb +0 -60
- data/lib/conjur/graph.rb +0 -295
- data/lib/conjur/has_id.rb +0 -43
- data/lib/conjur/has_identifier.rb +0 -36
- data/lib/conjur/has_owner.rb +0 -51
- data/lib/conjur/host-factory-api.rb +0 -38
- data/lib/conjur/layer-api.rb +0 -13
- data/lib/conjur/ldap_sync_job.rb +0 -89
- data/lib/conjur/path_based.rb +0 -86
- data/lib/conjur/pubkeys-api.rb +0 -50
- data/lib/conjur/standard_methods.rb +0 -91
- data/reqspeed.rb +0 -20
- data/spec/api/authn_spec.rb +0 -81
- data/spec/api/graph_spec.rb +0 -117
- data/spec/api/groups_spec.rb +0 -40
- data/spec/api/hosts_spec.rb +0 -36
- data/spec/api/info_spec.rb +0 -89
- data/spec/api/layer_spec.rb +0 -18
- data/spec/api/ldapsync_spec.rb +0 -44
- data/spec/api/pubkeys_spec.rb +0 -66
- data/spec/api/resources_spec.rb +0 -92
- data/spec/api/roles_spec.rb +0 -100
- data/spec/api/secrets_spec.rb +0 -16
- data/spec/api/users_spec.rb +0 -71
- data/spec/api/variables_spec.rb +0 -112
- data/spec/cas_rest_client.rb +0 -17
- data/spec/cidr_helper.rb +0 -24
- data/spec/lib/acts_as_user_spec.rb +0 -27
- data/spec/lib/annotations_spec.rb +0 -109
- data/spec/lib/api_spec.rb +0 -480
- data/spec/lib/asset_spec.rb +0 -80
- data/spec/lib/audit_spec.rb +0 -155
- data/spec/lib/build_from_response_spec.rb +0 -49
- data/spec/lib/deputy_spec.rb +0 -25
- data/spec/lib/exists_spec.rb +0 -24
- data/spec/lib/group_spec.rb +0 -18
- data/spec/lib/host_spec.rb +0 -31
- data/spec/lib/resource_spec.rb +0 -240
- data/spec/lib/role_grant_spec.rb +0 -13
- data/spec/lib/role_spec.rb +0 -231
- data/spec/lib/standard_methods_spec.rb +0 -66
- data/spec/lib/user_spec.rb +0 -77
- data/spec/standard_methods_helper.rb +0 -41
- data/spec/variable_spec.rb +0 -101
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_path-like_identifier.yml +0 -87
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_un-encoded_path-like_identifier.yml +0 -87
- data/spec/vcr_cassettes/Conjur_Resource/_create/with_uuid_identifier.yml +0 -87
data/lib/conjur/graph.rb
DELETED
@@ -1,295 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2015 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
|
-
module Conjur
|
22
|
-
|
23
|
-
# A Graph represents a directed graph of roles.
|
24
|
-
#
|
25
|
-
# An instance of this class is returned by {Conjur::API#role_graph}.
|
26
|
-
#
|
27
|
-
# @example Graphs act like arrays of edges
|
28
|
-
# graph.each do |edge|
|
29
|
-
# puts "#{edge.parent} -> #{edge.child}"
|
30
|
-
# end
|
31
|
-
# # role1 -> role2
|
32
|
-
# # role2 -> role3
|
33
|
-
#
|
34
|
-
class Graph
|
35
|
-
|
36
|
-
include Enumerable
|
37
|
-
|
38
|
-
# Returns an array containing the directed edges of the graph.
|
39
|
-
#
|
40
|
-
# @return [Array<Conjur::Graph::Edge>] the edges of this graph
|
41
|
-
attr_reader :edges
|
42
|
-
|
43
|
-
# @api private
|
44
|
-
#
|
45
|
-
# @param val [String, Hash, Array, Graph] Data from which to initialize the instance
|
46
|
-
def initialize val
|
47
|
-
@edges = case val
|
48
|
-
when String then JSON.parse(val)['graph']
|
49
|
-
when Hash then val['graph']
|
50
|
-
when Array then val
|
51
|
-
when Graph then val.edges
|
52
|
-
else raise ArgumentError, "don't know how to turn #{val}:#{val.class} into a Graph"
|
53
|
-
end.map{|pair| Edge.new(*pair) }.freeze
|
54
|
-
@next_node_id = 0
|
55
|
-
@node_ids = Hash.new
|
56
|
-
end
|
57
|
-
|
58
|
-
# Enumerates the edges of this graph.
|
59
|
-
#
|
60
|
-
# @yieldparam [Conjur::Graph::Edge] edge each edge of the graph
|
61
|
-
# @return [Conjur::Graph] this graph
|
62
|
-
def each_edge
|
63
|
-
return enum_for(__method__) unless block_given?
|
64
|
-
edges.each{|e| yield e}
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
alias each each_edge
|
69
|
-
|
70
|
-
# Enumerates the vertices (roles) of this graph
|
71
|
-
# @yieldparam [Conjur::Role] vertex each vertex in this graph
|
72
|
-
# @return [Conjur::Graph] this graph
|
73
|
-
def each_vertex
|
74
|
-
return enum_for(__method__) unless block_given?
|
75
|
-
vertices.each{|v| yield v}
|
76
|
-
end
|
77
|
-
|
78
|
-
# Serialize the graph as JSON
|
79
|
-
# @param [Boolean] short when true, the graph is serialized as an array of arrays instead of an array of hashes.
|
80
|
-
# @return [String] the JSON serialized graph.
|
81
|
-
# @see #as_json
|
82
|
-
#
|
83
|
-
def to_json short = false
|
84
|
-
as_json(short).to_json
|
85
|
-
end
|
86
|
-
|
87
|
-
# Convert the graph to a JSON serializable data structure. The value returned by this method can have two
|
88
|
-
# forms: An array of arrays when `short` is `true`, or hash like
|
89
|
-
# `{ 'graph' => [ {'parent' => 'roleid', 'child' => 'roleid'} ]}` otherwise.
|
90
|
-
#
|
91
|
-
# @example Graph formats
|
92
|
-
# graph = api.role_graph 'conjur:group:pubkeys-1.0/key-managers'
|
93
|
-
#
|
94
|
-
# # Short format
|
95
|
-
# graph.as_json true
|
96
|
-
# # => [
|
97
|
-
# # ["conjur:group:pubkeys-1.0/key-managers", "conjur:group:pubkeys-1.0/admin"],
|
98
|
-
# # ["conjur:group:pubkeys-1.0/admin", "conjur:user:admin"]
|
99
|
-
# # ]
|
100
|
-
#
|
101
|
-
# # Default format (you can omit the false parameter in this case)
|
102
|
-
# graph.as_json false
|
103
|
-
# # => {
|
104
|
-
# # "graph" => [
|
105
|
-
# # {"parent"=>"conjur:group:pubkeys-1.0/key-managers", "child"=>"conjur:group:pubkeys-1.0/admin"},
|
106
|
-
# # {"parent"=>"conjur:group:pubkeys-1.0/admin", "child"=>"conjur:user:admin"}
|
107
|
-
# # ]
|
108
|
-
# #}
|
109
|
-
#
|
110
|
-
# @param [Boolean] short whether to use short of default format
|
111
|
-
# @return [Hash, Array] JSON serializable representation of the graph
|
112
|
-
def as_json short = false
|
113
|
-
edges = self.edges.map{|e| e.as_json(short)}
|
114
|
-
short ? edges : {'graph' => edges}
|
115
|
-
end
|
116
|
-
|
117
|
-
# Returns a string formatted for use by the {http://www.graphviz.org/ graphviz dot} tool.
|
118
|
-
#
|
119
|
-
# @param [String, NilClass] name An identifier to assign to the graph. This can be omitted unless you
|
120
|
-
# are writing multiple graphs to a single file. This must be in the ID format specified by
|
121
|
-
# http://www.graphviz.org/content/dot-language.
|
122
|
-
#
|
123
|
-
# @return [String] the dot format (used by graphviz, among others) representation of this graph.
|
124
|
-
def to_dot name = nil
|
125
|
-
dot = "digraph #{name || ''} {"
|
126
|
-
vertices.each do |v|
|
127
|
-
dot << "\n\t" << dot_node(v)
|
128
|
-
end
|
129
|
-
edges.each do |e|
|
130
|
-
dot << "\n\t" << dot_edge(e)
|
131
|
-
end
|
132
|
-
dot << "\n}"
|
133
|
-
end
|
134
|
-
|
135
|
-
# Return the vertices (roles) of the graph as an array.
|
136
|
-
# @return [Array<Conjur::Role>] the vertices/roles
|
137
|
-
def vertices
|
138
|
-
@vertices ||= edges.inject([]) {|a, pair| a.concat pair.to_a }.uniq
|
139
|
-
end
|
140
|
-
|
141
|
-
alias roles vertices
|
142
|
-
|
143
|
-
private
|
144
|
-
|
145
|
-
def node_id_for role
|
146
|
-
role = role.id if role.respond_to?(:id)
|
147
|
-
node_id = @node_ids[role]
|
148
|
-
if node_id.nil?
|
149
|
-
node_id = @node_ids[role] = next_node_id
|
150
|
-
end
|
151
|
-
node_id
|
152
|
-
end
|
153
|
-
|
154
|
-
def next_node_id
|
155
|
-
id = @next_node_id
|
156
|
-
@next_node_id += 1
|
157
|
-
"node_#{id}"
|
158
|
-
end
|
159
|
-
|
160
|
-
def node_label_for role
|
161
|
-
role = role.id if role.respond_to? :id
|
162
|
-
if single_account?
|
163
|
-
role = role.split(':', 2).last
|
164
|
-
if single_kind?
|
165
|
-
role = role.split(':', 2).last
|
166
|
-
end
|
167
|
-
end
|
168
|
-
role
|
169
|
-
end
|
170
|
-
|
171
|
-
def single_account?
|
172
|
-
if @single_account.nil?
|
173
|
-
@single_account = roles.map do |role|
|
174
|
-
role = role.id if role.respond_to?(:id)
|
175
|
-
role.split(':').first
|
176
|
-
end.uniq.size == 1
|
177
|
-
end
|
178
|
-
@single_account
|
179
|
-
end
|
180
|
-
|
181
|
-
def single_kind?
|
182
|
-
if @single_kind.nil?
|
183
|
-
return @single_kind = false unless single_account?
|
184
|
-
@single_kind = roles.map do |role|
|
185
|
-
role = role.id if role.respond_to?(:id)
|
186
|
-
role.split(':')[1]
|
187
|
-
end.uniq.size == 1
|
188
|
-
end
|
189
|
-
@single_kind
|
190
|
-
end
|
191
|
-
|
192
|
-
def dot_node v
|
193
|
-
id = node_id_for v
|
194
|
-
label = node_label_for v
|
195
|
-
"#{id} [label=\"#{label}\"]"
|
196
|
-
end
|
197
|
-
|
198
|
-
def dot_edge e
|
199
|
-
parent_id = node_id_for(e.parent)
|
200
|
-
child_id = node_id_for(e.child)
|
201
|
-
"#{parent_id} -> #{child_id}"
|
202
|
-
end
|
203
|
-
|
204
|
-
# Represents a directed Edge between a parent role and a child role.
|
205
|
-
#
|
206
|
-
# In this context, the parent role is a *member of* the child role. For example,
|
207
|
-
# the `admin` role is a parent of every role, either directly or indirectly, because
|
208
|
-
# it is added as a member to all roles it creates.
|
209
|
-
class Edge
|
210
|
-
|
211
|
-
# Return the parent of this edge. The {#parent} role *is a member of* the {#child} role.
|
212
|
-
# @return [Conjur::Role] the parent role
|
213
|
-
attr_reader :parent
|
214
|
-
|
215
|
-
# Return the child of this edge. The {#parent} role *is a member of* the {#child} role.
|
216
|
-
# @return [Conjur::Role] the child role
|
217
|
-
attr_reader :child
|
218
|
-
|
219
|
-
# Was the role granted with admin_option? May be nil if unknown
|
220
|
-
# (e.g. if the server doesn't return it).
|
221
|
-
attr_reader :admin_option
|
222
|
-
alias :admin_option? :admin_option
|
223
|
-
|
224
|
-
# Create a directed edge with a parent and child
|
225
|
-
#
|
226
|
-
# @param [Conjur::Role] parent the parent or source of this edge
|
227
|
-
# @param [Conjur::Role] child the child or destination of this edge
|
228
|
-
def initialize parent, child, admin_option = nil
|
229
|
-
@parent = parent
|
230
|
-
@child = child
|
231
|
-
@admin_option = admin_option
|
232
|
-
end
|
233
|
-
|
234
|
-
# Serialize this edge as JSON.
|
235
|
-
#
|
236
|
-
# @see #as_json
|
237
|
-
# @param [Boolean] short when true, serialize the edge as an Array instead of a Hash
|
238
|
-
# @return [String] the JSON serialized edge
|
239
|
-
def to_json short = false
|
240
|
-
as_json(short).to_json
|
241
|
-
end
|
242
|
-
|
243
|
-
# Return a value suitable for JSON serialization.
|
244
|
-
#
|
245
|
-
# The `short` parameter determines whether to return a `["parent", "child"]` Array
|
246
|
-
# or a Hash like `{"parent" => "parent-role", "child" => "child-role"}`.
|
247
|
-
#
|
248
|
-
# @param [Boolean] short return an Array when true, otherwise return a Hash.
|
249
|
-
# @return [Array, Hash] value suitable for JSON serialization
|
250
|
-
def as_json short = false
|
251
|
-
short ? to_a : to_h
|
252
|
-
end
|
253
|
-
|
254
|
-
# Return this edge as a Hash like {"parent" => "...", "child" => "..."}.
|
255
|
-
#
|
256
|
-
# Note that the keys in the hash are strings.
|
257
|
-
#
|
258
|
-
# @return [Hash] a Hash representing this edge
|
259
|
-
def to_h
|
260
|
-
# return string keys to make testing less brittle
|
261
|
-
{'parent' => @parent, 'child' => @child}.tap {|h| h['admin_option'] = @admin_option unless @admin_option.nil?}
|
262
|
-
end
|
263
|
-
|
264
|
-
# Return this edge as an Array like ["parent", "child"]
|
265
|
-
#
|
266
|
-
# @return [Array<String>] the edge as an Array
|
267
|
-
def to_a
|
268
|
-
[@parent, @child].tap {|a| a.push(@admin_option) unless @admin_option.nil?}
|
269
|
-
end
|
270
|
-
|
271
|
-
# @api private
|
272
|
-
# :nodoc:
|
273
|
-
def to_s
|
274
|
-
"<Edge #{parent.id} --> #{child.id} (admin: #{@admin_option.inspect})>"
|
275
|
-
end
|
276
|
-
|
277
|
-
# Support using edges as hash keys
|
278
|
-
# @api private
|
279
|
-
# :nodoc:
|
280
|
-
def hash
|
281
|
-
@hash ||= to_a.map(&:to_s).hash
|
282
|
-
end
|
283
|
-
|
284
|
-
# Support using edges as hash keys and equality testing
|
285
|
-
# @api private
|
286
|
-
# :nodoc:
|
287
|
-
def == other
|
288
|
-
other.kind_of?(self.class) and other.parent == parent and other.child == child
|
289
|
-
end
|
290
|
-
|
291
|
-
alias eql? ==
|
292
|
-
end
|
293
|
-
|
294
|
-
end
|
295
|
-
end
|
data/lib/conjur/has_id.rb
DELETED
@@ -1,43 +0,0 @@
|
|
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
|
-
module Conjur
|
22
|
-
|
23
|
-
# Included in classes for assets that derive their id from their urls.
|
24
|
-
module HasId
|
25
|
-
# @api private
|
26
|
-
# This method is provided to support basic JSON serialization for all objects with `id`s.
|
27
|
-
#
|
28
|
-
# @param [Hash] options provided for backwards compatibility, do not use.
|
29
|
-
# @return [Hash] the JSON hash.
|
30
|
-
def to_json(options = {})
|
31
|
-
{ id: id }
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
# Get this assets id. This is the *unqualified* Conjur id for the asset,
|
36
|
-
# and is derived from the asset's url.
|
37
|
-
#
|
38
|
-
# @return [String] the asset's id
|
39
|
-
def id
|
40
|
-
URI.unescape self.url.split('/')[-1]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,36 +0,0 @@
|
|
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
|
-
module Conjur
|
22
|
-
# Included in Conjur assets that have an identifier attribute.
|
23
|
-
module HasIdentifier
|
24
|
-
include HasAttributes
|
25
|
-
|
26
|
-
# Get the identifier attribute. This is a *fully qualified* Conjur id.
|
27
|
-
#
|
28
|
-
# ### Permissions
|
29
|
-
# You must have the "`read`" permission on the underlying resource to call this method.
|
30
|
-
#
|
31
|
-
# @return [String] the asset's fully qualified id
|
32
|
-
def identifier
|
33
|
-
attributes['identifier']
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/conjur/has_owner.rb
DELETED
@@ -1,51 +0,0 @@
|
|
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
|
-
module Conjur
|
22
|
-
# Included in assets that have an *owner*.
|
23
|
-
module HasOwner
|
24
|
-
include HasAttributes
|
25
|
-
|
26
|
-
# Return the `userid` attribute. This is the id of the Conjur role that
|
27
|
-
# created this asset.
|
28
|
-
#
|
29
|
-
# ### Permissions
|
30
|
-
# You must have the "`read`" permission on the underlying resource to call this method.
|
31
|
-
#
|
32
|
-
# @return [String] the userid
|
33
|
-
def userid
|
34
|
-
attributes['userid']
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
# Return the owner of this resource or asset.
|
39
|
-
#
|
40
|
-
# The owner of a resource or an asset with an underlying resource is allowed to do anything to the resource,
|
41
|
-
# including granting permissions to other roles.
|
42
|
-
#
|
43
|
-
# ### Permissions
|
44
|
-
# You must have the "`read`" permission on the underlying resource to call this method.
|
45
|
-
#
|
46
|
-
# @return [String] the fully qualified role id of the asset's owner.
|
47
|
-
def ownerid
|
48
|
-
attributes['ownerid']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2014 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 'conjur/api'
|
22
|
-
require 'conjur/configuration'
|
23
|
-
|
24
|
-
class Conjur::Configuration
|
25
|
-
add_option :host_factory_url do
|
26
|
-
account_service_url 'host_factories', 500
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Conjur::API
|
31
|
-
class << self
|
32
|
-
def host_factory_asset_host
|
33
|
-
Conjur.configuration.host_factory_url
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
require 'conjur/api/host_factories'
|
data/lib/conjur/layer-api.rb
DELETED
data/lib/conjur/ldap_sync_job.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'conjur/event_source'
|
2
|
-
|
3
|
-
module Conjur
|
4
|
-
class LdapSyncJob
|
5
|
-
|
6
|
-
attr_reader :hash
|
7
|
-
|
8
|
-
# Creates a new `LdapSyncJob` from a Hash as returned
|
9
|
-
# by the LDAP sync service's `GET /jobs` route.
|
10
|
-
def self.new_from_json api, hash
|
11
|
-
new(api, hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize api, hash
|
15
|
-
@api = api
|
16
|
-
@hash = hash.with_indifferent_access
|
17
|
-
end
|
18
|
-
|
19
|
-
def exclusive?
|
20
|
-
self.exclusive
|
21
|
-
end
|
22
|
-
|
23
|
-
def [](k)
|
24
|
-
@hash[k]
|
25
|
-
end
|
26
|
-
|
27
|
-
def method_missing(sym, *arguments, &block)
|
28
|
-
@hash[sym]
|
29
|
-
end
|
30
|
-
|
31
|
-
# Stop this job (if running) and remove it from the list of jobs.
|
32
|
-
def delete
|
33
|
-
job_resource.delete
|
34
|
-
end
|
35
|
-
|
36
|
-
# Receive output from this job and pass them to the given block.
|
37
|
-
def output &block
|
38
|
-
events = []
|
39
|
-
wrapper = lambda do |e|
|
40
|
-
events << e
|
41
|
-
block[e] if block
|
42
|
-
end
|
43
|
-
|
44
|
-
follow_job_output(&wrapper)
|
45
|
-
|
46
|
-
events
|
47
|
-
end
|
48
|
-
|
49
|
-
def to_s
|
50
|
-
"<LdapSyncJob #{id} type=#{type} state=#{state}#{exclusive? ? ' exclusive' : ''}>"
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_h
|
54
|
-
@hash
|
55
|
-
end
|
56
|
-
|
57
|
-
alias as_json to_h
|
58
|
-
|
59
|
-
def to_json _unused
|
60
|
-
as_json.to_json
|
61
|
-
end
|
62
|
-
private
|
63
|
-
|
64
|
-
def follow_job_output &block
|
65
|
-
options = @api.credentials.dup.tap{|h| h[:headers][:accept] = 'text/event-stream'}
|
66
|
-
|
67
|
-
handle_response = lambda do |response|
|
68
|
-
response.error! unless response.code == '200'
|
69
|
-
es = EventSource.new
|
70
|
-
es.message{ |e| block[e.data] }
|
71
|
-
|
72
|
-
response.read_body do |chunk|
|
73
|
-
es.feed chunk
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
RestClient::Request.execute(
|
78
|
-
url: "#{job_resource['output'].url}",
|
79
|
-
headers: options[:headers],
|
80
|
-
method: :get,
|
81
|
-
block_response: handle_response
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
def job_resource
|
86
|
-
RestClient::Resource.new(Conjur.configuration.appliance_url, @api.credentials)['ldap-sync']['jobs'][id]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/lib/conjur/path_based.rb
DELETED
@@ -1,86 +0,0 @@
|
|
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
|
-
module Conjur
|
22
|
-
# This module provides methods for determining Conjur id components from an asset's
|
23
|
-
# REST URL.
|
24
|
-
module PathBased
|
25
|
-
# Return the Conjur {http://developer.conjur.net/reference/services/authorization#Organization.Account
|
26
|
-
# organizational account} for this role or resource. The `account`
|
27
|
-
# is the first token in a fully qualified Conjur id, like `"account:kind:identifier"`
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# role = api.role 'foo:bar:baz'
|
31
|
-
# role.account # => 'foo'
|
32
|
-
#
|
33
|
-
# @return [String] the Conjur organizational account
|
34
|
-
def account
|
35
|
-
match_path(0..0)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Return the *kind* for this role or resource. The kind partitions the space of roles and resources, generally
|
39
|
-
# according to their purpose (for example, roles representing users have kind `'user'`). The `kind` of a role or
|
40
|
-
# resource is the second token of a fully qualified Conjur id, like `"account:kind:identifier"`.
|
41
|
-
#
|
42
|
-
# @example Get the kind of a role
|
43
|
-
# role = api.host('postgres-1').role
|
44
|
-
# role.kind # => 'host'
|
45
|
-
#
|
46
|
-
# @example Get the kind of a resource
|
47
|
-
# res = api.host('postgres-1').resource
|
48
|
-
# res.kind # => 'host'
|
49
|
-
#
|
50
|
-
# @return [String] the kind of the role or resource
|
51
|
-
def kind
|
52
|
-
match_path(2..2)
|
53
|
-
end
|
54
|
-
|
55
|
-
protected
|
56
|
-
|
57
|
-
# @api private
|
58
|
-
#
|
59
|
-
# Returns the path parts in the given range.
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# self.url # => "https://10.0.3.100/api/authz/foo/roles/bar/baz"
|
63
|
-
# self.match_path 0..2 # => "foo/roles/bar"
|
64
|
-
# self.match_path 2..-1 # => "bar/baz"
|
65
|
-
#
|
66
|
-
# @param [Range] range the range of parts
|
67
|
-
# @return [String] the parts joined by `'/'`
|
68
|
-
def match_path(range)
|
69
|
-
tokens[range].map{|t| URI.unescape(t)}.join('/')
|
70
|
-
end
|
71
|
-
|
72
|
-
# @api private
|
73
|
-
#
|
74
|
-
# Returns the components of this asset's path starting with the first component
|
75
|
-
# that isn't part of the authz service url.
|
76
|
-
#
|
77
|
-
# @example
|
78
|
-
# self.url # => "https://10.0.3.100/api/authz/foo/roles/bar/baz"
|
79
|
-
# self.tokens # => ["foo", "roles", "bar", "baz"]
|
80
|
-
#
|
81
|
-
# @return [Array<String>] the path components
|
82
|
-
def tokens
|
83
|
-
self.url[RestClient::Resource.new(Conjur::Authz::API.host)[''].url.length..-1].split('/')
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|