conjur-cli 4.16.0 → 4.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7841ac532c814a5dbbcb6ac87ea78ab2e72f6e7a
4
- data.tar.gz: 438f120d06064aa3fc2fbe4e8e59918629ac8ddc
3
+ metadata.gz: 432110704aeb067fe4daed4e19defb8bcfce73ba
4
+ data.tar.gz: e515bff89602f42ec641655ff89724f8ce0402c8
5
5
  SHA512:
6
- metadata.gz: 8b9798edb33f962ed5cb1955aadd23e68a68bcf845e5e365280438596bafe7337706e2d650d8e8653f82cf407ce328d2b300ea5ba2b146817fc863183b22b295
7
- data.tar.gz: 1883d777e70a3ae5d53d3129f7779b948b3b86a88364923d6f81a2e19bd47dfa173133925cb4a9c426f2d0abcfb774e4ce29272d7ffaecf89e37145512b76c4c
6
+ metadata.gz: f79560aa69622e389202e12ce79d328e5d61d055dfea15660503c5684de9b9a031843d8a219f1b68e563db8fa53a7456e745cdcc5d29cf46dc23c747c767f7b3
7
+ data.tar.gz: 6d0045244faab16cd1bd009ac9b1252a6d1ef950aec5bfa266531189d7109513250da60014a4037e89fbf63477ffdc02994e68f42c80888f759493e9b383dd70
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 4.17.0
2
+
3
+ * Support --policy parameter in 'conjur env'
4
+ * Bugfix: failures on 'variable retire'
5
+ * Raise a better error in case of missing config
6
+
1
7
  # 4.16.0
2
8
 
3
9
  * Add 'bootstrap' CLI command
data/conjur.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
 
29
29
  gem.add_development_dependency 'rspec', '~> 3.0'
30
30
  gem.add_development_dependency 'simplecov'
31
- gem.add_development_dependency 'aruba'
31
+ gem.add_development_dependency 'aruba', '~> 0.6.1'
32
32
  gem.add_development_dependency 'ci_reporter_rspec', '~> 1.0'
33
33
  gem.add_development_dependency 'ci_reporter_cucumber'
34
34
  gem.add_development_dependency 'rake', '~> 10.0'
@@ -104,7 +104,7 @@ module Conjur
104
104
  obj.resource.attributes['permissions'].each do |p|
105
105
  role = api.role(p['role'])
106
106
  privilege = p['privilege']
107
- next if role.roleid == obj.roleid && privilege == 'read'
107
+ next if obj.respond_to?(:roleid) && role.roleid == obj.roleid && privilege == 'read'
108
108
  puts "Denying #{privilege} privilege to #{role.roleid}"
109
109
  obj.resource.deny(privilege, role)
110
110
  end
@@ -35,6 +35,9 @@ class Conjur::Command::Env < Conjur::Command
35
35
 
36
36
  c.desc "Environment configuration as inline yaml"
37
37
  c.flag ["yaml"]
38
+
39
+ c.desc "Policy id to substitute for $policy in the YAML values"
40
+ c.flag ["policy"]
38
41
  end
39
42
 
40
43
  def self.get_env_object options
@@ -42,12 +45,13 @@ class Conjur::Command::Env < Conjur::Command
42
45
  exit_now! "Options -c and --yaml can not be provided together"
43
46
  end
44
47
 
45
- env = if options[:yaml]
46
- Conjur::Env.new(yaml: options[:yaml])
47
- else
48
- Conjur::Env.new(file: (options[:c]||'.conjurenv'))
49
- end
50
- return env
48
+ env_options = if options[:yaml]
49
+ { yaml: options[:yaml]}
50
+ else
51
+ { file: (options[:c]||'.conjurenv') }
52
+ end
53
+ env_options[:substitutions] = { "$policy" => options[:policy] } if options[:policy]
54
+ Conjur::Env.new env_options
51
55
  end
52
56
 
53
57
  command :env do |env|
@@ -132,7 +136,6 @@ TEMPLATEDESC
132
136
  conjurenv = env.obtain(api) # needed for binding
