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

Use IAMPrefix() for hostedzone #8366

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/model/iam/iam_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (b *PolicyBuilder) BuildAWSPolicyMaster() (*Policy, error) {
}

if b.HostedZoneID != "" {
addRoute53Permissions(p, b.HostedZoneID)
b.addRoute53Permissions(p, b.HostedZoneID)
}

if b.Cluster.Spec.IAM.Legacy {
Expand Down Expand Up @@ -212,7 +212,7 @@ func (b *PolicyBuilder) BuildAWSPolicyNode() (*Policy, error) {

if b.Cluster.Spec.IAM.Legacy {
if b.HostedZoneID != "" {
addRoute53Permissions(p, b.HostedZoneID)
b.addRoute53Permissions(p, b.HostedZoneID)
}
addRoute53ListHostedZonesPermission(p)
}
Expand Down Expand Up @@ -536,10 +536,12 @@ func addECRPermissions(p *Policy) {
})
}

func addRoute53Permissions(p *Policy, hostedZoneID string) {
func (b *PolicyBuilder) addRoute53Permissions(p *Policy, hostedZoneID string) {

// TODO: Route53 currently not supported in China, need to check and fail/return

//if b.IAMPrefix() == "arn:aws-cn" {
lazzarello marked this conversation as resolved.
Show resolved Hide resolved
//
//}
// Remove /hostedzone/ prefix (if present)
hostedZoneID = strings.TrimPrefix(hostedZoneID, "/")
hostedZoneID = strings.TrimPrefix(hostedZoneID, "hostedzone/")
Expand All @@ -549,13 +551,13 @@ func addRoute53Permissions(p *Policy, hostedZoneID string) {
Action: stringorslice.Of("route53:ChangeResourceRecordSets",
"route53:ListResourceRecordSets",
"route53:GetHostedZone"),
Resource: stringorslice.Slice([]string{"arn:aws:route53:::hostedzone/" + hostedZoneID}),
Resource: stringorslice.Slice([]string{b.IAMPrefix() + ":route53:::hostedzone/" + hostedZoneID}),
})

p.Statement = append(p.Statement, &Statement{
Effect: StatementEffectAllow,
Action: stringorslice.Slice([]string{"route53:GetChange"}),
Resource: stringorslice.Slice([]string{"arn:aws:route53:::change/*"}),
Resource: stringorslice.Slice([]string{b.IAMPrefix() + ":route53:::change/*"}),
})

wildcard := stringorslice.Slice([]string{"*"})
Expand Down