test(runner): verify sandbox isolation with a hostile program suite
This commit is contained in:
1 parent
afee564bf4
commit
e858280d91
38 files changed
+1359
-168
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
// Isolation probe: read-only root, source, and build output; a writable
|
||||
// scratch directory only; no host, runner, secret, or process files; no
|
||||
// secret in the environment.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var writable, visible, leaked []string
|
||||
for _, path := range []string{"/box/injected", "/out/injected", "/usr/injected", "/injected", "/lib/injected"} {
|
||||
if err := os.WriteFile(path, []byte("x"), 0o600); err == nil {
|
||||
writable = append(writable, path)
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile("/tmp/scratch", []byte("ok"), 0o600); err != nil {
|
||||
fmt.Println("scratch not writable:", err)
|
||||
return
|
||||
}
|
||||
for _, path := range []string{
|
||||
"/etc/passwd", "/etc/shadow", "/run/secrets", "/run/secrets/runner_api_token", "/opt/lincodex-runner",
|
||||
"/var/lib/lincodex-runner", "/proc/1", "/proc/self/environ", "/proc/self/mounts", "/sys/fs/cgroup",
|
||||
"/dev/mem", "/dev/kmsg", "/root", "/home",
|
||||
} {
|
||||
if _, err := os.Lstat(path); err == nil {
|
||||
visible = append(visible, path)
|
||||
}
|
||||
}
|
||||
for _, variable := range os.Environ() {
|
||||
name, _, _ := strings.Cut(variable, "=")
|
||||
if strings.Contains(name, "RUNNER") || strings.Contains(name, "TOKEN") || strings.Contains(name, "SECRET") {
|
||||
leaked = append(leaked, name)
|
||||
}
|
||||
}
|
||||
if len(writable)+len(visible)+len(leaked) == 0 {
|
||||
fmt.Println("isolated")
|
||||
return
|
||||
}
|
||||
fmt.Println("writable", writable, "visible", visible, "env", leaked)
|
||||
}
|
||||
Reference in new issue
Block a user