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(redshift): support default role for redshift clusters #23554

Conversation

sean-beath
Copy link
Contributor

@sean-beath sean-beath commented Jan 4, 2023

Redshift clusters have the ability to specify a default role for the cluster. This is not currently available as a feature in CloudFormation so requires a AwsCustomResource to be done at runtime.

This feature allows users to specify a default role at cluster creation or post-cluster creation.

closes #22551


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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 Jan 4, 2023

@github-actions github-actions bot added p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels Jan 4, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team January 4, 2023 03:07
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. labels Jan 4, 2023
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 has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@sean-beath sean-beath changed the title feat(redshift):support default role for redshift clusters feat(redshift): support default role for redshift clusters Jan 4, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 4, 2023 03:20

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@HBobertz HBobertz self-assigned this Jan 4, 2023
Copy link
Contributor

@HBobertz HBobertz left a comment

Choose a reason for hiding this comment

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

Overall seems pretty good, but given we would be adding a custom resource to this construct, I'd like to see unit testing, as well as integ testing. If we did execute on the default role list I mention in the comments instead of default role, I'd like to see error checking to ensure it doesn't go over 10. May need to do this anyway but I'm not sure how this works with previously provisioned clusters.

Unit tests could just be added here https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-redshift/lib/cluster.ts

}),
});

defaultIamRole.grantPassRole(defaultRoleCustomeResource.grantPrincipal);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why this wouldn't be a valid use case for using a custom resource, and I like the functionality of the design, but just to be pedantic gonna verify with another team member.

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 would have expected not to require this line, but was facing an error when it wasn't included.

* @param defaultIamRole the IAM role to be set as the default role
*/
public addDefaultIamRole(defaultIamRole: iam.IRole): void {
const defaultRoleCustomeResource = new AwsCustomResource(this, 'default-role', {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is there an e in custom here? Can we change this to be just "Custom"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed spelling mistake

*
* @default - No default role is attached to the cluster.
*/
readonly defaultRole?: iam.IRole;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm absolutely fine with keeping this as a singleton, but given the roles prop is a list could this not also be a list? Is there a reason why a default singleton role would be preferable over a potential list of default roles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redshift only allows the one default role per cluster.
Assume your cluster has two IAM roles (role1 and role2). If role1 is default and then you modify the cluster to make role2 the default, role1 will still be a role for the cluster but no longer the default role.

});
```

A default role can also be added to a cluster using the `addDefaultIamRole` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be misunderstanding but can this be added to an already existing cluster? If so is there a possibility this default role could attempt to append an 11th role to an existing cluster and then go over 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way this is set up it could be added to an already existing cluster which would push the number of IAM roles to more than 10. It's interesting that this limit has been imposed as for most regions the role limit for a cluster is 50. Is there a way to make this limit region specific?

I'll try to find a way to check the total number of roles before adding the default role.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also interesting that there doesn't seem to be a check for the IAM role list to make sure there's less than 10 - should this be added?

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 am thinking of changing the functionality so that the default role needs to be defined in the roles parameter on cluster creation, or already attached to the cluster if adding post-creation. This would remove the need to check for the total number of IAM roles and I think would reflect better practice.
What are your thoughts?

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've now changed the behaviour so that the method will check to see if the role is already associated to the cluster, if it is not then an error will be thrown. This will stop the max roles being exceeded.

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome thanks

@HBobertz
Copy link
Contributor

HBobertz commented Jan 4, 2023

Also this is more a question for myself as well. How should we note that this custom resource functionality should be replaced when the cfn redshift cluster adds support for this. Another issue? Will sync with another engineer on that as well

@mergify mergify bot dismissed HBobertz’s stale review January 4, 2023 22:24

Pull request has been modified.

HBobertz
HBobertz previously approved these changes Jan 12, 2023
Copy link
Contributor

@HBobertz HBobertz left a comment

Choose a reason for hiding this comment

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

looks good to me 👍

@mergify
Copy link
Contributor

mergify bot commented Jan 12, 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 HBobertz’s stale review January 12, 2023 22:00

Pull request has been modified.

@sean-beath
Copy link
Contributor Author

@HBobertz - the build has failed due to a change in the integ test that is being created with this PR (integ.cluster-defaultiamrole) - is there something specific that needs to be done here?

@HBobertz
Copy link
Contributor

HBobertz commented Jan 13, 2023

@sean-beath run yarn integ --update-on-failed and update the cr

@sean-beath
Copy link
Contributor Author

@HBobertz - any movement on this PR?

@HBobertz
Copy link
Contributor

HBobertz commented Jan 30, 2023

If I remember correctly it will need to be merged from live again. I'll double check it and approve tommorow. I pulled it down and I think an integ test was failing due to a recent change, I don't think the pr will need to be changed though. Either way I'll let you know

HBobertz
HBobertz previously approved these changes Jan 30, 2023
});
```

A default role can also be added to a cluster using the `addDefaultIamRole` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

awesome thanks

@HBobertz HBobertz enabled auto-merge January 30, 2023 16:52
@mergify mergify bot dismissed HBobertz’s stale review January 30, 2023 16:52

Pull request has been modified.

Copy link
Contributor

@HBobertz HBobertz left a comment

Choose a reason for hiding this comment

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

I'm gonna babysit this today so I know it merges

@HBobertz HBobertz merged commit 7945fa6 into aws:main Jan 31, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

corymhall added a commit that referenced this pull request Jan 31, 2023
PR was merged manually without squash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-redshift-alpha: add functionality for default IAM role
4 participants