Skip to content
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

feat(backup): add disableDefaultBackupPolicy property to selection #27925

Merged
merged 9 commits into from
Nov 21, 2023

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Nov 10, 2023

This PR adds a new property disableDefaultBackupPolicy for BackupSelection. Setting this to true (a default value is false) disables the default role policy AWSBackupServiceRolePolicyForBackup attachment.

Closes #27900.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team November 10, 2023 12:12
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Nov 10, 2023
@go-to-k go-to-k marked this pull request as ready for review November 10, 2023 12:16
@go-to-k go-to-k changed the title feat(backup): add allowBackups property to selection feat(backup): add attachBackupPolicy property to selection Nov 10, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 10, 2023
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks, the implementation looks good!
Just some suggestions on a different name for the variable and documentation adjustments.

Comment on lines 34 to 41
/**
* Whether to automatically give backup permissions to the role that AWS
* Backup uses. If `true`, the `AWSBackupServiceRolePolicyForBackup` managed
* policy will be attached to the role.
*
* @default true
*/
readonly attachBackupPolicy?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* Whether to automatically give backup permissions to the role that AWS
* Backup uses. If `true`, the `AWSBackupServiceRolePolicyForBackup` managed
* policy will be attached to the role.
*
* @default true
*/
readonly attachBackupPolicy?: boolean;
/**
* Whether to disable automatically assigning default backup permissions to the role
* that AWS Backup uses.
* If `true`, the `AWSBackupServiceRolePolicyForBackup` managed policy will be
* attached to the role.
*
* @default - false
*/
readonly disableDefaultBackupPolicy?: boolean;

Comment on lines 62 to 94
You can set `attachBackupPolicy` to false and attach your role to the plan
if you don't want to use the managed policy.

```ts
declare const plan: backup.BackupPlan;

const role = new iam.Role(this, 'BackupRole', {
assumedBy: new iam.ServicePrincipal('backup.amazonaws.com'),
});
role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSBackupServiceRolePolicyForS3Backup'));
role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSBackupServiceRolePolicyForS3Restore'));

plan.addSelection('Selection', {
resources: [
backup.BackupResource.fromTag('stage', 'prod'),
],
role,
attachBackupPolicy: false,
});
```

A managed policy for restores will be attached to the role by setting
`allowRestores` to true.

```ts
declare const plan: backup.BackupPlan;

plan.addSelection('Selection', {
resources: [
backup.BackupResource.fromTag('stage', 'prod'),
],
allowRestores: true,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
You can set `attachBackupPolicy` to false and attach your role to the plan
if you don't want to use the managed policy.
```ts
declare const plan: backup.BackupPlan;
const role = new iam.Role(this, 'BackupRole', {
assumedBy: new iam.ServicePrincipal('backup.amazonaws.com'),
});
role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSBackupServiceRolePolicyForS3Backup'));
role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSBackupServiceRolePolicyForS3Restore'));
plan.addSelection('Selection', {
resources: [
backup.BackupResource.fromTag('stage', 'prod'),
],
role,
attachBackupPolicy: false,
});
```
A managed policy for restores will be attached to the role by setting
`allowRestores` to true.
```ts
declare const plan: backup.BackupPlan;
plan.addSelection('Selection', {
resources: [
backup.BackupResource.fromTag('stage', 'prod'),
],
allowRestores: true,
});
To disable the plan from assigning the default `AWSBackupServiceRolePolicyForBackup` backup policy use the `disableDefaultBackupPolicy` property.
This is useful if you want to avoid granting unnecessary permissions to the role.
```ts
declare const plan: backup.BackupPlan;
const role = new iam.Role(this, 'BackupRole', {
assumedBy: new iam.ServicePrincipal('backup.amazonaws.com'),
});
// Assign S3-specific backup policy
role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSBackupServiceRolePolicyForS3Backup'));
plan.addSelection('Selection', {
resources: [
backup.BackupResource.fromTag('stage', 'prod'),
],
role,
disableDefaultBackupPolicy: true,
});

Idea for revision, feel free to improve.

@@ -25,13 +25,21 @@ export interface BackupSelectionOptions {

/**
* The role that AWS Backup uses to authenticate when backuping or restoring
* the resources. The `AWSBackupServiceRolePolicyForBackup` managed policy
* will be attached to this role.
* the resources.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* the resources.
* The `AWSBackupServiceRolePolicyForBackup` managed policy
* will be attached to this role unless `disableDefaultBackupPolicy`
* is set to `true`.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 10, 2023
@go-to-k
Copy link
Contributor Author

go-to-k commented Nov 12, 2023

@lpizzinidev

Thanks for your review! I changed them.

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me 👍
Can you please update the title to use the new property name?

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 13, 2023
@go-to-k go-to-k changed the title feat(backup): add attachBackupPolicy property to selection feat(backup): add disableDefaultBackupPolicy property to selection Nov 13, 2023
sumupitchayan
sumupitchayan previously approved these changes Nov 13, 2023
Copy link
Contributor

@sumupitchayan sumupitchayan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Copy link
Contributor

mergify bot commented Nov 13, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 13, 2023
Copy link
Contributor

mergify bot commented Nov 13, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@go-to-k
Copy link
Contributor Author

go-to-k commented Nov 14, 2023

@sumupitchayan

Thanks for the approval! But the Queue: Embarked in merge queue failed. Could you please handle this?

@mergify mergify bot dismissed sumupitchayan’s stale review November 20, 2023 22:00

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 20, 2023
sumupitchayan
sumupitchayan previously approved these changes Nov 20, 2023
@mergify mergify bot dismissed sumupitchayan’s stale review November 20, 2023 22:34

Pull request has been modified.

sumupitchayan
sumupitchayan previously approved these changes Nov 21, 2023
@mergify mergify bot dismissed sumupitchayan’s stale review November 21, 2023 14:22

Pull request has been modified.

Copy link
Contributor

mergify bot commented Nov 21, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 21, 2023
Copy link
Contributor

mergify bot commented Nov 21, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: ac2fd9f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 55ffb3c into aws:main Nov 21, 2023
10 checks passed
Copy link
Contributor

mergify bot commented Nov 21, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@go-to-k go-to-k deleted the feat/backup-selection-role branch November 22, 2023 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@aws_cdk.aws_backup]: BackupSelection default role policy
5 participants