fix(openshell): sandboxes reach the embedded broker by the services host, and may open /dev/null and /proc (#1864)

This commit is contained in:
sam committed 2026-11-14 22:06:09 +11:00
1 parent 411632548c
commit 5d620461fe
2 files changed
+32 -6

No files matched your search

+28 -3
View File
@@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"log/slog"
"net"
"net/url"
"os"
"os/signal"
@@ -473,14 +474,38 @@ func (b *boot) startCallout(ctx context.Context, url, token string) error {
return nil
}
// natsHost is the address the embedded broker binds. OpenShell sandboxes run
// on the host network and reach the broker by the services host name, so it
// binds the address that name resolves to; Docker containers reach it on the
// bridge gateway.
func natsHost(ctx context.Context, cfg config.Config, pool *container.Pool) (string, error) {
shell := cfg.Containers.OpenShell
if cfg.Containers.Runtime == config.RuntimeOpenShell && shell.ServicesHost != "" {
addrs, err := net.DefaultResolver.LookupHost(ctx, shell.ServicesHost)
if err != nil || len(addrs) == 0 {
return "", fmt.Errorf("embedded nats: resolve services host %s: %w", shell.ServicesHost, err)
}
for _, a := range addrs {
if ip := net.ParseIP(a); ip != nil && ip.To4() != nil {
return a, nil
}
}
return addrs[0], nil
}
if pool != nil {
return pool.HostGateway(), nil
}
return "", nil
}
func (b *boot) startEmbeddedNATS(ctx context.Context) (string, string, error) {
cfg, log := b.cfg, b.log
if cfg.StateDir == "" {
return "", "", errors.New("embedded nats: state_dir is required")
}
host := ""
if b.containerPool != nil {
host = b.containerPool.HostGateway()
host, err := natsHost(ctx, cfg, b.containerPool)
if err != nil {
return "", "", err
}
// A restarted broker keeps the previous endpoint, so the Gateway and
// running agents reconnect to it instead of a broker that no longer exists.
+4 -3
View File
@@ -40,10 +40,11 @@ const anyBinary = "/**"
// writable are container paths tools write to inside the sandbox. They are
// the container's own layer, so writing them exposes nothing on the host.
var writable = []string{"/tmp", "/var/tmp", "/root", "/home"}
var writable = []string{"/tmp", "/var/tmp", "/root", "/home", "/dev/null"}
// readOnly are the system paths the agent and its tools read.
var readOnly = []string{"/usr", "/lib", "/lib64", "/bin", "/sbin", "/etc", "/opt"}
// readOnly are the system paths the agent and its tools read. git and the
// shell need /dev/null and /proc.
var readOnly = []string{"/usr", "/lib", "/lib64", "/bin", "/sbin", "/etc", "/opt", "/proc", "/dev/urandom"}
// Options configure a Runtime.
type Options struct {