Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/chromeos/arc/arc_util.cc

Issue 2890843002: Policy implementation for encryptfs to ext4 migration strategy (Closed)
Patch Set: Fixed review comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/arc/arc_util.h" 5 #include "chrome/browser/chromeos/arc/arc_util.h"
6 6
7 #include <linux/magic.h> 7 #include <linux/magic.h>
8 #include <sys/statfs.h> 8 #include <sys/statfs.h>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/optional.h"
15 #include "base/sys_info.h" 17 #include "base/sys_info.h"
16 #include "base/task_scheduler/post_task.h" 18 #include "base/task_scheduler/post_task.h"
17 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/values.h"
21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/browser_process_platform_part.h"
18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 23 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
19 #include "chrome/browser/chromeos/login/user_flow.h" 24 #include "chrome/browser/chromeos/login/user_flow.h"
20 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 25 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" 28 #include "chrome/browser/chromeos/profiles/profile_helper.h"
29 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chromeos/chromeos_switches.h"
24 #include "components/arc/arc_util.h" 33 #include "components/arc/arc_util.h"
25 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
26 #include "components/user_manager/known_user.h" 35 #include "components/user_manager/known_user.h"
27 #include "components/user_manager/user.h" 36 #include "components/user_manager/user.h"
28 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
29 38
39 using DeviceEcryptfsMigrationStrategyProto =
40 enterprise_management::DeviceEcryptfsMigrationStrategyProto;
41
30 namespace arc { 42 namespace arc {
31 43
32 namespace { 44 namespace {
33 45
34 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; 46 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION";
35 constexpr char kAndroidMSdkVersion[] = "23"; 47 constexpr char kAndroidMSdkVersion[] = "23";
36 48
37 // Let IsAllowedForProfile() return "false" for any profile. 49 // Let IsAllowedForProfile() return "false" for any profile.
38 bool g_disallow_for_testing = false; 50 bool g_disallow_for_testing = false;
39 51
40 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value 52 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value
41 // during test runs. 53 // during test runs.
42 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false; 54 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false;
43 55
44 // TODO(kinaba): Temporary workaround for crbug.com/729034. 56 // TODO(kinaba): Temporary workaround for crbug.com/729034.
45 // 57 //
46 // Some type of accounts don't have user prefs. As a short-term workaround, 58 // Some type of accounts don't have user prefs. As a short-term workaround,
47 // store the compatibility info from them on memory, ignoring the defect that 59 // store the compatibility info from them on memory, ignoring the defect that
48 // it cannot survive browser crash and restart. 60 // it cannot survive browser crash and restart.
49 // 61 //
50 // This will be removed once the forced migration for ARC Kiosk user is 62 // This will be removed once the forced migration for ARC Kiosk user is
51 // implemented. After it's done such types of accounts cannot even sign-in 63 // implemented. After it's done such types of accounts cannot even sign-in
52 // with incompatible filesystem. Hence it'll be safe to always regard compatible 64 // with incompatible filesystem. Hence it'll be safe to always regard compatible
53 // for them then. 65 // for them then.
54 base::LazyInstance<std::set<AccountId>>::DestructorAtExit 66 base::LazyInstance<std::set<AccountId>>::DestructorAtExit
55 g_known_compatible_users = LAZY_INSTANCE_INITIALIZER; 67 g_known_compatible_users = LAZY_INSTANCE_INITIALIZER;
56 68
69 // This flag is set the first time the check if migration to ext4 is allowed,
70 // and remains unchanged after that.
71 // TODO(igorcov): Remove this after migration. crbug.com/725493
72 base::Optional<bool> g_is_arc_migration_allowed;
73
57 // Returns whether ARC can run on the filesystem mounted at |path|. 74 // Returns whether ARC can run on the filesystem mounted at |path|.
58 // This function should run only on threads where IO operations are allowed. 75 // This function should run only on threads where IO operations are allowed.
59 bool IsArcCompatibleFilesystem(const base::FilePath& path) { 76 bool IsArcCompatibleFilesystem(const base::FilePath& path) {
60 base::ThreadRestrictions::AssertIOAllowed(); 77 base::ThreadRestrictions::AssertIOAllowed();
61 78
62 // If it can be verified it is not on ecryptfs, then it is ok. 79 // If it can be verified it is not on ecryptfs, then it is ok.
63 struct statfs statfs_buf; 80 struct statfs statfs_buf;
64 if (statfs(path.value().c_str(), &statfs_buf) < 0) 81 if (statfs(path.value().c_str(), &statfs_buf) < 0)
65 return false; 82 return false;
66 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; 83 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC;
(...skipping 20 matching lines...) Expand all
87 // TODO(kinaba): Remove this code for accounts without user prefs. 104 // TODO(kinaba): Remove this code for accounts without user prefs.
88 // See the comment for |g_known_compatible_users| for the detail. 105 // See the comment for |g_known_compatible_users| for the detail.
89 if (GetFileSystemCompatibilityPref(account_id) != 106 if (GetFileSystemCompatibilityPref(account_id) !=
90 arc::kFileSystemCompatible) { 107 arc::kFileSystemCompatible) {
91 g_known_compatible_users.Get().insert(account_id); 108 g_known_compatible_users.Get().insert(account_id);
92 } 109 }
93 } 110 }
94 callback.Run(); 111 callback.Run();
95 } 112 }
96 113
114 bool IsArcMigrationAllowedInternal() {
115 // If the device is not managed, then the migration allowed.
116 if (!g_browser_process->platform_part()
117 ->browser_policy_connector_chromeos()
118 ->IsEnterpriseManaged()) {
119 return true;
120 }
121
122 const auto* const command_line = base::CommandLine::ForCurrentProcess();
123 // If the command line flag is missing, the migration for this type of
124 // device is allowed regardless of the policy data.
125 if (!command_line->HasSwitch(
126 chromeos::switches::kNeedArcMigrationPolicyCheck)) {
127 return true;
128 }
129
130 const auto* policy =
131 chromeos::DeviceSettingsService::Get()->device_settings();
132 if (policy && policy->has_device_ecryptfs_migration_strategy()) {
133 const DeviceEcryptfsMigrationStrategyProto& container(
134 policy->device_ecryptfs_migration_strategy());
135 return container.has_migration_strategy() &&
136 container.migration_strategy() ==
137 DeviceEcryptfsMigrationStrategyProto::ALLOW_MIGRATION;
138 }
139
140 return false;
141 }
142
97 } // namespace 143 } // namespace
98 144
99 bool IsArcAllowedForProfile(const Profile* profile) { 145 bool IsArcAllowedForProfile(const Profile* profile) {
100 if (g_disallow_for_testing) { 146 if (g_disallow_for_testing) {
101 VLOG(1) << "ARC is disallowed for testing."; 147 VLOG(1) << "ARC is disallowed for testing.";
102 return false; 148 return false;
103 } 149 }
104 150
105 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. 151 // ARC Kiosk can be enabled even if ARC is not yet supported on the device.
106 // In that case IsArcKioskMode() should return true as profile is already 152 // In that case IsArcKioskMode() should return true as profile is already
(...skipping 29 matching lines...) Expand all
136 // users do this through GAIA, but Kiosk and Active Directory users use 182 // users do this through GAIA, but Kiosk and Active Directory users use
137 // different application install mechanism. ARC is not allowed otherwise 183 // different application install mechanism. ARC is not allowed otherwise
138 // (e.g. in public sessions). cf) crbug.com/605545 184 // (e.g. in public sessions). cf) crbug.com/605545
139 const user_manager::User* user = 185 const user_manager::User* user =
140 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 186 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
141 if (!IsArcAllowedForUser(user)) { 187 if (!IsArcAllowedForUser(user)) {
142 VLOG(1) << "ARC is not allowed for the user."; 188 VLOG(1) << "ARC is not allowed for the user.";
143 return false; 189 return false;
144 } 190 }
145 191
192 // If migration policy check is needed (specified by commandline flag), check
193 // the policy, which should be already available here. If policy says
194 // migration is not allowed, do not run ARC, regardless whether file system
195 // migration is actually needed. For example, even if file system is still
196 // ecryptfs and ARC version is M, or file system is already migrated into ext4
197 // crypt and ARC version is N or later, if policy says migration is not
198 // allowed, ARC will never run. Practically, in the former example case,
199 // --need-arc-migration-policy-check is not set, so this check passes and user
200 // can use ARC. In latter case, policy should say migration is allowed, so
201 // also user can use ARC then.
202 // TODO(igorcov): Remove this after migration. crbug.com/725493
203 if (!IsArcMigrationAllowed()) {
204 VLOG(1) << "ARC migration is not allowed by policy.";
205 return false;
206 }
207
146 // Do not run ARC instance when supervised user is being created. 208 // Do not run ARC instance when supervised user is being created.
147 // Otherwise noisy notification may be displayed. 209 // Otherwise noisy notification may be displayed.
148 chromeos::UserFlow* user_flow = 210 chromeos::UserFlow* user_flow =
149 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); 211 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId());
150 if (!user_flow || !user_flow->CanStartArc()) { 212 if (!user_flow || !user_flow->CanStartArc()) {
151 VLOG(1) << "ARC is not allowed in the current user flow."; 213 VLOG(1) << "ARC is not allowed in the current user flow.";
152 return false; 214 return false;
153 } 215 }
154 216
155 return true; 217 return true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 339
278 // Otherwise, check the underlying filesystem. 340 // Otherwise, check the underlying filesystem.
279 base::PostTaskWithTraitsAndReplyWithResult( 341 base::PostTaskWithTraitsAndReplyWithResult(
280 FROM_HERE, 342 FROM_HERE,
281 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, 343 {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
282 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, 344 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
283 base::Bind(&IsArcCompatibleFilesystem, profile_path), 345 base::Bind(&IsArcCompatibleFilesystem, profile_path),
284 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); 346 base::Bind(&StoreCompatibilityCheckResult, account_id, callback));
285 } 347 }
286 348
349 bool IsArcMigrationAllowed() {
350 if (!g_is_arc_migration_allowed.has_value())
351 g_is_arc_migration_allowed = IsArcMigrationAllowedInternal();
352 return g_is_arc_migration_allowed.value();
353 }
354
355 void ResetArcMigrationAllowedForTesting() {
356 g_is_arc_migration_allowed.reset();
357 }
358
287 } // namespace arc 359 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698