Repository navigation
fix: never trust a Helm release's own Hooks during internal recovery uninstalls - #2146
Merged
Merged
Conversation
…uninstalls handleUpgradeError/recoverRelease and handleInstall's consecutive-failure self-healing both call Helm's uninstall action, with hooks enabled by default, on a release whose recorded state (status, and the Hooks field that comes with it) Sveltos did not verify. Anyone with write access to Secrets in the release namespace can forge that state: relabel the current release as superseded, inject a next-revision Secret with status "unknown" and a pre-delete hook of their choosing, then trigger a redeploy. The upgrade fails with "has no deployed releases", recoverRelease decides to uninstall to clear the inconsistency, and the forged hook runs with addon-controller's own (often cluster-admin-level) credentials for the managed cluster - a confused-deputy privilege escalation from whatever RBAC the attacker had in their own namespace. Add forceDisableHooks to getHelmUninstallClient/uninstallRelease/ doUninstallRelease and set it for the two call sites that are an internal recovery heuristic rather than an admin decision: recoverRelease, and handleInstall's uninstall-after-N-consecutive- failures. Both read release state addon-controller never produced and has no reason to trust. The other three uninstallRelease callers (explicit HelmChartActionUninstall, a ClusterSummary's own teardown when its ClusterProfile/Profile is deleted or stops matching, and the stale/orphaned-release cleanup loop) are admin-driven lifecycle decisions and keep respecting the chart's own DisableHooks option, unchanged. Reproduced end-to-end on local kind clusters (management + managed, push mode): a ServiceAccount with only the built-in edit role in one namespace forged a release this way and had addon-controller create a ClusterRoleBinding granting it cluster-admin. Rebuilding with this fix and replaying the same forgery, the recovery still clears the inconsistent release but the forged hook no longer runs. handleInstall's path is harder to trigger than recoverRelease's: the same release-state read gates both whether handleInstall is entered (status nil/Uninstalled) and whether Helm's own Uninstall.Run skips hooks (it always does when status is already Uninstalled), so a static forged state can't satisfy both at once - reaching it for real would need winning a race between two near-simultaneous reads. Fixed anyway as free defense in depth: this is an internal heuristic, not an admin intent, so it should never have trusted hook content regardless of how hard it is to reach.
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.
handleUpgradeError/recoverRelease and handleInstall's consecutive-failure self-healing both call Helm's uninstall action, with hooks enabled by default, on a release whose recorded state (status, and the Hooks field that comes with it) Sveltos did not verify. Anyone with write access to Secrets in the release namespace can forge that state: relabel the current release as superseded, inject a next-revision Secret with status "unknown" and a pre-delete hook of their choosing, then trigger a redeploy. The upgrade fails with "has no deployed releases", recoverRelease decides to uninstall to clear the inconsistency, and the forged hook runs with addon-controller's own (often cluster-admin-level) credentials for the managed cluster - a confused-deputy privilege escalation from whatever RBAC the attacker had in their own namespace.
Add forceDisableHooks to getHelmUninstallClient/uninstallRelease/ doUninstallRelease and set it for the two call sites that are an internal recovery heuristic rather than an admin decision: recoverRelease, and handleInstall's uninstall-after-N-consecutive- failures. Both read release state addon-controller never produced and has no reason to trust. The other three uninstallRelease callers (explicit HelmChartActionUninstall, a ClusterSummary's own teardown when its ClusterProfile/Profile is deleted or stops matching, and the stale/orphaned-release cleanup loop) are admin-driven lifecycle decisions and keep respecting the chart's own DisableHooks option, unchanged.
Reproduced end-to-end on local kind clusters (management + managed, push mode): a ServiceAccount with only the built-in edit role in one namespace forged a release this way and had addon-controller create a ClusterRoleBinding granting it cluster-admin. Rebuilding with this fix and replaying the same forgery, the recovery still clears the inconsistent release but the forged hook no longer runs.
handleInstall's path is harder to trigger than recoverRelease's: the same release-state read gates both whether handleInstall is entered (status nil/Uninstalled) and whether Helm's own Uninstall.Run skips hooks (it always does when status is already Uninstalled), so a static forged state can't satisfy both at once - reaching it for real would need winning a race between two near-simultaneous reads. Fixed anyway as free defense in depth: this is an internal heuristic, not an admin intent, so it should never have trusted hook content regardless of how hard it is to reach.