Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

headscale-api-wrapper

Container image tags

Every Release Docker build publishes beclab/headscale-api-wrapper:sha-<7-character-commit> in addition to the existing version tag (or latest fallback). Both tags refer to one multi-platform build for linux/amd64 and linux/arm64. The image labels include the full source revision for traceability.

Use the SHA tag from the CI run for testing a specific commit. It is a Git commit identifier, not an image digest: rebuilding the same commit can replace that tag. Pin beclab/headscale-api-wrapper@sha256:<digest> when the exact image must remain unchanged across restarts.

Split DNS synchronization

Set SPLIT_DNS_CONFIGMAP_NAME=headscale-split-dns and POD_NAMESPACE=os-network to enable publication. Set POD_NAME from the Downward API to enable best-effort annotation acceleration. SPLIT_DNS_APPLICATION_ENABLED defaults to true; false disables Application collection. Changes take effect on process restart. The former SPLIT_DNS_RESOLVERS_FILE hostPath output is no longer supported.

The wrapper owns one ConfigMap and creates it only when GET returns NotFound. Helm must not manage its data, and it must not have a Pod ownerReference:

  • user-resolvers.json: sorted, deduplicated User domain array, initially [].
  • application-resolvers.json: Application domain array, initially [].
  • split-resolvers.json: merged domain-to-resolver map, initially {}.

User zones come from bytetrade.io/zone; Application domains come from spec.settings.customDomain and spec.userSettings[*].customDomain, using only third_party_domain. A bad application's JSON retains that application's last valid in-memory snapshot without preventing other applications from updating. These per-application snapshots survive relists but not process restarts.

Two independent collectors update immutable snapshots. A single coordinator GETs, calculates, compares and PATCHes all changed keys with resourceVersion. User publication never waits for Application's first successful list. Memory snapshots take precedence over valid persisted source arrays. If neither User source is valid, no update is published. If Application is unavailable, only User is merged and the invalid/missing application key is left untouched. Disabling Application clears that key to [] together with the merged result, when User is valid. Historical merged output is never used to infer sources. Successful empty lists clear the source; failed API calls do not.

TAILSCALE_IP_FILE defaults to /var/lib/headscale/bootstrap/tailscale.ip and remains shared with the Tailscale sync container, which publishes a verified IPv4. Only its parent directory is watched; periodic coordination runs every 30 seconds. Source keys contain no IP. An IP-only change patches only the merged key. Nonempty output with invalid/missing IP writes no keys until recovery; empty output requires no IP. Sources and merged output are committed atomically.

Conflicts, timeouts and uncertain responses are followed by a fresh GET and recalculation, never a replay of an old PATCH. Failures back off up to 30 seconds; new snapshots may wake retries sooner, with at least one second between failed attempt starts. HTTP requests time out after 10 seconds. Transport is reused, but each request rereads the projected service-account token. No capacity budget, size precheck, or oversized-object fallback is implemented; an oversized object can block User updates until data is reduced.

Only Headscale mounts the merged key, as a directory volume (not subPath) at /etc/headscale-split-dns, with optional: true. Set its dns.split_resolvers_path=/etc/headscale-split-dns/split-resolvers.json. Headscale must start when the file is absent and watch all relevant changes in the dedicated configuration directory, without filtering by the JSON filename or ..data. Each event reopens the configured JSON; unchanged hashes suppress duplicate broadcasts and failed reads retain the last valid configuration. 30-second polling continues after watcher failure. No debounce is required for this small directory. Wrapper does not read this mount.

On a successful changed merged result, annotation acceleration is scheduled asynchronously for min(last publication + 500ms, first pending publication + 2s). Each batch makes one attempt; new publications after the batch is taken form a new batch. Failures and propagation races rely on kubelet periodic projection. Annotation success does not prove that Headscale or clients have loaded the data.

The service account needs User and (when enabled) Application get/list/watch. An os-network Role grants get/patch on the named ConfigMap, ConfigMap create, and Pod patch. Create cannot be name-restricted, and Pod patch covers all Pods and fields in that namespace; code only patches its own refresh annotation. All containers sharing the service account share these permissions.

Use one replica with Recreate and rollout restart for normal operations. Direct or forced Pod deletion can overlap writers; resourceVersion does not determine which business snapshot is newer. This implementation accepts that boundary and does not add leader election.

Run local tests with a dummy key (no real Headscale or Kubernetes credentials):

