-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(dynamodb): addtoresourcepolicy fix for table (v1) construct #31516
Changes from all commits
49bfdb1
57dab53
057ab1e
4668ce7
3fb88ac
99284b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,7 @@ export interface TableAttributes { | |
} | ||
|
||
export abstract class TableBase extends Resource implements ITable, iam.IResourceWithPolicy { | ||
|
||
/** | ||
* @attribute | ||
*/ | ||
|
@@ -553,6 +554,22 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
|
||
protected readonly regionalArns = new Array<string>(); | ||
|
||
/** | ||
* Adds a statement to the resource policy associated with this table. | ||
* A resource policy will be automatically created upon the first call to `addToResourcePolicy`. | ||
* | ||
* Note that this does not work with imported tables | ||
* | ||
* @param statement The policy statement to add | ||
*/ | ||
public addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult { | ||
|
||
this.resourcePolicy = this.resourcePolicy ?? new iam.PolicyDocument({ statements: [] }); | ||
this.resourcePolicy?.addStatements(statement); | ||
|
||
return { statementAdded: true, policyDependable: this.resourcePolicy }; | ||
} | ||
|
||
/** | ||
* Adds an IAM policy statement associated with this table to an IAM | ||
* principal's policy. | ||
|
@@ -564,7 +581,7 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
* @param actions The set of actions to allow (i.e. "dynamodb:PutItem", "dynamodb:GetItem", ...) | ||
*/ | ||
public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { | ||
return iam.Grant.addToPrincipalOrResource({ | ||
return iam.Grant.addToPrincipal({ | ||
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. Why does this need to become 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. Because addToPrincipalOrResource never adds to the resource, as IAM is missing methods. So I'm putting it back to how it was before I changed it until I have time to implement the missing methods in IAM 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. I don't fully understand what methods are missing. Looking at 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. @LeeroyHannigan I want to check if I follow your line of thoughts here. I see the I agree with that. But if I understand @everilae correctly, even though 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. Hi, We rely on the "...OrResource" part, or would like to, once all this is fixed. If the call is replaced with just "addToPrincipal", then attempts at granting to external accounts would not work. |
||
grantee, | ||
actions, | ||
resourceArns: [ | ||
|
@@ -575,7 +592,7 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
produce: () => this.hasIndex ? `${arn}/index/*` : Aws.NO_VALUE, | ||
})), | ||
], | ||
resource: this, | ||
scope: this, | ||
}); | ||
} | ||
/** | ||
|
@@ -691,23 +708,6 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
return this.combinedGrant(grantee, { keyActions, tableActions: ['dynamodb:*'] }); | ||
} | ||
|
||
/** | ||
* Adds a statement to the resource policy associated with this file system. | ||
* A resource policy will be automatically created upon the first call to `addToResourcePolicy`. | ||
* | ||
* Note that this does not work with imported file systems. | ||
* | ||
* @param statement The policy statement to add | ||
*/ | ||
public addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult { | ||
this.resourcePolicy = this.resourcePolicy ?? new iam.PolicyDocument({ statements: [] }); | ||
this.resourcePolicy.addStatements(statement); | ||
return { | ||
statementAdded: true, | ||
policyDependable: this, | ||
}; | ||
} | ||
|
||
/** | ||
* Return the given named metric for this Table | ||
* | ||
|
@@ -958,11 +958,11 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
produce: () => this.hasIndex ? `${arn}/index/*` : Aws.NO_VALUE, | ||
})), | ||
]; | ||
const ret = iam.Grant.addToPrincipalOrResource({ | ||
const ret = iam.Grant.addToPrincipal({ | ||
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. Same as above, this would break Table v1 for us. |
||
grantee, | ||
actions: opts.tableActions, | ||
resourceArns: resources, | ||
resource: this, | ||
scope: this, | ||
}); | ||
return ret; | ||
} | ||
|
@@ -971,11 +971,11 @@ export abstract class TableBase extends Resource implements ITable, iam.IResourc | |
throw new Error(`DynamoDB Streams must be enabled on the table ${this.node.path}`); | ||
} | ||
const resources = [this.tableStreamArn]; | ||
const ret = iam.Grant.addToPrincipalOrResource({ | ||
const ret = iam.Grant.addToPrincipal({ | ||
grantee, | ||
actions: opts.streamActions, | ||
resourceArns: resources, | ||
resource: this, | ||
scope: this, | ||
}); | ||
return ret; | ||
} | ||
|
@@ -1150,6 +1150,8 @@ export class Table extends TableBase { | |
} | ||
this.validateProvisioning(props); | ||
|
||
this.resourcePolicy = props.resourcePolicy ?? new iam.PolicyDocument(); | ||
|
||
this.table = new CfnTable(this, 'Resource', { | ||
tableName: this.physicalName, | ||
keySchema: this.keySchema, | ||
|
@@ -1177,9 +1179,11 @@ export class Table extends TableBase { | |
kinesisStreamSpecification: props.kinesisStream ? { streamArn: props.kinesisStream.streamArn } : undefined, | ||
deletionProtectionEnabled: props.deletionProtection, | ||
importSourceSpecification: this.renderImportSourceSpecification(props.importSource), | ||
resourcePolicy: props.resourcePolicy | ||
? { policyDocument: props.resourcePolicy } | ||
: undefined, | ||
resourcePolicy: Lazy.any({ | ||
produce: () => (this.resourcePolicy && this.resourcePolicy.statementCount > 0 | ||
? { policyDocument: this.resourcePolicy.toJSON() } | ||
: undefined), | ||
}), | ||
}); | ||
this.table.applyRemovalPolicy(props.removalPolicy); | ||
|
||
|
@@ -1732,6 +1736,7 @@ export class Table extends TableBase { | |
}, | ||
}; | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
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.
I think the change in this PR is already covered in the unit test. Integ test does not seem necessary to me because we are not using new L1 props. Is there anything the integ test would catch while the unit test cannot?