8000 Harden the license client: offline license end, clock skew, lease copy by abahmed · Pull Request #568 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content

Harden the license client: offline license end, clock skew, lease copy - #568

Closed
abahmed wants to merge 1 commit into
fixes-4from
license-hardening
Closed

abahmed wants to merge 1 commit into
fixes-4from
license-hardening

Conversation

@abahmed
@abahmed abahmed commented Oct 21, 2026
Copy link
Copy Markdown
Owner

Stacked on #567 (base fixes-4). Client side of abahmed/kwatch-api#13.

Changes

  1. License end offline. When a verified lease has a lic_exp, that date is the license end. A later date is an extension and a sooner one ends the license early, both without a network call (state.go). evaluate_extension_test.go now asserts this. If a check-in comes back expired, revoked or suspended (403), the manager is told through Manager.ResyncOnVerdict, which wakes the renew loop at once. At most one resync runs per 5 minutes. The state still comes from the renew answer, never from the ping answer.
  2. Clock skew. Result.SrvTime is read from the body's srv_time. If that is missing, it falls back to X-Kwatch-Srv-Time and then to Date, so it works on 204s and on errors too. The manager keeps offset = srv - local and uses it to timestamp renew, deactivate, ping, activate and move. A stale_timestamp that carries a server time updates the offset and retries once. A second rejection is treated as transient: the state stays the same, so Pro does not flap to Expired and back. The offset is used only for request ts; it never feeds the clock guard.
  3. Reinstalls. No client change. kwatch-license-instance has helm.sh/resource-policy: keep, so helm uninstall keeps it. This was already in the chart README, and the README now also mentions the lease copy.
  4. emptyDir. The lease and the clock guard now go into the existing instance Secret as one JSON field, lease-cache. Its RBAC is unchanged (get/update on that name). On load, kwatch takes the newer verified lease from bolt or the Secret (license.NewerLease) and the later clock guard. The Secret is written when the lease changes or when the guard has moved by at least 1h. The chart README and values.yaml are updated.
  5. Hardening.
    • Retry backoff gets ±20% jitter.
    • At init, the clock guard is raised to the cached lease's signed iat/srv_time.
    • Bolt stores the lease and the guard as one record under license.lease, so the guard cannot be deleted on its own. The old layout (a string lease plus license.clock) is still read.
    • Also new: activate and move send ts and retry once on 409 nonce_reused with a fresh nonce. A reinstall over the cap gets 429 rate_limited + Retry-After, which goes through the existing ErrRateLimited path. It is not a verdict.

Protocol assumptions (API #13)

  • X-Kwatch-Srv-Time is unix seconds. The body's srv_time takes precedence.
  • ts on activate and move is unix seconds, checked against ±600s, with the error 400 stale_timestamp.
  • 409 {"error":"nonce_reused"} on activate and move.
  • Ping verdicts are 403 {"error":"expired"|"revoked"|"suspended"}.
  • Lease exp is at most lic_exp. The client does not depend on this.

Compatibility

An older kwatch build reading the new record at license.lease fails to parse it and activates again online. The fast edition grace check in the older binary is also skipped once.

Checks

  • make verify-focused PKGS=./internal/license/... ./internal/app/... passed. The disk was low, so I used this instead of the full make verify.
  • go test -race and -tags licensetest on both packages passed.
  • CI still has to run: the full make ci, e2e and helm tests.

- A verified lease's lic_exp now sets the license end in both directions.
- Expired, revoked and suspended check-in answers trigger an immediate
  resync (throttled to one per 5 minutes).
- Signed requests and activations carry server-corrected time from
  srv_time / X-Kwatch-Srv-Time; one retry after stale_timestamp.
- Activate and move retry once on nonce_reused and send ts.
- The lease and clock guard are stored as one record and mirrored to
  the kwatch-license-instance Secret, so emptyDir keeps offline grace.
- Init raises the clock guard to the cached lease's signed time.
- Retry backoff gets ±20% jitter.
@abahmed abahmed added the e2e Run the real-cluster E2E suite on this pull request label Oct 21, 2026
@abahmed
abahmed commented Oct 21, 2026
Copy link
Copy Markdown
Owner Author

Folded into #567.

@abahmed abahmed closed this Oct 21, 2026
@abahmed
abahmed deleted the license-hardening branch October 21, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run the real-cluster E2E suite on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0