Skip to content

Conversation

otaviomacedo
Copy link
Contributor

Add a generic grant() method to L1 constructs, of the form:

/**
 * Grant the given IGrantable permissions to perform the actions specified in actions on this resource.
 *
 * @param grantee The principal to grant permissions to.
 * @param actions The actions to grant permissions for.
 * @param conditions The conditions under which the actions should be allowed.
 */
public grant(grantee: iam.IGrantable, actions: Array<string>, conditions?: Record<string, Record<string, unknown>>): iam.Grant {
  return iam.Grant.addToPrincipal({
    "grantee": grantee,
    "actions": actions,
    "resourceArns": [this.attrArn],
    "scope": this,
    "conditions": conditions
  });
}

The only variation between different constructs is the ARN attribute name, passed in an array to resourceArns.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Oct 7, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team October 7, 2025 09:00
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 7, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we didn't really talk about this yet or write it down anywhere, but I want something like the following:

class BucketGrants {
  public static fromBucketRef(bucketRef: IBucketRef) { /* ... */ }

  constructor(private readonly bucketName: string /* all dimensions here */, resourceWithPolicy?: IResourceWithPolicy) { }

  public readData(grantee) {
  }
}

Or something similar, didn't nail down the specifics yet. We need to do some thinking around keys and resource policies as well, and what data we need in the database.

The main selling point would be that the grants facility isn't tied to any particular construct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants