mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
Two root file operations took a path the agent controls. - ingest_bbot opened the path it was given with os.Open in the server process, which is root in the image: any root-readable file could be named, and the result counts told its line structure. The tool now opens the file through the file tools' confinement (openWorkRoot on the run's working directory under the data directory, then os.Root): an absolute path elsewhere, "..", a symlink, a hard-linked file and a run directory reached by a symlink are refused. It fails closed without a data directory or a working directory. The worker passes its data directory to the ToolSet (SetWorkBase); the tool reads the ToolContext for the working directory, like ingest_scan_output. - execPython wrote the script of a custom tool as root to <run dir>/.tools and then chowned it. The executor can write the run directory, so it could turn .tools into a symlink and have root create and chown a file elsewhere. With the privilege drop on, the script now goes to <data>/exec-scripts, created by PrepareExecPrivilege as root:<exec gid> 0750, outside tasks/ and sessions/: the executor reads the 0640 script and cannot create, rename or replace an entry. An enabled drop without that directory is an error, not a fallback to the run directory. Without the drop nothing changes. PrepareExecPrivilege takes the privilege by pointer to record ExecPrivilege.ScriptDir. Tests: TestOpenBbotOutputConfined and TestIngestBbotToolConfined (no Postgres), TestExecPythonNeedsScriptDirWhenDropping, and the root-only TestExecPythonScriptDirAsRoot (.tools planted as a symlink to a root-only directory). TestIngestBbotScopeSplit now places its file in a run directory. SECURITY.md: the two paths leave the residual list; the command-output spill stays.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
//go:build !unix
|
|
|
|
package server
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
)
|
|
|
|
// Without unix credentials the privilege drop cannot be applied. ResolveExecPrivilege
|
|
// never enables it here, so these stubs only keep the package compiling; the
|
|
// functions that would act on an enabled drop return an error to fail closed.
|
|
|
|
var errExecUnsupported = errors.New("agent process isolation is not supported on this platform")
|
|
|
|
func execPrivilegeSupported() bool { return false }
|
|
|
|
func serverIsRoot() bool { return false }
|
|
|
|
func applyExecCredential(c *exec.Cmd, p ExecPrivilege) {}
|
|
|
|
func prepareExecScript(p ExecPrivilege, path string) error { return nil }
|
|
|
|
// PrepareExecPrivilege fails when a drop is enabled; a disabled one does nothing.
|
|
func PrepareExecPrivilege(p *ExecPrivilege, dataDir, keyDir, configPath string) error {
|
|
if p.Enabled {
|
|
return errExecUnsupported
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// InstallBashShim fails when a drop is enabled; a disabled one does nothing.
|
|
func InstallBashShim(p ExecPrivilege) error {
|
|
if p.Enabled {
|
|
return errExecUnsupported
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RunExecShimIfRequested does nothing: no shim is ever installed on this platform.
|
|
func RunExecShimIfRequested(argv []string) {}
|