Help us shape the future of Go! Take the 2026 Go Developer Survey

ipc

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package ipc is the console's local transport: a Unix domain socket in a directory private to the user (on Linux and macOS), newline-delimited JSON-RPC 2.0 framing capped at 1 MiB, and a peer check.

Index

Constants

View Source
const (
	MethodHello         = "hello"
	MethodStatus        = "status"
	MethodPIIList       = "pii.list"
	MethodPIIAdd        = "pii.add"
	MethodChangeRequest = "change.request"
	MethodLogout        = "logout"
)

lockkit's own methods, served by every console. A product adds its own (its Backend's Methods). None of them loosens policy: change.request only queues a proposal that the console shows to the human.

View Source
const (
	CodeRefused       = -32001 // the policy refused the request
	CodeDenied        = -32002 // the human denied
	CodeTimeout       = -32003 // no answer within the approval timeout
	CodeNoSuchPlan    = -32004 // unknown, used or expired plan id
	CodeConnLost      = -32005 // the backend connection was lost
	CodePolicyPending = -32006 // a policy change awaits the human

	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternal       = -32603
)

Error codes. The -320xx range is reserved by JSON-RPC for implementation errors; the standard codes are kept for protocol faults.

View Source
const MaxMessage = 1 << 20

MaxMessage is the largest message, excluding the newline, in bytes.

View Source
const ProtocolMajor = 1

ProtocolMajor is exchanged in the hello handshake. A client and a console with different majors refuse to talk.

Variables

View Source
var ErrAlreadyRunning = errors.New("ipc: a console is already running for this profile")

ErrAlreadyRunning means a live console already listens on the socket.

View Source
var ErrTooLarge = errors.New("ipc: message larger than 1 MiB")

ErrTooLarge means a message is over MaxMessage. After a read error the stream is out of step and the connection must be closed.

Functions

func Compatible

func Compatible(major int) bool

Compatible reports whether a peer's protocol major can talk to this one.

func Listen

func Listen(path string) (net.Listener, error)

Listen opens the console socket at path. The parent directory is made private (0700 and owned by the user) and the socket is 0600. A socket left by a dead console is replaced; one with a live console gives ErrAlreadyRunning; any other kind of file at path is left alone and refused. Closing the listener removes the socket.

func ListenShared

func ListenShared(p kit.Product, path string, gid int) (net.Listener, error)

ListenShared opens a console socket of p in the shared socket directory of a separated setup (see package sysconf): the directory must already exist (the product's install creates it), belong to the console's user and to the client group gid, and give others no access; the socket is made read-write for that group only (0660). The peer check still decides who is served.

func PeerAllowed

func PeerAllowed(c net.Conn) (bool, error)

PeerAllowed reports whether the process at the other end of c runs as the same user as the console (SO_PEERCRED).

func ReadMsg

func ReadMsg(r *bufio.Reader, v any) error

ReadMsg reads one line of at most MaxMessage bytes (a trailing CR is dropped) and decodes it into v. It returns io.EOF at a clean end of stream and ErrTooLarge as soon as the line passes the cap, without buffering the rest.

func SharedSocketPath

func SharedSocketPath(dir, projectHash, profile string) (string, error)

SharedSocketPath is SocketPath in the shared socket directory of a separated setup.

func SocketPath

func SocketPath(p kit.Product, projectHash, profile string) (string, error)

SocketPath returns the console socket of a project and profile of p: <p.RuntimeDir()>/<project-hash>-<profile>.sock (kit.Product.RuntimeDir: $<PREFIX>RUNTIME_DIR/<name> when set, else $XDG_RUNTIME_DIR/<name> on Linux or $TMPDIR/<name> on macOS, else /tmp/<name>-<uid>). A name that would exceed the OS socket path limit is replaced by <project-hash>-~<sha256(profile)[:16]>.sock, which is still stable, so the client and the console agree on it.

func WriteMsg

func WriteMsg(w io.Writer, v any) error

WriteMsg writes v as one line of JSON. Nothing is written when v encodes to more than MaxMessage bytes.

Types

type ChangeParams

type ChangeParams struct {
	Change string `json:"change"`
}

ChangeParams queues a policy change proposal for the human.

type ChangeResult

type ChangeResult struct {
	Queued bool `json:"queued"`
}

ChangeResult answers change.request.

type Cred

type Cred struct {
	UID, GID, PID int
}

Cred is what the kernel says about the process at the other end of a socket. PID is -1 when the platform does not report it.

func PeerCred

func PeerCred(c net.Conn) (Cred, error)

PeerCred returns the kernel's record of the process at the other end of c (SO_PEERCRED): it cannot be forged by the peer.

type HelloParams

type HelloParams struct {
	ProtocolMajor int    `json:"protocol_major"`
	Client        string `json:"client,omitempty"`
}

HelloParams opens a session; Client is a free-form name and version.

type HelloResult

type HelloResult struct {
	ProtocolMajor  int    `json:"protocol_major"`
	ConsoleVersion string `json:"console_version,omitempty"`
	Profile        string `json:"profile"`
}

HelloResult answers hello.

type PIIAddParams

type PIIAddParams struct {
	Pattern string `json:"pattern"`
}

PIIAddParams proposes a mask rule (its syntax is the product's).

type PIIListResult

type PIIListResult struct {
	Mask  []string `json:"mask"`
	Allow []string `json:"allow"`
}

PIIListResult answers pii.list with the mask and allow rules in force.

type RPCError

type RPCError struct {
	Code    int           `json:"code"`
	Message string        `json:"message"`
	Data    *refusal.Info `json:"data,omitempty"`
}

RPCError is a JSON-RPC 2.0 error object. Message must never carry a secret; the console sanitises it. Data is set on CodeRefused only: the structured form of the refusal (code, retry, hint and span).

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

Request is a JSON-RPC 2.0 request.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

Response is a JSON-RPC 2.0 response: Result or Error, never both.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL