-
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(redshift-alpha): implement IGrantable with a default service IAM Role #28018
Changes from all commits
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { Match, Template } from 'aws-cdk-lib/assertions'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
import * as kms from 'aws-cdk-lib/aws-kms'; | ||
import { CfnCluster } from 'aws-cdk-lib/aws-redshift'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType } from '../lib'; | ||
import { CfnCluster } from 'aws-cdk-lib/aws-redshift'; | ||
|
||
let stack: cdk.Stack; | ||
let vpc: ec2.IVpc; | ||
|
@@ -779,6 +779,31 @@ describe('default IAM role', () => { | |
}); | ||
|
||
describe('IAM role', () => { | ||
|
||
test('cluster instantiated with a default grantable IAM Role', () => { | ||
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 think we need unit tests for:
|
||
// GIVEN | ||
const cluster = new Cluster(stack, 'Redshift', { | ||
masterUser: { | ||
masterUsername: 'admin', | ||
}, | ||
vpc, | ||
}); | ||
|
||
const bucket = new s3.Bucket(stack, 'Bucket'); | ||
bucket.grantRead(cluster); | ||
// THEN | ||
const template = Template.fromStack(stack); | ||
|
||
template.hasResourceProperties('AWS::Redshift::Cluster', { | ||
IamRoles: Match.arrayEquals([ | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('ServiceRole*'), 'Arn'] }, | ||
]), | ||
}); | ||
|
||
template.hasResourceProperties('AWS::IAM::Policy', { | ||
PolicyDocument: Match.objectLike({ Statement: Match.arrayEquals([Match.objectLike({ Resource: Match.arrayWith([Match.objectLike({ 'Fn::GetAtt': [stack.getLogicalId(bucket.node.defaultChild as s3.CfnBucket), 'Arn'] })]) })]) }), | ||
}); | ||
}); | ||
test('roles can be directly attached to cluster during declaration', () => { | ||
// GIVEN | ||
const role = new iam.Role(stack, 'Role', { | ||
|
@@ -796,6 +821,7 @@ describe('IAM role', () => { | |
Template.fromStack(stack).hasResource('AWS::Redshift::Cluster', { | ||
Properties: { | ||
IamRoles: Match.arrayEquals([ | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('ServiceRole*'), 'Arn'] }, | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('Role*'), 'Arn'] }, | ||
]), | ||
}, | ||
|
@@ -821,6 +847,7 @@ describe('IAM role', () => { | |
Template.fromStack(stack).hasResource('AWS::Redshift::Cluster', { | ||
Properties: { | ||
IamRoles: Match.arrayEquals([ | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('ServiceRole*'), 'Arn'] }, | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('Role*'), 'Arn'] }, | ||
]), | ||
}, | ||
|
@@ -848,6 +875,7 @@ describe('IAM role', () => { | |
Template.fromStack(stack).hasResource('AWS::Redshift::Cluster', { | ||
Properties: { | ||
IamRoles: Match.arrayEquals([ | ||
{ 'Fn::GetAtt': [Match.stringLikeRegexp('ServiceRole*'), 'Arn'] }, | ||
{ 'Fn::ImportValue': Match.stringLikeRegexp('NewTestStack:ExportsOutputFnGetAttRole*') }, | ||
]), | ||
}, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
This file was deleted.
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.
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.
No need to make this public.
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 it's useful to either make this public or add additional methods to allow users to add permissions to the role directly.
It's convenient for adding additional permissions beyond what grants provide. For example if I wanted to allow my cluster to read from a Glue Data Catalog.