Skip to content

feat(rds): honor DeletionProtection on cluster restores and AWS::RDS::DBCluster - #9057

Merged
pgermosen merged 3 commits into
floci-io:mainfrom
rajp33:fix/rds-deletion-protection-restore-cfn
Nov 20, 2026
Merged

pgermosen merged 3 commits into
floci-io:mainfrom
rajp33:fix/rds-deletion-protection-restore-cfn

Conversation

@rajp33

@rajp33 rajp33 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

RestoreDBClusterFromSnapshot and RestoreDBClusterToPointInTime now honor DeletionProtection, and AWS::RDS::DBCluster passes it to the cluster. Follow-up to #8985.

  • Both restores read DeletionProtection and set it on the new cluster before it is first stored. A restore that fails after creating the cluster clears the flag before its cleanup delete.
  • AWS::RDS::DBCluster passes DeletionProtection on create and applies a changed value in place on update, so a stack can turn protection off before deleting. The property is removed from the accepted-and-ignored list in writable-property-gaps.tsv.
  • Deleting a stack whose cluster is protected fails: the cluster resource is DELETE_FAILED with the InvalidParameterCombination message, and the stack ends in DELETE_FAILED.
  • docs/services/rds.md notes that both restores set DeletionProtection.

Closes #9056

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

Previously both restores created an unprotected cluster whatever DeletionProtection said, and a CloudFormation cluster with DeletionProtection: true could be deleted. On AWS, both restores accept DeletionProtection, and DeleteStack fails while the stack's DBCluster is protected.

Covered by:

  • RdsClusterDeletionProtectionIntegrationTest: each restore with protection is described as protected and its delete is refused;
  • CloudFormationRdsDeletionProtectionIntegrationTest: a stack cluster created protected, updated to unprotected and back, then DeleteStack ends in DELETE_FAILED with the cluster still protected.

Checklist

  • ./mvnw test passes locally
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

./mvnw test is not ticked because the full suite runs out of memory during test discovery on main as well. Locally, the RDS cluster restore and deletion protection integration tests, the CloudFormation RDS integration tests, RdsCfnProvisionerTest, CfnSchemaCoverageTest, RdsQueryHandlerTest and RdsServiceTest pass (1154 tests, 0 failures), and ./mvnw checkstyle:check and make docs-check pass.

RestoreDBClusterFromSnapshot and RestoreDBClusterToPointInTime now read
DeletionProtection and set it on the new cluster before it is stored. A
restore that fails after creating the cluster clears the flag before
deleting it again.
The DBCluster provisioner reads DeletionProtection, creates the cluster
with it, and applies a changed value on stack update. A stack delete of a
protected cluster is refused by DeleteDBCluster and reported as the
resource's DELETE_FAILED, as on AWS.
@qodo-code-review

qodo-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Honor deletion protection on RDS cluster restores and CloudFormation clusters

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Apply requested deletion protection to snapshot and point-in-time cluster restores.
• Reconcile CloudFormation cluster protection on create and update, preventing protected stack
 deletion.
• Cover restore and stack behavior with integration tests and document the restore default.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: RDS DB-cluster lifecycle and restore integration.
  • The query handlers, restore service methods, persisted DbCluster flag, and delete guard form one end-to-end restore outcome: a caller requests a protected restored cluster and subsequent delete behavior honors that state.
  • Snapshot restore and point-in-time restore are distinct operations but share this bounded restore integration and persisted protection contract.
  • CloudFormation create, update, replacement, and stack-delete behavior manage one bounded RDS DB-cluster lifecycle contract.
  • The provisioner, persisted cluster state, shared cleanup helper, and delete guard are propagation hops of that capability rather than separate deployment or functional scopes.
Sources

src/main/java/io/floci/aws/services/rds/RdsService.java[2811-2811]

                discardCreatedCluster(effectiveRegion, clusterId, deletionProtection, e);
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Coordinated invariants

  • Before: restore methods created a cluster with deletion protection fixed to false, and failure cleanup used inline cleanup logic.
  • After: the requested flag remains propagated through both restore contracts and persistence, while failed-target cleanup is centralized and performs protection clearing and deletion as independent best-effort operations.
  • New correctness condition: the protection state must remain consistent across request parsing, persistence, deletion enforcement, and the exceptional cleanup sequence, including the rule that a failure to clear protection must not prevent an attempted delete of an unadopted target.
  • The restore transformation and existing state/deletion infrastructure remain unchanged; the follow-up does not introduce a new concurrency protocol or independent functional scope.
Sources

src/main/java/io/floci/aws/services/rds/RdsService.java[2811-2811]

                discardCreatedCluster(effectiveRegion, clusterId, deletionProtection, e);
