Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Windows Group Policy templates for Brave #15440

Merged
merged 27 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3cff67c
Brand Group Policy templates for Brave
mherrmann Oct 12, 2022
1a55e98
Create Brave Group Policy Template in create_dist
mherrmann Oct 27, 2022
3263578
Fix .adm Windows Group Policy Template
mherrmann Oct 27, 2022
067c701
Small code style improvements
mherrmann Oct 31, 2022
acc195f
Improve Branding in Windows Policy Templates
mherrmann Oct 31, 2022
e2bd2cd
Fix comment
mherrmann Oct 31, 2022
9ecccd5
Brand Windows Group Policy template file names
mherrmann Oct 31, 2022
b5b6226
Add copyright notice to new file
mherrmann Oct 31, 2022
61184ee
Rename file
mherrmann Oct 31, 2022
784fa6f
Refactor: Improve target name
mherrmann Oct 31, 2022
4895cea
Add comment
mherrmann Oct 31, 2022
086d94c
Fix lint error
mherrmann Oct 31, 2022
dc99c33
Fix lint error
mherrmann Nov 2, 2022
d48f161
Fix lint error
mherrmann Nov 2, 2022
51c4f05
Use override_utils to modify Chromium Py. function
mherrmann Nov 5, 2022
c582b1e
Extract test code into separate file
mherrmann Nov 5, 2022
f5e3527
Remove test file
mherrmann Nov 5, 2022
1027d13
Remove unnecessary file header
mherrmann Nov 5, 2022
0e69eab
Use override_utils to redefine method
mherrmann Nov 5, 2022
077e878
Fix indent
mherrmann Nov 5, 2022
301f465
Small improvement
mherrmann Nov 5, 2022
0152a89
Reformat code
mherrmann Nov 5, 2022
7b0a0fc
Reformat code
mherrmann Nov 5, 2022
bdc3a77
Fix wrong license header
mherrmann Nov 7, 2022
5c20d4b
Remove unnecessary newlines
mherrmann Nov 7, 2022
5d7b5d6
Convert some GN deps from relative to absolute
mherrmann Nov 7, 2022
3018c40
Simplify code
mherrmann Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ group("create_dist") {
}

if (is_win) {
deps += [ "build/win:create_signed_installer" ]
deps += [
"//brave/build/win:create_signed_installer",
"//brave/components/policy:pack_policy_templates",
]

if (build_omaha) {
deps += [ "//brave/vendor/omaha" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2022 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import override_utils

@override_utils.override_function(globals())
def GetConfigurationForBuild(original_function, defines):
base = original_function(defines)
return _merge_dicts(_BRAVE_VALUES, base)

_BRAVE_VALUES = {
'build': 'brave',
'app_name': 'Brave',
'doc_url':
'https://support.brave.com/hc/en-us/articles/360039248271-Group-Policy',
'frame_name': 'Brave Frame',
'webview_name': 'Brave WebView',
'win_config': {
'win': {
'reg_mandatory_key_name': 'Software\\Policies\\BraveSoftware\\Brave',
'reg_recommended_key_name':
'Software\\Policies\\BraveSoftware\\Brave\\Recommended',
'mandatory_category_path': ['Brave:Cat_Brave', 'brave'],
'recommended_category_path': ['Brave:Cat_Brave', 'brave_recommended'],
'category_path_strings': {
'brave': 'Brave',
'brave_recommended':
'Brave - {doc_recommended}'
},
'namespace': 'BraveSoftware.Policies.Brave',
},
},
# The string 'Brave' is defined in brave.adml for ADMX, but ADM doesn't
# support external references, so we define this map here.
'adm_category_path_strings': {
'Brave:Cat_Brave': 'Brave'
},
'admx_prefix': 'brave',
'admx_using_namespaces': {
'Brave': 'BraveSoftware.Policies' # prefix: namespace
},
'linux_policy_path': '/etc/brave/policies/',
'bundle_id': 'com.brave.ios.core',
}

def _merge_dicts(src, dst):
goodov marked this conversation as resolved.
Show resolved Hide resolved
result = dict(dst)
for k, v in src.items():
result[k] = _merge_dicts(v, dst.get(k, {})) if isinstance(v, dict) else v
return result
15 changes: 15 additions & 0 deletions chromium_src/tools/grit/grit/gather/policy_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2022 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import override_utils

@override_utils.override_method(PolicyJson)
def SetDefines(self, _, defines):
self._config = {
'build': 'brave',
'app_name': 'Brave',
'frame_name': 'Brave Frame',
'os_name': 'Google Chrome OS'
}
17 changes: 17 additions & 0 deletions components/policy/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if (is_win) {
action("pack_policy_templates") {
chrome_pack_policy_templates = "//components/policy:pack_policy_templates"
deps = [ chrome_pack_policy_templates ]
script = "pack_policy_templates.py"
chrome_policy_templates_zip =
get_label_info(chrome_pack_policy_templates, "root_out_dir") +
"/policy_templates.zip"
inputs = [ chrome_policy_templates_zip ]
output_zip_file = "$root_out_dir/brave_policy_templates.zip"
outputs = [ output_zip_file ]
args = [
rebase_path(chrome_policy_templates_zip, root_build_dir),
rebase_path(output_zip_file, root_build_dir),
]
}
}
52 changes: 52 additions & 0 deletions components/policy/pack_policy_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
# Copyright (c) 2022 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

"""
Create a Zip file of Windows Group Policy templates similar to Chrome's.
"""

import argparse
import os

from os.path import join, exists, relpath
from tempfile import TemporaryDirectory
from zipfile import ZipFile

def main():
chrome_policy_zip, dest_zip = _get_args()
_pack_policy_templates(chrome_policy_zip, dest_zip)

def _get_args():
parser = argparse.ArgumentParser()
parser.add_argument('chrome_policy_zip',
help="Path to Chrome's policy_templates.zip")
parser.add_argument('dest_zip',
help="Path to the Zip file to be created")
args = parser.parse_args()
return args.chrome_policy_zip, args.dest_zip

def _pack_policy_templates(chrome_policy_zip, dest_zip):
with TemporaryDirectory() as tmp_dir:
with ZipFile(chrome_policy_zip) as src_zip:
src_zip.extract('VERSION', tmp_dir)
namelist = src_zip.namelist()
for dir_ in ('windows/adm/', 'windows/admx/', 'windows/examples/'):
src_zip.extractall(tmp_dir, (n for n in namelist if n.startswith(dir_)))

# Some sanity checks:
assert exists(join(tmp_dir, 'windows/adm/en-US/chrome.adm'))
assert exists(join(tmp_dir, 'windows/admx/chrome.admx'))
assert exists(join(tmp_dir, 'windows/admx/en-US/chrome.adml'))

with ZipFile(dest_zip, 'w') as dest_zipfile:
mherrmann marked this conversation as resolved.
Show resolved Hide resolved
for dirpath, _, filenames in os.walk(tmp_dir):
for filename in filenames:
filepath = join(dirpath, filename)
arcname = relpath(filepath, tmp_dir).replace('chrome', 'brave')
dest_zipfile.write(filepath, arcname=arcname)

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/components/policy/tools/template_writers/writer_configuration.py b/components/policy/tools/template_writers/writer_configuration.py
index 259e467fee3e9280c512db87ab8f48ed09c20ed3..1e6b41f7853e1a5062c6a9e9c527da9c06e6a9d6 100755
--- a/components/policy/tools/template_writers/writer_configuration.py
+++ b/components/policy/tools/template_writers/writer_configuration.py
@@ -131,3 +131,4 @@ def GetConfigurationForBuild(defines):
config['mac_bundle_id'] = defines['mac_bundle_id']
config['android_webview_restriction_prefix'] = 'com.android.browser:'
return config
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/components/policy/tools/template_writers/writer_configuration.py", globals(), locals())
9 changes: 9 additions & 0 deletions patches/tools-grit-grit-gather-policy_json.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/tools/grit/grit/gather/policy_json.py b/tools/grit/grit/gather/policy_json.py
index dc50b9f5e68e2616810e9f451c2dbdaf94a0fe8e..e0a6c341e8b8e618ba6809e49f672078a4395f39 100644
--- a/tools/grit/grit/gather/policy_json.py
+++ b/tools/grit/grit/gather/policy_json.py
@@ -330,3 +330,4 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer):
}
else:
raise Exception('Unknown build')
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/grit/grit/gather/policy_json.py", globals(), locals())