Documentation
¶
Overview ¶
Package kuberead is officer_kube_read's engine: one typed, read-only request against a named cluster's API server, run by muster-server itself (docs/officers.md "Reading a cluster: officer_kube_read").
🔴 THE MODEL NEVER SENDS A URL, A PATH OR AN ADDRESS. It names a cluster (whose endpoint, CA and minter token are the server's sealed environment) and a typed request — {verb: get|list, group, version, resource, namespace?, name?, label_selector?, field_selector?, limit?} or {log: {namespace, pod, container?, previous?, since_seconds?, tail_lines?}} — and Allowlist.Build is the ONE place a request becomes a path: a GET under /api or /apis for a resource on that cluster's allowlist, or a pod's /log. watch is never offered. The allowlist is the deployment's configuration (ParseAllowlist): muster compiles in no resource list.
🔴 A FRESH, SHORT-LIVED IDENTITY PER CALL. Each Read mints a TokenSeconds TokenRequest for the officer's ServiceAccount with the cluster's minter token, then reads with that token alone; the minter token never reads. The minted token's jti goes in the audit record.
🔴 REFUSED, NOT TRUNCATED. An answer over MaxAnswerBytes or a list over MaxObjects is a refusal saying so — a partial answer would read as the whole.
Index ¶
Constants ¶
const ( ScopeNamespaced = "namespaced" ScopeCluster = "cluster" )
Resource scopes, as an allowlist spells them.
const ( // MaxAnswerBytes bounds one answer as returned, after stripping. MaxAnswerBytes = 1 << 20 // MaxObjects bounds one list: more is a refusal. MaxObjects = 500 // MaxTailLines and DefaultTailLines bound a pod log read. MaxTailLines = 2000 DefaultTailLines = 500 // MaxSinceSeconds bounds a pod log read's window: a day. MaxSinceSeconds = 86400 // MaxLogLineRunes caps one scrubbed log line. MaxLogLineRunes = 1000 // CallsPerMinute is each officer's call budget (Limiter). CallsPerMinute = 30 // TokenSeconds is a minted token's life: the API server's minimum. TokenSeconds = 600 // ServerName is the name every API server certificate carries, verified // whatever address the endpoint is. ServerName = "kubernetes.default.svc" )
Limits and fixed values.
const MaxArgsBytes = 8 << 10
MaxArgsBytes bounds the tool's arguments.
Variables ¶
var ErrRefused = errors.New("kuberead: refused")
ErrRefused wraps every refusal of a request's shape, before any network.
Functions ¶
func RedactLine ¶
RedactLine is one log line made fit to hand to the model, and how many substrings the scrub replaced. A structured line becomes a JSON object of its kept fields plus "dropped_fields" (names only).
Types ¶
type Allowlist ¶
type Allowlist struct {
// contains filtered or unexported fields
}
Allowlist is the resources muster builds a path for on ONE cluster. Immutable. It comes from the deployment's configuration (ParseAllowlist): muster compiles in no resource list of its own.
func ParseAllowlist ¶
ParseAllowlist reads one cluster's allowlist: a JSON list of
{"apiGroup": "<group, \"\" for core>", "resources": ["<plural>", …], "scope": "namespaced"|"cluster"}
with get and list implied (no verbs field: there are no others). It is STRICT: an unknown field, a "*" resource or group, a subresource other than core pods/log (deployments/status, */status …), a never-granted resource, an RBAC group, a missing or unknown scope, an empty resources list and a duplicate are each refused.
An empty document (blank, null or []) is NO allowlist: nil and no error. The caller treats that as the cluster's kube-read being disabled — never as "allow all".
type Audit ¶
type Audit struct {
Cluster string `json:"cluster"`
Verb string `json:"verb"`
Group string `json:"group"`
Version string `json:"version"`
Resource string `json:"resource"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
LabelSelector string `json:"label_selector,omitempty"`
FieldSelector string `json:"field_selector,omitempty"`
// Path is the GET path built (no query: the selectors are above).
Path string `json:"path"`
// JTI is the minted token's jti ("" when none was minted, or it had none).
JTI string `json:"jti,omitempty"`
// Status is the API server's HTTP status (0: no answer).
Status int `json:"status,omitempty"`
// Count is the objects (a list's items, 1 for a get) or log lines read.
Count int `json:"count"`
// Bytes is the answer's size as returned (or as read, when refused).
Bytes int `json:"bytes"`
Millis int64 `json:"ms"`
// Refusal says why muster refused the call or its answer ("" served).
Refusal string `json:"refusal,omitempty"`
}
Audit is one call's audit record: what was read, as whom, and how it went — NEVER what the API answered. internal/api writes it as the connector-audit row of kind `query` (connector kube-read), with the officer, instance and item.
type Built ¶
type Built struct {
Path string
Query url.Values
// List: the answer is a list (count its items); Log: a pod's log.
List bool
Log bool
}
Built is a request's GET path and query, as Build made them.
type Cluster ¶
Cluster is one cluster's API server as the server's sealed environment declares it: a host:port endpoint, the CA bundle its certificate chains to, and the minter token. The minter token is unexported: String and GoString never print it, and only Read spends it (on the TokenRequest route).
func NewCluster ¶
NewCluster validates and builds a cluster: endpoint is host:port (no scheme, no path), caPEM holds at least one certificate, and the minter token is set.
type Entry ¶
Entry is one allowlisted (group, resource): a top-level resource, or the one subresource ever admitted, core pods/log.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter allows at most n calls per key in any window (a sliding window: a call stops counting once it is window old). In memory: a restart forgets it, which can only allow a burst of one window's calls again.
func NewLimiter ¶
NewLimiter is a limiter of n calls per window per key; now nil is time.Now.
type LogRequest ¶
type LogRequest struct {
Namespace string `json:"namespace"`
Pod string `json:"pod"`
Container string `json:"container,omitempty"`
Previous bool `json:"previous,omitempty"`
// SinceSeconds is 0 (no bound) or 1..MaxSinceSeconds.
SinceSeconds int `json:"since_seconds,omitempty"`
// TailLines is 0 (DefaultTailLines) or 1..MaxTailLines.
TailLines int `json:"tail_lines,omitempty"`
}
LogRequest is a pod log read.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader runs reads over one allowlist (one cluster's). It holds no per-call state.
func (*Reader) Read ¶
func (r *Reader) Read(ctx context.Context, c Cluster, sa ServiceAccount, req Request) (json.RawMessage, Audit, error)
Read runs ONE read of c as sa: build the path (refused before any network when it is not allowed), mint a TokenSeconds token for sa with the minter token, GET the path with that token, and shape the answer. The Audit is filled whatever happens; the answer is nil on any error.
type Request ¶
type Request struct {
// Cluster names one of the officer's declared clusters (kube.clusters).
Cluster string `json:"cluster"`
// Verb is get (Name required) or list (Name refused).
Verb string `json:"verb,omitempty"`
Group string `json:"group"`
Version string `json:"version,omitempty"`
Resource string `json:"resource,omitempty"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
LabelSelector string `json:"label_selector,omitempty"`
FieldSelector string `json:"field_selector,omitempty"`
// Limit, on a list, is the most objects to return (1..MaxObjects); the
// answer says `more` when the API holds more. 0 asks for every object, and
// more than MaxObjects is then a refusal.
Limit int `json:"limit,omitempty"`
Log *LogRequest `json:"log,omitempty"`
}
Request is officer_kube_read's arguments: a resource read (Verb …) or a pod log read (Log), never both.
func ParseRequest ¶
ParseRequest decodes the tool's arguments STRICTLY: an unknown key — a url, a path, watch, follow — is refused, never ignored.
type ServiceAccount ¶
type ServiceAccount struct{ Namespace, Name string }
ServiceAccount is the officer's ServiceAccount on a cluster: the identity every read runs as, through a token minted for it per call.