Potential damage 🔴 High 🩹 Data loss

  • If protection is incorrectly false after a caller requested true, a later DeleteDBCluster operation can pass the existing deletion guard and remove the restored cluster.
  • Reverting the code does not restore a cluster already deleted.
  • Recovery requires an available snapshot, retained automated backup, or another supported backup path and a new restore; otherwise the cluster data is not recoverable.
  • Before deletion, ModifyDBCluster can correct the flag.
  • The follow-up helper improves failed-restore cleanup by attempting delete even when unprotect fails, but that target has not become an adopted capability and the helper does not repair a wrong value on a successful restore.
  • Potentially recoverable only when a usable snapshot or automated backup exists; code rollback alone does not repair persistent state or compensate for external deletion.
  • Failed-target cleanup is attempted directly, but cleanup failure may require manual intervention.
Sources

src/main/java/io/floci/aws/services/rds/RdsService.java[2811-2811]

                discardCreatedCluster(effectiveRegion, clusterId, deletionProtection, e);
Assessed commit 8d50484
Diagram

graph TD
  CFN["CloudFormation"] --> Service["RDS service"] --> Cluster[("Cluster state")] --> Guard{"Deletion protected?"} --> Outcome["Delete outcome"]
  Query["RDS restore API"] --> Service
Loading
High-Level Assessment

Passing protection into initial cluster creation avoids an unprotected interval. Reusing the existing protection setter for CloudFormation updates and clearing protection only during failed-create cleanup fits the current RDS lifecycle; a separate CloudFormation deletion rule would duplicate the service's delete guard.

Files changed (10) +193 / -70

Enhancement (3) +25 / -7
RdsCfnProvisioner.javaReconcile CloudFormation DBCluster deletion protection +8/-1

Reconcile CloudFormation DBCluster deletion protection

• Parses DeletionProtection, supplies it when creating a cluster, and applies changed values to existing clusters. Clears protection before deleting a newly created cluster if role association fails.

src/main/java/io/floci/aws/services/cloudformation/provisioners/RdsCfnProvisioner.java

RdsQueryHandler.javaPass restore protection requests to the RDS service +6/-2

Pass restore protection requests to the RDS service

• Reads DeletionProtection for both cluster restore actions and passes a boolean to the service, defaulting omitted values to false.

src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java

RdsService.javaCreate protected restored clusters and preserve failure cleanup +11/-4

Create protected restored clusters and preserve failure cleanup

• Both restore paths set deletion protection during cluster creation. If a subsequent data restore fails, they disable protection before deleting the incomplete cluster.

src/main/java/io/floci/aws/services/rds/RdsService.java

Tests (5) +166 / -62
CloudFormationRdsDeletionProtectionIntegrationTest.javaExercise protected CloudFormation cluster lifecycle +61/-0

Exercise protected CloudFormation cluster lifecycle

• Verifies protection on stack creation, in-place updates in both directions, and DELETE_FAILED when deleting a stack with a protected cluster.

src/test/java/io/floci/aws/services/cloudformation/CloudFormationRdsDeletionProtectionIntegrationTest.java

RdsCfnProvisionerTest.javaAlign DBCluster provisioner assertions with creation arguments +40/-40

Align DBCluster provisioner assertions with creation arguments

• Updates createDbCluster mocks and verifications to include the arguments used to pass deletion protection during provisioning.

src/test/java/io/floci/aws/services/cloudformation/RdsCfnProvisionerTest.java

RdsClusterDeletionProtectionIntegrationTest.javaVerify restored clusters refuse deletion when protected +48/-5

Verify restored clusters refuse deletion when protected

• Adds snapshot and point-in-time restore cases that check response and stored protection, then confirm deletion is refused. Extends cleanup to remove restored clusters and snapshots.

src/test/java/io/floci/aws/services/rds/RdsClusterDeletionProtectionIntegrationTest.java

RdsQueryHandlerTest.javaAdjust restore handler tests for protection arguments +6/-6

Adjust restore handler tests for protection arguments

• Updates restore service mocks and verifications for the new boolean argument, including the false default when DeletionProtection is omitted.

src/test/java/io/floci/aws/services/rds/RdsQueryHandlerTest.java

RdsServiceTest.javaUpdate direct restore calls for deletion protection +11/-11

Update direct restore calls for deletion protection

• Supplies the new protection argument in existing service tests for restore behavior, errors, ports, and cleanup.

src/test/java/io/floci/aws/services/rds/RdsServiceTest.java

Documentation (1) +2 / -0
rds.mdDocument deletion protection on cluster restores +2/-0

Document deletion protection on cluster restores

• States that snapshot and point-in-time restores set DeletionProtection on the new cluster and default it to false.

docs/services/rds.md

