41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
// Bash commands in a shell sandbox ("Workspaces" in the product overview:
|
||
|
|
// commands and files isolated from core systems). Each command runs in a new
|
||
|
|
// shell as an unprivileged user; cd and variables do not carry over.
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
#include "google/sandbox/caps.h"
|
||
|
|
#include "google/sandbox/sandbox_service.h"
|
||
|
|
|
||
|
|
namespace molo::google::sandbox {
|
||
|
|
|
||
|
|
struct ShellRequest {
|
||
|
|
std::string command;
|
||
|
|
std::string cwd; // Empty: the sandbox default (/workspace).
|
||
|
|
int timeout_seconds = SandboxCaps::kDefaultShellTimeoutSeconds;
|
||
|
|
};
|
||
|
|
|
||
|
|
class ShellRunner : public SandboxService {
|
||
|
|
public:
|
||
|
|
explicit ShellRunner(std::shared_ptr<GoogleClient> client);
|
||
|
|
|
||
|
|
ExecutionResult run(const std::string& sandbox_name,
|
||
|
|
const ShellRequest& request) const;
|
||
|
|
|
||
|
|
// Same call with a higher command ceiling, for WorkspaceFiles only (it
|
||
|
|
// ships file bytes inside the command line). Never exposed to routes.
|
||
|
|
ExecutionResult run_internal(const std::string& sandbox_name,
|
||
|
|
const ShellRequest& request) const;
|
||
|
|
|
||
|
|
static void validate(const ShellRequest& request, std::size_t max_command);
|
||
|
|
|
||
|
|
private:
|
||
|
|
ExecutionResult run_capped(const std::string& sandbox_name,
|
||
|
|
const ShellRequest& request,
|
||
|
|
std::size_t max_command) const;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace molo::google::sandbox
|