Documentation
¶
Overview ¶
Package agentgw is the controller's gRPC endpoint for agents (§12). Agents authenticate with client certificates issued by the internal CA; the node identity is the certificate's CommonName, checked against the nodes table (so deleting a node revokes its certificate).
Index ¶
- Variables
- func ProxyListener(ln net.Listener) net.Listener
- type Conn
- type Gateway
- func (g *Gateway) AddHooks(h Hooks)
- func (g *Gateway) Connect(...) error
- func (g *Gateway) Send(nodeID string, msg *agentv1.ConnectResponse) error
- func (g *Gateway) Serve(ctx context.Context, ca *pki.CA, addr, proxyAddr string, hosts []string) error
- func (g *Gateway) ServeListener(ctx context.Context, ca *pki.CA, hosts []string, lns ...net.Listener) error
- func (g *Gateway) SetEndpoints(f func(store.Node) []*agentv1.GatewayEndpoint)
- type Hooks
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("node is not connected")
Functions ¶
func ProxyListener ¶ added in v0.2.2
ProxyListener accepts connections that start with a PROXY protocol v1 header (Traefik passing agent.<domain>:443 on): RemoteAddr is then the agent's own address, which the mesh uses as its WireGuard endpoint. The header is read on first use, so a slow client never blocks Accept. A connection without a valid header fails.
Types ¶
type Conn ¶
type Conn struct {
Node store.Node
Hello *agentv1.Hello
Remote string // IP address the agent connected from
}
Conn describes a newly connected agent.
type Gateway ¶
type Gateway struct {
agentv1.UnimplementedAgentGatewayServiceServer
// contains filtered or unexported fields
}
func (*Gateway) Connect ¶
func (g *Gateway) Connect(stream grpc.BidiStreamingServer[agentv1.ConnectRequest, agentv1.ConnectResponse]) error
func (*Gateway) Send ¶
func (g *Gateway) Send(nodeID string, msg *agentv1.ConnectResponse) error
Send queues a command for a connected node.
func (*Gateway) Serve ¶
func (g *Gateway) Serve(ctx context.Context, ca *pki.CA, addr, proxyAddr string, hosts []string) error
Serve listens on addr with mTLS until ctx ends. hosts are the names and IPs agents use to reach the gateway (put in the server certificate). With proxyAddr set, it also listens there for connections Traefik passes on with a PROXY protocol header (agent.<domain>:443).
func (*Gateway) ServeListener ¶
func (g *Gateway) ServeListener(ctx context.Context, ca *pki.CA, hosts []string, lns ...net.Listener) error
ServeListener is Serve on existing listeners.
func (*Gateway) SetEndpoints ¶ added in v0.2.2
func (g *Gateway) SetEndpoints(f func(store.Node) []*agentv1.GatewayEndpoint)
SetEndpoints sets the gateway addresses agents are told to use, in order.
type Hooks ¶
type Hooks struct {
// OnConnect runs after the Welcome, with the node's Hello (including its
// container snapshot) and the IP address it connected from.
OnConnect func(c Conn)
// OnTaskStatus runs for every task status the agent reports.
OnTaskStatus func(node store.Node, s *agentv1.TaskStatus)
// OnTaskEvent runs for every step of a task the agent reports.
OnTaskEvent func(node store.Node, e *agentv1.TaskEvent)
// OnHeartbeat runs for every heartbeat.
OnHeartbeat func(node store.Node, hb *agentv1.Heartbeat)
// OnDisconnect runs when the stream ends.
OnDisconnect func(node store.Node)
// OnLogs runs for every batch of container output.
OnLogs func(node store.Node, b *agentv1.LogBatch)
// OnExecOutput runs for output of interactive exec sessions.
OnExecOutput func(node store.Node, o *agentv1.ExecOutput)
// OnUpgradeResult runs when an agent reports a failed self-upgrade.
OnUpgradeResult func(node store.Node, r *agentv1.UpgradeResult)
// OnDockerReply runs for answers to Docker requests (node management).
OnDockerReply func(node store.Node, r *agentv1.DockerReply)
}
Hooks let other controller components react to agents. Hooks run on the stream's goroutine and must not block.