Skip to content

Commit 73e9940

Browse files
committed
Merge branch 'CHEF-1015' of git://github.com/stormsilver/chef into stormsilver/CHEF-1015
2 parents ae9be74 + 84aaa6b commit 73e9940

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

chef-server/bin/chef-server

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ end
5656
ARGV.push *[ "-I", File.join(__DIR__, "config", "init.rb") ]
5757
ARGV.push *[ "-m", __DIR__]
5858

59+
# attempt to find the user and group that this process will become. Fixes CHEF-1015
60+
if (index = ARGV.index("-u"))
61+
Chef::Config[:signing_ca_user] = ARGV[index+1]
62+
end
63+
if (index = ARGV.index("-G"))
64+
Chef::Config[:signing_ca_group] = ARGV[index+1]
65+
end
66+
5967
if index = ARGV.index("-C")
6068
config = ARGV[index+1]
6169
ARGV.delete("-C")

chef/lib/chef/certificate.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def generate_signing_ca
7272

7373
File.open(ca_cert_file, "w") { |f| f.write ca_cert.to_pem }
7474
File.open(ca_keypair_file, File::WRONLY|File::EXCL|File::CREAT, 0600) { |f| f.write keypair.to_pem }
75+
if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
76+
FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], ca_keypair_file)
77+
end
7578
end
7679
self
7780
end
@@ -146,6 +149,9 @@ def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef
146149
File.open(key_file, File::WRONLY|File::EXCL|File::CREAT, 0600) do |f|
147150
f.print(api_client.private_key)
148151
end
152+
if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
153+
FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], key_file)
154+
end
149155
end
150156
end
151157

chef/lib/chef/config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def self.manage_secret_key
183183
# In truth, these don't even have to change
184184
signing_ca_cert "/var/chef/ca/cert.pem"
185185
signing_ca_key "/var/chef/ca/key.pem"
186+
signing_ca_user nil
187+
signing_ca_group nil
186188
signing_ca_country "US"
187189
signing_ca_state "Washington"
188190
signing_ca_location "Seattle"

chef/spec/unit/certificate_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def write(arg)
3333
describe Chef::Certificate do
3434
describe "generate_signing_ca" do
3535
before(:each) do
36+
Chef::Config[:signing_ca_user] = nil
37+
Chef::Config[:signing_ca_group] = nil
3638
FileUtils.stub!(:mkdir_p).and_return(true)
39+
FileUtils.stub!(:chown).and_return(true)
3740
File.stub!(:open).and_return(true)
3841
File.stub!(:exists?).and_return(false)
3942
@ca_cert = FakeFile.new
@@ -45,9 +48,19 @@ def write(arg)
4548
Chef::Certificate.generate_signing_ca
4649
@ca_cert.data.should =~ /BEGIN CERTIFICATE/
4750
end
48-
51+
4952
it "should generate an RSA private key" do
5053
File.should_receive(:open).with(Chef::Config[:signing_ca_key], File::WRONLY|File::EXCL|File::CREAT, 0600).and_yield(@ca_key)
54+
FileUtils.should_not_receive(:chown)
55+
Chef::Certificate.generate_signing_ca
56+
@ca_key.data.should =~ /BEGIN RSA PRIVATE KEY/
57+
end
58+
59+
it "should generate an RSA private key with user and group" do
60+
Chef::Config[:signing_ca_user] = "funky"
61+
Chef::Config[:signing_ca_group] = "fresh"
62+
File.should_receive(:open).with(Chef::Config[:signing_ca_key], File::WRONLY|File::EXCL|File::CREAT, 0600).and_yield(@ca_key)
63+
FileUtils.should_receive(:chown).with(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], Chef::Config[:signing_ca_key])
5164
Chef::Certificate.generate_signing_ca
5265
@ca_key.data.should =~ /BEGIN RSA PRIVATE KEY/
5366
end

0 commit comments

Comments
 (0)