Skip to content

Commit 0abd49b

Browse files
author
Christopher Brown
committed
moved session key management to Chef::Config
1 parent 924b6a1 commit 0abd49b

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

chef-server/Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ require 'rake/rdoctask'
44
require 'merb-core'
55
require 'merb-core/tasks/merb'
66

7+
require 'chef'
8+
79
include FileUtils
810

911
GEM = "chef-server"

chef-server/config/init.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
Merb::Config.use do |c|
1010
c[:use_mutex] = false
11-
c[:session_store] = 'cookie' # can also be 'memory', 'memcache', 'container', 'datamapper
12-
13-
# cookie session store configuration
14-
c[:session_secret_key] = '424458a3d40b41b5e6d4b19b9eaffb706e7eef42' # required for cookie session store
15-
c[:session_id_key] = '_chef-server_session_id' # cookie session id key, defaults to "_session_id"
11+
c[:session_id_key] = '_chef_server_session_id'
12+
c[:session_secret_key] = Chef::Config.manage_secret_key
13+
c[:session_store] = 'cookie'
14+
c[:exception_details] = true
15+
c[:reload_classes] = false
16+
c[:log_level] = Chef::Config[:log_level]
17+
c[:log_stream] = Chef::Config[:log_location]
1618
end
1719

1820
Merb::BootLoader.before_app_loads do

chef/lib/chef/config.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ def configure(&block)
9393
yield @configuration
9494
end
9595

96+
# Manages the chef secret session key
97+
# === Returns
98+
# <newkey>:: A new or retrieved session key
99+
#
100+
def manage_secret_key
101+
newkey = nil
102+
if Chef::FileCache.has_key?("chef_server_cookie_id")
103+
newkey = Chef::FileCache.load("chef_server_cookie_id")
104+
else
105+
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
106+
newkey = ""
107+
1.upto(40) { |i| newkey << chars[rand(chars.size-1)] }
108+
Chef::FileCache.store("chef_server_cookie_id", newkey)
109+
end
110+
newkey
111+
end
112+
96113
# Get the value of a configuration option
97114
#
98115
# === Parameters

0 commit comments

Comments
 (0)