chef-config 12.22.1 → 12.22.3
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 +4 -4
- data/LICENSE +201 -201
- data/README.md +4 -4
- data/Rakefile +17 -17
- data/chef-config.gemspec +34 -34
- data/lib/chef-config.rb +20 -20
- data/lib/chef-config/config.rb +1097 -1097
- data/lib/chef-config/exceptions.rb +27 -27
- data/lib/chef-config/fips.rb +51 -51
- data/lib/chef-config/logger.rb +59 -59
- data/lib/chef-config/mixin/dot_d.rb +38 -38
- data/lib/chef-config/mixin/fuzzy_hostname_matcher.rb +41 -41
- data/lib/chef-config/package_task.rb +272 -272
- data/lib/chef-config/path_helper.rb +283 -283
- data/lib/chef-config/version.rb +34 -34
- data/lib/chef-config/windows.rb +28 -28
- data/lib/chef-config/workstation_config_loader.rb +182 -182
- data/spec/spec_helper.rb +75 -75
- data/spec/unit/config_spec.rb +1190 -1190
- data/spec/unit/fips_spec.rb +128 -128
- data/spec/unit/path_helper_spec.rb +307 -307
- data/spec/unit/workstation_config_loader_spec.rb +366 -366
- metadata +2 -2
data/chef-config.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "chef-config/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "chef-config"
|
8
|
-
spec.version = ChefConfig::VERSION
|
9
|
-
spec.authors = ["Adam Jacob"]
|
10
|
-
spec.email = ["adam@chef.io"]
|
11
|
-
|
12
|
-
spec.summary = %q{Chef's default configuration and config loading}
|
13
|
-
spec.homepage = "https://github.com/chef/chef"
|
14
|
-
spec.license = "Apache-2.0"
|
15
|
-
|
16
|
-
spec.require_paths = ["lib"]
|
17
|
-
|
18
|
-
spec.add_dependency "mixlib-shellout", "~> 2.0"
|
19
|
-
spec.add_dependency "mixlib-config", "~> 2.0"
|
20
|
-
spec.add_dependency "fuzzyurl"
|
21
|
-
spec.add_dependency "addressable"
|
22
|
-
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
|
25
|
-
%w{rspec-core rspec-expectations rspec-mocks}.each do |rspec|
|
26
|
-
spec.add_development_dependency(rspec, "~> 3.2")
|
27
|
-
end
|
28
|
-
|
29
|
-
spec.files = %w{Rakefile LICENSE README.md} + Dir.glob("*.gemspec") +
|
30
|
-
Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
|
31
|
-
|
32
|
-
spec.bindir = "bin"
|
33
|
-
spec.executables = []
|
34
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "chef-config/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chef-config"
|
8
|
+
spec.version = ChefConfig::VERSION
|
9
|
+
spec.authors = ["Adam Jacob"]
|
10
|
+
spec.email = ["adam@chef.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Chef's default configuration and config loading}
|
13
|
+
spec.homepage = "https://github.com/chef/chef"
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "mixlib-shellout", "~> 2.0"
|
19
|
+
spec.add_dependency "mixlib-config", "~> 2.0"
|
20
|
+
spec.add_dependency "fuzzyurl"
|
21
|
+
spec.add_dependency "addressable"
|
22
|
+
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
%w{rspec-core rspec-expectations rspec-mocks}.each do |rspec|
|
26
|
+
spec.add_development_dependency(rspec, "~> 3.2")
|
27
|
+
end
|
28
|
+
|
29
|
+
spec.files = %w{Rakefile LICENSE README.md} + Dir.glob("*.gemspec") +
|
30
|
+
Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
|
31
|
+
|
32
|
+
spec.bindir = "bin"
|
33
|
+
spec.executables = []
|
34
|
+
end
|
data/lib/chef-config.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
module ChefConfig
|
19
|
-
|
20
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module ChefConfig
|
19
|
+
|
20
|
+
end
|
data/lib/chef-config/config.rb
CHANGED
@@ -1,1097 +1,1097 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
-
# Author:: AJ Christensen (<aj@chef.io>)
|
5
|
-
# Author:: Mark Mzyk (<mmzyk@chef.io>)
|
6
|
-
# Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
|
7
|
-
# Copyright:: Copyright 2008-2016, Chef Software Inc.
|
8
|
-
# License:: Apache License, Version 2.0
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
|
22
|
-
require "mixlib/config"
|
23
|
-
require "pathname"
|
24
|
-
|
25
|
-
require "chef-config/fips"
|
26
|
-
require "chef-config/logger"
|
27
|
-
require "chef-config/windows"
|
28
|
-
require "chef-config/path_helper"
|
29
|
-
require "chef-config/mixin/fuzzy_hostname_matcher"
|
30
|
-
|
31
|
-
require "mixlib/shellout"
|
32
|
-
require "uri"
|
33
|
-
require "addressable/uri"
|
34
|
-
require "openssl"
|
35
|
-
require "yaml"
|
36
|
-
|
37
|
-
module ChefConfig
|
38
|
-
|
39
|
-
class Config
|
40
|
-
|
41
|
-
extend Mixlib::Config
|
42
|
-
extend ChefConfig::Mixin::FuzzyHostnameMatcher
|
43
|
-
|
44
|
-
# Evaluates the given string as config.
|
45
|
-
#
|
46
|
-
# +filename+ is used for context in stacktraces, but doesn't need to be the name of an actual file.
|
47
|
-
def self.from_string(string, filename)
|
48
|
-
instance_eval(string, filename, 1)
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.inspect
|
52
|
-
configuration.inspect
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.platform_specific_path(path)
|
56
|
-
path = PathHelper.cleanpath(path)
|
57
|
-
if ChefConfig.windows?
|
58
|
-
# turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb
|
59
|
-
# Some installations will be on different drives so use the drive that
|
60
|
-
# the expanded path to __FILE__ is found.
|
61
|
-
drive = windows_installation_drive
|
62
|
-
if drive && path[0] == '\\' && path.split('\\')[2] == "chef"
|
63
|
-
path = PathHelper.join(drive, path.split('\\', 3)[2])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
path
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.windows_installation_drive
|
70
|
-
if ChefConfig.windows?
|
71
|
-
drive = File.expand_path(__FILE__).split("/", 2)[0]
|
72
|
-
drive = ENV["SYSTEMDRIVE"] if drive.to_s == ""
|
73
|
-
drive
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.add_formatter(name, file_path = nil)
|
78
|
-
formatters << [name, file_path]
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.add_event_logger(logger)
|
82
|
-
event_handlers << logger
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.apply_extra_config_options(extra_config_options)
|
86
|
-
if extra_config_options
|
87
|
-
extra_parsed_options = extra_config_options.inject({}) do |memo, option|
|
88
|
-
# Sanity check value.
|
89
|
-
if option.empty? || !option.include?("=")
|
90
|
-
raise UnparsableConfigOption, "Unparsable config option #{option.inspect}"
|
91
|
-
end
|
92
|
-
# Split including whitespace if someone does truly odd like
|
93
|
-
# --config-option "foo = bar"
|
94
|
-
key, value = option.split(/\s*=\s*/, 2)
|
95
|
-
# Call to_sym because Chef::Config expects only symbol keys. Also
|
96
|
-
# runs a simple parse on the string for some common types.
|
97
|
-
memo[key.to_sym] = YAML.safe_load(value)
|
98
|
-
memo
|
99
|
-
end
|
100
|
-
merge!(extra_parsed_options)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Config file to load (client.rb, knife.rb, etc. defaults set differently in knife, chef-client, etc.)
|
105
|
-
configurable(:config_file)
|
106
|
-
|
107
|
-
default(:config_dir) do
|
108
|
-
if config_file
|
109
|
-
PathHelper.dirname(PathHelper.canonical_path(config_file, false))
|
110
|
-
else
|
111
|
-
PathHelper.join(user_home, ".chef", "")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
default :formatters, []
|
116
|
-
|
117
|
-
def self.is_valid_url?(uri)
|
118
|
-
url = uri.to_s.strip
|
119
|
-
/^http:\/\// =~ url || /^https:\/\// =~ url || /^chefzero:/ =~ url
|
120
|
-
end
|
121
|
-
# Override the config dispatch to set the value of multiple server options simultaneously
|
122
|
-
#
|
123
|
-
# === Parameters
|
124
|
-
# url<String>:: String to be set for all of the chef-server-api URL's
|
125
|
-
#
|
126
|
-
configurable(:chef_server_url).writes_value do |uri|
|
127
|
-
unless is_valid_url? uri
|
128
|
-
raise ConfigurationError, "#{uri} is an invalid chef_server_url."
|
129
|
-
end
|
130
|
-
uri.to_s.strip
|
131
|
-
end
|
132
|
-
|
133
|
-
# When you are using ActiveSupport, they monkey-patch 'daemonize' into Kernel.
|
134
|
-
# So while this is basically identical to what method_missing would do, we pull
|
135
|
-
# it up here and get a real method written so that things get dispatched
|
136
|
-
# properly.
|
137
|
-
configurable(:daemonize).writes_value { |v| v }
|
138
|
-
|
139
|
-
# The root where all local chef object data is stored. cookbooks, data bags,
|
140
|
-
# environments are all assumed to be in separate directories under this.
|
141
|
-
# chef-solo uses these directories for input data. knife commands
|
142
|
-
# that upload or download files (such as knife upload, knife role from file,
|
143
|
-
# etc.) work.
|
144
|
-
default :chef_repo_path do
|
145
|
-
if configuration[:cookbook_path]
|
146
|
-
if configuration[:cookbook_path].kind_of?(String)
|
147
|
-
File.expand_path("..", configuration[:cookbook_path])
|
148
|
-
else
|
149
|
-
configuration[:cookbook_path].map do |path|
|
150
|
-
File.expand_path("..", path)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
elsif configuration[:cookbook_artifact_path]
|
154
|
-
File.expand_path("..", configuration[:cookbook_artifact_path])
|
155
|
-
else
|
156
|
-
cache_path
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.find_chef_repo_path(cwd)
|
161
|
-
# In local mode, we auto-discover the repo root by looking for a path with "cookbooks" under it.
|
162
|
-
# This allows us to run config-free.
|
163
|
-
path = cwd
|
164
|
-
until File.directory?(PathHelper.join(path, "cookbooks")) || File.directory?(PathHelper.join(path, "cookbook_artifacts"))
|
165
|
-
new_path = File.expand_path("..", path)
|
166
|
-
if new_path == path
|
167
|
-
ChefConfig.logger.warn("No cookbooks directory found at or above current directory. Assuming #{cwd}.")
|
168
|
-
return cwd
|
169
|
-
end
|
170
|
-
path = new_path
|
171
|
-
end
|
172
|
-
ChefConfig.logger.info("Auto-discovered chef repository at #{path}")
|
173
|
-
path
|
174
|
-
end
|
175
|
-
|
176
|
-
def self.derive_path_from_chef_repo_path(child_path)
|
177
|
-
if chef_repo_path.kind_of?(String)
|
178
|
-
PathHelper.join(chef_repo_path, child_path)
|
179
|
-
else
|
180
|
-
chef_repo_path.uniq.map { |path| PathHelper.join(path, child_path) }
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# Location of acls on disk. String or array of strings.
|
185
|
-
# Defaults to <chef_repo_path>/acls.
|
186
|
-
default(:acl_path) { derive_path_from_chef_repo_path("acls") }
|
187
|
-
|
188
|
-
# Location of clients on disk. String or array of strings.
|
189
|
-
# Defaults to <chef_repo_path>/clients.
|
190
|
-
default(:client_path) { derive_path_from_chef_repo_path("clients") }
|
191
|
-
|
192
|
-
# Location of client keys on disk. String or array of strings.
|
193
|
-
# Defaults to <chef_repo_path>/client_keys.
|
194
|
-
default(:client_key_path) { derive_path_from_chef_repo_path("client_keys") }
|
195
|
-
|
196
|
-
# Location of containers on disk. String or array of strings.
|
197
|
-
# Defaults to <chef_repo_path>/containers.
|
198
|
-
default(:container_path) { derive_path_from_chef_repo_path("containers") }
|
199
|
-
|
200
|
-
# Location of cookbook_artifacts on disk. String or array of strings.
|
201
|
-
# Defaults to <chef_repo_path>/cookbook_artifacts.
|
202
|
-
default(:cookbook_artifact_path) { derive_path_from_chef_repo_path("cookbook_artifacts") }
|
203
|
-
|
204
|
-
# Location of cookbooks on disk. String or array of strings.
|
205
|
-
# Defaults to <chef_repo_path>/cookbooks. If chef_repo_path
|
206
|
-
# is not specified, this is set to [/var/chef/cookbooks, /var/chef/site-cookbooks]).
|
207
|
-
default(:cookbook_path) do
|
208
|
-
if configuration[:chef_repo_path]
|
209
|
-
derive_path_from_chef_repo_path("cookbooks")
|
210
|
-
else
|
211
|
-
Array(derive_path_from_chef_repo_path("cookbooks")).flatten +
|
212
|
-
Array(derive_path_from_chef_repo_path("site-cookbooks")).flatten
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
# Location of data bags on disk. String or array of strings.
|
217
|
-
# Defaults to <chef_repo_path>/data_bags.
|
218
|
-
default(:data_bag_path) { derive_path_from_chef_repo_path("data_bags") }
|
219
|
-
|
220
|
-
# Location of environments on disk. String or array of strings.
|
221
|
-
# Defaults to <chef_repo_path>/environments.
|
222
|
-
default(:environment_path) { derive_path_from_chef_repo_path("environments") }
|
223
|
-
|
224
|
-
# Location of groups on disk. String or array of strings.
|
225
|
-
# Defaults to <chef_repo_path>/groups.
|
226
|
-
default(:group_path) { derive_path_from_chef_repo_path("groups") }
|
227
|
-
|
228
|
-
# Location of nodes on disk. String or array of strings.
|
229
|
-
# Defaults to <chef_repo_path>/nodes.
|
230
|
-
default(:node_path) { derive_path_from_chef_repo_path("nodes") }
|
231
|
-
|
232
|
-
# Location of policies on disk. String or array of strings.
|
233
|
-
# Defaults to <chef_repo_path>/policies.
|
234
|
-
default(:policy_path) { derive_path_from_chef_repo_path("policies") }
|
235
|
-
|
236
|
-
# Location of policy_groups on disk. String or array of strings.
|
237
|
-
# Defaults to <chef_repo_path>/policy_groups.
|
238
|
-
default(:policy_group_path) { derive_path_from_chef_repo_path("policy_groups") }
|
239
|
-
|
240
|
-
# Location of roles on disk. String or array of strings.
|
241
|
-
# Defaults to <chef_repo_path>/roles.
|
242
|
-
default(:role_path) { derive_path_from_chef_repo_path("roles") }
|
243
|
-
|
244
|
-
# Location of users on disk. String or array of strings.
|
245
|
-
# Defaults to <chef_repo_path>/users.
|
246
|
-
default(:user_path) { derive_path_from_chef_repo_path("users") }
|
247
|
-
|
248
|
-
# Location of policies on disk. String or array of strings.
|
249
|
-
# Defaults to <chef_repo_path>/policies.
|
250
|
-
default(:policy_path) { derive_path_from_chef_repo_path("policies") }
|
251
|
-
|
252
|
-
# Turn on "path sanity" by default. See also: http://wiki.opscode.com/display/chef/User+Environment+PATH+Sanity
|
253
|
-
default :enforce_path_sanity, true
|
254
|
-
|
255
|
-
# Formatted Chef Client output is a beta feature, disabled by default:
|
256
|
-
default :formatter, "null"
|
257
|
-
|
258
|
-
# The number of times the client should retry when registering with the server
|
259
|
-
default :client_registration_retries, 5
|
260
|
-
|
261
|
-
# An array of paths to search for knife exec scripts if they aren't in the current directory
|
262
|
-
default :script_path, []
|
263
|
-
|
264
|
-
# The root of all caches (checksums, cache and backup). If local mode is on,
|
265
|
-
# this is under the user's home directory.
|
266
|
-
default(:cache_path) do
|
267
|
-
if local_mode
|
268
|
-
PathHelper.join(config_dir, "local-mode-cache")
|
269
|
-
else
|
270
|
-
primary_cache_root = platform_specific_path("/var")
|
271
|
-
primary_cache_path = platform_specific_path("/var/chef")
|
272
|
-
# Use /var/chef as the cache path only if that folder exists and we can read and write
|
273
|
-
# into it, or /var exists and we can read and write into it (we'll create /var/chef later).
|
274
|
-
# Otherwise, we'll create .chef under the user's home directory and use that as
|
275
|
-
# the cache path.
|
276
|
-
unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
|
277
|
-
secondary_cache_path = PathHelper.join(user_home, ".chef")
|
278
|
-
ChefConfig.logger.info("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
|
279
|
-
secondary_cache_path
|
280
|
-
else
|
281
|
-
primary_cache_path
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
# Returns true only if the path exists and is readable and writeable for the user.
|
287
|
-
def self.path_accessible?(path)
|
288
|
-
File.exists?(path) && File.readable?(path) && File.writable?(path)
|
289
|
-
end
|
290
|
-
|
291
|
-
# Where cookbook files are stored on the server (by content checksum)
|
292
|
-
default(:checksum_path) { PathHelper.join(cache_path, "checksums") }
|
293
|
-
|
294
|
-
# Where chef's cache files should be stored
|
295
|
-
default(:file_cache_path) { PathHelper.join(cache_path, "cache") }
|
296
|
-
|
297
|
-
# Where backups of chef-managed files should go
|
298
|
-
default(:file_backup_path) { PathHelper.join(cache_path, "backup") }
|
299
|
-
|
300
|
-
# The chef-client (or solo) lockfile.
|
301
|
-
#
|
302
|
-
# If your `file_cache_path` resides on a NFS (or non-flock()-supporting
|
303
|
-
# fs), it's recommended to set this to something like
|
304
|
-
# '/tmp/chef-client-running.pid'
|
305
|
-
default(:lockfile) { PathHelper.join(file_cache_path, "chef-client-running.pid") }
|
306
|
-
|
307
|
-
## Daemonization Settings ##
|
308
|
-
# What user should Chef run as?
|
309
|
-
default :user, nil
|
310
|
-
default :group, nil
|
311
|
-
default :umask, 0022
|
312
|
-
|
313
|
-
# Valid log_levels are:
|
314
|
-
# * :debug
|
315
|
-
# * :info
|
316
|
-
# * :warn
|
317
|
-
# * :fatal
|
318
|
-
# These work as you'd expect. There is also a special `:auto` setting.
|
319
|
-
# When set to :auto, Chef will auto adjust the log verbosity based on
|
320
|
-
# context. When a tty is available (usually because the user is running chef
|
321
|
-
# in a console), the log level is set to :warn, and output formatters are
|
322
|
-
# used as the primary mode of output. When a tty is not available, the
|
323
|
-
# logger is the primary mode of output, and the log level is set to :info
|
324
|
-
default :log_level, :auto
|
325
|
-
|
326
|
-
# Logging location as either an IO stream or string representing log file path
|
327
|
-
default :log_location, STDOUT
|
328
|
-
|
329
|
-
# Using `force_formatter` causes chef to default to formatter output when STDOUT is not a tty
|
330
|
-
default :force_formatter, false
|
331
|
-
|
332
|
-
# Using `force_logger` causes chef to default to logger output when STDOUT is a tty
|
333
|
-
default :force_logger, false
|
334
|
-
|
335
|
-
# Using 'stream_execute_output' will have Chef always stream the execute output
|
336
|
-
default :stream_execute_output, false
|
337
|
-
|
338
|
-
# Using `show_download_progress` will display the overall progress
|
339
|
-
# of a remote file download
|
340
|
-
default :show_download_progress, false
|
341
|
-
# How often to update the progress meter, in percent
|
342
|
-
default :download_progress_interval, 10
|
343
|
-
|
344
|
-
default :http_retry_count, 5
|
345
|
-
default :http_retry_delay, 5
|
346
|
-
default :interval, nil
|
347
|
-
default :once, nil
|
348
|
-
default :json_attribs, nil
|
349
|
-
# toggle info level log items that can create a lot of output
|
350
|
-
default :verbose_logging, true
|
351
|
-
default :node_name, nil
|
352
|
-
default :diff_disabled, false
|
353
|
-
default :diff_filesize_threshold, 10000000
|
354
|
-
default :diff_output_threshold, 1000000
|
355
|
-
default :local_mode, false
|
356
|
-
|
357
|
-
# Configures the mode of operation for ChefFS, which is applied to the
|
358
|
-
# ChefFS-based knife commands and chef-client's local mode. (ChefFS-based
|
359
|
-
# knife commands include: knife delete, knife deps, knife diff, knife down,
|
360
|
-
# knife edit, knife list, knife show, knife upload, and knife xargs.)
|
361
|
-
#
|
362
|
-
# Valid values are:
|
363
|
-
# * "static": ChefFS only manages objects that exist in a traditional Chef
|
364
|
-
# Repo as of Chef 11.
|
365
|
-
# * "everything": ChefFS manages all object types that existed on the OSS
|
366
|
-
# Chef 11 server.
|
367
|
-
# * "hosted_everything": ChefFS manages all object types as of the Chef 12
|
368
|
-
# Server, including RBAC objects and Policyfile objects (new to Chef 12).
|
369
|
-
default :repo_mode do
|
370
|
-
if local_mode && !chef_zero.osc_compat
|
371
|
-
"hosted_everything"
|
372
|
-
elsif chef_server_url =~ /\/+organizations\/.+/
|
373
|
-
"hosted_everything"
|
374
|
-
else
|
375
|
-
"everything"
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
default :pid_file, nil
|
380
|
-
|
381
|
-
# Whether Chef Zero local mode should bind to a port. All internal requests
|
382
|
-
# will go through the socketless code path regardless, so the socket is
|
383
|
-
# only needed if other processes will connect to the local mode server.
|
384
|
-
#
|
385
|
-
# For compatibility this is set to true but it will be changed to false in
|
386
|
-
# the future.
|
387
|
-
default :listen, true
|
388
|
-
|
389
|
-
config_context :chef_zero do
|
390
|
-
config_strict_mode true
|
391
|
-
default(:enabled) { ChefConfig::Config.local_mode }
|
392
|
-
default :host, "localhost"
|
393
|
-
default :port, 8889.upto(9999) # Will try ports from 8889-9999 until one works
|
394
|
-
|
395
|
-
# When set to a String, Chef Zero disables multitenant support. This is
|
396
|
-
# what you want when using Chef Zero to serve a single Chef Repo. Setting
|
397
|
-
# this to `false` enables multi-tenant.
|
398
|
-
default :single_org, "chef"
|
399
|
-
|
400
|
-
# Whether Chef Zero should operate in a mode analogous to OSS Chef Server
|
401
|
-
# 11 (true) or Chef Server 12 (false). Chef Zero can still serve
|
402
|
-
# policyfile objects in Chef 11 mode, as long as `repo_mode` is set to
|
403
|
-
# "hosted_everything". The primary differences are:
|
404
|
-
# * Chef 11 mode doesn't support multi-tennant, so there is no
|
405
|
-
# distinction between global and org-specific objects (since there are
|
406
|
-
# no orgs).
|
407
|
-
# * Chef 11 mode doesn't expose RBAC objects
|
408
|
-
default :osc_compat, false
|
409
|
-
end
|
410
|
-
default :chef_server_url, "https://localhost:443"
|
411
|
-
|
412
|
-
default(:chef_server_root) do
|
413
|
-
# if the chef_server_url is a path to an organization, aka
|
414
|
-
# 'some_url.../organizations/*' then remove the '/organization/*' by default
|
415
|
-
if configuration[:chef_server_url] =~ /\/organizations\/\S*$/
|
416
|
-
configuration[:chef_server_url].split("/")[0..-3].join("/")
|
417
|
-
elsif configuration[:chef_server_url] # default to whatever chef_server_url is
|
418
|
-
configuration[:chef_server_url]
|
419
|
-
else
|
420
|
-
"https://localhost:443"
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
default :rest_timeout, 300
|
425
|
-
default :yum_timeout, 900
|
426
|
-
default :yum_lock_timeout, 30
|
427
|
-
default :solo, false
|
428
|
-
|
429
|
-
# Are we running in old Chef Solo legacy mode?
|
430
|
-
default :solo_legacy_mode, false
|
431
|
-
|
432
|
-
default :splay, nil
|
433
|
-
default :why_run, false
|
434
|
-
default :color, false
|
435
|
-
default :client_fork, true
|
436
|
-
default :ez, false
|
437
|
-
default :enable_reporting, true
|
438
|
-
default :enable_reporting_url_fatals, false
|
439
|
-
# Possible values for :audit_mode
|
440
|
-
# :enabled, :disabled, :audit_only,
|
441
|
-
#
|
442
|
-
# TODO: 11 Dec 2014: Currently audit-mode is an experimental feature
|
443
|
-
# and is disabled by default. When users choose to enable audit-mode,
|
444
|
-
# a warning is issued in application/client#reconfigure.
|
445
|
-
# This can be removed when audit-mode is enabled by default.
|
446
|
-
default :audit_mode, :disabled
|
447
|
-
|
448
|
-
# Chef only needs ohai to run the hostname plugin for the most basic
|
449
|
-
# functionality. If the rest of the ohai plugins are not needed (like in
|
450
|
-
# most of our testing scenarios)
|
451
|
-
default :minimal_ohai, false
|
452
|
-
|
453
|
-
###
|
454
|
-
# Policyfile Settings
|
455
|
-
#
|
456
|
-
# Policyfile is a feature where a node gets its run list and cookbook
|
457
|
-
# version set from a single document on the server instead of expanding the
|
458
|
-
# run list and having the server compute the cookbook version set based on
|
459
|
-
# environment constraints.
|
460
|
-
#
|
461
|
-
# Policyfiles are auto-versioned. The user groups nodes by `policy_name`,
|
462
|
-
# which generally describes a hosts's functional role, and `policy_group`,
|
463
|
-
# which generally groups nodes by deployment phase (a.k.a., "environment").
|
464
|
-
# The Chef Server maps a given set of `policy_name` plus `policy_group` to
|
465
|
-
# a particular revision of a policy.
|
466
|
-
|
467
|
-
default :policy_name, nil
|
468
|
-
default :policy_group, nil
|
469
|
-
|
470
|
-
# Policyfiles can have multiple run lists, via the named run list feature.
|
471
|
-
# Generally this will be set by a CLI option via Chef::Application::Client,
|
472
|
-
# but it could be set in client.rb if desired.
|
473
|
-
|
474
|
-
default :named_run_list, nil
|
475
|
-
|
476
|
-
# During initial development, users were required to set `use_policyfile true`
|
477
|
-
# in `client.rb` to opt-in to policyfile use. Chef Client now examines
|
478
|
-
# configuration, node json, and the stored node to determine if policyfile
|
479
|
-
# usage is desired. This flag is still honored if set, but is unnecessary.
|
480
|
-
default :use_policyfile, false
|
481
|
-
|
482
|
-
# Policyfiles can be used in a native mode (default) or compatibility mode.
|
483
|
-
# Native mode requires Chef Server 12.1 (it can be enabled via feature flag
|
484
|
-
# on some prior versions). In native mode, policies and associated
|
485
|
-
# cookbooks are accessed via feature-specific APIs. In compat mode,
|
486
|
-
# policies are stored as data bags and cookbooks are stored at the
|
487
|
-
# cookbooks/ endpoint. Compatibility mode can be dangerous on existing Chef
|
488
|
-
# Servers; it's recommended to upgrade your Chef Server rather than use
|
489
|
-
# compatibility mode. Compatibility mode remains available so you can use
|
490
|
-
# policyfiles with servers that don't yet support the native endpoints.
|
491
|
-
default :policy_document_native_api, true
|
492
|
-
|
493
|
-
# When policyfiles are used in compatibility mode, `policy_name` and
|
494
|
-
# `policy_group` are instead specified using a combined configuration
|
495
|
-
# setting, `deployment_group`. For example, if policy_name should be
|
496
|
-
# "webserver" and policy_group should be "staging", then `deployment_group`
|
497
|
-
# should be set to "webserver-staging", which is the name of the data bag
|
498
|
-
# item that the policy will be stored as. NOTE: this setting only has an
|
499
|
-
# effect if `policy_document_native_api` is set to `false`.
|
500
|
-
default :deployment_group, nil
|
501
|
-
|
502
|
-
# Set these to enable SSL authentication / mutual-authentication
|
503
|
-
# with the server
|
504
|
-
|
505
|
-
# Client side SSL cert/key for mutual auth
|
506
|
-
default :ssl_client_cert, nil
|
507
|
-
default :ssl_client_key, nil
|
508
|
-
|
509
|
-
# Whether or not to verify the SSL cert for all HTTPS requests. When set to
|
510
|
-
# :verify_peer (default), all HTTPS requests will be validated regardless of other
|
511
|
-
# SSL verification settings. When set to :verify_none no HTTPS requests will
|
512
|
-
# be validated.
|
513
|
-
default :ssl_verify_mode, :verify_peer
|
514
|
-
|
515
|
-
# Whether or not to verify the SSL cert for HTTPS requests to the Chef
|
516
|
-
# server API. If set to `true`, the server's cert will be validated
|
517
|
-
# regardless of the :ssl_verify_mode setting. This is set to `true` when
|
518
|
-
# running in local-mode.
|
519
|
-
# NOTE: This is a workaround until verify_peer is enabled by default.
|
520
|
-
default(:verify_api_cert) { ChefConfig::Config.local_mode }
|
521
|
-
|
522
|
-
# Path to the default CA bundle files.
|
523
|
-
default :ssl_ca_path, nil
|
524
|
-
default(:ssl_ca_file) do
|
525
|
-
if ChefConfig.windows? && embedded_dir
|
526
|
-
cacert_path = File.join(embedded_dir, "ssl/certs/cacert.pem")
|
527
|
-
cacert_path if File.exist?(cacert_path)
|
528
|
-
else
|
529
|
-
nil
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
# A directory that contains additional SSL certificates to trust. Any
|
534
|
-
# certificates in this directory will be added to whatever CA bundle ruby
|
535
|
-
# is using. Use this to add self-signed certs for your Chef Server or local
|
536
|
-
# HTTP file servers.
|
537
|
-
default(:trusted_certs_dir) { PathHelper.join(config_dir, "trusted_certs") }
|
538
|
-
|
539
|
-
# A directory that contains additional configuration scripts to load for chef-client
|
540
|
-
default(:client_d_dir) { PathHelper.join(config_dir, "client.d") }
|
541
|
-
|
542
|
-
# A directory that contains additional configuration scripts to load for solo
|
543
|
-
default(:solo_d_dir) { PathHelper.join(config_dir, "solo.d") }
|
544
|
-
|
545
|
-
# A directory that contains additional configuration scripts to load for
|
546
|
-
# the workstation config
|
547
|
-
default(:config_d_dir) { PathHelper.join(config_dir, "config.d") }
|
548
|
-
|
549
|
-
# Where should chef-solo download recipes from?
|
550
|
-
default :recipe_url, nil
|
551
|
-
|
552
|
-
# Set to true if Chef is to set OpenSSL to run in FIPS mode
|
553
|
-
default(:fips) do
|
554
|
-
# CHEF_FIPS is used in testing to override checking for system level
|
555
|
-
# enablement. There are 3 possible values that this variable may have:
|
556
|
-
# nil - no override and the system will be checked
|
557
|
-
# empty - FIPS is NOT enabled
|
558
|
-
# a non empty value - FIPS is enabled
|
559
|
-
if ENV["CHEF_FIPS"] == ""
|
560
|
-
false
|
561
|
-
else
|
562
|
-
!ENV["CHEF_FIPS"].nil? || ChefConfig.fips?
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
# Initialize openssl
|
567
|
-
def self.init_openssl
|
568
|
-
if fips
|
569
|
-
enable_fips_mode
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
# Sets the version of the signed header authentication protocol to use (see
|
574
|
-
# the 'mixlib-authorization' project for more detail). Currently, versions
|
575
|
-
# 1.0, 1.1, and 1.3 are available.
|
576
|
-
default :authentication_protocol_version do
|
577
|
-
if fips
|
578
|
-
"1.3"
|
579
|
-
else
|
580
|
-
"1.1"
|
581
|
-
end
|
582
|
-
end
|
583
|
-
|
584
|
-
# This key will be used to sign requests to the Chef server. This location
|
585
|
-
# must be writable by Chef during initial setup when generating a client
|
586
|
-
# identity on the server.
|
587
|
-
#
|
588
|
-
# The chef-server will look up the public key for the client using the
|
589
|
-
# `node_name` of the client.
|
590
|
-
#
|
591
|
-
# If chef-zero is enabled, this defaults to nil (no authentication).
|
592
|
-
default(:client_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/client.pem") }
|
593
|
-
|
594
|
-
# When registering the client, should we allow the client key location to
|
595
|
-
# be a symlink? eg: /etc/chef/client.pem -> /etc/chef/prod-client.pem
|
596
|
-
# If the path of the key goes through a directory like /tmp this should
|
597
|
-
# never be set to true or its possibly an easily exploitable security hole.
|
598
|
-
default :follow_client_key_symlink, false
|
599
|
-
|
600
|
-
# This secret is used to decrypt encrypted data bag items.
|
601
|
-
default(:encrypted_data_bag_secret) do
|
602
|
-
if File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
|
603
|
-
platform_specific_path("/etc/chef/encrypted_data_bag_secret")
|
604
|
-
else
|
605
|
-
nil
|
606
|
-
end
|
607
|
-
end
|
608
|
-
|
609
|
-
# As of Chef 11.0, version "1" is the default encrypted data bag item
|
610
|
-
# format. Version "2" is available which adds encrypt-then-mac protection.
|
611
|
-
# To maintain compatibility, versions other than 1 must be opt-in.
|
612
|
-
#
|
613
|
-
# Set this to `2` if you have chef-client 11.6.0+ in your infrastructure.
|
614
|
-
# Set this to `3` if you have chef-client 11.?.0+, ruby 2 and OpenSSL >= 1.0.1 in your infrastructure. (TODO)
|
615
|
-
default :data_bag_encrypt_version, 1
|
616
|
-
|
617
|
-
# When reading data bag items, any supported version is accepted. However,
|
618
|
-
# if all encrypted data bags have been generated with the version 2 format,
|
619
|
-
# it is recommended to disable support for earlier formats to improve
|
620
|
-
# security. For example, the version 2 format is identical to version 1
|
621
|
-
# except for the addition of an HMAC, so an attacker with MITM capability
|
622
|
-
# could downgrade an encrypted data bag to version 1 as part of an attack.
|
623
|
-
default :data_bag_decrypt_minimum_version, 0
|
624
|
-
|
625
|
-
# If there is no file in the location given by `client_key`, chef-client
|
626
|
-
# will temporarily use the "validator" identity to generate one. If the
|
627
|
-
# `client_key` is not present and the `validation_key` is also not present,
|
628
|
-
# chef-client will not be able to authenticate to the server.
|
629
|
-
#
|
630
|
-
# The `validation_key` is never used if the `client_key` exists.
|
631
|
-
#
|
632
|
-
# If chef-zero is enabled, this defaults to nil (no authentication).
|
633
|
-
default(:validation_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/validation.pem") }
|
634
|
-
default :validation_client_name, "chef-validator"
|
635
|
-
|
636
|
-
# When creating a new client via the validation_client account, Chef 11
|
637
|
-
# servers allow the client to generate a key pair locally and send the
|
638
|
-
# public key to the server. This is more secure and helps offload work from
|
639
|
-
# the server, enhancing scalability. If enabled and the remote server
|
640
|
-
# implements only the Chef 10 API, client registration will not work
|
641
|
-
# properly.
|
642
|
-
#
|
643
|
-
# The default value is `true`. Set to `false` to disable client-side key
|
644
|
-
# generation (server generates client keys).
|
645
|
-
default(:local_key_generation) { true }
|
646
|
-
|
647
|
-
# Zypper package provider gpg checks. Set to true to enable package
|
648
|
-
# gpg signature checking. This will be default in the
|
649
|
-
# future. Setting to false disables the warnings.
|
650
|
-
# Leaving this set to nil or false is a security hazard!
|
651
|
-
default :zypper_check_gpg, nil
|
652
|
-
|
653
|
-
# Report Handlers
|
654
|
-
default :report_handlers, []
|
655
|
-
|
656
|
-
# Event Handlers
|
657
|
-
default :event_handlers, []
|
658
|
-
|
659
|
-
default :disable_event_loggers, false
|
660
|
-
|
661
|
-
# Exception Handlers
|
662
|
-
default :exception_handlers, []
|
663
|
-
|
664
|
-
# Start handlers
|
665
|
-
default :start_handlers, []
|
666
|
-
|
667
|
-
# Syntax Check Cache. Knife keeps track of files that is has already syntax
|
668
|
-
# checked by storing files in this directory. `syntax_check_cache_path` is
|
669
|
-
# the new (and preferred) configuration setting. If not set, knife will
|
670
|
-
# fall back to using cache_options[:path], which is deprecated but exists in
|
671
|
-
# many client configs generated by pre-Chef-11 bootstrappers.
|
672
|
-
default(:syntax_check_cache_path) { cache_options[:path] }
|
673
|
-
|
674
|
-
# Deprecated:
|
675
|
-
# Move this to the default value of syntax_cache_path when this is removed.
|
676
|
-
default(:cache_options) { { :path => PathHelper.join(config_dir, "syntaxcache") } }
|
677
|
-
|
678
|
-
# Whether errors should be raised for deprecation warnings. When set to
|
679
|
-
# `false` (the default setting), a warning is emitted but code using
|
680
|
-
# deprecated methods/features/etc. should work normally otherwise. When set
|
681
|
-
# to `true`, usage of deprecated methods/features will raise a
|
682
|
-
# `DeprecatedFeatureError`. This is used by Chef's tests to ensure that
|
683
|
-
# deprecated functionality is not used internally by Chef. End users
|
684
|
-
# should generally leave this at the default setting (especially in
|
685
|
-
# production), but it may be useful when testing cookbooks or other code if
|
686
|
-
# the user wishes to aggressively address deprecations.
|
687
|
-
default(:treat_deprecation_warnings_as_errors) do
|
688
|
-
# Using an environment variable allows this setting to be inherited in
|
689
|
-
# tests that spawn new processes.
|
690
|
-
ENV.key?("CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS")
|
691
|
-
end
|
692
|
-
|
693
|
-
# Whether the resource count should be updated for log resource
|
694
|
-
# on running chef-client
|
695
|
-
default :count_log_resource_updates, true
|
696
|
-
|
697
|
-
# knife configuration data
|
698
|
-
config_context :knife do
|
699
|
-
# XXX: none of these default values are applied to knife (and would create a backcompat
|
700
|
-
# break in knife if this bug was fixed since many of the defaults below are wrong). this appears
|
701
|
-
# to be the start of an attempt to be able to use config_strict_mode true? if so, this approach
|
702
|
-
# is fraught with peril because this namespace is used by every knife plugin in the wild and
|
703
|
-
# we would need to validate every cli option in every knife attribute out there and list them all here.
|
704
|
-
#
|
705
|
-
# based on the way that people may define `knife[:foobar] = "something"` for the knife-foobar
|
706
|
-
# gem plugin i'm pretty certain we can never turn on anything like config_string_mode since
|
707
|
-
# any config value may be a typo or it may be in some gem in some knife plugin we don't know about.
|
708
|
-
#
|
709
|
-
# we do still need to maintain at least one of these so that the knife config hash gets
|
710
|
-
# created.
|
711
|
-
#
|
712
|
-
# this whole situation is deeply unsatisfying.
|
713
|
-
default :ssh_port, nil
|
714
|
-
default :ssh_user, nil
|
715
|
-
default :ssh_attribute, nil
|
716
|
-
default :ssh_gateway, nil
|
717
|
-
default :bootstrap_version, nil
|
718
|
-
default :bootstrap_proxy, nil
|
719
|
-
default :bootstrap_template, nil
|
720
|
-
default :secret, nil
|
721
|
-
default :secret_file, nil
|
722
|
-
default :identity_file, nil
|
723
|
-
default :host_key_verify, nil
|
724
|
-
default :forward_agent, nil
|
725
|
-
default :sort_status_reverse, nil
|
726
|
-
default :hints, {}
|
727
|
-
end
|
728
|
-
|
729
|
-
def self.set_defaults_for_windows
|
730
|
-
# Those lists of regular expressions define what chef considers a
|
731
|
-
# valid user and group name
|
732
|
-
# From http://technet.microsoft.com/en-us/library/cc776019(WS.10).aspx
|
733
|
-
principal_valid_regex_part = '[^"\/\\\\\[\]\:;|=,+*?<>]+'
|
734
|
-
default :user_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
735
|
-
default :group_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
736
|
-
|
737
|
-
default :fatal_windows_admin_check, false
|
738
|
-
end
|
739
|
-
|
740
|
-
def self.set_defaults_for_nix
|
741
|
-
# Those lists of regular expressions define what chef considers a
|
742
|
-
# valid user and group name
|
743
|
-
#
|
744
|
-
# user/group cannot start with '-', '+' or '~'
|
745
|
-
# user/group cannot contain ':', ',' or non-space-whitespace or null byte
|
746
|
-
# everything else is allowed (UTF-8, spaces, etc) and we delegate to your O/S useradd program to barf or not
|
747
|
-
# copies: http://anonscm.debian.org/viewvc/pkg-shadow/debian/trunk/debian/patches/506_relaxed_usernames?view=markup
|
748
|
-
default :user_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ]
|
749
|
-
default :group_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ]
|
750
|
-
end
|
751
|
-
|
752
|
-
# Those lists of regular expressions define what chef considers a
|
753
|
-
# valid user and group name
|
754
|
-
if ChefConfig.windows?
|
755
|
-
set_defaults_for_windows
|
756
|
-
else
|
757
|
-
set_defaults_for_nix
|
758
|
-
end
|
759
|
-
|
760
|
-
# This provides a hook which rspec can stub so that we can avoid twiddling
|
761
|
-
# global state in tests.
|
762
|
-
def self.env
|
763
|
-
ENV
|
764
|
-
end
|
765
|
-
|
766
|
-
def self.windows_home_path
|
767
|
-
ChefConfig.logger.deprecation("Chef::Config.windows_home_path is now deprecated. Consider using Chef::Util::PathHelper.home instead.")
|
768
|
-
PathHelper.home
|
769
|
-
end
|
770
|
-
|
771
|
-
# returns a platform specific path to the user home dir if set, otherwise default to current directory.
|
772
|
-
default( :user_home ) { PathHelper.home || Dir.pwd }
|
773
|
-
|
774
|
-
# Enable file permission fixup for selinux. Fixup will be done
|
775
|
-
# only if selinux is enabled in the system.
|
776
|
-
default :enable_selinux_file_permission_fixup, true
|
777
|
-
|
778
|
-
# Use atomic updates (i.e. move operation) while updating contents
|
779
|
-
# of the files resources. When set to false copy operation is
|
780
|
-
# used to update files.
|
781
|
-
#
|
782
|
-
# NOTE: CHANGING THIS SETTING MAY CAUSE CORRUPTION, DATA LOSS AND
|
783
|
-
# INSTABILITY.
|
784
|
-
default :file_atomic_update, true
|
785
|
-
|
786
|
-
# There are 3 possible values for this configuration setting.
|
787
|
-
# true => file staging is done in the destination directory
|
788
|
-
# false => file staging is done via tempfiles under ENV['TMP']
|
789
|
-
# :auto => file staging will try using destination directory if possible and
|
790
|
-
# will fall back to ENV['TMP'] if destination directory is not usable.
|
791
|
-
default :file_staging_uses_destdir, :auto
|
792
|
-
|
793
|
-
# Exit if another run is in progress and the chef-client is unable to
|
794
|
-
# get the lock before time expires. If nil, no timeout is enforced. (Exits
|
795
|
-
# immediately if 0.)
|
796
|
-
default :run_lock_timeout, nil
|
797
|
-
|
798
|
-
# Number of worker threads for syncing cookbooks in parallel. Increasing
|
799
|
-
# this number can result in gateway errors from the server (namely 503 and 504).
|
800
|
-
# If you are seeing this behavior while using the default setting, reducing
|
801
|
-
# the number of threads will help.
|
802
|
-
default :cookbook_sync_threads, 10
|
803
|
-
|
804
|
-
# At the beginning of the Chef Client run, the cookbook manifests are downloaded which
|
805
|
-
# contain URLs for every file in every relevant cookbook. Most of the files
|
806
|
-
# (recipes, resources, providers, libraries, etc) are immediately synchronized
|
807
|
-
# at the start of the run. The handling of "files" and "templates" directories,
|
808
|
-
# however, have two modes of operation. They can either all be downloaded immediately
|
809
|
-
# at the start of the run (no_lazy_load==true) or else they can be lazily loaded as
|
810
|
-
# cookbook_file or template resources are converged which require them (no_lazy_load==false).
|
811
|
-
#
|
812
|
-
# The advantage of lazily loading these files is that unnecessary files are not
|
813
|
-
# synchronized. This may be useful to users with large files checked into cookbooks which
|
814
|
-
# are only selectively downloaded to a subset of clients which use the cookbook. However,
|
815
|
-
# better solutions are to either isolate large files into individual cookbooks and only
|
816
|
-
# include those cookbooks in the run lists of the servers that need them -- or move to
|
817
|
-
# using remote_file and a more appropriate backing store like S3 for large file
|
818
|
-
# distribution.
|
819
|
-
#
|
820
|
-
# The disadvantages of lazily loading files are that users some time find it
|
821
|
-
# confusing that their cookbooks are not fully synchronzied to the cache initially,
|
822
|
-
# and more importantly the time-sensitive URLs which are in the manifest may time
|
823
|
-
# out on long Chef runs before the resource that uses the file is converged
|
824
|
-
# (leading to many confusing 403 errors on template/cookbook_file resources).
|
825
|
-
#
|
826
|
-
default :no_lazy_load, true
|
827
|
-
|
828
|
-
# Default for the chef_gem compile_time attribute. Nil is the same as true but will emit
|
829
|
-
# warnings on every use of chef_gem prompting the user to be explicit. If the user sets this to
|
830
|
-
# true then the user will get backcompat behavior but with a single nag warning that cookbooks
|
831
|
-
# may break with this setting in the future. The false setting is the recommended setting and
|
832
|
-
# will become the default.
|
833
|
-
default :chef_gem_compile_time, nil
|
834
|
-
|
835
|
-
# A whitelisted array of attributes you want sent over the wire when node
|
836
|
-
# data is saved.
|
837
|
-
# The default setting is nil, which collects all data. Setting to [] will not
|
838
|
-
# collect any data for save.
|
839
|
-
default :automatic_attribute_whitelist, nil
|
840
|
-
default :default_attribute_whitelist, nil
|
841
|
-
default :normal_attribute_whitelist, nil
|
842
|
-
default :override_attribute_whitelist, nil
|
843
|
-
|
844
|
-
# Pull down all the rubygems versions from rubygems and cache them the first time we do a gem_package or
|
845
|
-
# chef_gem install. This is memory-expensive and will grow without bounds, but will reduce network
|
846
|
-
# round trips.
|
847
|
-
default :rubygems_cache_enabled, false
|
848
|
-
|
849
|
-
config_context :windows_service do
|
850
|
-
# Set `watchdog_timeout` to the number of seconds to wait for a chef-client run
|
851
|
-
# to finish
|
852
|
-
default :watchdog_timeout, 2 * (60 * 60) # 2 hours
|
853
|
-
end
|
854
|
-
|
855
|
-
# Add an empty and non-strict config_context for chefdk. This lets the user
|
856
|
-
# have code like `chefdk.generator_cookbook "/path/to/cookbook"` in their
|
857
|
-
# config.rb, and it will be ignored by tools like knife and ohai. ChefDK
|
858
|
-
# itself can define the config options it accepts and enable strict mode,
|
859
|
-
# and that will only apply when running `chef` commands.
|
860
|
-
config_context :chefdk do
|
861
|
-
end
|
862
|
-
|
863
|
-
# Configuration options for Data Collector reporting. These settings allow
|
864
|
-
# the user to configure where to send their Data Collector data, what token
|
865
|
-
# to send, and whether Data Collector should report its findings in client
|
866
|
-
# mode vs. solo mode.
|
867
|
-
config_context :data_collector do
|
868
|
-
# Full URL to the endpoint that will receive our data. If nil, the
|
869
|
-
# data collector will not run.
|
870
|
-
# Ex: http://my-data-collector.mycompany.com/ingest
|
871
|
-
default(:server_url) do
|
872
|
-
if config_parent.solo || config_parent.local_mode
|
873
|
-
nil
|
874
|
-
else
|
875
|
-
File.join(config_parent.chef_server_url, "/data-collector")
|
876
|
-
end
|
877
|
-
end
|
878
|
-
|
879
|
-
# An optional pre-shared token to pass as an HTTP header (x-data-collector-token)
|
880
|
-
# that can be used to determine whether or not the poster of this
|
881
|
-
# run data should be trusted.
|
882
|
-
# Ex: some-uuid-here
|
883
|
-
default :token, nil
|
884
|
-
|
885
|
-
# The Chef mode during which Data Collector is allowed to function. This
|
886
|
-
# can be used to run Data Collector only when running as Chef Solo but
|
887
|
-
# not when using Chef Client.
|
888
|
-
# Options: :solo (for both Solo Legacy Mode and Client Local Mode), :client, :both
|
889
|
-
default :mode, :both
|
890
|
-
|
891
|
-
# When the Data Collector cannot send the "starting a run" message to
|
892
|
-
# the Data Collector server, the Data Collector will be disabled for that
|
893
|
-
# run. In some situations, such as highly-regulated environments, it
|
894
|
-
# may be more reasonable to prevent Chef from performing the actual run.
|
895
|
-
# In these situations, setting this value to true will cause the Chef
|
896
|
-
# run to raise an exception before starting any converge activities.
|
897
|
-
default :raise_on_failure, false
|
898
|
-
|
899
|
-
# A user-supplied Organization string that can be sent in payloads
|
900
|
-
# generated by the DataCollector when Chef is run in Solo mode. This
|
901
|
-
# allows users to associate their Solo nodes with faux organizations
|
902
|
-
# without the nodes being connected to an actual Chef Server.
|
903
|
-
default :organization, nil
|
904
|
-
end
|
905
|
-
|
906
|
-
configurable(:http_proxy)
|
907
|
-
configurable(:http_proxy_user)
|
908
|
-
configurable(:http_proxy_pass)
|
909
|
-
configurable(:https_proxy)
|
910
|
-
configurable(:https_proxy_user)
|
911
|
-
configurable(:https_proxy_pass)
|
912
|
-
configurable(:ftp_proxy)
|
913
|
-
configurable(:ftp_proxy_user)
|
914
|
-
configurable(:ftp_proxy_pass)
|
915
|
-
configurable(:no_proxy)
|
916
|
-
|
917
|
-
# Public method that users should call to export proxies to the appropriate
|
918
|
-
# environment variables. This method should be called after the config file is
|
919
|
-
# parsed and loaded.
|
920
|
-
# TODO add some post-file-parsing logic that automatically calls this so
|
921
|
-
# users don't have to
|
922
|
-
def self.export_proxies
|
923
|
-
export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if http_proxy
|
924
|
-
export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if https_proxy
|
925
|
-
export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if ftp_proxy
|
926
|
-
export_no_proxy(no_proxy) if no_proxy
|
927
|
-
end
|
928
|
-
|
929
|
-
# Character classes for Addressable
|
930
|
-
# See https://www.ietf.org/rfc/rfc3986.txt 3.2.1
|
931
|
-
# The user part may not have a : in it
|
932
|
-
USER = Addressable::URI::CharacterClasses::UNRESERVED + Addressable::URI::CharacterClasses::SUB_DELIMS
|
933
|
-
# The password part may have any valid USERINFO characters
|
934
|
-
PASSWORD = USER + "\\:"
|
935
|
-
|
936
|
-
# Builds a proxy uri and exports it to the appropriate environment variables. Examples:
|
937
|
-
# http://username:password@hostname:port
|
938
|
-
# https://username@hostname:port
|
939
|
-
# ftp://hostname:port
|
940
|
-
# when
|
941
|
-
# scheme = "http", "https", or "ftp"
|
942
|
-
# hostport = hostname:port or scheme://hostname:port
|
943
|
-
# user = username
|
944
|
-
# pass = password
|
945
|
-
# @api private
|
946
|
-
def self.export_proxy(scheme, path, user, pass)
|
947
|
-
path = "#{scheme}://#{path}" unless path.include?("://")
|
948
|
-
# URI.split returns the following parts:
|
949
|
-
# [scheme, userinfo, host, port, registry, path, opaque, query, fragment]
|
950
|
-
uri = Addressable::URI.encode(path, Addressable::URI)
|
951
|
-
|
952
|
-
if user && !user.empty?
|
953
|
-
userinfo = Addressable::URI.encode_component(user, USER)
|
954
|
-
if pass
|
955
|
-
userinfo << ":#{Addressable::URI.encode_component(pass, PASSWORD)}"
|
956
|
-
end
|
957
|
-
uri.userinfo = userinfo
|
958
|
-
end
|
959
|
-
|
960
|
-
path = uri.to_s
|
961
|
-
ENV["#{scheme}_proxy".downcase] = path unless ENV["#{scheme}_proxy".downcase]
|
962
|
-
ENV["#{scheme}_proxy".upcase] = path unless ENV["#{scheme}_proxy".upcase]
|
963
|
-
end
|
964
|
-
|
965
|
-
# @api private
|
966
|
-
def self.export_no_proxy(value)
|
967
|
-
ENV["no_proxy"] = value unless ENV["no_proxy"]
|
968
|
-
ENV["NO_PROXY"] = value unless ENV["NO_PROXY"]
|
969
|
-
end
|
970
|
-
|
971
|
-
# Given a scheme, host, and port, return the correct proxy URI based on the
|
972
|
-
# set environment variables, unless exluded by no_proxy, in which case nil
|
973
|
-
# is returned
|
974
|
-
def self.proxy_uri(scheme, host, port)
|
975
|
-
proxy_env_var = ENV["#{scheme}_proxy"].to_s.strip
|
976
|
-
|
977
|
-
# Check if the proxy string contains a scheme. If not, add the url's scheme to the
|
978
|
-
# proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy
|
979
|
-
# here since we are really just trying to get the string built correctly.
|
980
|
-
proxy = if !proxy_env_var.empty?
|
981
|
-
if proxy_env_var =~ /^.*:\/\//
|
982
|
-
URI.parse(proxy_env_var)
|
983
|
-
else
|
984
|
-
URI.parse("#{scheme}://#{proxy_env_var}")
|
985
|
-
end
|
986
|
-
end
|
987
|
-
|
988
|
-
return proxy unless fuzzy_hostname_match_any?(host, ENV["no_proxy"])
|
989
|
-
end
|
990
|
-
|
991
|
-
# Chef requires an English-language UTF-8 locale to function properly. We attempt
|
992
|
-
# to use the 'locale -a' command and search through a list of preferences until we
|
993
|
-
# find one that we can use. On Ubuntu systems we should find 'C.UTF-8' and be
|
994
|
-
# able to use that even if there is no English locale on the server, but Mac, Solaris,
|
995
|
-
# AIX, etc do not have that locale. We then try to find an English locale and fall
|
996
|
-
# back to 'C' if we do not. The choice of fallback is pick-your-poison. If we try
|
997
|
-
# to do the work to return a non-US UTF-8 locale then we fail inside of providers when
|
998
|
-
# things like 'svn info' return Japanese and we can't parse them. OTOH, if we pick 'C' then
|
999
|
-
# we will blow up on UTF-8 characters. Between the warn we throw and the Encoding
|
1000
|
-
# exception that ruby will throw it is more obvious what is broken if we drop UTF-8 by
|
1001
|
-
# default rather than drop English.
|
1002
|
-
#
|
1003
|
-
# If there is no 'locale -a' then we return 'en_US.UTF-8' since that is the most commonly
|
1004
|
-
# available English UTF-8 locale. However, all modern POSIXen should support 'locale -a'.
|
1005
|
-
def self.guess_internal_locale
|
1006
|
-
# https://github.com/chef/chef/issues/2181
|
1007
|
-
# Some systems have the `locale -a` command, but the result has
|
1008
|
-
# invalid characters for the default encoding.
|
1009
|
-
#
|
1010
|
-
# For example, on CentOS 6 with ENV['LANG'] = "en_US.UTF-8",
|
1011
|
-
# `locale -a`.split fails with ArgumentError invalid UTF-8 encoding.
|
1012
|
-
cmd = Mixlib::ShellOut.new("locale -a").run_command
|
1013
|
-
cmd.error!
|
1014
|
-
locales = cmd.stdout.split
|
1015
|
-
case
|
1016
|
-
when locales.include?("C.UTF-8")
|
1017
|
-
"C.UTF-8"
|
1018
|
-
when locales.include?("en_US.UTF-8"), locales.include?("en_US.utf8")
|
1019
|
-
"en_US.UTF-8"
|
1020
|
-
when locales.include?("en.UTF-8")
|
1021
|
-
"en.UTF-8"
|
1022
|
-
else
|
1023
|
-
# Will match en_ZZ.UTF-8, en_ZZ.utf-8, en_ZZ.UTF8, en_ZZ.utf8
|
1024
|
-
guesses = locales.select { |l| l =~ /^en_.*UTF-?8$/i }
|
1025
|
-
unless guesses.empty?
|
1026
|
-
guessed_locale = guesses.first
|
1027
|
-
# Transform into the form en_ZZ.UTF-8
|
1028
|
-
guessed_locale.gsub(/UTF-?8$/i, "UTF-8")
|
1029
|
-
else
|
1030
|
-
ChefConfig.logger.warn "Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support."
|
1031
|
-
"C"
|
1032
|
-
end
|
1033
|
-
end
|
1034
|
-
rescue
|
1035
|
-
if ChefConfig.windows?
|
1036
|
-
ChefConfig.logger.debug "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else."
|
1037
|
-
else
|
1038
|
-
ChefConfig.logger.debug "No usable locale -a command found, assuming you have en_US.UTF-8 installed."
|
1039
|
-
end
|
1040
|
-
"en_US.UTF-8"
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
default :internal_locale, guess_internal_locale
|
1044
|
-
|
1045
|
-
# Force UTF-8 Encoding, for when we fire up in the 'C' locale or other strange locales (e.g.
|
1046
|
-
# japanese windows encodings). If we do not do this, then knife upload will fail when a cookbook's
|
1047
|
-
# README.md has UTF-8 characters that do not encode in whatever surrounding encoding we have been
|
1048
|
-
# passed. Effectively, the Chef Ecosystem is globally UTF-8 by default. Anyone who wants to be
|
1049
|
-
# able to upload Shift_JIS or ISO-8859-1 files needs to mark *those* files explicitly with
|
1050
|
-
# magic tags to make ruby correctly identify the encoding being used. Changing this default will
|
1051
|
-
# break Chef community cookbooks and is very highly discouraged.
|
1052
|
-
default :ruby_encoding, Encoding::UTF_8
|
1053
|
-
|
1054
|
-
default :rubygems_url, "https://rubygems.org"
|
1055
|
-
|
1056
|
-
# This controls the behavior of resource cloning (and CHEF-3694 warnings). For Chef < 12 the behavior
|
1057
|
-
# has been that this is 'true', in Chef 13 this will change to false. Setting this to 'true' in Chef
|
1058
|
-
# 13 is not a viable or supported migration strategy since Chef 13 community cookbooks will be expected
|
1059
|
-
# to break with this setting set to 'true'.
|
1060
|
-
default :resource_cloning, true
|
1061
|
-
|
1062
|
-
# If installed via an omnibus installer, this gives the path to the
|
1063
|
-
# "embedded" directory which contains all of the software packaged with
|
1064
|
-
# omnibus. This is used to locate the cacert.pem file on windows.
|
1065
|
-
def self.embedded_dir
|
1066
|
-
Pathname.new(_this_file).ascend do |path|
|
1067
|
-
if path.basename.to_s == "embedded"
|
1068
|
-
return path.to_s
|
1069
|
-
end
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
nil
|
1073
|
-
end
|
1074
|
-
|
1075
|
-
# Path to this file in the current install.
|
1076
|
-
def self._this_file
|
1077
|
-
File.expand_path(__FILE__)
|
1078
|
-
end
|
1079
|
-
|
1080
|
-
# Set fips mode in openssl. Do any patching necessary to make
|
1081
|
-
# sure Chef runs do not crash.
|
1082
|
-
# @api private
|
1083
|
-
def self.enable_fips_mode
|
1084
|
-
OpenSSL.fips_mode = true
|
1085
|
-
require "digest"
|
1086
|
-
require "digest/sha1"
|
1087
|
-
require "digest/md5"
|
1088
|
-
# Remove pre-existing constants if they do exist to reduce the
|
1089
|
-
# amount of log spam and warnings.
|
1090
|
-
Digest.send(:remove_const, "SHA1") if Digest.const_defined?("SHA1")
|
1091
|
-
Digest.const_set("SHA1", OpenSSL::Digest::SHA1)
|
1092
|
-
OpenSSL::Digest.send(:remove_const, "MD5") if OpenSSL::Digest.const_defined?("MD5")
|
1093
|
-
OpenSSL::Digest.const_set("MD5", Digest::MD5)
|
1094
|
-
ChefConfig.logger.debug "FIPS mode is enabled."
|
1095
|
-
end
|
1096
|
-
end
|
1097
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
+
# Author:: AJ Christensen (<aj@chef.io>)
|
5
|
+
# Author:: Mark Mzyk (<mmzyk@chef.io>)
|
6
|
+
# Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
|
7
|
+
# Copyright:: Copyright 2008-2016, Chef Software Inc.
|
8
|
+
# License:: Apache License, Version 2.0
|
9
|
+
#
|
10
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
# you may not use this file except in compliance with the License.
|
12
|
+
# You may obtain a copy of the License at
|
13
|
+
#
|
14
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
#
|
16
|
+
# Unless required by applicable law or agreed to in writing, software
|
17
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
# See the License for the specific language governing permissions and
|
20
|
+
# limitations under the License.
|
21
|
+
|
22
|
+
require "mixlib/config"
|
23
|
+
require "pathname"
|
24
|
+
|
25
|
+
require "chef-config/fips"
|
26
|
+
require "chef-config/logger"
|
27
|
+
require "chef-config/windows"
|
28
|
+
require "chef-config/path_helper"
|
29
|
+
require "chef-config/mixin/fuzzy_hostname_matcher"
|
30
|
+
|
31
|
+
require "mixlib/shellout"
|
32
|
+
require "uri"
|
33
|
+
require "addressable/uri"
|
34
|
+
require "openssl"
|
35
|
+
require "yaml"
|
36
|
+
|
37
|
+
module ChefConfig
|
38
|
+
|
39
|
+
class Config
|
40
|
+
|
41
|
+
extend Mixlib::Config
|
42
|
+
extend ChefConfig::Mixin::FuzzyHostnameMatcher
|
43
|
+
|
44
|
+
# Evaluates the given string as config.
|
45
|
+
#
|
46
|
+
# +filename+ is used for context in stacktraces, but doesn't need to be the name of an actual file.
|
47
|
+
def self.from_string(string, filename)
|
48
|
+
instance_eval(string, filename, 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.inspect
|
52
|
+
configuration.inspect
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.platform_specific_path(path)
|
56
|
+
path = PathHelper.cleanpath(path)
|
57
|
+
if ChefConfig.windows?
|
58
|
+
# turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb
|
59
|
+
# Some installations will be on different drives so use the drive that
|
60
|
+
# the expanded path to __FILE__ is found.
|
61
|
+
drive = windows_installation_drive
|
62
|
+
if drive && path[0] == '\\' && path.split('\\')[2] == "chef"
|
63
|
+
path = PathHelper.join(drive, path.split('\\', 3)[2])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
path
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.windows_installation_drive
|
70
|
+
if ChefConfig.windows?
|
71
|
+
drive = File.expand_path(__FILE__).split("/", 2)[0]
|
72
|
+
drive = ENV["SYSTEMDRIVE"] if drive.to_s == ""
|
73
|
+
drive
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.add_formatter(name, file_path = nil)
|
78
|
+
formatters << [name, file_path]
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.add_event_logger(logger)
|
82
|
+
event_handlers << logger
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.apply_extra_config_options(extra_config_options)
|
86
|
+
if extra_config_options
|
87
|
+
extra_parsed_options = extra_config_options.inject({}) do |memo, option|
|
88
|
+
# Sanity check value.
|
89
|
+
if option.empty? || !option.include?("=")
|
90
|
+
raise UnparsableConfigOption, "Unparsable config option #{option.inspect}"
|
91
|
+
end
|
92
|
+
# Split including whitespace if someone does truly odd like
|
93
|
+
# --config-option "foo = bar"
|
94
|
+
key, value = option.split(/\s*=\s*/, 2)
|
95
|
+
# Call to_sym because Chef::Config expects only symbol keys. Also
|
96
|
+
# runs a simple parse on the string for some common types.
|
97
|
+
memo[key.to_sym] = YAML.safe_load(value)
|
98
|
+
memo
|
99
|
+
end
|
100
|
+
merge!(extra_parsed_options)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Config file to load (client.rb, knife.rb, etc. defaults set differently in knife, chef-client, etc.)
|
105
|
+
configurable(:config_file)
|
106
|
+
|
107
|
+
default(:config_dir) do
|
108
|
+
if config_file
|
109
|
+
PathHelper.dirname(PathHelper.canonical_path(config_file, false))
|
110
|
+
else
|
111
|
+
PathHelper.join(user_home, ".chef", "")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
default :formatters, []
|
116
|
+
|
117
|
+
def self.is_valid_url?(uri)
|
118
|
+
url = uri.to_s.strip
|
119
|
+
/^http:\/\// =~ url || /^https:\/\// =~ url || /^chefzero:/ =~ url
|
120
|
+
end
|
121
|
+
# Override the config dispatch to set the value of multiple server options simultaneously
|
122
|
+
#
|
123
|
+
# === Parameters
|
124
|
+
# url<String>:: String to be set for all of the chef-server-api URL's
|
125
|
+
#
|
126
|
+
configurable(:chef_server_url).writes_value do |uri|
|
127
|
+
unless is_valid_url? uri
|
128
|
+
raise ConfigurationError, "#{uri} is an invalid chef_server_url."
|
129
|
+
end
|
130
|
+
uri.to_s.strip
|
131
|
+
end
|
132
|
+
|
133
|
+
# When you are using ActiveSupport, they monkey-patch 'daemonize' into Kernel.
|
134
|
+
# So while this is basically identical to what method_missing would do, we pull
|
135
|
+
# it up here and get a real method written so that things get dispatched
|
136
|
+
# properly.
|
137
|
+
configurable(:daemonize).writes_value { |v| v }
|
138
|
+
|
139
|
+
# The root where all local chef object data is stored. cookbooks, data bags,
|
140
|
+
# environments are all assumed to be in separate directories under this.
|
141
|
+
# chef-solo uses these directories for input data. knife commands
|
142
|
+
# that upload or download files (such as knife upload, knife role from file,
|
143
|
+
# etc.) work.
|
144
|
+
default :chef_repo_path do
|
145
|
+
if configuration[:cookbook_path]
|
146
|
+
if configuration[:cookbook_path].kind_of?(String)
|
147
|
+
File.expand_path("..", configuration[:cookbook_path])
|
148
|
+
else
|
149
|
+
configuration[:cookbook_path].map do |path|
|
150
|
+
File.expand_path("..", path)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
elsif configuration[:cookbook_artifact_path]
|
154
|
+
File.expand_path("..", configuration[:cookbook_artifact_path])
|
155
|
+
else
|
156
|
+
cache_path
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.find_chef_repo_path(cwd)
|
161
|
+
# In local mode, we auto-discover the repo root by looking for a path with "cookbooks" under it.
|
162
|
+
# This allows us to run config-free.
|
163
|
+
path = cwd
|
164
|
+
until File.directory?(PathHelper.join(path, "cookbooks")) || File.directory?(PathHelper.join(path, "cookbook_artifacts"))
|
165
|
+
new_path = File.expand_path("..", path)
|
166
|
+
if new_path == path
|
167
|
+
ChefConfig.logger.warn("No cookbooks directory found at or above current directory. Assuming #{cwd}.")
|
168
|
+
return cwd
|
169
|
+
end
|
170
|
+
path = new_path
|
171
|
+
end
|
172
|
+
ChefConfig.logger.info("Auto-discovered chef repository at #{path}")
|
173
|
+
path
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.derive_path_from_chef_repo_path(child_path)
|
177
|
+
if chef_repo_path.kind_of?(String)
|
178
|
+
PathHelper.join(chef_repo_path, child_path)
|
179
|
+
else
|
180
|
+
chef_repo_path.uniq.map { |path| PathHelper.join(path, child_path) }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Location of acls on disk. String or array of strings.
|
185
|
+
# Defaults to <chef_repo_path>/acls.
|
186
|
+
default(:acl_path) { derive_path_from_chef_repo_path("acls") }
|
187
|
+
|
188
|
+
# Location of clients on disk. String or array of strings.
|
189
|
+
# Defaults to <chef_repo_path>/clients.
|
190
|
+
default(:client_path) { derive_path_from_chef_repo_path("clients") }
|
191
|
+
|
192
|
+
# Location of client keys on disk. String or array of strings.
|
193
|
+
# Defaults to <chef_repo_path>/client_keys.
|
194
|
+
default(:client_key_path) { derive_path_from_chef_repo_path("client_keys") }
|
195
|
+
|
196
|
+
# Location of containers on disk. String or array of strings.
|
197
|
+
# Defaults to <chef_repo_path>/containers.
|
198
|
+
default(:container_path) { derive_path_from_chef_repo_path("containers") }
|
199
|
+
|
200
|
+
# Location of cookbook_artifacts on disk. String or array of strings.
|
201
|
+
# Defaults to <chef_repo_path>/cookbook_artifacts.
|
202
|
+
default(:cookbook_artifact_path) { derive_path_from_chef_repo_path("cookbook_artifacts") }
|
203
|
+
|
204
|
+
# Location of cookbooks on disk. String or array of strings.
|
205
|
+
# Defaults to <chef_repo_path>/cookbooks. If chef_repo_path
|
206
|
+
# is not specified, this is set to [/var/chef/cookbooks, /var/chef/site-cookbooks]).
|
207
|
+
default(:cookbook_path) do
|
208
|
+
if configuration[:chef_repo_path]
|
209
|
+
derive_path_from_chef_repo_path("cookbooks")
|
210
|
+
else
|
211
|
+
Array(derive_path_from_chef_repo_path("cookbooks")).flatten +
|
212
|
+
Array(derive_path_from_chef_repo_path("site-cookbooks")).flatten
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Location of data bags on disk. String or array of strings.
|
217
|
+
# Defaults to <chef_repo_path>/data_bags.
|
218
|
+
default(:data_bag_path) { derive_path_from_chef_repo_path("data_bags") }
|
219
|
+
|
220
|
+
# Location of environments on disk. String or array of strings.
|
221
|
+
# Defaults to <chef_repo_path>/environments.
|
222
|
+
default(:environment_path) { derive_path_from_chef_repo_path("environments") }
|
223
|
+
|
224
|
+
# Location of groups on disk. String or array of strings.
|
225
|
+
# Defaults to <chef_repo_path>/groups.
|
226
|
+
default(:group_path) { derive_path_from_chef_repo_path("groups") }
|
227
|
+
|
228
|
+
# Location of nodes on disk. String or array of strings.
|
229
|
+
# Defaults to <chef_repo_path>/nodes.
|
230
|
+
default(:node_path) { derive_path_from_chef_repo_path("nodes") }
|
231
|
+
|
232
|
+
# Location of policies on disk. String or array of strings.
|
233
|
+
# Defaults to <chef_repo_path>/policies.
|
234
|
+
default(:policy_path) { derive_path_from_chef_repo_path("policies") }
|
235
|
+
|
236
|
+
# Location of policy_groups on disk. String or array of strings.
|
237
|
+
# Defaults to <chef_repo_path>/policy_groups.
|
238
|
+
default(:policy_group_path) { derive_path_from_chef_repo_path("policy_groups") }
|
239
|
+
|
240
|
+
# Location of roles on disk. String or array of strings.
|
241
|
+
# Defaults to <chef_repo_path>/roles.
|
242
|
+
default(:role_path) { derive_path_from_chef_repo_path("roles") }
|
243
|
+
|
244
|
+
# Location of users on disk. String or array of strings.
|
245
|
+
# Defaults to <chef_repo_path>/users.
|
246
|
+
default(:user_path) { derive_path_from_chef_repo_path("users") }
|
247
|
+
|
248
|
+
# Location of policies on disk. String or array of strings.
|
249
|
+
# Defaults to <chef_repo_path>/policies.
|
250
|
+
default(:policy_path) { derive_path_from_chef_repo_path("policies") }
|
251
|
+
|
252
|
+
# Turn on "path sanity" by default. See also: http://wiki.opscode.com/display/chef/User+Environment+PATH+Sanity
|
253
|
+
default :enforce_path_sanity, true
|
254
|
+
|
255
|
+
# Formatted Chef Client output is a beta feature, disabled by default:
|
256
|
+
default :formatter, "null"
|
257
|
+
|
258
|
+
# The number of times the client should retry when registering with the server
|
259
|
+
default :client_registration_retries, 5
|
260
|
+
|
261
|
+
# An array of paths to search for knife exec scripts if they aren't in the current directory
|
262
|
+
default :script_path, []
|
263
|
+
|
264
|
+
# The root of all caches (checksums, cache and backup). If local mode is on,
|
265
|
+
# this is under the user's home directory.
|
266
|
+
default(:cache_path) do
|
267
|
+
if local_mode
|
268
|
+
PathHelper.join(config_dir, "local-mode-cache")
|
269
|
+
else
|
270
|
+
primary_cache_root = platform_specific_path("/var")
|
271
|
+
primary_cache_path = platform_specific_path("/var/chef")
|
272
|
+
# Use /var/chef as the cache path only if that folder exists and we can read and write
|
273
|
+
# into it, or /var exists and we can read and write into it (we'll create /var/chef later).
|
274
|
+
# Otherwise, we'll create .chef under the user's home directory and use that as
|
275
|
+
# the cache path.
|
276
|
+
unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root)
|
277
|
+
secondary_cache_path = PathHelper.join(user_home, ".chef")
|
278
|
+
ChefConfig.logger.info("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}")
|
279
|
+
secondary_cache_path
|
280
|
+
else
|
281
|
+
primary_cache_path
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
# Returns true only if the path exists and is readable and writeable for the user.
|
287
|
+
def self.path_accessible?(path)
|
288
|
+
File.exists?(path) && File.readable?(path) && File.writable?(path)
|
289
|
+
end
|
290
|
+
|
291
|
+
# Where cookbook files are stored on the server (by content checksum)
|
292
|
+
default(:checksum_path) { PathHelper.join(cache_path, "checksums") }
|
293
|
+
|
294
|
+
# Where chef's cache files should be stored
|
295
|
+
default(:file_cache_path) { PathHelper.join(cache_path, "cache") }
|
296
|
+
|
297
|
+
# Where backups of chef-managed files should go
|
298
|
+
default(:file_backup_path) { PathHelper.join(cache_path, "backup") }
|
299
|
+
|
300
|
+
# The chef-client (or solo) lockfile.
|
301
|
+
#
|
302
|
+
# If your `file_cache_path` resides on a NFS (or non-flock()-supporting
|
303
|
+
# fs), it's recommended to set this to something like
|
304
|
+
# '/tmp/chef-client-running.pid'
|
305
|
+
default(:lockfile) { PathHelper.join(file_cache_path, "chef-client-running.pid") }
|
306
|
+
|
307
|
+
## Daemonization Settings ##
|
308
|
+
# What user should Chef run as?
|
309
|
+
default :user, nil
|
310
|
+
default :group, nil
|
311
|
+
default :umask, 0022
|
312
|
+
|
313
|
+
# Valid log_levels are:
|
314
|
+
# * :debug
|
315
|
+
# * :info
|
316
|
+
# * :warn
|
317
|
+
# * :fatal
|
318
|
+
# These work as you'd expect. There is also a special `:auto` setting.
|
319
|
+
# When set to :auto, Chef will auto adjust the log verbosity based on
|
320
|
+
# context. When a tty is available (usually because the user is running chef
|
321
|
+
# in a console), the log level is set to :warn, and output formatters are
|
322
|
+
# used as the primary mode of output. When a tty is not available, the
|
323
|
+
# logger is the primary mode of output, and the log level is set to :info
|
324
|
+
default :log_level, :auto
|
325
|
+
|
326
|
+
# Logging location as either an IO stream or string representing log file path
|
327
|
+
default :log_location, STDOUT
|
328
|
+
|
329
|
+
# Using `force_formatter` causes chef to default to formatter output when STDOUT is not a tty
|
330
|
+
default :force_formatter, false
|
331
|
+
|
332
|
+
# Using `force_logger` causes chef to default to logger output when STDOUT is a tty
|
333
|
+
default :force_logger, false
|
334
|
+
|
335
|
+
# Using 'stream_execute_output' will have Chef always stream the execute output
|
336
|
+
default :stream_execute_output, false
|
337
|
+
|
338
|
+
# Using `show_download_progress` will display the overall progress
|
339
|
+
# of a remote file download
|
340
|
+
default :show_download_progress, false
|
341
|
+
# How often to update the progress meter, in percent
|
342
|
+
default :download_progress_interval, 10
|
343
|
+
|
344
|
+
default :http_retry_count, 5
|
345
|
+
default :http_retry_delay, 5
|
346
|
+
default :interval, nil
|
347
|
+
default :once, nil
|
348
|
+
default :json_attribs, nil
|
349
|
+
# toggle info level log items that can create a lot of output
|
350
|
+
default :verbose_logging, true
|
351
|
+
default :node_name, nil
|
352
|
+
default :diff_disabled, false
|
353
|
+
default :diff_filesize_threshold, 10000000
|
354
|
+
default :diff_output_threshold, 1000000
|
355
|
+
default :local_mode, false
|
356
|
+
|
357
|
+
# Configures the mode of operation for ChefFS, which is applied to the
|
358
|
+
# ChefFS-based knife commands and chef-client's local mode. (ChefFS-based
|
359
|
+
# knife commands include: knife delete, knife deps, knife diff, knife down,
|
360
|
+
# knife edit, knife list, knife show, knife upload, and knife xargs.)
|
361
|
+
#
|
362
|
+
# Valid values are:
|
363
|
+
# * "static": ChefFS only manages objects that exist in a traditional Chef
|
364
|
+
# Repo as of Chef 11.
|
365
|
+
# * "everything": ChefFS manages all object types that existed on the OSS
|
366
|
+
# Chef 11 server.
|
367
|
+
# * "hosted_everything": ChefFS manages all object types as of the Chef 12
|
368
|
+
# Server, including RBAC objects and Policyfile objects (new to Chef 12).
|
369
|
+
default :repo_mode do
|
370
|
+
if local_mode && !chef_zero.osc_compat
|
371
|
+
"hosted_everything"
|
372
|
+
elsif chef_server_url =~ /\/+organizations\/.+/
|
373
|
+
"hosted_everything"
|
374
|
+
else
|
375
|
+
"everything"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
default :pid_file, nil
|
380
|
+
|
381
|
+
# Whether Chef Zero local mode should bind to a port. All internal requests
|
382
|
+
# will go through the socketless code path regardless, so the socket is
|
383
|
+
# only needed if other processes will connect to the local mode server.
|
384
|
+
#
|
385
|
+
# For compatibility this is set to true but it will be changed to false in
|
386
|
+
# the future.
|
387
|
+
default :listen, true
|
388
|
+
|
389
|
+
config_context :chef_zero do
|
390
|
+
config_strict_mode true
|
391
|
+
default(:enabled) { ChefConfig::Config.local_mode }
|
392
|
+
default :host, "localhost"
|
393
|
+
default :port, 8889.upto(9999) # Will try ports from 8889-9999 until one works
|
394
|
+
|
395
|
+
# When set to a String, Chef Zero disables multitenant support. This is
|
396
|
+
# what you want when using Chef Zero to serve a single Chef Repo. Setting
|
397
|
+
# this to `false` enables multi-tenant.
|
398
|
+
default :single_org, "chef"
|
399
|
+
|
400
|
+
# Whether Chef Zero should operate in a mode analogous to OSS Chef Server
|
401
|
+
# 11 (true) or Chef Server 12 (false). Chef Zero can still serve
|
402
|
+
# policyfile objects in Chef 11 mode, as long as `repo_mode` is set to
|
403
|
+
# "hosted_everything". The primary differences are:
|
404
|
+
# * Chef 11 mode doesn't support multi-tennant, so there is no
|
405
|
+
# distinction between global and org-specific objects (since there are
|
406
|
+
# no orgs).
|
407
|
+
# * Chef 11 mode doesn't expose RBAC objects
|
408
|
+
default :osc_compat, false
|
409
|
+
end
|
410
|
+
default :chef_server_url, "https://localhost:443"
|
411
|
+
|
412
|
+
default(:chef_server_root) do
|
413
|
+
# if the chef_server_url is a path to an organization, aka
|
414
|
+
# 'some_url.../organizations/*' then remove the '/organization/*' by default
|
415
|
+
if configuration[:chef_server_url] =~ /\/organizations\/\S*$/
|
416
|
+
configuration[:chef_server_url].split("/")[0..-3].join("/")
|
417
|
+
elsif configuration[:chef_server_url] # default to whatever chef_server_url is
|
418
|
+
configuration[:chef_server_url]
|
419
|
+
else
|
420
|
+
"https://localhost:443"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
default :rest_timeout, 300
|
425
|
+
default :yum_timeout, 900
|
426
|
+
default :yum_lock_timeout, 30
|
427
|
+
default :solo, false
|
428
|
+
|
429
|
+
# Are we running in old Chef Solo legacy mode?
|
430
|
+
default :solo_legacy_mode, false
|
431
|
+
|
432
|
+
default :splay, nil
|
433
|
+
default :why_run, false
|
434
|
+
default :color, false
|
435
|
+
default :client_fork, true
|
436
|
+
default :ez, false
|
437
|
+
default :enable_reporting, true
|
438
|
+
default :enable_reporting_url_fatals, false
|
439
|
+
# Possible values for :audit_mode
|
440
|
+
# :enabled, :disabled, :audit_only,
|
441
|
+
#
|
442
|
+
# TODO: 11 Dec 2014: Currently audit-mode is an experimental feature
|
443
|
+
# and is disabled by default. When users choose to enable audit-mode,
|
444
|
+
# a warning is issued in application/client#reconfigure.
|
445
|
+
# This can be removed when audit-mode is enabled by default.
|
446
|
+
default :audit_mode, :disabled
|
447
|
+
|
448
|
+
# Chef only needs ohai to run the hostname plugin for the most basic
|
449
|
+
# functionality. If the rest of the ohai plugins are not needed (like in
|
450
|
+
# most of our testing scenarios)
|
451
|
+
default :minimal_ohai, false
|
452
|
+
|
453
|
+
###
|
454
|
+
# Policyfile Settings
|
455
|
+
#
|
456
|
+
# Policyfile is a feature where a node gets its run list and cookbook
|
457
|
+
# version set from a single document on the server instead of expanding the
|
458
|
+
# run list and having the server compute the cookbook version set based on
|
459
|
+
# environment constraints.
|
460
|
+
#
|
461
|
+
# Policyfiles are auto-versioned. The user groups nodes by `policy_name`,
|
462
|
+
# which generally describes a hosts's functional role, and `policy_group`,
|
463
|
+
# which generally groups nodes by deployment phase (a.k.a., "environment").
|
464
|
+
# The Chef Server maps a given set of `policy_name` plus `policy_group` to
|
465
|
+
# a particular revision of a policy.
|
466
|
+
|
467
|
+
default :policy_name, nil
|
468
|
+
default :policy_group, nil
|
469
|
+
|
470
|
+
# Policyfiles can have multiple run lists, via the named run list feature.
|
471
|
+
# Generally this will be set by a CLI option via Chef::Application::Client,
|
472
|
+
# but it could be set in client.rb if desired.
|
473
|
+
|
474
|
+
default :named_run_list, nil
|
475
|
+
|
476
|
+
# During initial development, users were required to set `use_policyfile true`
|
477
|
+
# in `client.rb` to opt-in to policyfile use. Chef Client now examines
|
478
|
+
# configuration, node json, and the stored node to determine if policyfile
|
479
|
+
# usage is desired. This flag is still honored if set, but is unnecessary.
|
480
|
+
default :use_policyfile, false
|
481
|
+
|
482
|
+
# Policyfiles can be used in a native mode (default) or compatibility mode.
|
483
|
+
# Native mode requires Chef Server 12.1 (it can be enabled via feature flag
|
484
|
+
# on some prior versions). In native mode, policies and associated
|
485
|
+
# cookbooks are accessed via feature-specific APIs. In compat mode,
|
486
|
+
# policies are stored as data bags and cookbooks are stored at the
|
487
|
+
# cookbooks/ endpoint. Compatibility mode can be dangerous on existing Chef
|
488
|
+
# Servers; it's recommended to upgrade your Chef Server rather than use
|
489
|
+
# compatibility mode. Compatibility mode remains available so you can use
|
490
|
+
# policyfiles with servers that don't yet support the native endpoints.
|
491
|
+
default :policy_document_native_api, true
|
492
|
+
|
493
|
+
# When policyfiles are used in compatibility mode, `policy_name` and
|
494
|
+
# `policy_group` are instead specified using a combined configuration
|
495
|
+
# setting, `deployment_group`. For example, if policy_name should be
|
496
|
+
# "webserver" and policy_group should be "staging", then `deployment_group`
|
497
|
+
# should be set to "webserver-staging", which is the name of the data bag
|
498
|
+
# item that the policy will be stored as. NOTE: this setting only has an
|
499
|
+
# effect if `policy_document_native_api` is set to `false`.
|
500
|
+
default :deployment_group, nil
|
501
|
+
|
502
|
+
# Set these to enable SSL authentication / mutual-authentication
|
503
|
+
# with the server
|
504
|
+
|
505
|
+
# Client side SSL cert/key for mutual auth
|
506
|
+
default :ssl_client_cert, nil
|
507
|
+
default :ssl_client_key, nil
|
508
|
+
|
509
|
+
# Whether or not to verify the SSL cert for all HTTPS requests. When set to
|
510
|
+
# :verify_peer (default), all HTTPS requests will be validated regardless of other
|
511
|
+
# SSL verification settings. When set to :verify_none no HTTPS requests will
|
512
|
+
# be validated.
|
513
|
+
default :ssl_verify_mode, :verify_peer
|
514
|
+
|
515
|
+
# Whether or not to verify the SSL cert for HTTPS requests to the Chef
|
516
|
+
# server API. If set to `true`, the server's cert will be validated
|
517
|
+
# regardless of the :ssl_verify_mode setting. This is set to `true` when
|
518
|
+
# running in local-mode.
|
519
|
+
# NOTE: This is a workaround until verify_peer is enabled by default.
|
520
|
+
default(:verify_api_cert) { ChefConfig::Config.local_mode }
|
521
|
+
|
522
|
+
# Path to the default CA bundle files.
|
523
|
+
default :ssl_ca_path, nil
|
524
|
+
default(:ssl_ca_file) do
|
525
|
+
if ChefConfig.windows? && embedded_dir
|
526
|
+
cacert_path = File.join(embedded_dir, "ssl/certs/cacert.pem")
|
527
|
+
cacert_path if File.exist?(cacert_path)
|
528
|
+
else
|
529
|
+
nil
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
# A directory that contains additional SSL certificates to trust. Any
|
534
|
+
# certificates in this directory will be added to whatever CA bundle ruby
|
535
|
+
# is using. Use this to add self-signed certs for your Chef Server or local
|
536
|
+
# HTTP file servers.
|
537
|
+
default(:trusted_certs_dir) { PathHelper.join(config_dir, "trusted_certs") }
|
538
|
+
|
539
|
+
# A directory that contains additional configuration scripts to load for chef-client
|
540
|
+
default(:client_d_dir) { PathHelper.join(config_dir, "client.d") }
|
541
|
+
|
542
|
+
# A directory that contains additional configuration scripts to load for solo
|
543
|
+
default(:solo_d_dir) { PathHelper.join(config_dir, "solo.d") }
|
544
|
+
|
545
|
+
# A directory that contains additional configuration scripts to load for
|
546
|
+
# the workstation config
|
547
|
+
default(:config_d_dir) { PathHelper.join(config_dir, "config.d") }
|
548
|
+
|
549
|
+
# Where should chef-solo download recipes from?
|
550
|
+
default :recipe_url, nil
|
551
|
+
|
552
|
+
# Set to true if Chef is to set OpenSSL to run in FIPS mode
|
553
|
+
default(:fips) do
|
554
|
+
# CHEF_FIPS is used in testing to override checking for system level
|
555
|
+
# enablement. There are 3 possible values that this variable may have:
|
556
|
+
# nil - no override and the system will be checked
|
557
|
+
# empty - FIPS is NOT enabled
|
558
|
+
# a non empty value - FIPS is enabled
|
559
|
+
if ENV["CHEF_FIPS"] == ""
|
560
|
+
false
|
561
|
+
else
|
562
|
+
!ENV["CHEF_FIPS"].nil? || ChefConfig.fips?
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
# Initialize openssl
|
567
|
+
def self.init_openssl
|
568
|
+
if fips
|
569
|
+
enable_fips_mode
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
# Sets the version of the signed header authentication protocol to use (see
|
574
|
+
# the 'mixlib-authorization' project for more detail). Currently, versions
|
575
|
+
# 1.0, 1.1, and 1.3 are available.
|
576
|
+
default :authentication_protocol_version do
|
577
|
+
if fips
|
578
|
+
"1.3"
|
579
|
+
else
|
580
|
+
"1.1"
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
# This key will be used to sign requests to the Chef server. This location
|
585
|
+
# must be writable by Chef during initial setup when generating a client
|
586
|
+
# identity on the server.
|
587
|
+
#
|
588
|
+
# The chef-server will look up the public key for the client using the
|
589
|
+
# `node_name` of the client.
|
590
|
+
#
|
591
|
+
# If chef-zero is enabled, this defaults to nil (no authentication).
|
592
|
+
default(:client_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/client.pem") }
|
593
|
+
|
594
|
+
# When registering the client, should we allow the client key location to
|
595
|
+
# be a symlink? eg: /etc/chef/client.pem -> /etc/chef/prod-client.pem
|
596
|
+
# If the path of the key goes through a directory like /tmp this should
|
597
|
+
# never be set to true or its possibly an easily exploitable security hole.
|
598
|
+
default :follow_client_key_symlink, false
|
599
|
+
|
600
|
+
# This secret is used to decrypt encrypted data bag items.
|
601
|
+
default(:encrypted_data_bag_secret) do
|
602
|
+
if File.exist?(platform_specific_path("/etc/chef/encrypted_data_bag_secret"))
|
603
|
+
platform_specific_path("/etc/chef/encrypted_data_bag_secret")
|
604
|
+
else
|
605
|
+
nil
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
# As of Chef 11.0, version "1" is the default encrypted data bag item
|
610
|
+
# format. Version "2" is available which adds encrypt-then-mac protection.
|
611
|
+
# To maintain compatibility, versions other than 1 must be opt-in.
|
612
|
+
#
|
613
|
+
# Set this to `2` if you have chef-client 11.6.0+ in your infrastructure.
|
614
|
+
# Set this to `3` if you have chef-client 11.?.0+, ruby 2 and OpenSSL >= 1.0.1 in your infrastructure. (TODO)
|
615
|
+
default :data_bag_encrypt_version, 1
|
616
|
+
|
617
|
+
# When reading data bag items, any supported version is accepted. However,
|
618
|
+
# if all encrypted data bags have been generated with the version 2 format,
|
619
|
+
# it is recommended to disable support for earlier formats to improve
|
620
|
+
# security. For example, the version 2 format is identical to version 1
|
621
|
+
# except for the addition of an HMAC, so an attacker with MITM capability
|
622
|
+
# could downgrade an encrypted data bag to version 1 as part of an attack.
|
623
|
+
default :data_bag_decrypt_minimum_version, 0
|
624
|
+
|
625
|
+
# If there is no file in the location given by `client_key`, chef-client
|
626
|
+
# will temporarily use the "validator" identity to generate one. If the
|
627
|
+
# `client_key` is not present and the `validation_key` is also not present,
|
628
|
+
# chef-client will not be able to authenticate to the server.
|
629
|
+
#
|
630
|
+
# The `validation_key` is never used if the `client_key` exists.
|
631
|
+
#
|
632
|
+
# If chef-zero is enabled, this defaults to nil (no authentication).
|
633
|
+
default(:validation_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/validation.pem") }
|
634
|
+
default :validation_client_name, "chef-validator"
|
635
|
+
|
636
|
+
# When creating a new client via the validation_client account, Chef 11
|
637
|
+
# servers allow the client to generate a key pair locally and send the
|
638
|
+
# public key to the server. This is more secure and helps offload work from
|
639
|
+
# the server, enhancing scalability. If enabled and the remote server
|
640
|
+
# implements only the Chef 10 API, client registration will not work
|
641
|
+
# properly.
|
642
|
+
#
|
643
|
+
# The default value is `true`. Set to `false` to disable client-side key
|
644
|
+
# generation (server generates client keys).
|
645
|
+
default(:local_key_generation) { true }
|
646
|
+
|
647
|
+
# Zypper package provider gpg checks. Set to true to enable package
|
648
|
+
# gpg signature checking. This will be default in the
|
649
|
+
# future. Setting to false disables the warnings.
|
650
|
+
# Leaving this set to nil or false is a security hazard!
|
651
|
+
default :zypper_check_gpg, nil
|
652
|
+
|
653
|
+
# Report Handlers
|
654
|
+
default :report_handlers, []
|
655
|
+
|
656
|
+
# Event Handlers
|
657
|
+
default :event_handlers, []
|
658
|
+
|
659
|
+
default :disable_event_loggers, false
|
660
|
+
|
661
|
+
# Exception Handlers
|
662
|
+
default :exception_handlers, []
|
663
|
+
|
664
|
+
# Start handlers
|
665
|
+
default :start_handlers, []
|
666
|
+
|
667
|
+
# Syntax Check Cache. Knife keeps track of files that is has already syntax
|
668
|
+
# checked by storing files in this directory. `syntax_check_cache_path` is
|
669
|
+
# the new (and preferred) configuration setting. If not set, knife will
|
670
|
+
# fall back to using cache_options[:path], which is deprecated but exists in
|
671
|
+
# many client configs generated by pre-Chef-11 bootstrappers.
|
672
|
+
default(:syntax_check_cache_path) { cache_options[:path] }
|
673
|
+
|
674
|
+
# Deprecated:
|
675
|
+
# Move this to the default value of syntax_cache_path when this is removed.
|
676
|
+
default(:cache_options) { { :path => PathHelper.join(config_dir, "syntaxcache") } }
|
677
|
+
|
678
|
+
# Whether errors should be raised for deprecation warnings. When set to
|
679
|
+
# `false` (the default setting), a warning is emitted but code using
|
680
|
+
# deprecated methods/features/etc. should work normally otherwise. When set
|
681
|
+
# to `true`, usage of deprecated methods/features will raise a
|
682
|
+
# `DeprecatedFeatureError`. This is used by Chef's tests to ensure that
|
683
|
+
# deprecated functionality is not used internally by Chef. End users
|
684
|
+
# should generally leave this at the default setting (especially in
|
685
|
+
# production), but it may be useful when testing cookbooks or other code if
|
686
|
+
# the user wishes to aggressively address deprecations.
|
687
|
+
default(:treat_deprecation_warnings_as_errors) do
|
688
|
+
# Using an environment variable allows this setting to be inherited in
|
689
|
+
# tests that spawn new processes.
|
690
|
+
ENV.key?("CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS")
|
691
|
+
end
|
692
|
+
|
693
|
+
# Whether the resource count should be updated for log resource
|
694
|
+
# on running chef-client
|
695
|
+
default :count_log_resource_updates, true
|
696
|
+
|
697
|
+
# knife configuration data
|
698
|
+
config_context :knife do
|
699
|
+
# XXX: none of these default values are applied to knife (and would create a backcompat
|
700
|
+
# break in knife if this bug was fixed since many of the defaults below are wrong). this appears
|
701
|
+
# to be the start of an attempt to be able to use config_strict_mode true? if so, this approach
|
702
|
+
# is fraught with peril because this namespace is used by every knife plugin in the wild and
|
703
|
+
# we would need to validate every cli option in every knife attribute out there and list them all here.
|
704
|
+
#
|
705
|
+
# based on the way that people may define `knife[:foobar] = "something"` for the knife-foobar
|
706
|
+
# gem plugin i'm pretty certain we can never turn on anything like config_string_mode since
|
707
|
+
# any config value may be a typo or it may be in some gem in some knife plugin we don't know about.
|
708
|
+
#
|
709
|
+
# we do still need to maintain at least one of these so that the knife config hash gets
|
710
|
+
# created.
|
711
|
+
#
|
712
|
+
# this whole situation is deeply unsatisfying.
|
713
|
+
default :ssh_port, nil
|
714
|
+
default :ssh_user, nil
|
715
|
+
default :ssh_attribute, nil
|
716
|
+
default :ssh_gateway, nil
|
717
|
+
default :bootstrap_version, nil
|
718
|
+
default :bootstrap_proxy, nil
|
719
|
+
default :bootstrap_template, nil
|
720
|
+
default :secret, nil
|
721
|
+
default :secret_file, nil
|
722
|
+
default :identity_file, nil
|
723
|
+
default :host_key_verify, nil
|
724
|
+
default :forward_agent, nil
|
725
|
+
default :sort_status_reverse, nil
|
726
|
+
default :hints, {}
|
727
|
+
end
|
728
|
+
|
729
|
+
def self.set_defaults_for_windows
|
730
|
+
# Those lists of regular expressions define what chef considers a
|
731
|
+
# valid user and group name
|
732
|
+
# From http://technet.microsoft.com/en-us/library/cc776019(WS.10).aspx
|
733
|
+
principal_valid_regex_part = '[^"\/\\\\\[\]\:;|=,+*?<>]+'
|
734
|
+
default :user_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
735
|
+
default :group_valid_regex, [ /^(#{principal_valid_regex_part}\\)?#{principal_valid_regex_part}$/ ]
|
736
|
+
|
737
|
+
default :fatal_windows_admin_check, false
|
738
|
+
end
|
739
|
+
|
740
|
+
def self.set_defaults_for_nix
|
741
|
+
# Those lists of regular expressions define what chef considers a
|
742
|
+
# valid user and group name
|
743
|
+
#
|
744
|
+
# user/group cannot start with '-', '+' or '~'
|
745
|
+
# user/group cannot contain ':', ',' or non-space-whitespace or null byte
|
746
|
+
# everything else is allowed (UTF-8, spaces, etc) and we delegate to your O/S useradd program to barf or not
|
747
|
+
# copies: http://anonscm.debian.org/viewvc/pkg-shadow/debian/trunk/debian/patches/506_relaxed_usernames?view=markup
|
748
|
+
default :user_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ]
|
749
|
+
default :group_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ]
|
750
|
+
end
|
751
|
+
|
752
|
+
# Those lists of regular expressions define what chef considers a
|
753
|
+
# valid user and group name
|
754
|
+
if ChefConfig.windows?
|
755
|
+
set_defaults_for_windows
|
756
|
+
else
|
757
|
+
set_defaults_for_nix
|
758
|
+
end
|
759
|
+
|
760
|
+
# This provides a hook which rspec can stub so that we can avoid twiddling
|
761
|
+
# global state in tests.
|
762
|
+
def self.env
|
763
|
+
ENV
|
764
|
+
end
|
765
|
+
|
766
|
+
def self.windows_home_path
|
767
|
+
ChefConfig.logger.deprecation("Chef::Config.windows_home_path is now deprecated. Consider using Chef::Util::PathHelper.home instead.")
|
768
|
+
PathHelper.home
|
769
|
+
end
|
770
|
+
|
771
|
+
# returns a platform specific path to the user home dir if set, otherwise default to current directory.
|
772
|
+
default( :user_home ) { PathHelper.home || Dir.pwd }
|
773
|
+
|
774
|
+
# Enable file permission fixup for selinux. Fixup will be done
|
775
|
+
# only if selinux is enabled in the system.
|
776
|
+
default :enable_selinux_file_permission_fixup, true
|
777
|
+
|
778
|
+
# Use atomic updates (i.e. move operation) while updating contents
|
779
|
+
# of the files resources. When set to false copy operation is
|
780
|
+
# used to update files.
|
781
|
+
#
|
782
|
+
# NOTE: CHANGING THIS SETTING MAY CAUSE CORRUPTION, DATA LOSS AND
|
783
|
+
# INSTABILITY.
|
784
|
+
default :file_atomic_update, true
|
785
|
+
|
786
|
+
# There are 3 possible values for this configuration setting.
|
787
|
+
# true => file staging is done in the destination directory
|
788
|
+
# false => file staging is done via tempfiles under ENV['TMP']
|
789
|
+
# :auto => file staging will try using destination directory if possible and
|
790
|
+
# will fall back to ENV['TMP'] if destination directory is not usable.
|
791
|
+
default :file_staging_uses_destdir, :auto
|
792
|
+
|
793
|
+
# Exit if another run is in progress and the chef-client is unable to
|
794
|
+
# get the lock before time expires. If nil, no timeout is enforced. (Exits
|
795
|
+
# immediately if 0.)
|
796
|
+
default :run_lock_timeout, nil
|
797
|
+
|
798
|
+
# Number of worker threads for syncing cookbooks in parallel. Increasing
|
799
|
+
# this number can result in gateway errors from the server (namely 503 and 504).
|
800
|
+
# If you are seeing this behavior while using the default setting, reducing
|
801
|
+
# the number of threads will help.
|
802
|
+
default :cookbook_sync_threads, 10
|
803
|
+
|
804
|
+
# At the beginning of the Chef Client run, the cookbook manifests are downloaded which
|
805
|
+
# contain URLs for every file in every relevant cookbook. Most of the files
|
806
|
+
# (recipes, resources, providers, libraries, etc) are immediately synchronized
|
807
|
+
# at the start of the run. The handling of "files" and "templates" directories,
|
808
|
+
# however, have two modes of operation. They can either all be downloaded immediately
|
809
|
+
# at the start of the run (no_lazy_load==true) or else they can be lazily loaded as
|
810
|
+
# cookbook_file or template resources are converged which require them (no_lazy_load==false).
|
811
|
+
#
|
812
|
+
# The advantage of lazily loading these files is that unnecessary files are not
|
813
|
+
# synchronized. This may be useful to users with large files checked into cookbooks which
|
814
|
+
# are only selectively downloaded to a subset of clients which use the cookbook. However,
|
815
|
+
# better solutions are to either isolate large files into individual cookbooks and only
|
816
|
+
# include those cookbooks in the run lists of the servers that need them -- or move to
|
817
|
+
# using remote_file and a more appropriate backing store like S3 for large file
|
818
|
+
# distribution.
|
819
|
+
#
|
820
|
+
# The disadvantages of lazily loading files are that users some time find it
|
821
|
+
# confusing that their cookbooks are not fully synchronzied to the cache initially,
|
822
|
+
# and more importantly the time-sensitive URLs which are in the manifest may time
|
823
|
+
# out on long Chef runs before the resource that uses the file is converged
|
824
|
+
# (leading to many confusing 403 errors on template/cookbook_file resources).
|
825
|
+
#
|
826
|
+
default :no_lazy_load, true
|
827
|
+
|
828
|
+
# Default for the chef_gem compile_time attribute. Nil is the same as true but will emit
|
829
|
+
# warnings on every use of chef_gem prompting the user to be explicit. If the user sets this to
|
830
|
+
# true then the user will get backcompat behavior but with a single nag warning that cookbooks
|
831
|
+
# may break with this setting in the future. The false setting is the recommended setting and
|
832
|
+
# will become the default.
|
833
|
+
default :chef_gem_compile_time, nil
|
834
|
+
|
835
|
+
# A whitelisted array of attributes you want sent over the wire when node
|
836
|
+
# data is saved.
|
837
|
+
# The default setting is nil, which collects all data. Setting to [] will not
|
838
|
+
# collect any data for save.
|
839
|
+
default :automatic_attribute_whitelist, nil
|
840
|
+
default :default_attribute_whitelist, nil
|
841
|
+
default :normal_attribute_whitelist, nil
|
842
|
+
default :override_attribute_whitelist, nil
|
843
|
+
|
844
|
+
# Pull down all the rubygems versions from rubygems and cache them the first time we do a gem_package or
|
845
|
+
# chef_gem install. This is memory-expensive and will grow without bounds, but will reduce network
|
846
|
+
# round trips.
|
847
|
+
default :rubygems_cache_enabled, false
|
848
|
+
|
849
|
+
config_context :windows_service do
|
850
|
+
# Set `watchdog_timeout` to the number of seconds to wait for a chef-client run
|
851
|
+
# to finish
|
852
|
+
default :watchdog_timeout, 2 * (60 * 60) # 2 hours
|
853
|
+
end
|
854
|
+
|
855
|
+
# Add an empty and non-strict config_context for chefdk. This lets the user
|
856
|
+
# have code like `chefdk.generator_cookbook "/path/to/cookbook"` in their
|
857
|
+
# config.rb, and it will be ignored by tools like knife and ohai. ChefDK
|
858
|
+
# itself can define the config options it accepts and enable strict mode,
|
859
|
+
# and that will only apply when running `chef` commands.
|
860
|
+
config_context :chefdk do
|
861
|
+
end
|
862
|
+
|
863
|
+
# Configuration options for Data Collector reporting. These settings allow
|
864
|
+
# the user to configure where to send their Data Collector data, what token
|
865
|
+
# to send, and whether Data Collector should report its findings in client
|
866
|
+
# mode vs. solo mode.
|
867
|
+
config_context :data_collector do
|
868
|
+
# Full URL to the endpoint that will receive our data. If nil, the
|
869
|
+
# data collector will not run.
|
870
|
+
# Ex: http://my-data-collector.mycompany.com/ingest
|
871
|
+
default(:server_url) do
|
872
|
+
if config_parent.solo || config_parent.local_mode
|
873
|
+
nil
|
874
|
+
else
|
875
|
+
File.join(config_parent.chef_server_url, "/data-collector")
|
876
|
+
end
|
877
|
+
end
|
878
|
+
|
879
|
+
# An optional pre-shared token to pass as an HTTP header (x-data-collector-token)
|
880
|
+
# that can be used to determine whether or not the poster of this
|
881
|
+
# run data should be trusted.
|
882
|
+
# Ex: some-uuid-here
|
883
|
+
default :token, nil
|
884
|
+
|
885
|
+
# The Chef mode during which Data Collector is allowed to function. This
|
886
|
+
# can be used to run Data Collector only when running as Chef Solo but
|
887
|
+
# not when using Chef Client.
|
888
|
+
# Options: :solo (for both Solo Legacy Mode and Client Local Mode), :client, :both
|
889
|
+
default :mode, :both
|
890
|
+
|
891
|
+
# When the Data Collector cannot send the "starting a run" message to
|
892
|
+
# the Data Collector server, the Data Collector will be disabled for that
|
893
|
+
# run. In some situations, such as highly-regulated environments, it
|
894
|
+
# may be more reasonable to prevent Chef from performing the actual run.
|
895
|
+
# In these situations, setting this value to true will cause the Chef
|
896
|
+
# run to raise an exception before starting any converge activities.
|
897
|
+
default :raise_on_failure, false
|
898
|
+
|
899
|
+
# A user-supplied Organization string that can be sent in payloads
|
900
|
+
# generated by the DataCollector when Chef is run in Solo mode. This
|
901
|
+
# allows users to associate their Solo nodes with faux organizations
|
902
|
+
# without the nodes being connected to an actual Chef Server.
|
903
|
+
default :organization, nil
|
904
|
+
end
|
905
|
+
|
906
|
+
configurable(:http_proxy)
|
907
|
+
configurable(:http_proxy_user)
|
908
|
+
configurable(:http_proxy_pass)
|
909
|
+
configurable(:https_proxy)
|
910
|
+
configurable(:https_proxy_user)
|
911
|
+
configurable(:https_proxy_pass)
|
912
|
+
configurable(:ftp_proxy)
|
913
|
+
configurable(:ftp_proxy_user)
|
914
|
+
configurable(:ftp_proxy_pass)
|
915
|
+
configurable(:no_proxy)
|
916
|
+
|
917
|
+
# Public method that users should call to export proxies to the appropriate
|
918
|
+
# environment variables. This method should be called after the config file is
|
919
|
+
# parsed and loaded.
|
920
|
+
# TODO add some post-file-parsing logic that automatically calls this so
|
921
|
+
# users don't have to
|
922
|
+
def self.export_proxies
|
923
|
+
export_proxy("http", http_proxy, http_proxy_user, http_proxy_pass) if http_proxy
|
924
|
+
export_proxy("https", https_proxy, https_proxy_user, https_proxy_pass) if https_proxy
|
925
|
+
export_proxy("ftp", ftp_proxy, ftp_proxy_user, ftp_proxy_pass) if ftp_proxy
|
926
|
+
export_no_proxy(no_proxy) if no_proxy
|
927
|
+
end
|
928
|
+
|
929
|
+
# Character classes for Addressable
|
930
|
+
# See https://www.ietf.org/rfc/rfc3986.txt 3.2.1
|
931
|
+
# The user part may not have a : in it
|
932
|
+
USER = Addressable::URI::CharacterClasses::UNRESERVED + Addressable::URI::CharacterClasses::SUB_DELIMS
|
933
|
+
# The password part may have any valid USERINFO characters
|
934
|
+
PASSWORD = USER + "\\:"
|
935
|
+
|
936
|
+
# Builds a proxy uri and exports it to the appropriate environment variables. Examples:
|
937
|
+
# http://username:password@hostname:port
|
938
|
+
# https://username@hostname:port
|
939
|
+
# ftp://hostname:port
|
940
|
+
# when
|
941
|
+
# scheme = "http", "https", or "ftp"
|
942
|
+
# hostport = hostname:port or scheme://hostname:port
|
943
|
+
# user = username
|
944
|
+
# pass = password
|
945
|
+
# @api private
|
946
|
+
def self.export_proxy(scheme, path, user, pass)
|
947
|
+
path = "#{scheme}://#{path}" unless path.include?("://")
|
948
|
+
# URI.split returns the following parts:
|
949
|
+
# [scheme, userinfo, host, port, registry, path, opaque, query, fragment]
|
950
|
+
uri = Addressable::URI.encode(path, Addressable::URI)
|
951
|
+
|
952
|
+
if user && !user.empty?
|
953
|
+
userinfo = Addressable::URI.encode_component(user, USER)
|
954
|
+
if pass
|
955
|
+
userinfo << ":#{Addressable::URI.encode_component(pass, PASSWORD)}"
|
956
|
+
end
|
957
|
+
uri.userinfo = userinfo
|
958
|
+
end
|
959
|
+
|
960
|
+
path = uri.to_s
|
961
|
+
ENV["#{scheme}_proxy".downcase] = path unless ENV["#{scheme}_proxy".downcase]
|
962
|
+
ENV["#{scheme}_proxy".upcase] = path unless ENV["#{scheme}_proxy".upcase]
|
963
|
+
end
|
964
|
+
|
965
|
+
# @api private
|
966
|
+
def self.export_no_proxy(value)
|
967
|
+
ENV["no_proxy"] = value unless ENV["no_proxy"]
|
968
|
+
ENV["NO_PROXY"] = value unless ENV["NO_PROXY"]
|
969
|
+
end
|
970
|
+
|
971
|
+
# Given a scheme, host, and port, return the correct proxy URI based on the
|
972
|
+
# set environment variables, unless exluded by no_proxy, in which case nil
|
973
|
+
# is returned
|
974
|
+
def self.proxy_uri(scheme, host, port)
|
975
|
+
proxy_env_var = ENV["#{scheme}_proxy"].to_s.strip
|
976
|
+
|
977
|
+
# Check if the proxy string contains a scheme. If not, add the url's scheme to the
|
978
|
+
# proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy
|
979
|
+
# here since we are really just trying to get the string built correctly.
|
980
|
+
proxy = if !proxy_env_var.empty?
|
981
|
+
if proxy_env_var =~ /^.*:\/\//
|
982
|
+
URI.parse(proxy_env_var)
|
983
|
+
else
|
984
|
+
URI.parse("#{scheme}://#{proxy_env_var}")
|
985
|
+
end
|
986
|
+
end
|
987
|
+
|
988
|
+
return proxy unless fuzzy_hostname_match_any?(host, ENV["no_proxy"])
|
989
|
+
end
|
990
|
+
|
991
|
+
# Chef requires an English-language UTF-8 locale to function properly. We attempt
|
992
|
+
# to use the 'locale -a' command and search through a list of preferences until we
|
993
|
+
# find one that we can use. On Ubuntu systems we should find 'C.UTF-8' and be
|
994
|
+
# able to use that even if there is no English locale on the server, but Mac, Solaris,
|
995
|
+
# AIX, etc do not have that locale. We then try to find an English locale and fall
|
996
|
+
# back to 'C' if we do not. The choice of fallback is pick-your-poison. If we try
|
997
|
+
# to do the work to return a non-US UTF-8 locale then we fail inside of providers when
|
998
|
+
# things like 'svn info' return Japanese and we can't parse them. OTOH, if we pick 'C' then
|
999
|
+
# we will blow up on UTF-8 characters. Between the warn we throw and the Encoding
|
1000
|
+
# exception that ruby will throw it is more obvious what is broken if we drop UTF-8 by
|
1001
|
+
# default rather than drop English.
|
1002
|
+
#
|
1003
|
+
# If there is no 'locale -a' then we return 'en_US.UTF-8' since that is the most commonly
|
1004
|
+
# available English UTF-8 locale. However, all modern POSIXen should support 'locale -a'.
|
1005
|
+
def self.guess_internal_locale
|
1006
|
+
# https://github.com/chef/chef/issues/2181
|
1007
|
+
# Some systems have the `locale -a` command, but the result has
|
1008
|
+
# invalid characters for the default encoding.
|
1009
|
+
#
|
1010
|
+
# For example, on CentOS 6 with ENV['LANG'] = "en_US.UTF-8",
|
1011
|
+
# `locale -a`.split fails with ArgumentError invalid UTF-8 encoding.
|
1012
|
+
cmd = Mixlib::ShellOut.new("locale -a").run_command
|
1013
|
+
cmd.error!
|
1014
|
+
locales = cmd.stdout.split
|
1015
|
+
case
|
1016
|
+
when locales.include?("C.UTF-8")
|
1017
|
+
"C.UTF-8"
|
1018
|
+
when locales.include?("en_US.UTF-8"), locales.include?("en_US.utf8")
|
1019
|
+
"en_US.UTF-8"
|
1020
|
+
when locales.include?("en.UTF-8")
|
1021
|
+
"en.UTF-8"
|
1022
|
+
else
|
1023
|
+
# Will match en_ZZ.UTF-8, en_ZZ.utf-8, en_ZZ.UTF8, en_ZZ.utf8
|
1024
|
+
guesses = locales.select { |l| l =~ /^en_.*UTF-?8$/i }
|
1025
|
+
unless guesses.empty?
|
1026
|
+
guessed_locale = guesses.first
|
1027
|
+
# Transform into the form en_ZZ.UTF-8
|
1028
|
+
guessed_locale.gsub(/UTF-?8$/i, "UTF-8")
|
1029
|
+
else
|
1030
|
+
ChefConfig.logger.warn "Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support."
|
1031
|
+
"C"
|
1032
|
+
end
|
1033
|
+
end
|
1034
|
+
rescue
|
1035
|
+
if ChefConfig.windows?
|
1036
|
+
ChefConfig.logger.debug "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else."
|
1037
|
+
else
|
1038
|
+
ChefConfig.logger.debug "No usable locale -a command found, assuming you have en_US.UTF-8 installed."
|
1039
|
+
end
|
1040
|
+
"en_US.UTF-8"
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
default :internal_locale, guess_internal_locale
|
1044
|
+
|
1045
|
+
# Force UTF-8 Encoding, for when we fire up in the 'C' locale or other strange locales (e.g.
|
1046
|
+
# japanese windows encodings). If we do not do this, then knife upload will fail when a cookbook's
|
1047
|
+
# README.md has UTF-8 characters that do not encode in whatever surrounding encoding we have been
|
1048
|
+
# passed. Effectively, the Chef Ecosystem is globally UTF-8 by default. Anyone who wants to be
|
1049
|
+
# able to upload Shift_JIS or ISO-8859-1 files needs to mark *those* files explicitly with
|
1050
|
+
# magic tags to make ruby correctly identify the encoding being used. Changing this default will
|
1051
|
+
# break Chef community cookbooks and is very highly discouraged.
|
1052
|
+
default :ruby_encoding, Encoding::UTF_8
|
1053
|
+
|
1054
|
+
default :rubygems_url, "https://rubygems.org"
|
1055
|
+
|
1056
|
+
# This controls the behavior of resource cloning (and CHEF-3694 warnings). For Chef < 12 the behavior
|
1057
|
+
# has been that this is 'true', in Chef 13 this will change to false. Setting this to 'true' in Chef
|
1058
|
+
# 13 is not a viable or supported migration strategy since Chef 13 community cookbooks will be expected
|
1059
|
+
# to break with this setting set to 'true'.
|
1060
|
+
default :resource_cloning, true
|
1061
|
+
|
1062
|
+
# If installed via an omnibus installer, this gives the path to the
|
1063
|
+
# "embedded" directory which contains all of the software packaged with
|
1064
|
+
# omnibus. This is used to locate the cacert.pem file on windows.
|
1065
|
+
def self.embedded_dir
|
1066
|
+
Pathname.new(_this_file).ascend do |path|
|
1067
|
+
if path.basename.to_s == "embedded"
|
1068
|
+
return path.to_s
|
1069
|
+
end
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
nil
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
# Path to this file in the current install.
|
1076
|
+
def self._this_file
|
1077
|
+
File.expand_path(__FILE__)
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
# Set fips mode in openssl. Do any patching necessary to make
|
1081
|
+
# sure Chef runs do not crash.
|
1082
|
+
# @api private
|
1083
|
+
def self.enable_fips_mode
|
1084
|
+
OpenSSL.fips_mode = true
|
1085
|
+
require "digest"
|
1086
|
+
require "digest/sha1"
|
1087
|
+
require "digest/md5"
|
1088
|
+
# Remove pre-existing constants if they do exist to reduce the
|
1089
|
+
# amount of log spam and warnings.
|
1090
|
+
Digest.send(:remove_const, "SHA1") if Digest.const_defined?("SHA1")
|
1091
|
+
Digest.const_set("SHA1", OpenSSL::Digest::SHA1)
|
1092
|
+
OpenSSL::Digest.send(:remove_const, "MD5") if OpenSSL::Digest.const_defined?("MD5")
|
1093
|
+
OpenSSL::Digest.const_set("MD5", Digest::MD5)
|
1094
|
+
ChefConfig.logger.debug "FIPS mode is enabled."
|
1095
|
+
end
|
1096
|
+
end
|
1097
|
+
end
|