Introducing a new way to review your PRs.

Read the announcement

nklmilojevic / sofka

A Kubernetes TUI, reimagined in Rust - built on kube-rs and ratatui, async-first from the ground up.

View on GitHub

19 documents · Updated Nov 4, 2026

docs / diagnostics-logging-and-data-protection

Diagnostics, logging, and data protection

This area helps an engineer explain a session, inspect log data, and share useful evidence without exposing credentials or private network details. It combines runtime reports, bounded application logs, log-view filters, redacted support bundles, and TLS checks around the Kubernetes connection.

Diagnostic collection

Diagnostic collection turns session state into information that can explain a slow, broken, or misconfigured connection. It reports local facts and selected cluster health facts while keeping the report safe to paste into an issue.

Runtime reports

The runtime report is available from the :info view and the sofka info command. Both forms present the same broad picture: build and version, cluster identity, discovery and metrics status, watch health, active configuration, logging status, and storage paths. The command can work offline, while a connected run adds cluster checks and a watch probe.

The report favors identifiers, paths, counts, and health results over raw resource data. Error text and connection values pass through the shared protection step before they reach the screen or standard output. Configuration warnings are summarized in the report, while the status message points the engineer to :config for their details; discovery warnings point to :info. This makes the report useful for support work without making it a copy of the cluster.

References: src/…/diagnostics.rs• L3-12 src/…/diagnostics.rs• L47-65 src/…/diagnostics.rs• L90-145 src/…/diagnostics.rs• L149-169 src/main.rs• L776-785 src/main.rs• L899-966

Request health

Request health gives the report a small performance view of the Kubernetes API. Requests are grouped by purpose, such as reads, watches, writes, metrics, pod logs, and upgraded connections. Each active group can show count, failures, average time, approximate percentiles, and the slowest request.

This data stays in the running process and supports diagnosis of connection behavior. It does not collect request bodies or credentials. A 4xx response remains an API result rather than a transport failure, so the summary does not label a valid permission or resource response as a broken connection.

References: src/diagnostics.rs• L70-95 src/diagnostics.rs• L210-244 src/diagnostics.rs• L246-291

Application logging

Application logging records events produced by sofka itself for review after a session. It is separate from Kubernetes pod logs: the application log explains sofka's actions and connection work, while the log view displays workload or external log data.

Structured application logs

The application log uses one machine-readable line per event with a time, level, event name, and fields. Logging is off by default. A configured level or the one-run SOFKA_LOG override enables it, and the configured file is kept within a size limit with one previous generation.

The writer uses a bounded queue so a slow disk does not stop the user interface. If the writer falls behind, lines can be dropped and the diagnostic report exposes that count. Shutdown gives the writer a short drain period rather than allowing a stuck file system to hold the application open.

References: src/config.rs• L413-460 src/applog.rs• L42-56 src/applog.rs• L149-186

Log filtering

The log view narrows a live or buffered stream without changing the source of the logs. A plain term performs a case-insensitive text match. A term wrapped in / uses a case-insensitive regular expression, and a leading ! inverts either form. An empty filter shows all lines.

The view also detects common severity forms so warnings and errors can be highlighted across structured logs and common Kubernetes log formats. A malformed regular expression matches nothing and is marked as an error instead of silently showing an unfiltered stream.

The filter flow connects incoming log sources to a bounded display buffer and then to the visible result:

flowchart LR
    A[Pod or log provider stream] --> B[Log view buffer]
    B --> C[Severity detection]
    B --> D[Text or regex filter]
    C --> E[Colored visible lines]
    D --> E

References: src/logfilter.rs• L1-12 src/logfilter.rs• L134-145 src/logfilter.rs• L219-270 src/…/logs.rs• L274-310

Data protection

Data protection limits what sofka writes to disk or includes in material that users share. The same redaction rules protect runtime reports, application log fields, and diagnostic bundles, while bundle-specific rules protect Kubernetes object data.

Text redaction

Text redaction replaces credential-like values and literal IP addresses with the «redacted» marker. It covers named values such as tokens, passwords, API keys, and certificate data. It also covers bearer or basic credentials, loose JWTs, URL user information, and sensitive values inside error text.

The redactor keeps useful context around the replacement. For example, it can preserve a URL path or a port while hiding the identity or address that could identify a protected endpoint. This approach favors preventing leaks over preserving every value exactly.

References: src/redact.rs• L1-13 src/redact.rs• L21-58 src/redact.rs• L85-100

Diagnostic bundles

The diagnostic bundle is a shareable incident record for one selected resource. It combines the resource view with related context such as ownership, conditions, events, findings, a session timeline, bounded logs, and a metrics snapshot. The bundle is previewed before save so the engineer can inspect the planned handoff.

