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

feat(efs): add grantRead and grantReadWrite, grantRootAccess to FileSystem #25486

Merged
merged 39 commits into from
Aug 23, 2023

Conversation

WinterYukky
Copy link
Contributor

@WinterYukky WinterYukky commented May 8, 2023

What change

I added grantRead() and grantReadWrite(), grantRootAccess() to efs.FileSystem as Beta1 method.

Why need this change?

To make IAM authentication easier for clients.

Currently, v2.78.0 has implemented grant() method in efs.FileSystem. However, EFS can't restrict only granted client even when customers only use the grant() method. Because EFS default file system policy grants full access to any anonymous client that can connect to the file system using a mount target. To avoid this issue, customers must set file system policies that not grant anonymous clients, to EFS. In this PR, when using the grantXxx method that allows IAM authentication for clients, a file system policy that does not allow anonymous clients is set to efs.FileSystem by default to suit the customer's use case. Next example is grant read and write access to EC2 Instance.

declare const client: ec2.Instance;
const fileSystem = new efs.FileSystem(this, 'FileSystem', {
  vpc: new ec2.Vpc(this, 'VPC'),
});
fileSystem.grantReadWrite(client);

How do I continue to allow anonymous access?

You can use allowAnonymousAccess props for allow anonymous access.

declare const client: ec2.Instance;
const fileSystem = new efs.FileSystem(this, 'FileSystem', {
  vpc: new ec2.Vpc(this, 'VPC'),
  allowAnonymousAccess: true,
});
fileSystem.grantRead(client);

Others

The file system policies created to prevent anonymous clients are based on the AWS Management Console.
image


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

@gitpod-io
Copy link

gitpod-io bot commented May 8, 2023

@aws-cdk-automation aws-cdk-automation requested a review from a team May 8, 2023 17:38
@github-actions github-actions bot added admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2 labels May 8, 2023
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label May 8, 2023
packages/aws-cdk-lib/aws-efs/README.md Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This integration test tests the following:

  1. Clients granted by grantReadWrite() write files during deployment
  2. Assert that anonymous client mounts fail
  3. Assert that a client authorized by grantRead() will read the file

Copy link
Contributor

Choose a reason for hiding this comment

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

Love this!

Comment on lines +321 to +327
return iam.Grant.addToPrincipalOrResource({
grantee: grantee,
actions: actions,
resourceArns: [this.fileSystemArn],
resource: this,
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Looks great! Especially love the integ test! Just a couple of comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Love this!

* @param conditions The conditions to grant
* @internal
*/
public _grantClient(grantee: iam.IGrantable, actions: ClientAction[], conditions?: Record<string, Record<string, unknown>>): iam.Grant {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be public or can it be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was planning to use this method on AccessPoint, so I made it public. Currently, it doesn't need to be public, so I will change to private until open the PR that add grant API to AccessPoint :)

* Grant read permissions for this file system to an IAM principal.
* @param grantee The principal to grant read to
*/
public grantReadBeta1(grantee: iam.IGrantable): iam.Grant {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is safe to remove the Beta1 from these. Based on the API I can't
foresee any breaking changes that we would need to make.

fileSystemPolicy: Lazy.any({ produce: () => this._fileSystemPolicy }),
fileSystemPolicy: Lazy.any({
produce: () => {
const allowAnonymousAccess = props.allowAnonymousAccess ?? !this._grantedClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be the default behavior. Would you mind/be able to create a
new feature flag and make this the new default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean that the behavior of deny anonymous clients should be made the default even when not using grantClient?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but only with the feature flag.

@corymhall corymhall self-assigned this Jun 5, 2023
@corymhall corymhall removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 5, 2023
@mergify mergify bot dismissed corymhall’s stale review June 7, 2023 08:53

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 7, 2023
@corymhall corymhall removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 12, 2023
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Hi @WinterYukky just a couple minor comments :)

packages/aws-cdk-lib/cx-api/lib/features.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-efs/README.md Outdated Show resolved Hide resolved
fileSystemPolicy: Lazy.any({
produce: () => {
const denyAnonymousAccessFlag = FeatureFlags.of(this).isEnabled(cxapi.EFS_DENY_ANONYMOUS_ACCESS) ?? false;
const denyAnonymousAccessByDefault = denyAnonymousAccessFlag || this._grantedClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

help me understand why this._grantedClient is included here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, my design was to reject anonymous clients only when using grantXXX (e.g. grantRead). Currently, an implementation that rejects anonymous clients by default based on feature flags has been added. Therefore, it is also possible to remove _grantedClient and switch to feature flags only.
However, even if a user who has upgraded the CDK from an older version starts using grantXXX, anonymous clients will not be rejected unless the feature flag is enabled, so I implemented an implementation that determines the permission of an anonymous client with both the feature flag and _grantedClient according to the original purpose. Nonetheless, I'm going to try not to use _grantedClient if it's unnecessary because it affects maintainability. What do you think?

WinterYukky and others added 2 commits August 7, 2023 23:20
Co-authored-by: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com>
Co-authored-by: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com>
@mergify mergify bot dismissed kaizencc’s stale review August 7, 2023 14:22

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@rix0rrr rix0rrr assigned rix0rrr and unassigned corymhall Aug 23, 2023
rix0rrr
rix0rrr previously approved these changes Aug 23, 2023
@mergify
Copy link
Contributor

mergify bot commented Aug 23, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed rix0rrr’s stale review August 23, 2023 15:16

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Aug 23, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9101d71
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 9c12199 into aws:main Aug 23, 2023
8 checks passed
@mergify
Copy link
Contributor

mergify bot commented Aug 23, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants