conjur-api 2.4.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +2 -0
  2. data/LICENSE +1 -1
  3. data/Rakefile +3 -1
  4. data/conjur-api.gemspec +3 -1
  5. data/lib/conjur-api/version.rb +1 -1
  6. data/lib/conjur/has_id.rb +1 -1
  7. data/lib/conjur/log.rb +6 -26
  8. data/lib/conjur/resource.rb +10 -1
  9. data/manual/asset/about.markdown +12 -0
  10. data/manual/asset/members.add.markdown +52 -0
  11. data/manual/asset/show.markdown +50 -0
  12. data/manual/group/about.markdown +6 -0
  13. data/manual/group/create.markdown +20 -0
  14. data/manual/host/about.markdown +23 -0
  15. data/manual/host/create.markdown +34 -0
  16. data/manual/host/enroll.markdown +21 -0
  17. data/manual/resource/about.markdown +11 -0
  18. data/manual/resource/create.markdown +29 -0
  19. data/manual/resource/deny.markdown +23 -0
  20. data/manual/resource/permit.markdown +35 -0
  21. data/manual/role/about.markdown +10 -0
  22. data/manual/role/members.markdown +40 -0
  23. data/manual/role/memberships.markdown +26 -0
  24. data/spec/api/authn_spec.rb +49 -0
  25. data/spec/api/groups_spec.rb +24 -0
  26. data/spec/api/hosts_spec.rb +29 -0
  27. data/spec/api/resources_spec.rb +19 -0
  28. data/spec/api/secrets_spec.rb +16 -0
  29. data/spec/api/users_spec.rb +16 -0
  30. data/spec/api/variables_spec.rb +14 -0
  31. data/spec/cas_rest_client.rb +17 -0
  32. data/spec/io_helper.rb +18 -0
  33. data/spec/lib/build_from_response_spec.rb +49 -0
  34. data/spec/lib/host_spec.rb +12 -8
  35. data/spec/lib/log_source_spec.rb +13 -0
  36. data/spec/lib/log_spec.rb +42 -0
  37. data/spec/lib/resource_spec.rb +98 -5
  38. data/spec/lib/role_grant_spec.rb +12 -0
  39. data/spec/lib/role_spec.rb +83 -3
  40. data/spec/lib/standard_methods_spec.rb +66 -0
  41. data/spec/lib/user_spec.rb +2 -1
  42. data/spec/spec_helper.rb +27 -0
  43. data/spec/standard_methods_helper.rb +30 -0
  44. data/spec/variable_spec.rb +41 -0
  45. metadata +71 -8
  46. data/.rvmrc +0 -1
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  .kateproject.d
20
+ .rvmrc
21
+
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Rafał Rzepecki
1
+ Copyright (c) 2012 Conjur Inc
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -3,7 +3,9 @@ require "bundler/gem_tasks"
3
3
 
4
4
  begin
5
5
  require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec)
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.rspec_opts = '--order rand'
8
+ end
7
9
  rescue LoadError
8
10
  $stderr.puts "RSpec Rake tasks not available in environment #{ENV['RACK_ENV']}"
9
11
  end
