-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(route53): add support for grantDelegation on imported PublicHostedZone #26333
Changes from 2 commits
cfba443
76fde39
1c6d8aa
50bc8ee
6690af4
9594bf0
7523cdd
f9b5daa
d651da1
f7f1898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { HostedZoneProviderProps } from './hosted-zone-provider'; | |
import { HostedZoneAttributes, IHostedZone, PublicHostedZoneAttributes } from './hosted-zone-ref'; | ||
import { CaaAmazonRecord, ZoneDelegationRecord } from './record-set'; | ||
import { CfnHostedZone } from './route53.generated'; | ||
import { makeHostedZoneArn, validateZoneName } from './util'; | ||
import { makeGrantDelegation, makeHostedZoneArn, validateZoneName } from './util'; | ||
import * as ec2 from '../../aws-ec2'; | ||
import * as iam from '../../aws-iam'; | ||
import * as cxschema from '../../cloud-assembly-schema'; | ||
|
@@ -238,7 +238,12 @@ export interface PublicHostedZoneProps extends CommonHostedZoneProps { | |
/** | ||
* Represents a Route 53 public hosted zone | ||
*/ | ||
export interface IPublicHostedZone extends IHostedZone { } | ||
export interface IPublicHostedZone extends IHostedZone { | ||
/** | ||
* Grant permissions to add delegation records to this zone | ||
*/ | ||
grantDelegation(grantee: iam.IGrantable): void; | ||
} | ||
|
||
/** | ||
* Create a Route53 public hosted zone. | ||
|
@@ -264,6 +269,9 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone { | |
public get hostedZoneArn(): string { | ||
return makeHostedZoneArn(this, this.hostedZoneId); | ||
} | ||
public grantDelegation(grantee: iam.IGrantable) { | ||
makeGrantDelegation(grantee, this.hostedZoneArn); | ||
}; | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
@@ -284,6 +292,9 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone { | |
public get hostedZoneArn(): string { | ||
return makeHostedZoneArn(this, this.hostedZoneId); | ||
} | ||
public grantDelegation(grantee: iam.IGrantable) { | ||
makeGrantDelegation(grantee, this.hostedZoneArn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
}; | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
@@ -354,28 +365,8 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone { | |
}); | ||
} | ||
|
||
/** | ||
* Grant permissions to add delegation records to this zone | ||
*/ | ||
public grantDelegation(grantee: iam.IGrantable) { | ||
const g1 = iam.Grant.addToPrincipal({ | ||
grantee, | ||
actions: ['route53:ChangeResourceRecordSets'], | ||
resourceArns: [this.hostedZoneArn], | ||
conditions: { | ||
'ForAllValues:StringEquals': { | ||
'route53:ChangeResourceRecordSetsRecordTypes': ['NS'], | ||
'route53:ChangeResourceRecordSetsActions': ['UPSERT', 'DELETE'], | ||
}, | ||
}, | ||
}); | ||
const g2 = iam.Grant.addToPrincipal({ | ||
grantee, | ||
actions: ['route53:ListHostedZonesByName'], | ||
resourceArns: ['*'], | ||
}); | ||
|
||
return g1.combine(g2); | ||
makeGrantDelegation(grantee, this.hostedZoneArn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Construct } from 'constructs'; | ||
import { IHostedZone } from './hosted-zone-ref'; | ||
import * as iam from '../../aws-iam'; | ||
import { Stack } from '../../core'; | ||
|
||
/** | ||
|
@@ -69,3 +70,24 @@ export function makeHostedZoneArn(construct: Construct, hostedZoneId: string): s | |
resourceName: hostedZoneId, | ||
}); | ||
} | ||
|
||
export function makeGrantDelegation(grantee: iam.IGrantable, hostedZoneArn: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please specify the return type in the function definition (looks like iam.Grant or iam.IGrantable) |
||
const g1 = iam.Grant.addToPrincipal({ | ||
grantee, | ||
actions: ['route53:ChangeResourceRecordSets'], | ||
resourceArns: [hostedZoneArn], | ||
conditions: { | ||
'ForAllValues:StringEquals': { | ||
'route53:ChangeResourceRecordSetsRecordTypes': ['NS'], | ||
'route53:ChangeResourceRecordSetsActions': ['UPSERT', 'DELETE'], | ||
}, | ||
}, | ||
}); | ||
const g2 = iam.Grant.addToPrincipal({ | ||
grantee, | ||
actions: ['route53:ListHostedZonesByName'], | ||
resourceArns: ['*'], | ||
}); | ||
|
||
return g1.combine(g2); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you need to return
makeGrantDelegation