Skip to content

feat: Implement MRAP cleanup and bucket version deletion#76

Merged
venkatamutyala merged 1 commit into
mainfrom
venkatamutyala-patch-3
Jan 27, 2026
Merged

feat: Implement MRAP cleanup and bucket version deletion#76
venkatamutyala merged 1 commit into
mainfrom
venkatamutyala-patch-3

Conversation

@venkatamutyala

Copy link
Copy Markdown
Contributor

Added robust cleanup for Multi-Region Access Points (MRAPs) and bucket versions, including safety checks for jq installation.

Added robust cleanup for Multi-Region Access Points (MRAPs) and bucket versions, including safety checks for jq installation.
Copilot AI review requested due to automatic review settings January 27, 2026 01:57
@venkatamutyala venkatamutyala merged commit a332fad into main Jan 27, 2026
6 checks passed
@venkatamutyala venkatamutyala deleted the venkatamutyala-patch-3 branch January 27, 2026 01:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a pre-aws-nuke cleanup phase to remove S3 Multi-Region Access Points (MRAPs) and fully empty associated regional buckets (including object versions and delete markers) before running the existing account nuke workflow.

Changes:

  • Added MRAP discovery and per-region bucket cleanup (delete versions, delete markers, remove bucket).
  • Added MRAP deletion via s3control delete-multi-region-access-point.
  • Added a jq presence check around the MRAP cleanup block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/aws/account-nuke.sh
Comment on lines +127 to +140
while true; do
# Fetch batch of versions (suppress errors if bucket is already gone)
versions=$(aws s3api list-object-versions --bucket "$bucket_name" --region "$region_id" --max-items 1000 --query '{Objects: Versions[].{Key:Key,VersionId:VersionId}}' --output json 2>/dev/null || echo "")

# Check if empty (jq returns null or empty list)
count=$(echo "$versions" | jq '.Objects | length' 2>/dev/null || echo "0")

if [ "$count" == "0" ] || [ "$versions" == "" ] || [ "$count" == "null" ]; then
break
fi

echo " - Deleting batch of $count versions..."
aws s3api delete-objects --bucket "$bucket_name" --region "$region_id" --delete "$versions" >/dev/null 2>&1 || true
done

Copilot AI Jan 27, 2026

Copy link

Choose a reason for hiding this comment

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

These deletion loops can become infinite if delete-objects fails (e.g., AccessDenied, Object Lock, invalid region) because the failure is ignored (|| true) and the next iteration will re-list the same versions and keep retrying forever. Capture and check the exit status (and/or add a max-iterations/timeout or break when a delete attempt makes no progress) so the script can fail fast or skip with a clear warning instead of hanging indefinitely.

Copilot uses AI. Check for mistakes.
Comment thread tools/aws/account-nuke.sh
Comment on lines +142 to +154
# 5. Loop to delete ALL Delete Markers (Handles >1000 items pagination)
while true; do
markers=$(aws s3api list-object-versions --bucket "$bucket_name" --region "$region_id" --max-items 1000 --query '{Objects: DeleteMarkers[].{Key:Key,VersionId:VersionId}}' --output json 2>/dev/null || echo "")

count=$(echo "$markers" | jq '.Objects | length' 2>/dev/null || echo "0")

if [ "$count" == "0" ] || [ "$markers" == "" ] || [ "$count" == "null" ]; then
break
fi

echo " - Deleting batch of $count markers..."
aws s3api delete-objects --bucket "$bucket_name" --region "$region_id" --delete "$markers" >/dev/null 2>&1 || true
done

Copilot AI Jan 27, 2026

Copy link

Choose a reason for hiding this comment

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

Same infinite-loop risk as the versions loop: if delete-objects fails, the marker count may never decrease and this while true will run indefinitely because errors are suppressed. Add failure handling/progress detection (or a bounded retry policy) so the cleanup phase can terminate predictably with actionable output.

Copilot uses AI. Check for mistakes.
Comment thread tools/aws/account-nuke.sh
Comment on lines +100 to +103
# 0. Safety Check: Ensure jq is installed
if ! command -v jq &> /dev/null; then
echo -e "\e[31mError: 'jq' is not installed. MRAP cleanup requires jq. Skipping.\e[0m"
else

Copilot AI Jan 27, 2026

Copy link

Choose a reason for hiding this comment

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

The jq “safety check” here is ineffective because this script already uses jq earlier (e.g., parsing list-accounts and assume-role output) and will exit due to set -e before reaching this block if jq is missing. Move the jq dependency check to the top before the first jq usage (or remove this block-level check) so the behavior matches the message about skipping MRAP cleanup.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants