Archie runs its own agent loop only. Removes Kit resolution and launch, the harness runner and adapters, the setup terminal and sandbox view, harness secrets and OAuth capture (table dropped in migration 0075), the task-tools contract that only Kit containers reached, and the sandbox-kit-spec dependency. Agent profiles carry image and tools only. The egress proxy keeps the model-session path; the sandbox relay code stays for #1867.
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package egress
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Endpoints are the host-reachable addresses a sandboxed task's worker
|
|
// needs, with the task's own credentials for them.
|
|
type Endpoints struct {
|
|
NATS string
|
|
NATSToken string
|
|
StateStore string
|
|
StateStoreToken string
|
|
StateStoreCA []byte
|
|
}
|
|
|
|
// WorkerEnv is the worker's entire environment in a sandboxed container: NATS and
|
|
// the State Store at the relay's fixed ports, and the task's credentials.
|
|
// Nothing else crosses, so no model provider key enters the container.
|
|
func WorkerEnv(e Endpoints, uid, gid int) ([]string, error) {
|
|
u, err := url.Parse(e.NATS)
|
|
if err != nil || u.Scheme == "" {
|
|
return nil, fmt.Errorf("nats url %q: want scheme://host:port", e.NATS)
|
|
}
|
|
env := []string{"NATS_URL=" + u.Scheme + "://" + relayAddr(RelayNATSPort)}
|
|
if e.NATSToken != "" {
|
|
env = append(env, "NATS_TOKEN="+e.NATSToken)
|
|
}
|
|
if e.StateStore != "" {
|
|
env = append(env, "STATE_STORE_URL="+relayAddr(RelayStateStorePort))
|
|
if e.StateStoreToken != "" {
|
|
env = append(env, "STATE_STORE_TOKEN="+e.StateStoreToken)
|
|
}
|
|
if len(e.StateStoreCA) > 0 {
|
|
env = append(env, "STATE_STORE_CA="+string(e.StateStoreCA))
|
|
}
|
|
}
|
|
return append(env, "WORKTREE_UID="+strconv.Itoa(uid), "WORKTREE_GID="+strconv.Itoa(gid)), nil
|
|
}
|
|
|
|
// relayTargets are the host:port addresses the relay forwards NATS and the
|
|
// State Store to.
|
|
func relayTargets(e Endpoints) (nats, stateStore string, err error) {
|
|
if strings.Contains(e.NATS, ",") {
|
|
return "", "", fmt.Errorf("nats url %q lists several servers; the relay forwards one", e.NATS)
|
|
}
|
|
u, err := url.Parse(e.NATS)
|
|
if err != nil || u.Host == "" {
|
|
return "", "", fmt.Errorf("nats url %q: want scheme://host:port", e.NATS)
|
|
}
|
|
stateStore = e.StateStore
|
|
if _, rest, ok := strings.Cut(stateStore, ":///"); ok {
|
|
stateStore = rest
|
|
}
|
|
return u.Host, stateStore, nil
|
|
}
|
|
|
|
func relayAddr(port int) string {
|
|
return net.JoinHostPort(RelayAlias, strconv.Itoa(port))
|
|
}
|
|
|
|
// RelayCommand is the relay's archie-agent arguments, forwarding its fixed
|
|
// ports to the proxy and to the daemon's NATS and State Store.
|
|
func RelayCommand(proxy string, e Endpoints) ([]string, error) {
|
|
nats, stateStore, err := relayTargets(e)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return RelayArgs(proxy, nats, stateStore), nil
|
|
}
|