133
137
  rendered = ERB.new(template).result(binding)
134
138
 
135
- #
136
139
  tempfile = if File.directory?("/dev/shm") and File.writable?("/dev/shm")
137
140
  Tempfile.new("conjur","/dev/shm")
138
141
  else
data/lib/conjur/config.rb CHANGED
@@ -52,6 +52,7 @@ module Conjur
52
52
  def load(config_files = default_config_files)
53
53
  require 'yaml'
54
54
  require 'conjur/log'
55
+
55
56
  config_files.each do |f|
56
57
  if File.file?(f)
57
58
  if Conjur.log
@@ -66,8 +67,10 @@ module Conjur
66
67
  end
67
68
  end
68
69
 
70
+
69
71
  def apply
70
72
  require 'conjur/configuration'
73
+
71
74
  keys = Config.keys.dup
72
75
  keys.delete(:plugins)
73
76
 
@@ -88,7 +91,10 @@ module Conjur
88
91
  require 'conjur/api'
89
92
  Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
90
93
  rescue RuntimeError
91
- raise $! unless $!.message == "Missing required option account"
94
+ if $!.message == "Missing required option account"
95
+ $stderr.puts "Your config is invalid, did you run 'conjur init'?"
96
+ end
97
+ raise $!
92
98
  end
93
99
  end
94
100
  if Config[:cert_file]
@@ -121,6 +127,18 @@ module Conjur
121
127
  def [](key)
122
128
  @@attributes[key.to_s]
123
129
  end
130
+
131
+ def member? key
132
+ @@attributes.member?(key) || @@attributes.member?(alternate_key(key))
133
+ end
134
+
135
+ def alternate_key key
136
+ case key
137
+ when String then key.to_sym
138
+ when Symbol then key.to_s
139
+ else key
140
+ end
141
+ end
124
142
  end
125
143
  end
126
144
  end
@@ -29,6 +29,9 @@ module Conjur
29
29
  raise "#{self.class.name.split('::').last} requires a parameter" if id.to_s.empty?
30
30
  @id=id
31
31
  end
32
+ def gsub! pattern, replace
33
+ @id.gsub! pattern, replace
34
+ end
32
35
  def init_with(coder)
33
36
  initialize(coder.scalar)
34
37
  end
@@ -61,21 +64,22 @@ module Conjur
61
64
  raise ":file and :yaml options can not be provided together" if ( options.has_key?(:file) and options.has_key?(:yaml) )
62
65
 
63
66
  yaml = if options.has_key?(:yaml)
64
- raise ":yaml option should be non-empty string" unless options[:yaml].kind_of?(String)
65
- raise ":yaml option should be non-empty string" if options[:yaml].empty?
66
- options[:yaml]
67
- elsif options.has_key?(:file)
68
- raise ":file option should be non-empty string" unless options[:file].kind_of?(String)
69
- raise ":file option should be non-empty string" if options[:file].empty?
70
- File.read(options[:file])
71
- else
72
- raise "either :file or :yaml option is mandatory"
73
- end
74
-
75
- @definition = parse(yaml)
67
+ raise ":yaml option should be non-empty string" unless options[:yaml].kind_of?(String)
68
+ raise ":yaml option should be non-empty string" if options[:yaml].empty?
69
+ options[:yaml]
70
+ elsif options.has_key?(:file)
71
+ raise ":file option should be non-empty string" unless options[:file].kind_of?(String)
72
+ raise ":file option should be non-empty string" if options[:file].empty?
73
+ File.read(options[:file])
74
+ else
75
+ raise "either :file or :yaml option is mandatory"
76
+ end
77
+ parse_arguments = [ yaml ]
78
+ parse_arguments << options[:substitutions] if options[:substitutions]
79
+ @definition = parse(*parse_arguments)
76
80
  end
77
81
 
78
- def parse(yaml)
82
+ def parse(yaml, substitutions = {})
79
83
  YAML.add_tag("!var", ConjurVariable)
