Skip to content
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

create-irsa-role-for-ebs-driver #212

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add tags from `AWSCluster.Spec.AdditionalTags` and `AWSManagedControlPlane.Spec.AdditionalTags` to all created resources.
- Add IRSA role for EBS CSI driver.

## [0.11.0] - 2023-11-01

Expand Down
136 changes: 136 additions & 0 deletions pkg/iam/ebs_csi_driver_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package iam

const EBSCSIDriverPolicyTemplate = `{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:CreateSnapshot",
"ec2:AttachVolume",
"ec2:DetachVolume",
"ec2:ModifyVolume",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeInstances",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeVolumes",
"ec2:DescribeVolumesModifications"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateTags"
],
"Resource": [
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:snapshot/*"
],
"Condition": {
"StringEquals": {
"ec2:CreateAction": [
"CreateVolume",
"CreateSnapshot"
]
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteTags"
],
"Resource": [
"arn:aws:ec2:*:*:volume/*",
"arn:aws:ec2:*:*:snapshot/*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateVolume"
],
"Resource": "*",
"Condition": {
"StringLike": {
"aws:RequestTag/ebs.csi.aws.com/cluster": "true"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateVolume"
],
"Resource": "*",
"Condition": {
"StringLike": {
"aws:RequestTag/CSIVolumeName": "*"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteVolume"
],
"Resource": "*",
"Condition": {
"StringLike": {
"ec2:ResourceTag/ebs.csi.aws.com/cluster": "true"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteVolume"
],
"Resource": "*",
"Condition": {
"StringLike": {
"ec2:ResourceTag/CSIVolumeName": "*"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteVolume"
],
"Resource": "*",
"Condition": {
"StringLike": {
"ec2:ResourceTag/kubernetes.io/created-for/pvc/name": "*"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteSnapshot"
],
"Resource": "*",
"Condition": {
"StringLike": {
"ec2:ResourceTag/CSIVolumeSnapshotName": "*"
}
}
},
{
"Effect": "Allow",
"Action": [
"ec2:DeleteSnapshot"
],
"Resource": "*",
"Condition": {
"StringLike": {
"ec2:ResourceTag/ebs.csi.aws.com/cluster": "true"
}
}
}
]
}
`
7 changes: 5 additions & 2 deletions pkg/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
IRSARole = "irsa-role"
CertManagerRole = "cert-manager-role"
ALBConrollerRole = "ALBController-Role"
EBSCSIDriverRole = "ebs-csi-driver-role"

IAMControllerOwnedTag = "capi-iam-controller/owned"
ClusterIDTag = "sigs.k8s.io/cluster-api-provider-aws/cluster/%s"
Expand Down Expand Up @@ -156,7 +157,7 @@ func (s *IAMService) ReconcileKiamRole() error {
func (s *IAMService) ReconcileRolesForIRSA(awsAccountID string, cloudFrontDomain string) error {
s.log.Info("reconciling IAM roles for IRSA")

for _, roleTypeToReconcile := range []string{Route53Role, CertManagerRole, ALBConrollerRole} {
for _, roleTypeToReconcile := range []string{Route53Role, CertManagerRole, ALBConrollerRole, EBSCSIDriverRole} {
var params Route53RoleParams
params, err := s.generateRoute53RoleParams(roleTypeToReconcile, awsAccountID, cloudFrontDomain)
if err != nil {
Expand Down Expand Up @@ -667,7 +668,9 @@ func getServiceAccount(role string) (string, error) {
return "external-dns", nil
} else if role == ALBConrollerRole {
return "aws-load-balancer-controller", nil
} else if role == EBSCSIDriverRole {
return "ebs-csi-controller-sa", nil
}

return "", fmt.Errorf("Cannot get service account for specified role - %s", role)
return "", fmt.Errorf("cannot get service account for specified role - %s", role)
}
5 changes: 5 additions & 0 deletions pkg/iam/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func getInlinePolicyTemplate(roleType string) string {
return route53RolePolicyTemplateForCertManager
case ALBConrollerRole:
return ALBControllerPolicyTemplate
case EBSCSIDriverRole:
return EBSCSIDriverPolicyTemplate
default:
return ""
}
Expand All @@ -76,6 +78,9 @@ func getTrustPolicyTemplate(roleType string) string {
return trustIdentityPolicyKIAMAndIRSA
case ALBConrollerRole:
return trustIdentityPolicyKIAMAndIRSA
case EBSCSIDriverRole:
return trustIdentityPolicyKIAMAndIRSA

default:
return ""
}
Expand Down