Skip to content

Commit

Permalink
fix chrome intial preference location
Browse files Browse the repository at this point in the history
Summary:

In June 2020, Chromium landed a diff which changed the install location for Chromium (and Google Chrome some time not too much later).  Historically, Chrome had used C:\Program Files (x86)\ even for x86_64 versions.  Now they continue to use that location for existing installs which upgrade to new versions, but use C:\Program Files\ for new installs.

In addition, Chrome is migrating from the master_preferences file name to initial_preferences, presumably to the biased terminology of master.

This diff replaces writing to one location with writing to all 4 locations, to ensure that we'll be writing the file for all places chrome might be looking for it.

Reviewed By: steelcowboy

Differential Revision: D30918324

fbshipit-source-id: 38fe87842fa6156eacb865b2aeb569ac278474cc
  • Loading branch information
dschleimer authored and facebook-github-bot committed Sep 14, 2021
1 parent 4fe1c07 commit d001ffc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 46 deletions.
1 change: 1 addition & 0 deletions itchef/cookbooks/cpe_chrome/metadata.rb
Expand Up @@ -10,3 +10,4 @@

depends 'cpe_profiles'
depends 'cpe_helpers'
depends 'fb_osquery'
107 changes: 61 additions & 46 deletions itchef/cookbooks/cpe_chrome/resources/cpe_chrome_win.rb
Expand Up @@ -24,6 +24,8 @@
# chrome is installed on all machines
chrome_installed = ::File.file?(
"#{ENV['ProgramFiles(x86)']}\\Google\\Chrome\\Application\\chrome.exe",
) || ::File.file?(
"#{ENV['ProgramFiles']}\\Google\\Chrome\\Application\\chrome.exe",
)
return unless chrome_installed || node.installed?('Google Chrome')
return unless node['cpe_chrome']['profile'].values.any?
Expand Down Expand Up @@ -250,54 +252,67 @@
end
end

# Apply the Master Preferences file
master_path =
'c:\\Program Files (x86)\\Google\\Chrome\\Application\\master_preferences'
file "delete-#{master_path}" do
only_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
end
path master_path
action :delete
end
# There are two migrations going on here. From the legacy x86
# program files to the x86_64 one, and from master_preferences to
# initial_preferences. At time of writing, we have Chrome instances
# installed in both locations. While we probably do not have any
# chromes old enough to be unaware of the new initial_preferences
# file name, we might, and the current files use that name. It's
# safer to just keep creating it until we're sure everything is on
# the new name.
['initial_preferences', 'master_preferences'].each do |basename|
[
'C:\\Program Files (x86)\\',
'C:\\Program Files\\',
].each do |prefix|

[
'C:\\Program Files (x86)\\Google',
'C:\\Program Files (x86)\\Google\\Chrome',
'C:\\Program Files (x86)\\Google\\Chrome\\Application',
].each do |dir|
directory dir do # ~FB024
rights :read, 'Everyone', :applies_to_children => true
rights :read_execute, 'Users', :applies_to_children => true
rights :full_control, ['Administrators', 'SYSTEM'],
:applies_to_children => true
action :create
end
end
pref_path = "#{prefix}\\Google\\Chrome\\Application\\#{basename}"
file "delete-#{pref_path}" do
only_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
end
path pref_path
action :delete
end

[
"#{prefix}\\Google",
"#{prefix}\\Google\\Chrome",
"#{prefix}\\Google\\Chrome\\Application",
].each do |dir|
directory dir do # ~FB024
rights :read, 'Everyone', :applies_to_children => true
rights :read_execute, 'Users', :applies_to_children => true
rights :full_control, ['Administrators', 'SYSTEM'],
:applies_to_children => true
action :create
end
end

# Create the Master Preferences file
file "create-#{master_path}" do # ~FB023
not_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
file "create-#{pref_path}" do # ~FB023
not_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
end
content lazy {
Chef::JSONCompat.to_json_pretty(
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? },
)
}
path pref_path
rights :read, 'Everyone', :applies_to_children => true
rights :read_execute, 'Users', :applies_to_children => true
rights :full_control, ['Administrators', 'SYSTEM'],
:applies_to_children => true
action :create
end
end
content lazy {
Chef::JSONCompat.to_json_pretty(
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? },
)
}
path master_path
rights :read, 'Everyone', :applies_to_children => true
rights :read_execute, 'Users', :applies_to_children => true
rights :full_control, ['Administrators', 'SYSTEM'],
:applies_to_children => true
action :create
end
end

0 comments on commit d001ffc

Please sign in to comment.