endpoint

package
v0.1.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package endpoint reads and writes the protected local-TCP API discovery document. The TCP listener is opt-in; the default Unix socket never writes this file. The document is written only by a daemon that holds the data directory lock, is atomically replaced, and carries a per-run bearer token plus the pinned self-signed certificate for that run.

Index

Constants

View Source
const (
	// Version is the only accepted discovery document version.
	Version = 1
	// NetworkTCP is the only accepted transport.
	NetworkTCP = "tcp"
)

Variables

This section is empty.

Functions

func Path

func Path(dataDir string) string

Path returns <dataDir>/api.endpoint.json.

func Remove

func Remove(dataDir string) error

Remove deletes a stale/current discovery file. A missing file is not an error. It never follows a symlink.

func Supported

func Supported() error

Supported reports whether this platform can protect the endpoint secret with a verifiable owner-only ACL. The TCP transport is explicitly unsupported where that check is unavailable; the default Unix socket stays untouched.

func WriteAtomic

func WriteAtomic(dataDir string, doc Document) error

WriteAtomic writes a validated document to the endpoint path, using a same-directory temporary file and an atomic publish. The caller must hold the existing data-directory lock (the daemon does via identity.Open).

writeProtectedFile owns the platform-specific creation policy: on Unix the temporary and final files are 0600; on Windows the temporary file is created with a protected DACL containing only the current user SID, verified through the same handle that is later renamed, and no unprotected byte ever contains the token.

Types

type Document

type Document struct {
	Version         int    `json:"version"`
	Network         string `json:"network"`
	Address         string `json:"address"`
	Token           string `json:"token"`
	CertPEM         string `json:"cert_pem"`
	CertSHA256      string `json:"cert_sha256"`
	PID             int    `json:"pid"`
	StartedAtUnixMS int64  `json:"started_at_unix_ms"`
}

Document is the atomic discovery record for one daemon run. Token is a secret; callers must keep it host-side and out of renderer output and logs.

func Read

func Read(dataDir string) (Document, error)

Read is ReadIfPresent with a stale/missing error suitable for a client that explicitly expects the TCP endpoint.

func ReadIfPresent

func ReadIfPresent(dataDir string) (Document, bool, error)

ReadIfPresent reads and validates the endpoint when it exists. A missing file is not an error. A stale or malformed file is an error so callers fail closed instead of silently falling back to the Unix socket.

The platform-specific readProtectedFile implementation must validate the object it actually reads. On Windows that means one opened handle used for the type/owner/DACL checks and the bytes, never a path reopen.

func (Document) TLSConfig

func (d Document) TLSConfig() (*tls.Config, error)

TLSConfig returns a standard-library TLS configuration that trusts only the certificate named by this run's endpoint and additionally pins its SHA-256 fingerprint. It never disables normal certificate verification.

func (Document) Validate

func (d Document) Validate() error

Validate enforces the loopback-only contract and fails closed on a stale, malformed or mismatched discovery document.

Jump to

Keyboard shortcuts

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