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

Fix permissive access policy for backup vaults #1110

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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