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

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"
22 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "chromeos/chromeos_switches.h"
24 #include "components/arc/arc_util.h" 32 #include "components/arc/arc_util.h"
25 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
26 #include "components/user_manager/known_user.h" 34 #include "components/user_manager/known_user.h"
27 #include "components/user_manager/user.h" 35 #include "components/user_manager/user.h"
28 #include "components/user_manager/user_manager.h" 36 #include "components/user_manager/user_manager.h"
29 37
30 namespace arc { 38 namespace arc {
31 39
32 namespace { 40 namespace {
33 41
(...skipping 13 matching lines...) Expand all
47 // store the compatibility info from them on memory, ignoring the defect that 55 // store the compatibility info from them on memory, ignoring the defect that
48 // it cannot survive browser crash and restart. 56 // it cannot survive browser crash and restart.
49 // 57 //
50 // This will be removed once the forced migration for ARC Kiosk user is 58 // 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 59 // 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 60 // with incompatible filesystem. Hence it'll be safe to always regard compatible
53 // for them then. 61 // for them then.
54 base::LazyInstance<std::set<AccountId>>::DestructorAtExit 62 base::LazyInstance<std::set<AccountId>>::DestructorAtExit
55 g_known_compatible_users = LAZY_INSTANCE_INITIALIZER; 63 g_known_compatible_users = LAZY_INSTANCE_INITIALIZER;
56 64
65 // This flag is set the first time the check if migration to ext4 is allowed,
66 // and remains unchanged after that.
67 // TODO(igorcov): Remove this after migration. crbug.com/725493
68 base::Optional<bool> g_is_arc_migration_allowed;
69
57 // Returns whether ARC can run on the filesystem mounted at |path|. 70 // Returns whether ARC can run on the filesystem mounted at |path|.
58 // This function should run only on threads where IO operations are allowed. 71 // This function should run only on threads where IO operations are allowed.
59 bool IsArcCompatibleFilesystem(const base::FilePath& path) { 72 bool IsArcCompatibleFilesystem(const base::FilePath& path) {
60 base::ThreadRestrictions::AssertIOAllowed(); 73 base::ThreadRestrictions::AssertIOAllowed();
61 74
62 // If it can be verified it is not on ecryptfs, then it is ok. 75 // If it can be verified it is not on ecryptfs, then it is ok.
63 struct statfs statfs_buf; 76 struct statfs statfs_buf;
64 if (statfs(path.value().c_str(), &statfs_buf) < 0) 77 if (statfs(path.value().c_str(), &statfs_buf) < 0)
65 return false; 78 return false;
66 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; 79 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. 100 // TODO(kinaba): Remove this code for accounts without user prefs.
88 // See the comment for |g_known_compatible_users| for the detail. 101 // See the comment for |g_known_compatible_users| for the detail.
89 if (GetFileSystemCompatibilityPref(account_id) != 102 if (GetFileSystemCompatibilityPref(account_id) !=
90 arc::kFileSystemCompatible) { 103 arc::kFileSystemCompatible) {
91 g_known_compatible_users.Get().insert(account_id); 104 g_known_compatible_users.Get().insert(account_id);
92 } 105 }
93 } 106 }
94 callback.Run(); 107 callback.Run();
95 } 108 }
96 109
110 bool IsArcMigrationAllowedInternal() {
111 // If the device is not managed, then the migration allowed.
112 if (!g_browser_process->platform_part()
113 ->browser_policy_connector_chromeos()
114 ->IsEnterpriseManaged()) {
115 return true;
116 }
117
118 const auto* const command_line = base::CommandLine::ForCurrentProcess();
119 // If the command line flag is missing, the migration for this type of
120 // device is allowed regardless of the policy data.
121 if (!command_line->HasSwitch(
122 chromeos::switches::kNeedArcMigrationPolicyCheck)) {
123 return true;
124 }
125
126 const PrefService* const pref_service =
127 user_manager::UserManager::Get()->GetLocalState();
128 const PrefService::Preference* const pref =
129 pref_service->FindPreference(prefs::kDeviceEcryptfsMigrationStrategy);
130
131 return pref && pref->GetValue() &&
132 pref->GetValue()->GetInt() ==
133 enterprise_management::DeviceEcryptfsMigrationStrategyProto::
134 ALLOW_MIGRATION;
135 }
136
97 } // namespace 137 } // namespace
98 138
99 bool IsArcAllowedForProfile(const Profile* profile) { 139 bool IsArcAllowedForProfile(const Profile* profile) {
100 if (g_disallow_for_testing) { 140 if (g_disallow_for_testing) {
101 VLOG(1) << "ARC is disallowed for testing."; 141 VLOG(1) << "ARC is disallowed for testing.";
102 return false; 142 return false;
103 } 143 }
104 144
105 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. 145 // 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 146 // 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 176 // users do this through GAIA, but Kiosk and Active Directory users use
137 // different application install mechanism. ARC is not allowed otherwise 177 // different application install mechanism. ARC is not allowed otherwise
138 // (e.g. in public sessions). cf) crbug.com/605545 178 // (e.g. in public sessions). cf) crbug.com/605545
139 const user_manager::User* user = 179 const user_manager::User* user =
140 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 180 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
141 if (!IsArcAllowedForUser(user)) { 181 if (!IsArcAllowedForUser(user)) {
142 VLOG(1) << "ARC is not allowed for the user."; 182 VLOG(1) << "ARC is not allowed for the user.";
143 return false; 183 return false;
144 } 184 }
145 185
186 // If migration policy check is needed (specified by commandline flag), check
187 // the policy, which should be already available here. If policy says
188 // migration is not allowed, do not run ARC, regardless whether file system
189 // migration is actually needed. For example, even if file system is still
190 // ecryptfs and ARC version is M, or file system is already migrated into ext4
191 // crypt and ARC version is N or later, if policy says migration is not
192 // allowed, ARC will never run. Practically, in the former example case,
193 // --need-arc-migration-policy-check is not set, so this check passes and user
194 // can use ARC. In latter case, policy should say migration is allowed, so
195 // also user can use ARC then.
196 // TODO(igorcov): Remove this after migration. crbug.com/725493
197 if (!IsArcMigrationAllowed()) {
198 VLOG(1) << "ARC migration is not allowed by the policy.";
bartfab (slow) 2017/06/13 09:56:01 Nit: s/the //
igorcov 2017/06/16 11:13:04 Done.
199 return false;
200 }
201
146 // Do not run ARC instance when supervised user is being created. 202 // Do not run ARC instance when supervised user is being created.
147 // Otherwise noisy notification may be displayed. 203 // Otherwise noisy notification may be displayed.
148 chromeos::UserFlow* user_flow = 204 chromeos::UserFlow* user_flow =
149 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); 205 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId());
150 if (!user_flow || !user_flow->CanStartArc()) { 206 if (!user_flow || !user_flow->CanStartArc()) {
151 VLOG(1) << "ARC is not allowed in the current user flow."; 207 VLOG(1) << "ARC is not allowed in the current user flow.";
152 return false; 208 return false;
153 } 209 }
154 210
155 return true; 211 return true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 333
278 // Otherwise, check the underlying filesystem. 334 // Otherwise, check the underlying filesystem.
279 base::PostTaskWithTraitsAndReplyWithResult( 335 base::PostTaskWithTraitsAndReplyWithResult(
280 FROM_HERE, 336 FROM_HERE,
281 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, 337 {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
282 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, 338 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
283 base::Bind(&IsArcCompatibleFilesystem, profile_path), 339 base::Bind(&IsArcCompatibleFilesystem, profile_path),
284 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); 340 base::Bind(&StoreCompatibilityCheckResult, account_id, callback));
285 } 341 }
286 342
343 bool IsArcMigrationAllowed() {
344 if (!g_is_arc_migration_allowed.has_value())
345 g_is_arc_migration_allowed = IsArcMigrationAllowedInternal();
346 return g_is_arc_migration_allowed.value();
347 }
348
349 void ResetArcMigrationAllowedForTesting() {
350 g_is_arc_migration_allowed.reset();
351 }
352
287 } // namespace arc 353 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698