fix(snapshot): refuse standalone restore while vcluster.service is active#4083
Open
rlmcpherson wants to merge 4 commits into
Open
fix(snapshot): refuse standalone restore while vcluster.service is active#4083rlmcpherson wants to merge 4 commits into
rlmcpherson wants to merge 4 commits into
Conversation
…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).
Contributor
E2E Ginkgo Tests
|
loft-bot
reviewed
Jul 15, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
restoresubcommand now refuses to run while the standalonevcluster.serviceunit is active, with an error pointing at the supported entry point (vcluster restore --standalone, which stops and restarts the service around the restore).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").restoreis 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'sRestart=alwaysrespawn 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
TestIsServiceActivecovers the probe (active on zero exit, not-active on any failure, exact systemctl args);go test ./pkg/util/standalone/green.restoredirectly, 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 drivesvcluster restore --standaloneend-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
restorecommand from running whilevcluster.serviceis active, returning an error that points users tovcluster restore --standaloneorsystemctl stop. The guard uses a newstandalone.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
systemctlinfind. Help text documents the internal restore contract and adds a--standaloneCLI example.Reviewed by Cursor Bugbot for commit a489e60. Bugbot is set up for automated code reviews on this repo. Configure here.