Bundle protection removes or replaces data that can carry secrets. It strips managed-field noise, protects credential-looking annotations and last-applied configuration, replaces all Secret data values, and reports references to Secret-backed environment variables without including their values. The manifest states what was included and what was withheld. Optional anonymization hides cluster and context names.

The collection and protection flow is:

flowchart TD
    A[Selected resource] --> B[Collect related evidence]
    B --> C[Bounded logs and metrics]
    B --> D[Resource and owner data]
    C --> E[Redact and anonymize]
    D --> E
    E --> F[Preview bundle]
    F --> G[Explicit save]

References: src/bundle.rs• L1-9 src/bundle.rs• L16-24 src/…/bundle.rs• L8-13 src/…/bundle.rs• L134-155 src/…/bundle.rs• L196-227

TLS verification

TLS protects the connection between sofka and the Kubernetes API, including connections made through supported proxies. The client keeps the trust and identity rules from the kubeconfig path instead of treating a connection workaround as permission to disable server checks.

When a configured CA needs special handling, the connection still checks the exact trusted certificate, server name, validity dates, certificate usage, and handshake proof. Invalid-certificate mode remains distinct from this path. Legacy X.509 v1 client certificates require an explicit run-time opt-in, which limits an old credential format without weakening normal certificate checks.

References: src/server_tls.rs• L22-49 src/server_tls.rs• L74-108 src/legacy_tls.rs• L34-72 src/legacy_tls.rs• L74-100

Sensitive information safeguards

Sensitive information can enter through configuration, cluster responses, library errors, log fields, or exported object data. Protection therefore runs at output boundaries rather than relying only on the code that first receives the value.

The main safeguards are:

  • Runtime reports redact connection values and error messages before display or output.
  • Application log fields are redacted before they enter the log queue or file.
  • Diagnostic bundles apply object-aware protection before YAML and log sections are rendered.
  • Bundle collection bounds the amount of workload log data and the number of contributing pods.
  • TLS handling preserves server identity and certificate checks when custom trust or compatibility paths are needed.

These safeguards complement the parent page, Persistence and support artifacts. For state capture and the wider export flow, see State snapshots and bundles.

References: src/diagnostics.rs• L307-324 src/applog.rs• L209-271 src/bundle.rs• L24-63 src/…/bundle.rs• L49-55

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the :info and sofka info report sections aligned so a support engineer can compare interactive and headless output.
  • Keep every new report, log, or bundle field behind the shared redaction boundary when its value can come from a URL, credential, error, or cluster object.
  • Keep bundle limits and manifest entries aligned so the preview states the same evidence that collection can fetch.
  • Keep log level names and SOFKA_LOG precedence aligned between configuration validation, startup, and the diagnostics view.
  • Keep custom TLS trust paths subject to hostname, validity, usage, and proof checks, and keep legacy certificate use opt-in.
  • Keep log filtering behavior consistent with severity detection so a malformed filter cannot reveal a wider stream by accident.

Important failure modes

TriggerConsequenceGuard
A log writer falls behind a slow file systemSome application log lines are droppedThe bounded queue drops instead of blocking, and the diagnostics report shows the drop count
A configured log level or SOFKA_LOG value is invalidLogging may stay off or keep the configured level rather than using the invalid overrideConfiguration validation and startup warnings name the bad value
A regular-expression log filter does not compileThe view shows no lines and could otherwise look emptyThe matcher marks the filter as an error, including for an inverted filter
A diagnostic value contains a token, credential, or echoed request URLSensitive data could enter a report or logShared text redaction runs before report rendering and log-file enqueue
A bundle includes a Secret or Secret-backed environment referenceExported YAML could disclose secret materialSecret values are replaced and references are counted without copying values
A custom TLS certificate fails name, time, usage, or handshake checksThe API connection is rejectedThe custom trust path retains the standard certificate checks and exact trust match

Key files

FileWhy to read it
src/diagnostics.rsDefines the shared report facts, request health summary, safe output helpers, and state paths.
src/…/diagnostics.rsShows how the interactive diagnostics view presents session and cluster health, and directs warning details to the right view.
src/main.rsShows startup logging and the headless sofka info report flow.
src/applog.rsDefines application log levels, redacted structured events, queue behavior, and rotation.
src/logfilter.rsDefines text, regex, inverse filtering, and severity recognition for the log view.
src/…/logs.rsShows how workload and provider log streams enter the bounded log view.
src/redact.rsDefines the shared credential, URL, JWT, and IP redaction rules.
src/bundle.rsDefines object-aware sanitization and the bundle document model.
src/…/bundle.rsShows the evidence collection, preview, and explicit save flow for bundles.
src/server_tls.rsDefines the guarded custom CA verification path.
src/legacy_tls.rsShows the shared TLS transport and explicit compatibility path for older client certificates.