80
84
  YAML.add_tag("!tmp", ConjurTempfile)
81
85
  definition = YAML.load(yaml)
@@ -84,6 +88,14 @@ module Conjur
84
88
  definition.keys.select { |k| definition[k].kind_of? Fixnum }.each { |k| definition[k]="#{definition[k]}" }
85
89
  bad_types = definition.values.select { |v| not (v.kind_of?(String) or v.kind_of?(CustomTag)) }.map {|v| v.class}.uniq
86
90
  raise "Definition can not include values of types: #{bad_types}" unless bad_types.empty?
91
+ definition.inject({}) do |memo,e|
92
+ key, value = e
93
+ substitutions.each do |k,v|
94
+ value.gsub! k, v
95
+ end
96
+ memo[key] = value
97
+ memo
98
+ end
87
99
  definition
88
100
  end
89
101
 
@@ -19,6 +19,6 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module Conjur
22
- VERSION = "4.16.0"
22
+ VERSION = "4.17.0"
23
23
  ::Version=VERSION
24
24
  end
@@ -38,11 +38,25 @@ shared_examples_for "processes environment definition" do |cmd, options|
38
38
  end
39
39
  end
40
40
 
41
+ shared_examples_for "accepts policy option" do |cmd, options|
42
+ before { # suspend all interaction with the environment
43
+ allow(Kernel).to receive(:system).and_return(true)
44
+ }
45
+ let(:stub_object) { double(obtain:{}, check:{}) }
46
+ describe_command "env:#{cmd} --policy foobar #{options}" do
47
+ it "uses .conjurenv file by default" do
48
+ expect(Conjur::Env).to receive(:new).with(file:".conjurenv", substitutions: { "$policy" => "foobar" }).and_return(stub_object)
49
+ invoke
50
+ end
51
+ end
52
+ end
53
+
41
54
  describe Conjur::Command::Env, logged_in: true do
42
55
 
43
56
  let(:stub_env) { double() }
44
57
  describe ":check" do
45
58
  it_behaves_like "processes environment definition", "check", ''
59
+ it_behaves_like "accepts policy option", "check", ''
46
60
 
47
61
  describe_command "env:check" do
48
62
  before { expect(Conjur::Env).to receive(:new).and_return(stub_env) }
@@ -81,6 +95,7 @@ describe Conjur::Command::Env, logged_in: true do
81
95
 
82
96
  describe ":run" do
83
97
  it_behaves_like "processes environment definition", "run","-- extcmd"
98
+ it_behaves_like "accepts policy option", "run", '-- extcmd'
84
99
  describe_command "env:run" do
85
100
  it 'fails because of missing argument' do
86
101
  expect(Kernel).not_to receive(:system)
@@ -119,6 +134,7 @@ describe Conjur::Command::Env, logged_in: true do
119
134
  allow(FileUtils).to receive(:copy).and_return(true)
120
135
  }
121
136
  it_behaves_like "processes environment definition", "template","config.erb"
137
+ it_behaves_like "accepts policy option", "template", 'config.erb'
122
138
  end
123
139
  describe_command "env:template" do
124
140
  it 'fails because of missing argument' do
data/spec/command_spec.rb CHANGED
@@ -57,4 +57,24 @@ describe Conjur::Command do
57
57
  end
58
58
  end
59
59
  end
60
+
61
+ describe "supports asset retirement" do
62
+ let(:role){ double('Role', roleid: 'the-role-id')}
63
+ let(:permission){ { 'role' => 'the-role-id', 'privilege' => 'read' } }
64
+ let(:permissions){ [ permission ] }
65
+ let(:resource){ double('Resource', deny: nil, attributes: {'permissions' => permissions}) }
66
+ let(:resources){ [resource] }
67
+ let(:api){ double('API') }
68
+ let(:asset){ double('Asset', resources: resources, resource: resource) }
69
+ describe "#retire_resource" do
70
+ context "when given an object without a role" do
71
+ it 'works' do
72
+ expect(described_class).to receive(:api).and_return api
73
+ expect(api).to receive(:role).with('the-role-id').and_return role
74
+ described_class.retire_resource(asset)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
60
80
  end
