Skip to content

Commit d4059a9

Browse files
authored
Merge pull request ekristen#605 from oreillymedia/backup-vault-policy-fix
fix(backup-vaults-access-policies): Allow cross-account assumed roles to delete Backup Vault Policies
2 parents 04a7e5d + a9cae71 commit d4059a9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

resources/backup-vaults-access-policies.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/ekristen/libnuke/pkg/registry"
88
"github.com/ekristen/libnuke/pkg/resource"
99

10+
"fmt"
11+
1012
"github.com/aws/aws-sdk-go/service/backup"
1113
)
1214

@@ -60,6 +62,7 @@ func (l *AWSBackupVaultAccessPolicyLister) List(_ context.Context, o interface{}
6062
if resp.Policy != nil {
6163
resources = append(resources, &BackupVaultAccessPolicy{
6264
svc: svc,
65+
accountID: opts.AccountID,
6366
backupVaultName: *out.BackupVaultName,
6467
})
6568
}
@@ -70,6 +73,7 @@ func (l *AWSBackupVaultAccessPolicyLister) List(_ context.Context, o interface{}
7073

7174
type BackupVaultAccessPolicy struct {
7275
svc *backup.Backup
76+
accountID *string
7377
backupVaultName string
7478
}
7579

@@ -105,19 +109,19 @@ func (b *BackupVaultAccessPolicy) Remove(_ context.Context) error {
105109
//
106110
// While deletion is Denied, you can update the policy with one that
107111
// doesn't deny and then delete at will.
108-
allowDeletionPolicy := `{
109-
"Version": "2012-10-17",
110-
"Statement": [
111-
{
112-
"Effect": "Allow",
113-
"Principal": {
114-
"AWS": "*"
115-
},
116-
"Action": "backup:DeleteBackupVaultAccessPolicy",
117-
"Resource": "*"
118-
}
119-
]
120-
}`
112+
allowDeletionPolicy := fmt.Sprintf(`{
113+
"Version": "2012-10-17",
114+
"Statement": [
115+
{
116+
"Effect": "Allow",
117+
"Principal": {
118+
"AWS": "arn:aws:iam::%s:root"
119+
},
120+
"Action": "backup:DeleteBackupVaultAccessPolicy",
121+
"Resource": "*"
122+
}
123+
]
124+
}`, *b.accountID)
121125
// Ignore error from if we can't put permissive backup vault policy in for some reason, that's OK.
122126
_, _ = b.svc.PutBackupVaultAccessPolicy(&backup.PutBackupVaultAccessPolicyInput{
123127
BackupVaultName: &b.backupVaultName,

0 commit comments

Comments
 (0)