clientdebug

package
v0.2.0-dev.11 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 21 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 clientdebug takes the logs a person's app sends for support (client API: POST <base>/debug, client_debug.proto of the plan "logs for support"). It reads the delivery strictly, cleans every text the person's machine wrote, and hands the lines to the store, which keeps them as rows of debug_capture_line under the bundle's id. It is the VPS edition's: the Cloudflare edition takes no logs, and none of this is in its wasm.

Index

Constants

View Source
const (
	MaxText = 4 << 20
	MaxLine = 8 << 10
	// MaxLines is the most records of a delivery.
	MaxLines = 20000
	// MaxKV is the most attributes a record may carry on the way in (those not in the allow-list are dropped, those kept are cut).
	MaxKV = 16
	// MessageBytes is how much of a message is kept, after cleaning; ValueRunes how much of an attribute value.
	MessageBytes = 1024
	ValueRunes   = 160
)

The delivery: newline-delimited JSON, one record per line, oldest first (client contract "logs for support"). Unpacked it is at most MaxText bytes and MaxLines lines of at most MaxLine bytes each.

View Source
const (
	AuditReceived = "client_debug_received"
	AuditDeclined = "client_debug_declined"
	EventReceived = "client_logs_received"
	EventDeclined = "client_logs_declined"
)

Audit actions and the event code of the logs people send. The audit rows are written for the person ("user:<id>" acting for themselves, as an enrolment is) with the ids of the bundle, the person and the device; the event says that logs came, and neither carries a word of the logs.

View Source
const (
	NoticeReceived = "received"
	NoticeUnasked  = "unasked"
	NoticeDeclined = "declined"
)

The kinds of a Notice: logs came because the owner asked, logs came because the person sent them on their own, the person refused.

NoteRunes is the longest note of a request.

Variables

View Source
var (
	// ErrTooLarge: more than MaxText bytes or MaxLines lines, or more than the wire allows.
	ErrTooLarge = errors.New("clientdebug: the delivery is too large")
)
View Source
var KVKeys = map[string]bool{
	"path": true, "server": true, "protocol": true, "via": true, "engine": true, "phase": true, "state": true, "reason": true,
	"code": true, "err": true, "mode": true, "version": true, "count": true, "ms": true, "bytes": true, "attempt": true,
	"net": true, "event": true, "status": true, "http": true,
}

KVKeys are the attribute keys that are kept; any other key of a record is dropped (and counted).

Functions

func Note

func Note(s string) string

Note is the owner's note of a request as the person gets it: control and invisible formatting characters removed or turned to blanks (the same step 1 as the logs), the ends trimmed, at most NoteRunes characters. It is plain text; the app shows it as such.

Types

type BadLine

type BadLine struct {
	Line  int
	Field string
}

BadLine is a record that breaks the contract: Line counts from 1, Field names the part, never its value.

func (*BadLine) Error

func (e *BadLine) Error() string

type Bundle

type Bundle struct {
	Lines           []store.ClientDebugLine
	Bytes           int // what the records cost in the store (the node captures count the same way)
	DroppedKV       int // attributes not in the allow-list
	FirstMs, LastMs int64
}

Bundle is a delivery as it is kept: the cleaned records and what describes them.

func Parse

func Parse(body io.Reader, now time.Time, c *Cleaner) (Bundle, error)

Parse reads the unpacked body, which the caller has bounded (an io.LimitReader of MaxText+1 over the unpacked stream) and whose read errors it passes on: a *http.MaxBytesError is the wire's limit (ErrTooLarge), any other is a stream that does not unpack (a *BadLine of field "gzip"). The first fault ends the reading: a *BadLine, or ErrTooLarge for the size and the line count, in which case nothing is returned. Every text of a record is cleaned by c. now is the panel's clock.

type Cleaner

type Cleaner struct {
	// contains filtered or unexported fields
}

Cleaner cleans the text of a person's log. Every text of a line (the message and the attribute values) goes through Text.

func NewCleaner

func NewCleaner(secrets []string) *Cleaner

NewCleaner takes the panel's secret names (the agent SNI, the secret path prefixes); names shorter than minSecret are ignored.

func (*Cleaner) Secrets

func (c *Cleaner) Secrets(s string) string

Secrets replaces the panel's secret names in a text that is checked against a shape otherwise (the source of a line, the app's name).

func (*Cleaner) Text

func (c *Cleaner) Text(s string) string

Text cleans one text. The order matters:

  1. text in another script is normalized (NFKC: full-width letters and look-alike hyphens become the ASCII ones that the steps below look for); control characters (C0, C1) and line and paragraph separators become blanks; format characters (bidirectional controls, zero width) and private-use characters are removed, so nothing hides from the steps below or reorders what the owner reads;
  2. the panel's secret names become <secret> (they may sit inside an address-like string);
  3. IP addresses become <ip> or <ip>:port;
  4. hardware addresses, e-mail addresses, the account name in a home directory and the made-up name of a Windows machine;
  5. secrets by the name of their field (password=…, short_id=…), Bearer and Basic values, share links in percent-encoding, 32 hex digits (UUID, HWID);
  6. credential-shaped text: share links, JWTs, PEM blocks, API keys, query strings, UUIDs, base64 keys, long tokens;
  7. DNS names with a real top-level domain become <host>; file names and type names stay (state.json, Mistgate.exe, System.Net.Http.HttpRequestException).

type Config

type Config struct {
	Store *store.Store
	// Secrets are the panel's secret names (the agent SNI and the secret path prefixes), cut out of every text.
	Secrets []string
	// Notify tells the owner (the Telegram module) that logs came or were refused. nil = nobody is told. It is called once per bundle
	// and per refusal, after the rows are written, and must not block.
	Notify func(Notice)
	Log    *slog.Logger
}

Config configures Service. Store is required.

type Notice

type Notice struct {
	Kind   string
	UserID string
	Person string
	Device string
	Lines  int
}

Notice is what the owner is told when a person answers or sends logs: who, from which device, how many lines. Never a word of the logs. The names are the panel's today (the person's name, the device's model or platform), whatever the person's app wrote about itself.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is subs.ClientDebug: what the app's debug routes and sync call.

func New

func New(cfg Config) *Service

New returns the service.

func (*Service) Admit

func (s *Service) Admit(ctx context.Context, dev store.AccessDevice, requestID string, now time.Time) (*subs.ClientDebugResult, error)

Admit is the check before the body is read. A delivery for a request: it must be this device's and open; if it was answered already, that answer is returned. A delivery with no request is the person's own: the device's ten-minute spacing and the panel's ceiling apply.

func (*Service) Decline

func (s *Service) Decline(ctx context.Context, dev store.AccessDevice, requestID string, now time.Time) (string, error)

Decline is the person's refusal. The owner sees it as the request's state at once, and the audit log says who refused.

func (*Service) Open

func (s *Service) Open(ctx context.Context, deviceID string, now time.Time) (subs.ClientDebugRequest, bool, error)

Open is the device's open request, for sync.

func (*Service) Receive

Receive reads and cleans the body and stores it as the answer to the request, or as the person's own bundle.

Jump to

Keyboard shortcuts

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