Introducing a new way to review your PRs.

Read the announcement

hcavarsan / kftray

kubectl port-forward manager and reverse tunnel (ngrok-like) for exposing local services publicly, with TLS termination, HTTP traffic inspection, UDP forwarding, multi-hop proxy routing through k8s clusters, stateful config via filesystem or git - GUI and TUI available

View on GitHub

19 documents · Updated Nov 23, 2026

docs / configuration-workflows

Configuration workflows

Configuration workflows let the desktop app turn user choices and shared JSON files into saved forwarding configurations. The workflow keeps the form, native command layer, local database, forward state, and optional Git source aligned so that a configuration can be used, changed, shared, and restored without losing its identity.

This page is a child of Desktop application. For the surrounding native boundary and user interface, see Native desktop orchestration and Desktop frontend.

Configuration lifecycle

Configuration creation

The add flow starts with a draft that matches the selected workload. The user can create Kubernetes service or pod forwards, proxy forwards, endpoint exposure entries, or SSH forwards. The form uses the selected kubeconfig, context, and namespace to offer relevant resources and ports, while tags and workload-specific fields add searchable or specialised settings. frontend/…/index.tsx and frontend/…/utils.ts define this user-facing flow.

Changing a parent choice clears dependent choices. For example, a new kubeconfig clears its context and target, and a new workload type clears the old target. This prevents a draft from combining values that came from different Kubernetes scopes or forwarding modes.

References: frontend/…/index.tsx• L42-165 frontend/…/utils.ts• L7-41

Configuration validation

Validation checks the draft before it reaches the saved configuration store. It requires the fields that identify each workload and limits ports to the valid network range. It also checks SSH provider data, exposure rules, and tag names so that the native side receives a complete configuration.

Imported data receives a second check at the shared configuration boundary. That check accepts a single JSON object or an array, rejects unknown workload shapes and invalid protocol values, and applies rules for namespace, exposure, SSH, tags, and HTTP log limits. This protects non-UI entry points such as Git sync and file import.

References: frontend/…/utils.ts• L206-276 crates/…/config.rs• L384-500

Configuration persistence

After validation, the native command layer inserts or updates the configuration in the active local store. Persistence assigns a stable ID, fills safe defaults such as a local port and kubeconfig choice, normalizes tags, and keeps HTTP log settings in step with the configuration. Export removes the local ID and omits values that only describe the current machine or default behavior.

The active store is selected by configuration-directory precedence: KFTRAY_CONFIG, then XDG_CONFIG_HOME/kftray, then ~/.kftray. A database file in that directory marks it as a saved configuration location. The app can report more than one such location because using different stores can make configurations appear to vanish between launches.

References: crates/…/config.rs• L320-377 crates/…/config.rs• L128-166 crates/…/config.rs• L368-382 crates/…/config_dir.rs• L15-36 crates/…/validate_configs.rs• L25-65

Configuration edits and synchronization

Configuration editing

An edit uses the same draft and validation path as creation, but keeps the existing configuration ID. The desktop flow treats a running forward as part of the edit: it stops the old forward, saves the new values, and starts the saved version again. If the save fails after the stop, it attempts to restore the old forward and reports whether the restore also failed.

The saved value is read back after an update. This matters when the native layer assigns or normalizes a value, such as an automatic local port. The frontend then merges that authoritative value into its query cache while preserving the current running state.

References: frontend/…/configTransactions.ts• L107-261 frontend/…/index.tsx• L133-143

Configuration deletion

Deletion is allowed only for configurations that are present in the latest native snapshot and are not running. The native side also coordinates deletion with forward ownership, removes related shortcut targets, and refreshes derived resources such as SSL coverage. This makes deletion a state change across the saved configuration and the services that depend on it.

References: frontend/…/configTransactions.ts• L26-105 crates/…/config.rs• L264-306 crates/…/config.rs• L78-103

Configuration state synchronization

The frontend reads saved configuration data and forward state as one view. It combines configuration rows with runtime state such as running, retrying, last error, and ownership by another live process. After a mutation, it updates the local query cache for immediate display and performs a native refresh so later changes cannot be hidden by stale data.

The cache update cancels an in-flight query before applying a local change. This prevents an older response from restoring a deleted row or replacing a newly saved value.

References: frontend/…/useConfigs.ts• L6-34 frontend/…/configCache.ts• L6-17 crates/…/config_state.rs• L10-43

Git configuration workflow

Git source configuration

The Git workflow treats a repository as a versioned source for one or more configuration JSON files. The user supplies a repository URL, one or more paths inside that repository, an authentication mode, a polling interval, and an optional replace-existing choice. The desktop stores this sync setup in the operating-system keyring rather than in the configuration database.

The workflow supports system credentials or a token. The token is passed only to the Git operation and is not part of the repository URL or normal error text. Stored settings also accept an older single-path shape and convert it to the current list of paths when loaded.

References: frontend/…/gitService.ts• L4-53 crates/…/github.rs• L94-126

Git synchronization

Git synchronization fetches the selected repository into a temporary workspace, reads the requested files, combines their JSON values, validates the combined configuration, and merges it into the local store. A path must stay inside the cloned repository, which keeps the selected file set bounded to the Git source.

The normal mode is incremental. Matching entries are updated and new entries are added without removing local entries that are absent from Git. Replace-existing mode first checks that the current configurations are idle, then replaces them with the validated source. A concurrent save during that check aborts the replacement and asks the user to sync again.

The following diagram shows the Git path from saved sync settings to local forwarding configurations.

flowchart LR
    A[Saved Git settings] --> B[Fetch repository]
    B --> C[Read selected JSON files]
    C --> D[Merge and validate]
    D --> E{Replace existing?}
    E -->|No| F[Incremental merge]
    E -->|Yes| G[Check idle local configs]
    G --> H[Replace local set]
    F --> I[Persist configs]
    H --> I
    I --> J[Refresh desktop state]

References: frontend/…/gitService.ts• L55-64 crates/…/github.rs• L129-186 crates/…/github.rs• L38-49 crates/…/github.rs• L197-280

Git merge identity

Git import does not rely on local database IDs because repository data does not carry the identity of the local row. It matches entries by workload, protocol, Kubernetes scope where relevant, target, and endpoint details. An unambiguous match keeps its local ID and is updated; an unmatched entry is inserted. Ambiguous matches are skipped instead of changing an uncertain local entry.

The merge also preserves machine-assigned values when the source leaves them open, such as a local port or alias. This lets a shared file describe the forwarding intent without overwriting a value already chosen on the desktop.

References: crates/…/config.rs• L510-651 crates/…/config.rs• L664-715

Supplied configuration examples

Example forwarding set

The supplied examples/configs.json shows a small Kubernetes service set for a kind cluster. It demonstrates the portable fields that describe a forwarding intent: alias, context, kubeconfig path, namespace, local and remote ports, protocol, service name, and workload type.

The example is a starting point, not a ready-to-run universal file. Its kubeconfig path and cluster context are specific to the example environment, so a user must adjust those values before importing it into another desktop.

References: examples/configs.json• L1-57 crates/…/config_model.rs• L78-160

Change checklist

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

  • Keep the frontend draft variants, shared configuration model, import validation, and export cleanup aligned when adding or renaming a workload field.
  • Preserve the identity rules used by local import and Git merge when changing fields that define whether two forwards are the same.
  • Keep Git path validation and the selected-path UI aligned so a valid repository file is neither rejected by the backend nor silently omitted.
  • Keep replace-existing sync checks coupled to forward ownership and concurrent saves. A replacement must not remove a running or newly saved configuration.
  • Keep configuration-directory precedence consistent across database access, keyring scoping, and multiple-directory warnings.

Important failure modes

TriggerConsequenceGuard
Editing a running configuration while its forward is busyThe edit is refused or the old forward cannot be safely stoppedPer-configuration pending actions and native lifecycle checks
Replacing local configs while a forward is runningSync can delete a configuration that still owns a live forwardReplace mode checks that targets are idle before deletion
A save occurs during a replace-existing syncThe replacement could lose a newly created configurationThe sync compares saved IDs again and requires another sync
Two saved configurations match one imported entryGit data could update the wrong local rowAmbiguous identity matches are skipped
Git config path is absolute, parent-relative, or outside the cloneThe sync can read an unintended filePaths are resolved and checked against the clone root
Multiple configuration directories contain databasesThe desktop can show a different saved set from the one the user expectsStartup detection reports the active location and competing locations

Key files

FileWhy to read it
frontend/…/index.tsxMain create and edit form flow
frontend/…/utils.tsDraft conversion, dependency clearing, and form validation
frontend/…/configTransactions.tsSave and delete coordination with running forwards
frontend/…/useConfigs.tsCombined saved-configuration and runtime-state view
frontend/…/gitService.tsFrontend contract for Git sync settings and import
crates/…/config.rsNative create, update, import, export, and delete boundary
crates/…/github.rsNative Git sync and keyring command boundary
crates/…/config.rsShared persistence, import identity, and export behavior
crates/…/github.rsRepository fetch, file selection, and Git merge entry point
crates/…/config_model.rsShared configuration shape and export semantics
examples/configs.jsonSupplied example of a Kubernetes forwarding set