-
Notifications
You must be signed in to change notification settings - Fork 4k
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(rds): fixed the IAM policy that grantConnect() generates for DatabaseInstanceReadReplica #31068
fix(rds): fixed the IAM policy that grantConnect() generates for DatabaseInstanceReadReplica #31068
Conversation
…baseInstanceReadReplica
e821569
to
4b8b0d5
Compare
@@ -1366,7 +1366,7 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements | |||
this.instanceIdentifier = instance.ref; | |||
this.dbInstanceEndpointAddress = instance.attrEndpointAddress; | |||
this.dbInstanceEndpointPort = instance.attrEndpointPort; | |||
this.instanceResourceId = instance.attrDbInstanceArn; |
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 am afraid that this can be a breaking change to customers. I know that we assigned a wrong value, but may be there are some customers that use this property to get the DB Instance Arn and use it some how. So, my recommendation is to deprecate this property, and to add a new property for the instance resource id, and use it in grant method, and also check where else we use the current property.
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.
@moelasmar Thanks for your review comment. Would creating a feature flag (example #29794) be the recommended approach instead of adding a new property? Please advise.
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 the feature flag here will not fix the problem, as the flag default value will be false (to avoid breaking customers), so the policy will still referring to the wrong replica instance id. So, I do not prefer feature flag, it add a lot of confusion on us when we write code, so we can use this property in similar cases assuming that we are using the correct property, but because the feature flag is disabled, this may cause more issues for customers.
I prefer to go with deprecation, and adding new property.
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.
@moelasmar Thanks for your review comment. I have added a commit to:
- Deprecate
instanceResourceId
property and add newinstanceResourceIdV2
property inDatabaseInstanceReadReplica
. - Added a copy of
grantConnect()
inDatabaseInstanceReadReplica
that makes use ofinstanceResourceIdV2
.
Please review.
Thanks,
Ashish
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.
Thanks @ashishdhingra for resolving my comment, and sorry for late response.
I actually, did a deeper check, and I found that I missed that the property instanceResourceId
is actually exist in the Interface IDatabaseInstance
so, adding a new property will actually break the idea of that interface, and also deprecating this property is not a good idea.
So, I think it is better to make this change under feature flag, and to enable the feature flag by default, and the customers who want to keep the current behaviour, they can disable the flag.
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 pushed some updates to this change to add the feature flag. Could you please take a look.
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.
Looks good reviewing at high level. Needs review from the maintainer.
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.
left one comment
4b8b0d5
to
ad7c2de
Compare
ad7c2de
to
113ab2a
Compare
Pull request has been modified.
…ceResourceIdV2 property in DatabaseInstanceReadReplica to use in grantConnect().
ced2113
to
4d0239a
Compare
…InstanceReadReplica-GrantRead-Fix # Conflicts: # packages/@aws-cdk/cx-api/FEATURE_FLAGS.md # packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md # packages/aws-cdk-lib/cx-api/README.md # packages/aws-cdk-lib/cx-api/lib/features.ts # packages/aws-cdk-lib/cx-api/test/features.test.ts
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
Changes look good, just a couple comments about how the feature flag is defined and the default value being true
.
@@ -73,6 +73,7 @@ Flags come in three types: | |||
| [@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault](#aws-cdkcustom-resourceslogapiresponsedatapropertytruedefault) | When enabled, the custom resource used for `AwsCustomResource` will configure the `logApiResponseData` property as true by default | 2.145.0 | (fix) | | |||
| [@aws-cdk/aws-s3:keepNotificationInImportedBucket](#aws-cdkaws-s3keepnotificationinimportedbucket) | When enabled, Adding notifications to a bucket in the current stack will not remove notification from imported stack. | 2.155.0 | (fix) | | |||
| [@aws-cdk/aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask](#aws-cdkaws-stepfunctions-tasksusenews3uriparametersforbedrockinvokemodeltask) | When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model. | V2NEXT | (fix) | | |||
| [@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId](#aws-rds-setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId) | When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn` | V2NEXT | (fix) | |
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.
| [@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId](#aws-rds-setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId) | When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn` | V2NEXT | (fix) | | |
| [@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId](#aws-rds-setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId) | When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn` | V2NEXT | (fix) | |
| ----- |---------|-------------| | ||
| (not in v1) | | | | ||
| V2NEXT | `true` | `true` | |
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.
The spacing on some of these seem off, was it manually generated or auto generated by running the build?
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.
it seems while I merged the conflicts I messed up these files, let me rerun the build and see if it will fix it
| Since | Default | Recommended | | ||
| ----- | ----- | ----- | | ||
| (not in v1) | | | | ||
| V2NEXT | `true` | `true` | |
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.
Do we want this to be true
by default? Would that not break customers?
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.
my idea was which behaviour should I keep, shall I keep the wrong behaviour, or should I fix it. I chose to fix the wrong behaviour with an option to let people keep the current one. But, honestly you have a point, it is a breaking change
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 will change it to false.
for some reason I am not able to update this PR, and push changes to @ashishdhingra forked repo, so I created this new PR #31579 that includes @ashishdhingra changes, and close this one. |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #31061.
Reason for this change
Calling
grantConnect()
on an instance ofDatabaseInstanceReadReplica
generates an incorrect policy that uses the full ARN of the instance instead of the instanceResourceId value. It should have created policy with correct resource formatarn:aws:rds-db:region:account-id:dbuser:DbiResourceId/db-user-name
per Creating and using an IAM policy for IAM database access.Description of changes
Fixed the IAM policy that
grantConnect()
generates forDatabaseInstanceReadReplica
. The change correctly sets the value ofinstanceResourceId
to replica instanceattrDbiResourceId
. The value ofinstanceResourceId
is used to generate IAM policy.Description of how you validated changes
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license