mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 18:19:07 +01:00
Close command-channel session hijacking, transport stalls, and read-only policy bypasses across agentexec and hostagent: - Always qualify agentexec session keys with the organization ID (including default), reject control characters in agent IDs, and verify organization ownership on session lookup. - Enforce a 10s write deadline on agentexec text writes and close timed-out connections so a non-reading agent cannot pin the session write lock and block action admission. - Refuse first-use install-token command bindings when another unexpired token of the organization holds the live command session, monitor host record, or durable token binding for that agent ID. - Confine auto-approved host log reads beneath /var/log via os.Root and /dev/fd descriptors to prevent symlink escapes, and require approval for guest (container/vm) log reads where host confinement does not apply. - Restrict auto-approved pvesh get commands to listed non-credential API subtrees and restrict docker/podman format templates to direct field selections so output masking cannot be stripped. Contract-Neutral: Security hardening of AI tool sandboxing, agentexec sessions, and Patrol/Assistant authorization without public contract delta
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package agentexec
|
|
|
|
import "github.com/gorilla/websocket"
|
|
|
|
// TestRegisterAgent registers a fake agent for testing purposes.
|
|
// This bypasses the WebSocket handshake and directly inserts into the agents map.
|
|
// It also installs a no-op writeTextMessage so that send operations don't panic
|
|
// on the nil websocket connection. The original writer is restored via the
|
|
// returned cleanup function (typically deferred by the caller).
|
|
//
|
|
// NOTE: This mutates the package-global writeTextMessage without synchronization.
|
|
// Callers must NOT use t.Parallel() when using this helper.
|
|
func (s *Server) TestRegisterAgent(agentID, hostname string) (cleanup func()) {
|
|
// Save and override the global writer.
|
|
origWriter := writeTextMessage
|
|
writeTextMessage = func(_ *websocket.Conn, _ []byte) error {
|
|
return nil
|
|
}
|
|
|
|
key := agentSessionKey(defaultOrganizationID, agentID)
|
|
s.mu.Lock()
|
|
s.agents[key] = &agentConn{
|
|
agent: ConnectedAgent{
|
|
AgentID: agentID,
|
|
Hostname: hostname,
|
|
},
|
|
done: make(chan struct{}),
|
|
}
|
|
s.mu.Unlock()
|
|
|
|
return func() {
|
|
writeTextMessage = origWriter
|
|
s.mu.Lock()
|
|
delete(s.agents, key)
|
|
s.mu.Unlock()
|
|
}
|
|
}
|