Skip to content

fix(snapshot): refuse standalone restore while vcluster.service is active#4083

Open
rlmcpherson wants to merge 4 commits into
mainfrom
engcp-1022/restore-service-guard
Open

fix(snapshot): refuse standalone restore while vcluster.service is active#4083
rlmcpherson wants to merge 4 commits into
mainfrom
engcp-1022/restore-service-guard

Conversation

@rlmcpherson

@rlmcpherson rlmcpherson commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The server binary's restore subcommand now refuses to run while the standalone vcluster.service unit is active, with an error pointing at the supported entry point (vcluster restore --standalone, which stops and restarts the service around the restore).
  • New standalone.IsServiceActive() probe (systemctl is-active --quiet): reports not-active wherever systemd cannot answer affirmatively, so the in-pod restore path and non-systemd hosts are unaffected (fail-open by design; the guard only ever refuses on an affirmative "active").
  • Documents the contract in both commands' help text: the server binary's restore is an internal interface that must run with the control plane down; the CLI owns the service lifecycle on standalone hosts.

Why

A direct binary restore against a live standalone had no protection and demonstrably corrupts: exercised on an active control plane, the restore renamed the live state.db (and -wal/-shm) out from under the running server, started a second kine on the same socket, and was SIGKILLed mid-restore while racing the unit's Restart=always respawn loop. The CLI envelope (restoreStandaloneVCluster) is the intended design (ENGCP-975, resolved as "intended: CLI-managed"); this guard closes the direct-invocation gap it leaves.

Test plan

  • Unit: TestIsServiceActive covers the probe (active on zero exit, not-active on any failure, exact systemctl args); go test ./pkg/util/standalone/ green.
  • e2e (vcluster-pro, red-first): a new guard spec snapshots a running standalone, invokes the server binary restore directly, and asserts the refusal message, an unchanged MainPID (no restart, no flapping), and an untouched datastore. Failed against the unguarded binary with the corruption behavior above; passes with this change. A second spec drives vcluster restore --standalone end-to-end (failure and success paths) and confirms the CLI envelope is unaffected by the guard. Both land in vcluster-pro together with a dependency bump once this merges.

Part of ENGCP-1022 (the e2e specs and the vcluster bump in vcluster-pro complete it).

🤖 Generated with Claude Code


Note

Medium Risk
Changes snapshot restore behavior on standalone hosts (datastore corruption prevention); the fail-open probe design limits impact on non-standalone paths.

Overview
Blocks the internal server restore command from running while vcluster.service is active, returning an error that points users to vcluster restore --standalone or systemctl stop. The guard uses a new standalone.IsServiceActive() probe (systemctl is-active --quiet); it only refuses on an affirmative “active,” so in-pod restores and hosts without systemd still proceed.

Standalone cluster listing now uses the same probe instead of ad-hoc systemctl in find. Help text documents the internal restore contract and adds a --standalone CLI example.

Reviewed by Cursor Bugbot for commit a489e60. Bugbot is set up for automated code reviews on this repo. Configure here.

…tive

The server binary's `restore` subcommand rewrites the backing store and must
never run while the standalone control plane is up: it renames the live
kine/etcd data out from under the running server and races the unit's
Restart=always respawn loop. The vcluster CLI ("vcluster restore
--standalone") stops and restarts the service around this command, but a
direct invocation had no protection.

Add standalone.IsServiceActive (systemctl is-active probe that reports
not-active wherever systemd cannot answer affirmatively, so the in-pod
restore path is unaffected) and refuse the restore with a clear error
pointing at the CLI when the unit is active. Document the contract in both
commands' help text.

Verified by a vcluster-pro e2e spec that snapshots a running standalone,
invokes the binary restore directly, and asserts the refusal plus an
untouched datastore (ENGCP-1022).
@rlmcpherson
rlmcpherson requested review from a team as code owners July 14, 2026 19:02
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

E2E Ginkgo Tests

Status Commit Run
Passed a489e601757187f5435580b1df2c8441dc97be1f View run #30113616194

Comment thread cmd/vcluster/cmd/snapshot/restore.go Outdated
Comment thread pkg/util/standalone/service_manager.go
Make the service-active probe injectable in the restore command and add
unit tests that reach RunE: an active unit yields the refusal error with
both remediations, an inactive unit proceeds past the guard.
Replace the inline systemctl is-active check in GetStandaloneVCluster
with the standalone package probe so the is-active check has a single
implementation.
…store-service-guard

* 'main' of github.com:loft-sh/vcluster:
  fix(backport): reference existing LINEAR_TOKEN secret so sub-issue linking runs (#4084)
  chore: align OSS mirror with monorepo staging tree
  ci: convert release pipeline to dispatcher + tag-dispatched validators (#4072)
  fix(snapshot): Ensure range delete for external database (#4097)
  docs: add AI conformance reference copies for v1.34 and v1.35
  fix: node's download timeout (#4092)
  fix: bump release image base to alpine 3.24 to resolve openssl cves (#4070)
  fix(cli): skip snapshots and log status when vcluster is not running (#4080)
  ci(backport): bump backport pin and wire linear-token (#4067)

# Conflicts:
#	pkg/cli/find/find.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants