Add the sandbox network protocol, client and Linux network service - #346
Merged
Merged
Conversation
internal/sandboxnet defines the Network protocol (one Connect per Link stream, then raw bytes), its strict codec, host grammar and egress check, the Connect client with a net.Conn, and the generic Serve that resolves, checks, dials and splices with orderly half-close and abort kept apart. apps/sandboxio/internal/netservice is the Linux resolver and dialer. sandboxlink.Stream gains the deadline methods yamux streams already have.
Never permit an unspecified destination, which a TCP stack connects to the sandbox itself, and dial the checked literal over tcp4 or tcp6. Give an errno-typed dial failure EffectNone only when socket or connect returned it. Hold bytes that arrive after a successful dial until Connected is written. Serialize Conn reads and writes and fail calls after a passed deadline, as net.Conn does. State the Stream deadline and concurrency contract, the two request ID sequences on a service stream and the half-close residual.
Take the write lock for CloseWrite and the orderly Close, so no Write lands after the FIN; Close aborts instead when a Write is in progress, which ends the pending call. Update a deadline and its cached copy under one lock. Type a native dial timeout as TimedOut in the Linux service, and read the Connect's deadline from the clock, since a socket deadline can fire before the context reports its end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the Network protocol. The agent-host gateway uses it to open TCP connections that originate in the sandbox: names resolve and connections dial from the sandbox's network namespace, inside the egress the Link grants each Network stream.
internal/sandboxnet/protocol.go, the protocol. OneConnect{Host, Port, TimeoutMillis}per stream, answered byConnectedor a typed failure. Twelve codes, each with a declared effect. The file also defines:Egress;Serviceinterface (Resolve,Dial).client.go.Connect(ctx, stream, host, port, timeout)returns a*Conn, which is anet.Conn.CloseWritesends FIN, andCloseaborts withResetunless the read side ended cleanly.server.go. A genericServe(ctx, stream, egress, svc), so the egress check and the splice are the same for every implementation:CloseWriteafter draining, and an error or the end of the attachment resets both sides.apps/sandboxio/internal/netservice(Linux). The system resolver plus an errno-mapped dialer.oac-sandbox-ionow servesServiceNetworkand advertises it inServeHello.sandboxlink.Streamgains thenet.Conndeadline methods, which*yamux.Streamalready implements.Connneeds them to be a realnet.Connwithout a type assertion.docs/sandbox-network-protocol.md.docs/sandbox-link-protocol.md: the stream deadline methods, plus a link from the Egress bullet.docs/sandbox-bootstrap.md: the service also serves Network.Review fixes (two blind-review rounds):
EffectNoneapplies only to failures atsocketorconnect. Native dial timeouts are typedTimedOut.Connectedis written.Conn: reads and writes are serialized, deadlines follownet.Connsemantics, and FIN is ordered after writes.Tests:
FuzzDecode.Deniedwithout the listener ever accepting;NameNotResolved,ConnectionRefusedandTimedOut;EffectPossible.oac-sandbox-ioend-to-end test now also echoes bytes over a Network stream restricted to one loopback address and port.Checks:
go test -race: ten runs over sandboxnet and netservice, three over sandboxio.FuzzDecode, 30 smake build-sandbox-ioPart of the agent-outside-sandbox work, milestone M1, lane L6a.