data/conjur-api.gemspec CHANGED
@@ -3,10 +3,11 @@ require File.expand_path('../lib/conjur-api/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Rafa\305\202 Rzepecki","Kevin Gilpin"]
6
- gem.email = ["divided.mind@gmail.com","kevin.gilpin@inscitiv.com"]
6
+ gem.email = ["divided.mind@gmail.com","kgilpin@conjur.net"]
7
7
  gem.description = %q{Conjur API}
8
8
  gem.summary = %q{Conjur API}
9
9
  gem.homepage = ""
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.files = `git ls-files`.split($\) + Dir['build_number']
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -23,4 +24,5 @@ Gem::Specification.new do |gem|
23
24
  gem.add_development_dependency 'rspec'
24
25
  gem.add_development_dependency 'webmock'
25
26
  gem.add_development_dependency 'ci_reporter'
27
+ gem.add_development_dependency 'simplecov'
26
28
  end
@@ -1,6 +1,6 @@
1
1
  module Conjur
2
2
  class API
3
- VERSION = "2.4.0"
3
+ VERSION = "2.5.1"
4
4
  # Note: when bumping major version, please remove compatibility code in role#grant_to
5
5
  end
6
6
  end
data/lib/conjur/has_id.rb CHANGED
@@ -5,7 +5,7 @@ module Conjur
5
5
  end
6
6
 
7
7
  def id
8
- path_components[-1]
8
+ path_components[2..-1].join('/')
9
9
  end
10
10
  end
11
11
  end
data/lib/conjur/log.rb CHANGED
@@ -1,40 +1,20 @@
1
- # Logging mechanism borrowed from rest-client
1
+ require 'logger'
2
+
2
3
  module Conjur
3
4
  # You can also configure logging by the environment variable CONJURAPI_LOG.
4
5
  def self.log= log
5
6
  @@log = create_log log
6
7
  end
7
8
 
8
- # Create a log that respond to << like a logger
9
- # param can be 'stdout', 'stderr', a string (then we will log to that file) or a logger (then we return it)
10
9
  def self.create_log param
11
10
  if param
12
11
  if param.is_a? String
13
12
  if param == 'stdout'
14
- stdout_logger = Class.new do
15
- def << obj
16
- STDOUT.write obj
17
- end
18
- end
19
- stdout_logger.new
13
+ Logger.new $stdout
20
14
  elsif param == 'stderr'
21
- stderr_logger = Class.new do
22
- def << obj
23
- STDERR.write obj
24
- end
25
- end
26
- stderr_logger.new
15
+ Logger.new $stderr
27
16
  else
28
- file_logger = Class.new do
29
- attr_writer :target_file
30
-
31
- def << obj
32
- File.open(@target_file, 'a') { |f| f.write obj }
33
- end
34
- end
35
- logger = file_logger.new
36
- logger.target_file = param
37
- logger
17
+ Logger.new param
38
18
  end
39
19
  else
40
20
  param
@@ -49,4 +29,4 @@ module Conjur
49
29
  def self.log # :nodoc:
50
30
  @@env_log || @@log
51
31
  end
52
- end
32
+ end
@@ -35,7 +35,7 @@ module Conjur
35
35
  logger << " with options #{options.to_json}"
36
36
  end
37
37
  end
38
- super.delete(options)
38
+ super options
39
39
  end
40
40
 
41
41
  def permit(privilege, role, options = {})
@@ -62,6 +62,15 @@ module Conjur
62
62
  self["?deny&privilege=#{query_escape p}&role=#{query_escape role}"].post(options)
63
63
  end
64
64
  end
65
+
66
+ # True if the logged-in role, or a role specified using the acting-as option, has the
67
+ # specified +privilege+ on this resource.
68
+ def permitted?(privilege, options = {})
69
+ self["?check&privilege=#{query_escape privilege}"].get(options)
70
+ true
71
+ rescue RestClient::ResourceNotFound
72
+ false
73
+ end
65
74
 
66
75
  protected
67
76
 
@@ -0,0 +1,12 @@
1
+ Asset
2
+ =====
3
+
4
+ Implements a domain-specific permission modeling concept. Assets combine functionality of roles, resources, and other assets
5
+ together into unified APIs.
6
+
7
+ Assets commonly perform the following functions:
8
+
9
+ * **containment** An asset can contain other assets, such as an environment which contains variables or a deployment which contains hosts.
10
+ Assets can be collected and re-combined arbitrarily.
11
+ * **role management** Container assets can define roles which manage permissions on child assets.
12
+
@@ -0,0 +1,52 @@
1
+ Asset#members#add
2
+ =================
3
+
4
+ A common purpose of an asset is to manage access to a collection of "child" assets. Permissions on child assets are granted
5
+ via roles defined on the parent asset.
6
+
7
+ For example, consider an Environment asset which contains a number of child Variables:
8
+
9
+ ```
10
+ Environment[e1]
11
+ - variables
12
+ - Variable[v1]
13
+ - Variable[v2]
14
+ - Variable[v3]
15
+ ```
16
+
17
+ The Environment may define a role "use_variable" and permit "read" and "execute" on each variable by the "use_variable" role.
18
+ Therefore, granting the "use_variable" role to another role "r1" will permit r1 to read and execute each variable.
19
+
20
+ Examples
21
+ --------
22
+
23
+ ### Command Line
24
+
25
+ ```bash
26
+ $ conjur asset:create environment `conjur id:create`
27
+ {
28
+ "id": "9yxa80",
29
+ <snip>
30
+ }
31
+ $ conjur host:create
32
+ {
33
+ "id": "9bfqx5",
34
+ <snip>
35
+ }
36
+ $ conjur environment:variables:create 9yxa80 test-var test text/plain "the-value"
37
+ Variable created
38
+ $ conjur asset:show environment 9yxa80
39
+ {
40
+ "id": "9yxa80",
41
+ "variables": {
42
+ "test-var": "he2e00"
43
+ },
44
+ <snip>
45
+ }
46
+ $ conjur resource:check variable he2e00 host:9bfqx5 execute
47
+ false
48
+ $ conjur asset:members:add environment 9yxa80 use_variable host:9bfqx5
49
+ Membership granted
50
+ $ conjur resource:check variable he2e00 host:9bfqx5 execute
51
+ true
52
+ ```
@@ -0,0 +1,50 @@
1
+ Asset#show
2
+ ==========
3
+
4
+ Display an asset as JSON.
5
+
6
+ The Conjur `jsonfield` utility can be used to pluck JSON values.
7
+
8
+ Examples
9
+ --------
10
+
11
+ ### Command Line
12
+
13
+ #### Create and show an environment
14
+
15
+ ```bash
16
+ $ id=`conjur id:create`
17
+ $ e=`conjur asset:create environment $id`
18
+ $ conjur asset:show environment id
19
+ {
20
+ "id": "0y3s00",
21
+ "variables": {
22
+ },
23
+ "userid": "kgilpin",
24
+ "ownerid": "sandbox:user:kgilpin",
25
+ "resource_identifier": "sandbox:environment:0y3s00"
26
+ }
27
+ ```
28
+ #### Create and show a host
29
+
30
+ ```bash
31
+ $ hostid=`conjur host:create | jsonfield id`
32
+ $ conjur asset:show host $hostid
33
+ {
34
+ "id": "g7hytz",
35
+ "userid": "kgilpin",
36
+ "created_at": "2013-07-09T21:10:06+00:00",
37
+ "ownerid": "sandbox:user:kgilpin",
38
+ "roleid": "sandbox:host:g7hytz",
39
+ "resource_identifier": "sandbox:host:g7hytz"
40
+ }
41
+ ```
42
+
43
+ #### Attempt to show a non-existant asset.
44
+
45
+ ```bash
46
+ $ conjur asset:show host foo
47
+ error: 404 Resource Not Found
48
+ $ echo $?
49
+ 1
50
+ ```
@@ -0,0 +1,6 @@
1
+ Group
2
+ =====
3
+
4
+ A group represents a collection of other roles (users, groups, hosts, generic roles, etc). Essentially
5
+ it is just a role whose `kind` is "group".
6
+
@@ -0,0 +1,20 @@
1
+ Group#create
2
+ ============
3
+
4
+ A group is created from an identifier. The identifier should be unique.
5
+
6
+ Example
7
+ -------
8
+
9
+ ### Command Line
10
+
11
+ ```bash
12
+ $ conjur group:create `conjur id:create`
13
+ Created https://core-sandbox-conjur.herokuapp.com/groups/5zjys0
14
+ ```
15
+
16
+ ### API
17
+
18
+ ```ruby
19
+ conjur.create_group SecureRandom.uuid
20
+ ```
@@ -0,0 +1,23 @@
1
+ Host
2
+ ====
3
+
4
+ A host represents a non-human user. VMs, processes, and jobs are all commonly represented as Hosts.
5
+
6
+ Attributes
7
+ ----------
8
+
9
+ * **username** the host username is composed of the word 'host' composed with the host identifier. For example, "host/i-bbe231db"
10
+ * **api_key** each host is assigned an API key, just like a human user
11
+
12
+ Like a human User, a Host can authenticate with Conjur and perform actions.
13
+
14
+ Roles
15
+ -----
16
+
17
+ On creation, the host creates a Conjur role to represent itself. The role kind is 'host'.
18
+
19
+ Resources
20
+ ---------
21
+
22
+ On creation, the host creates a Conjur resource to represent itself.
23
+
@@ -0,0 +1,34 @@
1
+ Host#create
2
+ ===========
3
+
4
+ A host is created with an identifier. The identifier must be unique.
5
+ It can be assigned, or it can be generated by Conjur.
6
+
7
+ When the host is created, the `api_key` field is included in the JSON response.
8
+
9
+ Host#show does not include the `api_key`.
10
+
11
+ Example
12
+ -------
13
+
14
+ ```bash
15
+ $ conjur host:create
16
+ {
17
+ "id": "8y2p5w",
18
+ "userid": "kgilpin",
19
+ "created_at": "2013-07-09T21:12:57+00:00",
20
+ "ownerid": "sandbox:user:kgilpin",
21
+ "roleid": "sandbox:host:8y2p5w",
22
+ "resource_identifier": "sandbox:host:8y2p5w",
23
+ "api_key": "vj98ne10ar6vvmwrjt02ryfj6924a4vkch6yqcw292v9p12sv1rd"
24
+ }
25
+ $ conjur asset:show host 8y2p5w
26
+ {
27
+ "id": "8y2p5w",
28
+ "userid": "kgilpin",
29
+ "created_at": "2013-07-09T21:12:57+00:00",
30
+ "ownerid": "sandbox:user:kgilpin",
31
+ "roleid": "sandbox:host:8y2p5w",
32
+ "resource_identifier": "sandbox:host:8y2p5w"
33
+ }
34
+ ```
@@ -0,0 +1,21 @@
1
+ Host#enroll
2
+ ===========
3
+
4
+ Returns a unique URL which, when fetched, returns a shell command which will login
5
+ the host with Conjur.
6
+
7
+ Example
8
+ -------
9
+
10
+ ```bash
11
+ $ conjur host:enroll vaz7qg
12
+ https://core-sandbox-conjur.herokuapp.com/hosts/enroll?key=7fxt_HiRfOodA3J6wh5s2X9a6gm-b-wkPmF0g-HOPYo=
13
+ On the target host, please execute the following command:
14
+ curl -L https://core-sandbox-conjur.herokuapp.com/hosts/enroll?key=7fxt_HiRfOodA3J6wh5s2X9a6gm-b-wkPmF0g-HOPYo= | bash
15
+ $ curl -L https://core-sandbox-conjur.herokuapp.com/hosts/enroll?key=7fxt_HiRfOodA3J6wh5s2X9a6gm-b-wkPmF0g-HOPYo=
16
+ #!/bin/sh
17
+ set -e
18
+
19
+ conjur authn:login -u host/vaz7qg -p 39c63b3d5bc372de1c100feec852e05f747bc9eb
20
+ ```
21
+
@@ -0,0 +1,11 @@
1
+ Resource
2
+ ========
3
+
4
+ A resource is an entity on which permissions are assigned.
5
+
6
+ Resources are partitioned into "kinds", such as "group", "host",
7
+ "file", "environment", "variable", etc.
8
+
9
+ Resources are not frequently used directly. Instead, higher-level "assets" such as Host, Group, User,
10
+ Variable provide more intuitive functionality. For example, Assets often combine role and resource
11
+ functionality together.
@@ -0,0 +1,29 @@
1
+ Resource#create
2
+ ===============
3
+
4
+ A resource is composed of a `kind` and `identifier`. The `kind`
5
+ indicates the semantic purpose of the resource, the identifier identifies
6
+ it uniquely within the kind.
7
+
8
+ Example
9
+ -------
10
+
11
+ ### Command Line
12
+
13
+ ```bash
14
+ $ conjur resource:create food bacon
15
+ {
16
+ "id": {
17
+ "account": "sandbox",
18
+ "kind": "food",
19
+ "id": "bacon"
20
+ },
21
+ "owner": {
22
+ "account": "sandbox",
23
+ "id": "user:kgilpin"
24
+ },
25
+ "permissions": [
26
+
27
+ ]
28
+ }
29
+ ```
@@ -0,0 +1,23 @@
1
+ Resource#deny
2
+ =============
3
+
4
+ Removes a specific permission on a resource from a role.
5
+
6
+ The owner of a resource always has all permissions on the resource, even if specific permissions
7
+ are denied.
8
+
9
+ Example
10
+ -------
11
+
12
+ ### Command Line
13
+
14
+ ```bash
15
+ $ conjur resource:permit food bacon host:a4yta8 fry
16
+ Permission granted
17
+ $ conjur resource:check food bacon host:a4yta8 fry
18
+ true
19
+ $ conjur resource:deny food bacon host:a4yta8 fry
20
+ Permission revoked
21
+ $ conjur resource:check food bacon host:a4yta8 fry
22
+ false
23
+ ```
@@ -0,0 +1,35 @@
1
+ Resource#permit
2
+ ===============
3
+
4
+ Gives a specific permission on a resource to a role.
5
+
6
+ Example
7
+ -------
8
+
9
+ ### Command Line
10
+
11
+ ```bash
12
+ $ conjur host:create
13
+ <snip>
14
+ $ conjur resource:permit food bacon host:a4yta8 fry
15
+ Permission granted
16
+ $ conjur resource:check food bacon host:a4yta8 fry
17
+ true
18
+ $ conjur resource:check food bacon host:a4yta8 bake
19
+ false
20
+ $ conjur resource:permitted_roles food bacon fry
21
+ [
22
+ {
23
+ "id": {
24
+ "account": "sandbox",
25
+ "id": "user:kgilpin"
26
+ }
27
+ },
28
+ {
29
+ "id": {
30
+ "account": "sandbox",
31
+ "id": "host:a4yta8"
32
+ }
33
+ }
34
+ ]
35
+ ```