Skip to content

Feat/data retention backup #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

jusdino
Copy link
Collaborator

@jusdino jusdino commented Jul 4, 2025

Description List

  • Added a backup app to multi-account for a common Backup Vault copy destination for environment accounts
  • Added Backup Vaults to environment accounts, one for general data, one for SSN data
  • Added backup plans to all DynamoDB tables and S3 buckets with original data
  • Added a Cognito user pool lambda to export user attributes to s3
  • Added a backup plan for the cognito export s3 buckets

Testing List

  • pytest
  • smoke test for cross-account copies
  • verify scheduled backups for resources including the ssn table
  • verify the cognito export for both user pools (with MFA enabled and users with MFA configured)
  • Code review

We have the option to remove the backup account app and only back up data direct to the secondary environment account vault when that work is ready. Alternately, we could do the direct-to-secondary copy where applicable but use the backup account for pre-prod environments without a secondary deployment.

Deployment

  • Remove working files from this PR
  • CDK deploy control-tower app to management account (for new SCP)
  • CDK deploy backup app to backup account (if we keep it)
  • Put ssm configs to deployment accounts with updated context for backup vault & policy configs
  • Merge this PR for standard deploy

Closes #246

Copy link
Contributor

coderabbitai bot commented Jul 4, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jusdino jusdino requested a review from landonshumway-ia July 4, 2025 06:39
@jusdino jusdino force-pushed the feat/data-retention-backup branch from f9a8670 to c59119e Compare July 4, 2025 06:41
Comment on lines +139 to +141
'backup:CopyTargets': [self.cross_account_ssn_backup_vault.backup_vault_arn]
}
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be the generic cross_account_backup_vault shouldn't it?

@@ -26,8 +26,38 @@
"workspace_id": "T01234567"
}
]
},
"backup_policies": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not be backing up our beta environment data. As it is intended to be ephemeral in nature, since it will likely have real SSNs mixed in with test data, which we don't want to backup for non-prod purposes

@@ -147,6 +147,7 @@ def __init__(
self.pipeline_environment_context = self.ssm_context['environments']['pipeline']
self.connection_arn = self.pipeline_environment_context['connection_arn']
self.github_repo_string = self.ssm_context['github_repo_string']
self.backup_config = self.ssm_context['backup_config']
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be optional in the base pipeline, since beta should not include it. We can enforce it in the prod and test pipelines, and throw an exception if not found, since it is mandatory for those.

@@ -21,6 +21,7 @@ def __init__(
app_name: str,
environment_name: str,
environment_context: dict,
backup_config: dict,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be optional, since not every environment will have backups

Suggested change
backup_config: dict,
backup_config: dict | None,

@@ -50,6 +51,7 @@ def __init__(
app_name: str,
environment_name: str,
environment_context: dict,
backup_config: dict,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Suggested change
backup_config: dict,
backup_config: dict | None,

Comment on lines +252 to +254
def _add_data_resources(
self, removal_policy: RemovalPolicy, backup_infrastructure_stack: BackupInfrastructureStack
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of these will need to be updated to account for an optional backup_infrastructure_stack

Suggested change
def _add_data_resources(
self, removal_policy: RemovalPolicy, backup_infrastructure_stack: BackupInfrastructureStack
):
def _add_data_resources(
self, removal_policy: RemovalPolicy, backup_infrastructure_stack: BackupInfrastructureStack | None
):

Comment on lines +28 to +48
class _AppSynthesizer:
"""
A helper class to cache apps based on context.
This is useful to avoid re-synthesizing the app for each test.
"""

def __init__(self):
super().__init__()
self._cached_apps: dict[str, CompactConnectApp] = {}

def get_app(self, context: Mapping) -> CompactConnectApp:
context_hash = self._get_context_hash(context)
if context_hash not in self._cached_apps.keys():
self._cached_apps[context_hash] = CompactConnectApp(context=context)
return self._cached_apps[context_hash]

def _get_context_hash(self, context: Mapping) -> str:
return hash(json.dumps(context, sort_keys=True))


_app_synthesizer = _AppSynthesizer()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat!

Comment on lines +505 to +513
def _check_backend_stage_resource_counts(self, stage: BackendStage):
"""
Check resource counts for all stacks in a BackendStage and emit warnings/errors.

Emits a warning if any stack has more than 400 resources.
Fails the test if any stack has more than 475 resources.

:param stage: The BackendStage containing stacks to check
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love this!

Comment on lines +6 to +19
class BackupsApp(App):
def __init__(self, *args, **kwargs):
"""
An app for deploying data retention backup destination infrastructure in the backup account.
This application creates the centralized backup infrastructure that receives and stores
backup copies from CompactConnect environment accounts:
- Cross-account backup vaults (general and SSN-specific)
- Customer-managed KMS keys for backup encryption
- Organization-level access policies for secure cross-account backup operations
Environment account backup infrastructure (local vaults, IAM roles, backup plans)
is managed by the CompactConnect application deployment.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I recall correctly, it was mentioned that if these vaults don't exist in the secondary backup account for whatever reason, the application pipeline deployments will still succeed, but the backup processes will silently fail. If this is true, is there a way we can add alerting for this in prod? We will need to know if the backup processes are failing for whatever reason.

AWSTemplateFormatVersion: "2010-09-09"

Description: >
This template creates the IAM role required for the "How to secure recovery with cross-account backup and cross-Region copy using AWS Backuap" blog in each member account.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This description is a little confusing, and has some typos. Can we find a way to reword this?

Comment on lines +4 to +5
Description: >
This template creates backup vault(cabvault) required for the "How to secure recovery with cross-account backup and cross-Region copy using AWS Backup" blog.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, this is needed for a blog? Or is it copied over from a blog that demonstrated this setup?

We are moving towards a setup where test and prod will have their
own respective secondary accounts to which we will replicate their
backups to. This updates the readme to reflect that change.
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.

Define retention policy
2 participants