-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
There was a problem hiding this 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.
/** | ||
* 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* 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; |
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, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* the resources. | |
* The `AWSBackupServiceRolePolicyForBackup` managed policy | |
* will be attached to this role unless `disableDefaultBackupPolicy` | |
* is set to `true`. |
Thanks for your review! I changed them. |
There was a problem hiding this 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?
There was a problem hiding this 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!
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). |
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). |
Thanks for the approval! But the |
Pull request has been modified.
Pull request has been modified.
Pull request has been modified.
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). |
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
This PR adds a new property
disableDefaultBackupPolicy
forBackupSelection
. Setting this to true (a default value is false) disables the default role policyAWSBackupServiceRolePolicyForBackup
attachment.Closes #27900.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license