blob: 547730929dc886544775256d13f911b870c523d6 [file] [log] [blame]
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#ifndef DEBUGD_SRC_SANDBOXED_PROCESS_H_
6#define DEBUGD_SRC_SANDBOXED_PROCESS_H_
Ben Chana0011d82014-05-13 00:19:29 -07007
8#include <string>
Ricky Liang1ef73e52016-05-24 16:32:34 +08009#include <vector>
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050010
Alex Vakulenkoe7696532015-10-16 16:27:29 -070011#include <brillo/process.h>
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050012
13namespace debugd {
14
Alex Vakulenkoe7696532015-10-16 16:27:29 -070015class SandboxedProcess : public brillo::ProcessImpl {
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050016 public:
17 SandboxedProcess();
Eric Carusoa6f1adb2017-05-24 14:19:46 -070018 ~SandboxedProcess() override = default;
Ben Chan297c3c22013-07-17 17:34:12 -070019
20 // Get the full path of a helper executable located at the |relative_path|
21 // relative to the debugd helpers directory. Return false if the full path
22 // is too long.
23 static bool GetHelperPath(const std::string& relative_path,
24 std::string* full_path);
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050025
26 virtual bool Init();
27
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070028 // Disable the default sandboxing for this process.
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050029 virtual void DisableSandbox();
30
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070031 // Change the default sandboxing for this process.
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050032 virtual void SandboxAs(const std::string& user, const std::string& group);
33
Justin Carlson73310fb2016-10-11 16:13:26 -070034 // Set a file to be used as the seccomp bpf file for this process. See
35 // minijail0 -S for details of what can be in this file.
36 virtual void SetSeccompFilterPolicyFile(const std::string& path);
37
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070038 // Allow this process to access the root mount namespace.
39 virtual void AllowAccessRootMountNamespace();
40
Jorge Lucangeli Obes389a9ee2015-05-14 17:37:01 -070041 // Kill the sandboxed process' process group.
42 virtual bool KillProcessGroup();
43
Ben Chanaf125862017-02-08 23:11:18 -080044 static const char kDefaultUser[];
45 static const char kDefaultGroup[];
Elly Fong-Jones215b5622013-03-20 14:32:18 -040046
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050047 private:
48 bool sandboxing_;
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070049 bool access_root_mount_ns_;
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050050 std::string user_;
51 std::string group_;
Justin Carlson73310fb2016-10-11 16:13:26 -070052 std::string seccomp_filter_policy_file_;
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050053};
54
Ben Chana0011d82014-05-13 00:19:29 -070055} // namespace debugd
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050056
Alex Vakulenko262be3f2014-07-30 15:25:50 -070057#endif // DEBUGD_SRC_SANDBOXED_PROCESS_H_