Skip to content

Commit

Permalink
Merge pull request #11571 from olemarkus/snapshot-tighten-deletion
Browse files Browse the repository at this point in the history
Only allow deletion of snapshots owned by the cluster
  • Loading branch information
k8s-ci-robot committed May 23, 2021
2 parents 9235f35 + 0004bce commit 5e720e9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/model/iam/iam_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (r *NodeRoleMaster) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
}

if b.Cluster.Spec.SnapshotController != nil && fi.BoolValue(b.Cluster.Spec.SnapshotController.Enabled) {
addSnapshotPersmissions(p)
addSnapshotPersmissions(p, b.Cluster.GetName())
}
return p, nil
}
Expand Down Expand Up @@ -783,17 +783,29 @@ func AddAWSLoadbalancerControllerPermissions(p *Policy, resource stringorslice.S
)
}

func addSnapshotPersmissions(p *Policy) {
func addSnapshotPersmissions(p *Policy, clusterName string) {
p.Statement = append(p.Statement, &Statement{
Effect: StatementEffectAllow,
Action: stringorslice.Of(
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeSnapshots",
),
Resource: stringorslice.Slice([]string{"*"}),
})
p.Statement = append(p.Statement, &Statement{
Effect: StatementEffectAllow,
Action: stringorslice.Of(
"ec2:DeleteSnapshot",
),
Resource: stringorslice.Slice([]string{"*"}),
Condition: Condition{
"StringEquals": map[string]string{
"aws:ResourceTag/KubernetesCluster": clusterName,
},
},
})

}

// addLegacyDNSControllerPermissions adds legacy IAM permissions used by the node roles.
Expand Down

0 comments on commit 5e720e9

Please sign in to comment.