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
- Variables
- func Note(s string) string
- type BadLine
- type Bundle
- type Cleaner
- type Config
- type Notice
- type Service
- func (s *Service) Admit(ctx context.Context, dev store.AccessDevice, requestID string, now time.Time) (*subs.ClientDebugResult, error)
- func (s *Service) Decline(ctx context.Context, dev store.AccessDevice, requestID string, now time.Time) (string, error)
- func (s *Service) Open(ctx context.Context, deviceID string, now time.Time) (subs.ClientDebugRequest, bool, error)
- func (s *Service) Receive(ctx context.Context, in subs.ClientDebugIn) (subs.ClientDebugResult, error)
Constants ¶
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.
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.
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.
const NoteRunes = store.ClientDebugNoteRunes
NoteRunes is the longest note of a request.
Variables ¶
var ( // ErrTooLarge: more than MaxText bytes or MaxLines lines, or more than the wire allows. ErrTooLarge = errors.New("clientdebug: the delivery is too large") )
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 ¶
Types ¶
type BadLine ¶
BadLine is a record that breaks the contract: Line counts from 1, Field names the part, never its value.
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 ¶
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 ¶
NewCleaner takes the panel's secret names (the agent SNI, the secret path prefixes); names shorter than minSecret are ignored.
func (*Cleaner) Secrets ¶
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 ¶
Text cleans one text. The order matters:
- 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;
- the panel's secret names become <secret> (they may sit inside an address-like string);
- IP addresses become <ip> or <ip>:port;
- hardware addresses, e-mail addresses, the account name in a home directory and the made-up name of a Windows machine;
- secrets by the name of their field (password=…, short_id=…), Bearer and Basic values, share links in percent-encoding, 32 hex digits (UUID, HWID);
- credential-shaped text: share links, JWTs, PEM blocks, API keys, query strings, UUIDs, base64 keys, long tokens;
- 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 ¶
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 (*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 ¶
func (s *Service) Receive(ctx context.Context, in subs.ClientDebugIn) (subs.ClientDebugResult, error)
Receive reads and cleans the body and stores it as the answer to the request, or as the person's own bundle.