Other (1) +0 / -1
writable-property-gaps.tsvMark DBCluster DeletionProtection as implemented +0/-1

Mark DBCluster DeletionProtection as implemented

• Removes DeletionProtection from the CloudFormation DBCluster properties recorded as accepted but ignored.

src/test/resources/cloudformation/writable-property-gaps.tsv

@qodo-code-review

qodo-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Failed updates strand replacement clusters ✗ Dismissed
Description
provisionDbCluster creates protected clusters, but neither ReplacementCleanup.rollback nor the
stack-create rollback path clears protection before deleting a newly created cluster. If a later
resource fails during an update or creation, RDS refuses the rollback deletion, leaving the stack in
UPDATE_ROLLBACK_FAILED or ROLLBACK_FAILED, respectively, with the new cluster still present.

2. Failed updates keep the wrong protection ✗ Dismissed
Description
provisionDbCluster changes an existing cluster's protection with setDeletionProtection but saves
no prior value for rollback. If another resource later fails the stack update, rollbackUpdate
cannot restore that value, so the cluster retains the attempted setting and the resource's rollback
fails.

3. Restore cleanup logic is copied into two restore paths ✓ Resolved

Resolving commit: 8d50484

Resolution reason
The author added a shared helper `discardCreatedCluster(region, clusterId, deletionProtection,
cause)` in RdsService that unprotects when needed and deletes the cluster, recording cleanup errors
as suppressed. Both restore cleanup blocks in RdsService (snapshot restore and point-in-time
restore) now call this helper, and the RdsCfnProvisioner catch block also calls it instead of its
inline copy. This matches the suggested fix prompt's recommended helper and removes the duplication.
Description
The two-line sequence if (deletionProtection) setDeletionProtection(..., false) followed by
deleteDbCluster is repeated verbatim in restoreDbClusterFromSnapshot and
restoreDbClusterToPointInTime, and RdsCfnProvisioner has a near copy. Any later change to the
cleanup order, such as the failure handling in the finding above, has to be made in each copy, and
the copies can drift apart.

View medium (3)
4. Replacement leaves the old cluster running ✗ Dismissed
Description
provisionDbCluster now creates and updates clusters with deletion protection, but replacement
cleanup still tries to delete the displaced cluster without accounting for that flag. When a
protected cluster is replaced under the default cleanup policy, the old cluster survives the refused
deletion while the stack reports UPDATE_COMPLETE and points to the replacement.

5. Failed restores can lose protection ✗ Dismissed
Description
Both restore failure handlers clear DeletionProtection and call deleteDbCluster as separate
synchronized operations. If another request attaches an instance between those calls, deletion
refuses the nonempty cluster and leaves the failed restore present with protection turned off.

6. Failed restore cleanup can leave a protected cluster behind ✓ Resolved

Resolving commit: 8d50484

Resolution reason
Extracted a shared discardCreatedCluster helper that unprotects in its own try/catch (recording
failure as suppressed on the original exception) and always attempts deleteDbCluster afterward; all
restore and CFN cleanup paths now use it, keeping the original exception as the one rethrown.
Description
In restoreDbClusterFromSnapshot the cleanup block first calls
setDeletionProtection(effectiveRegion, clusterId, false) and only then deleteDbCluster, both
inside one try. If the unprotect call throws, deleteDbCluster is skipped and the `catch
(Exception cleanupError)` only adds the error as suppressed, so the cluster that the failed restore
created is left in place and still protected. The same ordering exists in
restoreDbClusterToPointInTime, and RdsCfnProvisioner.reconcileClusterRoles has the same pattern,
where a throw from setDeletionProtection replaces the original AwsException and skips
CfnDeletes.safeDelete. Because the leftover cluster is protected, a later DeleteDBCluster will
refuse it until someone unprotects it manually.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #8985
✅ Compliance rules (platform): 21 rules
✅ Web pages:
  +2 more
✅ Cross-repo context — repo relationships
  Explored: repo: floci-io/floci-ui (sha: 11c808ad) — View relationship
Review mode: Auto: 🧠 Deep: Multiple RDS restore and CloudFormation paths create subtle deletion-safety risks.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@pgermosen pgermosen added cloudformation AWS CloudFormation enhancement New feature or request rds Amazon Relational Database Service (RDS) labels Nov 20, 2026

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rajp33 thanks, these are both follow-ups from #8985: the two restores now create the cluster with the DeletionProtection they're given, AWS::RDS::DBCluster passes it on create and update so a stack can turn it off before deleting, and a failed restore or role attach clears it before removing what it made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cloudformation AWS CloudFormation enhancement New feature or request rds Amazon Relational Database Service (RDS)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RDS cluster restores and AWS::RDS::DBCluster ignore DeletionProtection

2 participants