Skip to content

Commit

Permalink
fix route53 policy parameter calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Berk Dehrioglu committed Jan 2, 2024
1 parent 2e793e3 commit b472ee1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions pkg/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ type IAMService struct {
}

type Route53RoleParams struct {
EC2ServiceDomain string
AccountID string
CloudFrontDomain string
Namespace string
ServiceAccount string
PrincipalRoleARN string
IsMigrate bool
EC2ServiceDomain string
AccountID string
CloudFrontDomain string
AdditionalCloudFrontDomain string
Namespace string
ServiceAccount string
PrincipalRoleARN string
}

func New(config IAMServiceConfig) (*IAMService, error) {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (s *IAMService) ReconcileRolesForIRSA(awsAccountID string, cloudFrontDomain
return nil
}

func (s *IAMService) generateRoute53RoleParams(roleTypeToReconcile string, awsAccountID string, cloudFrontDomain string, oldCloudFrontDomain string) (Route53RoleParams, error) {
func (s *IAMService) generateRoute53RoleParams(roleTypeToReconcile string, awsAccountID string, cloudFrontDomain string, additionalCloudFrontDomain string) (Route53RoleParams, error) {
namespace := "kube-system"
serviceAccount, err := getServiceAccount(roleTypeToReconcile)
if err != nil {
Expand All @@ -194,9 +194,8 @@ func (s *IAMService) generateRoute53RoleParams(roleTypeToReconcile string, awsAc
ServiceAccount: serviceAccount,
}

if oldCloudFrontDomain != "" {
params.IsMigrate = true
params.CloudFrontDomain = oldCloudFrontDomain
if additionalCloudFrontDomain != "" {
params.AdditionalCloudFrontDomain = additionalCloudFrontDomain
}

return params, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/iam/route53_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ const trustIdentityPolicyIRSA = `{
"{{.CloudFrontDomain}}:sub": "system:serviceaccount:{{.Namespace}}:{{.ServiceAccount}}"
}
}
}{{if .IsMigrate}},
}{{if .AdditionalCloudFrontDomain}},
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::{{.AccountID}}:oidc-provider/{{.OldCloudFrontDomain}}"
"Federated": "arn:aws:iam::{{.AccountID}}:oidc-provider/{{.AdditionalCloudFrontDomain}}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"{{.OldCloudFrontDomain}}:sub": "system:serviceaccount:{{.Namespace}}:{{.ServiceAccount}}"
"{{.AdditionalCloudFrontDomain}}:sub": "system:serviceaccount:{{.Namespace}}:{{.ServiceAccount}}"
}
}
}
Expand Down

0 comments on commit b472ee1

Please sign in to comment.