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

fix(neptune): create correct IAM statement in grantConnect() #13641

Merged
merged 2 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/@aws-cdk/aws-neptune/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export interface IDatabaseCluster extends IResource, ec2.IConnectable {
*/
readonly clusterIdentifier: string;

/**
* Resource identifier of the cluster
* @attribute ClusterResourceId
*/
readonly clusterResourceIdentifier: string;

/**
* The endpoint to use for read/write operations
* @attribute Endpoint,Port
Expand Down Expand Up @@ -266,6 +272,11 @@ export interface DatabaseClusterAttributes {
*/
readonly clusterIdentifier: string;

/**
* Resource Identifier for the cluster
*/
readonly clusterResourceIdentifier: string;

/**
* Cluster endpoint address
*/
Expand Down Expand Up @@ -293,6 +304,7 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC
defaultPort: this.defaultPort,
});
public readonly clusterIdentifier = attrs.clusterIdentifier;
public readonly clusterResourceIdentifier = attrs.clusterResourceIdentifier;
public readonly clusterEndpoint = new Endpoint(attrs.clusterEndpointAddress, attrs.port);
public readonly clusterReadEndpoint = new Endpoint(attrs.readerEndpointAddress, attrs.port);
protected enableIamAuthentication = true;
Expand All @@ -306,6 +318,11 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC
*/
public abstract readonly clusterIdentifier: string;

/**
* Resource identifier of the cluster
*/
public abstract readonly clusterResourceIdentifier: string;

/**
* The endpoint to use for read/write operations
*/
Expand Down Expand Up @@ -339,7 +356,7 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC
'neptune-db',
Aws.REGION,
Aws.ACCOUNT_ID,
`${this.clusterIdentifier}/*`,
`${this.clusterResourceIdentifier}/*`,
].join(':'),
],
});
Expand Down
26 changes: 25 additions & 1 deletion packages/@aws-cdk/aws-neptune/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ describe('DatabaseCluster', () => {
const cluster = DatabaseCluster.fromDatabaseClusterAttributes(stack, 'Database', {
clusterEndpointAddress: 'addr',
clusterIdentifier: 'identifier',
clusterResourceIdentifier: 'resourceIdentifier',
port: 3306,
readerEndpointAddress: 'reader-address',
securityGroup: ec2.SecurityGroup.fromSecurityGroupId(stack, 'SG', 'sg-123456789', {
Expand All @@ -360,6 +361,7 @@ describe('DatabaseCluster', () => {
const cluster = DatabaseCluster.fromDatabaseClusterAttributes(stack, 'Database', {
clusterEndpointAddress: 'addr',
clusterIdentifier: 'identifier',
clusterResourceIdentifier: 'resourceIdentifier',
port: 3306,
readerEndpointAddress: 'reader-address',
securityGroup: ec2.SecurityGroup.fromSecurityGroupId(stack, 'SG', 'sg-123456789', {
Expand Down Expand Up @@ -474,7 +476,29 @@ describe('DatabaseCluster', () => {
Effect: 'Allow',
Action: 'neptune-db:*',
Resource: {
'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':neptune-db:', { Ref: 'AWS::Region' }, ':', { Ref: 'AWS::AccountId' }, ':', { Ref: 'ClusterEB0386A7' }, '/*']],
'Fn::Join': [
'', [
'arn:', {
Ref: 'AWS::Partition',
},
':neptune-db:',
{
Ref: 'AWS::Region',
},
':',
{
Ref: 'AWS::AccountId',
},
':',
{
'Fn::GetAtt': [
'ClusterEB0386A7',
'ClusterResourceId',
],
},
'/*',
],
],
},
}],
Version: '2012-10-17',
Expand Down