Skip to content

Commit

Permalink
[aws][feat] Integrate Backup Service collection (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Jun 17, 2024
1 parent 4df872b commit 48acc1c
Show file tree
Hide file tree
Showing 16 changed files with 1,341 additions and 6 deletions.
2 changes: 2 additions & 0 deletions plugins/aws/fix_plugin_aws/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
opensearch,
acm,
waf,
backup,
)
from fix_plugin_aws.resource.base import AwsAccount, AwsApiSpec, AwsRegion, AwsResource, GraphBuilder
from fixlib.baseresources import Cloud, EdgeType, BaseOrganizationalRoot, BaseOrganizationalUnit
Expand Down Expand Up @@ -103,6 +104,7 @@
+ ssm.resources
+ sqs.resources
+ redshift.resources
+ backup.resources
)
all_resources: List[Type[AwsResource]] = global_resources + regional_resources

Expand Down
939 changes: 939 additions & 0 deletions plugins/aws/fix_plugin_aws/resource/backup.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions plugins/aws/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def count_kind(clazz: Type[AwsResource]) -> int:
return count

for resource in all_resources:
assert count_kind(resource) > 0, "No instances of {} found".format(resource.__name__)
assert count_kind(resource) > 0, f"No instances of {resource.__name__} found"

# make sure all threads have been joined
assert len(threading.enumerate()) == 1
# ensure the correct number of nodes and edges
assert count_kind(AwsResource) == 225
assert len(account_collector.graph.edges) == 519
assert count_kind(AwsResource) == 236
assert len(account_collector.graph.edges) == 540
assert len(account_collector.graph.deferred_edges) == 2
for node in account_collector.graph.nodes:
if isinstance(node, AwsRegion):
Expand Down
59 changes: 59 additions & 0 deletions plugins/aws/test/resources/backup_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from fix_plugin_aws.resource.backup import (
AwsBackupJob,
AwsBackupPlan,
AwsBackupVault,
AwsBackupRecoveryPoint,
AwsBackupProtectedResource,
AwsBackupReportPlan,
AwsBackupRestoreTestingPlan,
AwsBackupLegalHold,
AwsBackupRestoreJob,
AwsBackupCopyJob,
AwsBackupFramework,
)
from test.resources import round_trip_for, build_graph


def test_backup_jobs() -> None:
round_trip_for(AwsBackupJob)


def test_backup_plans() -> None:
round_trip_for(AwsBackupPlan)


def test_backup_vaults() -> None:
round_trip_for(AwsBackupVault)


def test_backup_recovery_points() -> None:
builder = build_graph(AwsBackupVault)
assert len(list(builder.nodes(AwsBackupRecoveryPoint))) > 0


def test_backup_protected_resources() -> None:
round_trip_for(AwsBackupProtectedResource)


def test_backup_report_plans() -> None:
round_trip_for(AwsBackupReportPlan)


def test_backup_restore_testing_plans() -> None:
round_trip_for(AwsBackupRestoreTestingPlan)


def test_backup_legal_holds() -> None:
round_trip_for(AwsBackupLegalHold)


def test_backup_restore_jobs() -> None:
round_trip_for(AwsBackupRestoreJob)


def test_backup_copy_jobs() -> None:
round_trip_for(AwsBackupCopyJob)


def test_backup_frameworks() -> None:
round_trip_for(AwsBackupFramework)
39 changes: 39 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"BackupJobs": [
{
"BackupJobId": "1234567890abcdef",
"CreationDate": "2023-03-15T12:34:56.789Z",
"AccountId": "123456789012",
"BackupVaultName": "MyBackupVault",
"BackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
"RecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
"CompletionDate": "2023-03-15T13:34:56.789Z",
"State": "COMPLETED",
"StatusMessage": "Backup completed successfully",
"PercentDone": 100,
"BackupSizeInBytes": 1024,
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
"CreatedBy": {
"BackupPlanId": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanVersion": "1234567890abcdef",
"BackupRuleId": "MyBackupRule"
},
"ExpectedCompletionDate": "2023-03-15T13:34:56.789Z",
"StartBy": "2023-03-15T12:34:56.789Z",
"ResourceType": "EC2",
"BytesTransferred": 1024,
"BackupOptions": {
"WindowsVSS": "enabled"
},
"BackupType": "FULL",
"ParentJobId": "1234567890abcdef",
"IsParent": true,
"ResourceName": "MyEC2Instance",
"InitiationDate": "2023-03-15T12:34:56.789Z",
"MessageCategory": "SUCCESS"
}
],
"NextToken": "foo"
}
23 changes: 23 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-plans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"NextToken": "foo",
"BackupPlansList": [
{
"BackupPlanId": "8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanName": "MyBackupPlan",
"CreationDate": "2023-03-15T12:34:56.789Z",
"DeletionDate": "2023-03-16T12:34:56.789Z",
"VersionId": "1234567890abcdef",
"CreatorRequestId": "my-unique-request-id",
"LastExecutionDate": "2023-03-14T12:34:56.789Z",
"AdvancedBackupSettings": [
{
"ResourceType": "EC2",
"BackupOptions": {
"WindowsVSS": "enabled"
}
}
]
}
]
}
17 changes: 17 additions & 0 deletions plugins/aws/test/resources/files/backup/list-backup-vaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"BackupVaultList": [
{
"BackupVaultName": "MyBackupVault",
"BackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
"CreationDate": "2023-03-15T12:34:56.789Z",
"EncryptionKeyArn": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"CreatorRequestId": "my-unique-request-id",
"NumberOfRecoveryPoints": 10,
"Locked": false,
"MinRetentionDays": 30,
"MaxRetentionDays": 365,
"LockDate": "2023-03-16T12:34:56.789Z"
}
],
"NextToken": "foo"
}
36 changes: 36 additions & 0 deletions plugins/aws/test/resources/files/backup/list-copy-jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"CopyJobs": [
{
"CopyJobId": "1234567890abcdef",
"CreationDate": "2023-03-15T12:34:56.789Z",
"AccountId": "123456789012",
"SourceBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MySourceVault",
"SourceRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"DestinationBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyDestinationVault",
"DestinationRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:2EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
"CompletionDate": "2023-03-15T13:34:56.789Z",
"State": "COMPLETED",
"StatusMessage": "Copy completed successfully",
"BackupSizeInBytes": 1024,
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
"CreatedBy": {
"BackupPlanId": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanVersion": "1234567890abcdef",
"BackupRuleId": "MyBackupRule"
},
"ResourceType": "EC2",
"ParentJobId": "1234567890abcdef",
"IsParent": true,
"CompositeMemberIdentifier": "MyEC2Instance",
"NumberOfChildJobs": 1,
"ChildJobsInState": {
"COMPLETED": 1
},
"ResourceName": "MyEC2Instance",
"MessageCategory": "SUCCESS"
}
],
"NextToken": "foo"
}
13 changes: 13 additions & 0 deletions plugins/aws/test/resources/files/backup/list-frameworks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Frameworks": [
{
"FrameworkArn": "arn:aws:backup:us-east-1:123456789012:framework:MyFramework",
"FrameworkName": "MyFramework",
"FrameworkDescription": "My framework description",
"NumberOfControls": 10,
"CreationTime": "2023-03-15T12:34:56.789Z",
"DeploymentStatus": "COMPLETED"
}
],
"NextToken": "foo"
}
14 changes: 14 additions & 0 deletions plugins/aws/test/resources/files/backup/list-legal-holds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"NextToken": "foo",
"LegalHolds": [
{
"LegalHoldId": "1234567890abcdef",
"CreationDate": "2023-03-15T12:34:56.789Z",
"Title": "My Legal Hold",
"Status": "ACTIVE",
"Description": "My legal hold description",
"LegalHoldArn": "arn:aws:backup:us-east-1:123456789012:legal-hold:1234567890abcdef",
"CancellationDate": "2023-03-16T12:34:56.789Z"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Results": [
{
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
"ResourceName": "MyEC2Instance",
"ResourceType": "EC2",
"LastBackupTime": "2023-03-15T12:34:56.789Z",
"LastBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
"LastRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45"
}
],
"NextToken": "foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"NextToken": "foo",
"RecoveryPoints": [
{
"RecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"CreationDate": "2023-03-15T12:34:56.789Z",
"BackupVaultName": "MyBackupVault",
"BackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
"SourceBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
"ResourceType": "EC2",
"RecoveryPointCreatedBy": {
"BackupPlanId": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
"BackupPlanVersion": "1234567890abcdef",
"BackupRuleId": "MyBackupRule"
},
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
"Status": "COMPLETED",
"StatusMessage": "Recovery point created successfully",
"CompletionDate": "2023-03-15T13:34:56.789Z",
"BackupSizeInBytes": 1024,
"CalculatedLifecycle": {
"MoveToColdStorageAt": "2023-03-22T12:34:56.789Z",
"DeleteAt": "2023-03-29T12:34:56.789Z"
},
"Lifecycle": {
"MoveToColdStorageAfterDays": 7,
"DeleteAfterDays": 14,
"OptInToArchiveForSupportedResources": true
},
"EncryptionKeyArn": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"IsEncrypted": true,
"LastRestoreTime": "2023-03-16T12:34:56.789Z",
"ParentRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"CompositeMemberIdentifier": "MyEC2Instance",
"IsParent": false,
"ResourceName": "MyEC2Instance",
"VaultType": "STANDARD"
}
]
}
42 changes: 42 additions & 0 deletions plugins/aws/test/resources/files/backup/list-report-plans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"ReportPlans": [
{
"ReportPlanArn": "arn:aws:backup:us-east-1:123456789012:report-plan:MyReportPlan",
"ReportPlanName": "MyReportPlan",
"ReportPlanDescription": "My report plan description",
"ReportSetting": {
"ReportTemplate": "RESOURCE_COMPLIANCE_REPORT",
"FrameworkArns": [
"arn:aws:backup:us-east-1:123456789012:framework:MyFramework"
],
"NumberOfFrameworks": 1,
"Accounts": [
"123456789012"
],
"OrganizationUnits": [
"ou-1234567890abcdef0"
],
"Regions": [
"us-east-1"
]
},
"DeploymentStatus": "DEPLOYED",
"ReportDeliveryChannel": {
"S3BucketName": "my-report-bucket",
"S3KeyPrefix": "backup-reports",
"Formats": [
"CSV",
"JSON"
]
},
"CreatedBy": {
"RestoreTestingPlanArn": "arn:aws:backup:us-east-1:123456789012:restore-testing-plan:MyRestoreTestingPlan"
},
"PlanDeploymentStatus": "COMPLETED",
"CreationTime": "2023-03-15T12:34:56.789Z",
"LastAttemptedExecutionTime": "2023-03-16T12:34:56.789Z",
"LastSuccessfulExecutionTime": "2023-03-15T12:34:56.789Z"
}
],
"NextToken": "foo"
}
28 changes: 28 additions & 0 deletions plugins/aws/test/resources/files/backup/list-restore-jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"RestoreJobs": [
{
"RestoreJobId": "1234567890abcdef",
"CreationDate": "2023-03-15T12:34:56.789Z",
"AccountId": "123456789012",
"RecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
"CompletionDate": "2023-03-15T13:34:56.789Z",
"Status": "COMPLETED",
"StatusMessage": "Restore completed successfully",
"PercentDone": 100,
"BackupSizeInBytes": 1024,
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
"ExpectedCompletionTimeMinutes": 60,
"CreatedResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
"ResourceType": "EC2",
"RecoveryPointCreationDate": "2023-03-15T12:34:56.789Z",
"CreatedBy": {
"RestoreTestingPlanArn": "arn:aws:backup:us-east-1:123456789012:restore-testing-plan:MyRestoreTestingPlan"
},
"ValidationStatus": "SUCCESSFUL",
"ValidationStatusMessage": "Restore validation successful",
"DeletionStatus": "SUCCESSFUL",
"DeletionStatusMessage": "Restore test data deleted successfully"
}
],
"NextToken": "foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"NextToken": "foo",
"RestoreTestingPlans": [
{
"RestoreTestingPlanArn": "arn:aws:backup:us-east-1:123456789012:restore-testing-plan:MyRestoreTestingPlan",
"RestoreTestingPlanName": "MyRestoreTestingPlan",
"CreationTime": "2023-03-15T12:34:56.789Z",
"LastUpdateTime": "2023-03-16T12:34:56.789Z",
"LastExecutionTime": "2023-03-15T12:34:56.789Z",
"ScheduleExpression": "cron(0 0 * * ? *)",
"ScheduleExpressionTimezone": "UTC",
"StartWindowHours": 24
}
]
}
Loading

0 comments on commit 48acc1c

Please sign in to comment.