Skip to content

fix(secrets): compensate managed value delete failures - #1298

Merged
skevetter merged 2 commits into
mainfrom
fix/issue-1293-managed-value-delete-transaction
Sep 27, 2026
Merged

skevetter merged 2 commits into
mainfrom
fix/issue-1293-managed-value-delete-transaction

Conversation

@skevetter

@skevetter skevetter commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make managed-store deletion compensatable across backend and index changes, with a typed indeterminate-state error when restoration fails.
  • Use one config-first saga for secret and environment-variable deletion, preserving attachment order and reporting config rollback failures explicitly.
  • Keep rollback decisions independent of Store.Get; context deletion continues to propagate store errors without masking their type.

Closes #1293

Validation

  • go test ./pkg/secrets/... ./cmd/internal/managedvalue/... ./cmd/secrets/... ./cmd/env/... ./cmd/context/...
  • go vet ./pkg/secrets/... ./cmd/secrets/... ./cmd/env/... ./cmd/context/... ./cmd/internal/managedvalue/...
  • Diff-aware golangci-lint on affected packages: 0 findings
  • git diff --check
  • task cli:lint reports 233 repository-wide findings outside this branch diff.
  • CodeRabbit uncommitted review: 0 findings.

Summary by CodeRabbit

  • Bug Fixes
    • Improved deletion of environment variables and secrets: if deletion fails, the app attempts to restore the value and its configuration. When restoration cannot be confirmed, an error reports that the final state may be uncertain.
    • Prevented incomplete secret deletions from silently leaving stored values or index entries out of sync.

@netlify

netlify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit bbe5be1
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ab8a7bb8b13c40008e733fa

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 7e0593d6-4016-4572-8d53-bc16453c998c

📥 Commits

Reviewing files that changed from the base of the PR and between 17cbd5d and bbe5be1.

📒 Files selected for processing (9)
  • cmd/env/delete.go
  • cmd/env/delete_test.go
  • cmd/internal/managedvalue/delete.go
  • cmd/internal/managedvalue/delete_test.go
  • cmd/secrets/delete.go
  • cmd/secrets/delete_test.go
  • pkg/secrets/local_store.go
  • pkg/secrets/store.go
  • pkg/secrets/store_internal_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Environment-variable and secret deletion now use a shared managed-value flow. The flow persists binding detachment before store deletion and applies compensation based on the store outcome. The local secret store snapshots backend values and restores them when backend removal or index persistence fails.

Changes

Managed-value deletion

Layer / File(s) Summary
Secret store compensation
pkg/secrets/store.go, pkg/secrets/local_store.go, pkg/secrets/store_internal_test.go
The store documents ordinary and indeterminate deletion errors. Sensitive value deletion snapshots backend values and restores them if backend removal or index saving fails. Failed restoration returns a MutationError. Tests cover these outcomes.
Shared binding deletion
cmd/internal/managedvalue/delete.go, cmd/internal/managedvalue/delete_test.go
The shared Delete function removes and saves an existing binding before deleting its value. It restores the binding after ordinary store errors. It reports consistency errors for indeterminate store outcomes and failed rollback saves. Tests cover environment and secret bindings and save failures.
Command integration
cmd/env/delete.go, cmd/secrets/delete.go, cmd/env/delete_test.go, cmd/secrets/delete_test.go
The environment and secret deletion handlers delegate to the shared function with the corresponding binding kind. Tests verify that bindings remain persisted in order after store deletion failures.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant ManagedValueDelete
  participant Config
  participant SecretsStore
  Command->>ManagedValueDelete: submit deletion request
  ManagedValueDelete->>Config: save detached binding
  ManagedValueDelete->>SecretsStore: delete managed value
  alt ordinary store error
    ManagedValueDelete->>Config: restore and save binding
  else indeterminate store error
    ManagedValueDelete-->>Command: return consistency error
  end
Loading

Merge Risk: ⚪ Minimal · up to bbe5b

No deletion-consistency issue remains established by this review; the change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to bbe5b

The new flow improves recovery from ordinary deletion failures, but an interrupted deletion can leave a credential stored after its context attachment has been removed. The identified exposure is limited to the selected local context; no new remote entrypoint is evident.

Retained concerns

  • Medium · security · inferred: An interruption after the context attachment is saved as detached but before store deletion can leave a retained credential without its attachment or an automatic recovery record.
Security review details

Security Blast Radius

  • inferred — The identified residual-value state concerns a named value in the selected context and its local backend and index; the inspected commands do not add a remote caller or expose a backend handle.

Security Findings and Attack Paths

  • inferred — If execution stops after the detached config is saved and before Store.Delete, a credential can remain stored despite no longer being attached. An indexed value can be targeted by a later deletion attempt; the interrupted attempt itself is not reported as successful.

Trust Boundaries and Controls

  • observed — For ordinary store errors, the flow restores and saves an attached binding; for an indeterminate store error, it leaves the binding detached and returns a typed consistency error. Inconclusive probing of an unowned secret aborts its deletion.

Resilience and Maintainability Implications

  • observed — Backend-restoration failure is exposed as an indeterminate mutation rather than an ordinary error, preventing the command flow from assuming the stored value was restored.

Hardening Proposals

  • proposed — Consider a recoverable deletion marker or reconciliation path for values whose attachment was durably removed before store deletion completed.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary change: compensating managed-value deletion failures. The secrets scope is relevant, although the changes also cover environment-variable bindings.
Linked Issues check ✅ Passed Issue #1293 requires consistent secret deletion or an explicit repair state. managedvalue.Delete detaches and saves the binding before deletion, restores and persists it after an ordinary store erro…
Out of Scope Changes check ✅ Passed The changes remain connected to issue #1293. The managed-value abstraction supports both secret and environment-variable deletion, and the environment-variable refactor uses the same compensation beha…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit bbe5be1
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ab8a7bbe981120008045547

@skevetter

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Critical risk] Adds failure compensation to secret and environment variable deletion.

The PR appears safe to merge, with a non-blocking regression in persisting legacy ownership repairs on absent-entry deletes.

Findings

  1. P2 Legacy repairs are not saved ▶

Summary

The PR moves secret and environment-variable deletion to a shared config-first saga and adds backend snapshots and compensation for managed-store deletion.

  • Ordinary store failures restore attachments without relying on Store.Get.
  • Failed backend restoration produces an indeterminate-state error.
  • An absent-entry delete can now discard unrelated legacy-ownership repairs.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Detach binding and save config] --> B[Snapshot and delete store value]
  B -->|Success| C[Deletion complete]
  B -->|Ordinary failure| D[Restore binding and save config]
  B -->|Restoration failed| E[Report indeterminate state]
  D -->|Save fails| F[Report config rollback failure]
Loading

Reviews (1) · Last reviewed commit: "style(pre-commit): apply Go formatter ou..."

Comment on lines +192 to +193
if !exists {
return nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Legacy repairs are not saved

If the requested name is absent, Delete may still have repaired ownership information for other legacy secrets in memory. This return skips saving those repairs, unlike the previous delete path, so they remain absent from the index on disk until a later operation saves them. Save the index when the ownership repair changed it.

@skevetter
skevetter marked this pull request as ready for review September 27, 2026 06:49
@mergify

mergify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit 0f94c60 into main Sep 27, 2026
88 checks passed
@skevetter
skevetter deleted the fix/issue-1293-managed-value-delete-transaction branch September 27, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failed secret delete can leave the context detached while the value still exists

1 participant