Skip to content

Conversation

FurqanHabibi
Copy link
Collaborator

This implements a tool to sanitize RDS snapshots for sharing with external accounts.

Note that this is a public repository.

@FurqanHabibi FurqanHabibi requested review from hanscg and a team March 24, 2025 07:18
@FurqanHabibi FurqanHabibi self-assigned this Mar 24, 2025
- `SANITIZER_DELETE_OLD_SNAPSHOTS`: (Optional) Whether to delete old snapshots. Defaults to False.
- `SANITIZER_OLD_SNAPSHOT_DAYS`: (Optional) Number of days for a snapshot to be considered old. Defaults to 30.

# Configuration
Copy link

Choose a reason for hiding this comment

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

Could you add a sample of the configuration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will add 🙏


Create sanitized copy of RDS snapshots and share them with selected accounts.

It works by restoring an unsanitized snapshot to a temporary cluster and executing sanitizing SQL queries against it, after which sanitized snapshot will be created and optionally shared with other accounts.
Copy link

Choose a reason for hiding this comment

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

I think it's better if you provide guide on how to run this locally (either with Docker or with Poetry)

Copy link

Choose a reason for hiding this comment

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

Also, I think it's useful to describe what IAM permissions are required for this

Copy link
Collaborator Author

@FurqanHabibi FurqanHabibi Mar 24, 2025

Choose a reason for hiding this comment

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

Also, I think it's useful to describe what IAM permissions are required for this

Yes, I'm thinking of creating a pod-identity terraform module for it in the style of https://github.com/terraform-aws-modules/terraform-aws-eks-pod-identity

I think it's better if you provide guide on how to run this locally (either with Docker or with Poetry)

The thing is the tool needs to be connected to the RDS subnet for running the SQL query. I'll probably add a flag to set the postgres host to localhost, with the assumption that the user can connect their localhost to the RDS (via bastion port-forwarding for example).

Copy link

Choose a reason for hiding this comment

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

I see, if it's expected to run within AWS it's fine too, just add a note describing as such.

click.echo("")

click.echo("#################### Creating shared snapshot ####################")
shared_snapshot = share_snapshot(sanitized_snapshot)
Copy link

Choose a reason for hiding this comment

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

The shared snapshot is always created even if SANITIZER_SHARE_ACCOUNT_IDS is not set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, will make the step optional 🙏

DBClusterIdentifier=restored_cluster["DBClusterIdentifier"],
AutoMinorVersionUpgrade=False,
BackupRetentionPeriod=1,
PreferredBackupWindow="22:00-22:30",
Copy link

Choose a reason for hiding this comment

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

Why does this need to be set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If not set, there is a possibility that RDS will execute automatic backup just after the temporary cluster is created, prolonging the wait time (this happened to me once).
Unfortunately RDS aurora does not support disabling automatic backup, so I set it to a time outside the usual backup window.

@hanscg hanscg requested a review from a team March 24, 2025 07:52
@FurqanHabibi FurqanHabibi merged commit 2a1b78f into main Mar 25, 2025
3 checks passed
@FurqanHabibi FurqanHabibi deleted the dev branch March 25, 2025 09:51
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