data/spec/config_spec.rb CHANGED
@@ -26,7 +26,10 @@ describe Conjur::Config do
26
26
  context "when CONJURRC is not set" do
27
27
  around do |example|
28
28
  oldrc = ENV.delete 'CONJURRC'
29
+
30
+
29
31
  example.run
32
+
30
33
  ENV['CONJURRC'] = oldrc
31
34
  end
32
35
 
data/spec/env_spec.rb CHANGED
@@ -78,7 +78,29 @@ describe Conjur::Env do
78
78
  expect(result.keys.sort).to eq(["a","b","c"])
79
79
  expect(result["a"]).to eq('literal')
80
80
  expect(result["b"]).to be_a_kind_of(Conjur::Env::ConjurTempfile)
81
+ expect(result["b"].conjur_id).to eq('sometmp')
81
82
  expect(result["c"]).to be_a_kind_of(Conjur::Env::ConjurVariable)
83
+ expect(result["c"].conjur_id).to eq('somevar')
84
+ end
85
+
86
+ it "Accepts empty string substitution" do
87
+ substitutions = {
88
+ }
89
+ result = Conjur::Env.new(yaml: "{a: $foo, b: !tmp '$foo$foo$bar', c: !var '$foo$bar'}", substitutions: substitutions).instance_variable_get("@definition")
90
+ expect(result["a"]).to eq('$foo')
91
+ expect(result["b"].conjur_id).to eq('$foo$foo$bar')
92
+ expect(result["c"].conjur_id).to eq('$foo$bar')
93
+ end
94
+
95
+ it "Performs requested string substitution" do
96
+ substitutions = {
97
+ "$foo" => "alice",
98
+ "$bar" => "bob"
99
+ }
100
+ result = Conjur::Env.new(yaml: "{a: $foo, b: !tmp '$foo$foo$bar', c: !var '$foo$bar'}", substitutions: substitutions).instance_variable_get("@definition")
101
+ expect(result["a"]).to eq('alice')
102
+ expect(result["b"].conjur_id).to eq('alicealicebob')
103
+ expect(result["c"].conjur_id).to eq('alicebob')
82
104
  end
83
105
 
84
106
  it "Converts numbers to string literals" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.16.0
4
+ version: 4.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Rzepecki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-14 00:00:00.000000000 Z
12
+ date: 2014-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -155,16 +155,16 @@ dependencies:
155
155
  name: aruba
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - '>='
158
+ - - ~>
159
159
  - !ruby/object:Gem::Version
160
- version: '0'
160
+ version: 0.6.1
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - '>='
165
+ - - ~>
166
166
  - !ruby/object:Gem::Version
167
- version: '0'
167
+ version: 0.6.1
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: ci_reporter_rspec
170
170
  requirement: !ruby/object:Gem::Requirement
@@ -294,7 +294,6 @@ files:
294
294
  - lib/conjur/identifier_manipulation.rb
295
295
  - lib/conjur/version.rb
296
296
  - profile.rb
297
- - spec/audit/follower_spec.rb
298
297
  - spec/authn_spec.rb
299
298
  - spec/command/assets_spec.rb
300
299
  - spec/command/audit_spec.rb
@@ -336,7 +335,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
335
  version: '0'
337
336
  requirements: []
338
337
  rubyforge_project:
339
- rubygems_version: 2.2.2
338
+ rubygems_version: 2.0.14
340
339
  signing_key:
341
340
  specification_version: 4
342
341
  summary: Conjur command line interface
@@ -352,7 +351,6 @@ test_files:
352
351
  - features/step_definitions/dsl_steps.rb
353
352
  - features/support/env.rb
354
353
  - features/support/hooks.rb
355
- - spec/audit/follower_spec.rb
356
354
  - spec/authn_spec.rb
357
355
  - spec/command/assets_spec.rb
358
356
  - spec/command/audit_spec.rb
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conjur::Audit::Follower do
4
-
5
- end