blob: 2fa7470084c4577ee07b899fe4af6eb1ded16d4b [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
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050020 virtual bool Init();
Mike Frysinger56379d72019-02-19 16:03:03 -050021 virtual bool Init(const std::vector<std::string>& minijail_extra_args);
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050022
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070023 // Disable the default sandboxing for this process.
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050024 virtual void DisableSandbox();
25
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070026 // Change the default sandboxing for this process.
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050027 virtual void SandboxAs(const std::string& user, const std::string& group);
28
David Valleau09f46642017-12-19 17:55:14 -080029 // Allow the sandbox to inherit supplementary groups from the uid.
30 virtual void InheritUsergroups();
31
Edward Hillad7de4e2017-07-05 14:45:17 -060032 // Set the capabilities mask for this process. Requires that the process is
33 // not running as root.
34 void SetCapabilities(uint64_t capabilities_mask) override;
35
Justin Carlson73310fb2016-10-11 16:13:26 -070036 // Set a file to be used as the seccomp bpf file for this process. See
37 // minijail0 -S for details of what can be in this file.
38 virtual void SetSeccompFilterPolicyFile(const std::string& path);
39
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070040 // Allow this process to access the root mount namespace.
41 virtual void AllowAccessRootMountNamespace();
42
Jorge Lucangeli Obes389a9ee2015-05-14 17:37:01 -070043 // Kill the sandboxed process' process group.
44 virtual bool KillProcessGroup();
45
Ben Chanaf125862017-02-08 23:11:18 -080046 static const char kDefaultUser[];
47 static const char kDefaultGroup[];
Elly Fong-Jones215b5622013-03-20 14:32:18 -040048
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050049 private:
50 bool sandboxing_;
Jorge Lucangeli Obesc99a12a2014-09-17 16:43:40 -070051 bool access_root_mount_ns_;
Edward Hillad7de4e2017-07-05 14:45:17 -060052 bool set_capabilities_;
David Valleau09f46642017-12-19 17:55:14 -080053 bool inherit_usergroups_;
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050054 std::string user_;
55 std::string group_;
Justin Carlson73310fb2016-10-11 16:13:26 -070056 std::string seccomp_filter_policy_file_;
Edward Hillad7de4e2017-07-05 14:45:17 -060057 uint64_t capabilities_mask_;
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050058};
59
Ben Chana0011d82014-05-13 00:19:29 -070060} // namespace debugd
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050061
Alex Vakulenko262be3f2014-07-30 15:25:50 -070062#endif // DEBUGD_SRC_SANDBOXED_PROCESS_H_