APIKEY=hskey-api-test go test -race ./...

Before release, validate a real ConfigMap ..data update on Linux, startup with no ConfigMap, restart preservation, User updates while Application fails, and client DNS updates without reconnecting. Event-triggered loading must be proved by Headscale's trigger=fsnotify log and expected content hash, not masked by polling. Also exercise watcher closure and trigger=poll recovery. Local tests do not establish kubelet projection latency or client propagation.

Instance identity mode

One binary supports --identity-mode=user-id|uuid (or HEADSCALE_IDENTITY_MODE). An omitted setting defaults to user-id. Existing instances keep usernames; new shared installations explicitly use UUID names (u-<lldap-uuid>). The Olares chart stores the mode alongside the PostgreSQL password in the existing Secret. No database inspection, migration command or journal is used. LLDAP_READONLY_URL is required for synchronization in both modes.

Startup uses the original SDK Init to fetch the full directory and establish the baseline before starting NATS. It validates the configured identity mode against Headscale before any writes. The initial gate blocks identity writes; a confirmed startup conflict also makes GET /readyz return 503. Once startup validation passes, ordinary request/sync errors do not close the global gate. Each request still authenticates independently. UUID sessions validate token issuance against the current account creation time; user-ID sessions keep legacy behavior. Runtime manual database identity changes are outside this scope.

UUID directory fetch/parse/validation failures, including an invalid account creation timestamp, return 503 from authentication middleware and the preauthkey endpoint. Invalid sessions, absent accounts and tokens issued at or before account creation return 401. In both modes, token-verification transport failures, unexpected HTTP statuses (including 5xx), malformed JSON and missing usernames return 503. Verification rejection (400 in the current LLDAP API, or 401/403) returns 401. This changes error classification without adding calls or retries. Successful key creation and device renaming fill the response owner name from the already authenticated/authorized username, without another directory lookup or a new display-name conversion error. Other response fields and numeric IDs remain. /readyz is excluded from access logs; panic recovery remains enabled.

NATS uses the original OnChanges / applyChanges incremental path. The callback already carries user IDs and UUIDs, including removed users' old UUIDs, so the wrapper does not query LLDAP again. Additions/updates run before removals, as in the original flow; a UUID replacement creates the new identity and revokes the old one without transferring devices or policy. Both halves are attempted and errors are returned to the SDK for its existing retry behavior. No directory cache or independent timer is added. Without NATS, the original periodic full reconcile remains; it and startup attempt cleanup then creation independently. Startup reconciliation errors keep the existing full-reconcile retry loop active before either driver starts. Logs call this "initial reconciliation incomplete"; cleanup is not abandoned merely to start incremental consumption.

Revocation removes policy references, nodes and then the user. Audit logs retain known usernames, UUIDs and numeric IDs; unknown usernames after restart are explicit, and no node deletion counter is maintained. UUID policy conversion stays strict: reads/updates may fail until stale references are removed.

Policy reads and conversions reuse the directory pinned to the request. An actual UUID policy write still fetches one additional directory snapshot and compares the entire username-to-UUID-name mapping before submitting to Headscale. Unrelated account changes can therefore reject the write for retry. The discussed removal of this check is not implemented, and the check is not a cross-service transaction. There is no cross-request directory cache: UUID authentication fetches the full directory once per request; response owner-name presentation adds no fetch.

Malformed UUID directory accounts are still rejected rather than quarantined. They can prevent initial validation (writes blocked, readiness remains 200) or make an incremental batch keep failing, affecting other users' synchronization. A missing UUID cannot safely identify which old Headscale identity to preserve; there is no automatic skip-and-sweep behavior for this case.

The SDK used by builds is third_party/lldap-clients-go, unchanged by this work. Its timer starts after consumer setup; there is no independent fallback while setup/restart is blocked. UUID/creation-time-only changes are ignored by the SDK diff. A missed same-name recreation is not guaranteed to be repaired by later events or the timer; restart performs a full reconciliation. No custom SDK callbacks or historical identity database are introduced.

The prior UUID migration implementation is archived on archive/headscale-uuid-migration-20261204 (commit e1e973a3f8b3c97869c5d4b600f923865ea0f1d2). Do not run that migration concurrently with this service. It is not included in this runtime or required to upgrade a user-ID instance.

Image publishing uses the existing .github/workflows/release-docker.yml. The dedicated dailybuild-uuid.yml experiment workflow has been removed.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages