Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Fix permissive access policy for backup vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ppmathis committed Oct 28, 2023
1 parent 4e8c0c5 commit 4192726
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion resources/backup-vaults-access-policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/backup"
"github.com/aws/aws-sdk-go/service/sts"
)

type BackupVaultAccessPolicy struct {
svc *backup.Backup
backupVaultName string
accountId string
}

func init() {
register("AWSBackupVaultAccessPolicy", ListBackupVaultAccessPolicies)
}

func ListBackupVaultAccessPolicies(sess *session.Session) ([]Resource, error) {
// Lookup current account ID, which is required for building a permissive vault policy
stsSvc := sts.New(sess)
identity, err := stsSvc.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err != nil {
return nil, err
}
accountId := *identity.Account

svc := backup.New(sess)
maxVaultsLen := int64(100)
params := &backup.ListBackupVaultsInput{
Expand Down Expand Up @@ -50,6 +60,7 @@ func ListBackupVaultAccessPolicies(sess *session.Session) ([]Resource, error) {
resources = append(resources, &BackupVaultAccessPolicy{
svc: svc,
backupVaultName: *out.BackupVaultName,
accountId: accountId,
})
}
}
Expand Down Expand Up @@ -95,7 +106,7 @@ func (b *BackupVaultAccessPolicy) Remove() error {
{
"Effect": "Allow",
"Principal": {
"AWS": "*"
"AWS": "arn:aws:iam::` + b.accountId + `:root"
},
"Action": "backup:DeleteBackupVaultAccessPolicy",
"Resource": "*"
Expand Down

0 comments on commit 4192726

Please sign in to comment.