2020-01-17 21:05:03 +08:00
|
|
|
// Copyright 2019 Google LLC
|
2019-03-19 00:21:48 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
2022-01-28 17:38:27 +08:00
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2019-03-19 00:21:48 +08:00
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// The sandbox2::Namespace class defines ways of inserting the sandboxed process
|
|
|
|
// into Linux namespaces.
|
|
|
|
|
|
|
|
#ifndef SANDBOXED_API_SANDBOX2_NAMESPACE_H_
|
|
|
|
#define SANDBOXED_API_SANDBOX2_NAMESPACE_H_
|
|
|
|
|
2023-08-24 21:23:03 +08:00
|
|
|
#include <sched.h>
|
2019-03-19 00:21:48 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cstdint>
|
2019-03-26 22:54:02 +08:00
|
|
|
#include <string>
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
#include "sandboxed_api/sandbox2/mounts.h"
|
2019-03-20 20:19:28 +08:00
|
|
|
#include "sandboxed_api/sandbox2/violation.pb.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
namespace sandbox2 {
|
|
|
|
|
|
|
|
class Namespace final {
|
|
|
|
public:
|
|
|
|
// Performs the namespace setup (mounts, write the uid_map, etc.).
|
|
|
|
static void InitializeNamespaces(uid_t uid, gid_t gid, int32_t clone_flags,
|
2023-01-19 21:44:11 +08:00
|
|
|
const Mounts& mounts,
|
2019-11-20 01:01:59 +08:00
|
|
|
const std::string& hostname,
|
2022-03-09 00:00:46 +08:00
|
|
|
bool avoid_pivot_root,
|
|
|
|
bool allow_mount_propagation);
|
2019-11-20 01:01:59 +08:00
|
|
|
static void InitializeInitialNamespaces(uid_t uid, gid_t gid);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2019-03-26 22:54:02 +08:00
|
|
|
Namespace(bool allow_unrestricted_networking, Mounts mounts,
|
2022-03-09 00:00:46 +08:00
|
|
|
std::string hostname, bool allow_mount_propagation);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Stores information about this namespace in the protobuf structure.
|
2023-08-07 21:46:50 +08:00
|
|
|
void GetNamespaceDescription(NamespaceDescription* pb_description) const;
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2023-08-03 20:41:58 +08:00
|
|
|
int32_t clone_flags() const { return clone_flags_; }
|
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
Mounts& mounts() { return mounts_; }
|
|
|
|
const Mounts& mounts() const { return mounts_; }
|
|
|
|
|
|
|
|
const std::string& hostname() const { return hostname_; }
|
|
|
|
|
2022-03-09 00:00:46 +08:00
|
|
|
bool allow_mount_propagation() const { return allow_mount_propagation_; }
|
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
private:
|
2023-08-03 20:41:58 +08:00
|
|
|
int32_t clone_flags_ = CLONE_NEWUSER | CLONE_NEWNS | CLONE_NEWUTS |
|
|
|
|
CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWNET;
|
2019-03-19 00:21:48 +08:00
|
|
|
Mounts mounts_;
|
|
|
|
std::string hostname_;
|
2023-08-03 20:41:58 +08:00
|
|
|
bool allow_mount_propagation_ = false;
|
2019-03-19 00:21:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sandbox2
|
|
|
|
|
|
|
|
#endif // SANDBOXED_API_SANDBOX2_NAMESPACE_H_
|