Skip to content

Conversation

@aaronchung-bitquill
Copy link
Contributor

Summary

fix: IAM auth in CN RDS (#579)

Description

Previously AwsIamAuthenticationTokenHelper#getRegion aurora DNS pattern did not support CN regions. Added an aurora DNS pattern for CN region specifically.

Additional Reviewers

By submitting this pull request, I confirm that my contribution is made under the terms of the GPLv2 license.

final Pattern auroraDnsPattern =
Pattern.compile(
"(.+)\\.(proxy-|cluster-|cluster-ro-|cluster-custom-)?[a-zA-Z0-9]+\\.([a-zA-Z0-9\\-]+)\\.rds\\.amazonaws\\.com",
"(.+)\\.(proxy-|cluster-|cluster-ro-|cluster-custom-)?[a-zA-Z0-9]+\\.([a-zA-Z0-9\\-]+)\\.rds\\.amazonaws\\.com(\\.cn)?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the last (\.cn) in this regexp? The code checks for China url pattern further.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to replocate entire method getRdsRegion() to RdsUtils.

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 double checking this DNS pattern against the one in RdSUtils.java and it contains (\.cn)? at the end. Same thing in the aws-advanced-jdbc-wrapper. So it looks like this pattern may have been missing it.

final Pattern auroraDnsPattern =
Pattern.compile(
"(.+)\\.(proxy-|cluster-|cluster-ro-|cluster-custom-)?[a-zA-Z0-9]+\\.([a-zA-Z0-9\\-]+)\\.rds\\.amazonaws\\.com",
"(.+)\\.(proxy-|cluster-|cluster-ro-|cluster-custom-)?[a-zA-Z0-9]+\\.([a-zA-Z0-9\\-]+)\\.rds\\.amazonaws\\.com(\\.cn)?",

Choose a reason for hiding this comment

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

i think there might be some confusion here (?)

the first regex was supposed to try to match non-CN endpoints

and then there was the CN-matcher for CN endpoints

do you want to merge them so one regex matches both?

I would suggest to put the regex string as a static variable and in the comments put the patterns that are valid

Copy link
Contributor Author

@aaronchung-bitquill aaronchung-bitquill May 27, 2024

Choose a reason for hiding this comment

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

Added (\\.cn)? to the end because i noticed that the pattern in RdsUtils.java has it, but it doesnt have it here.
Personally, I'd prefer not to mix them. I'd rather keep it simple with two separate patterns, than one more complex one.
I will put them in static vars are you suggested though.
edit: I think i might actually just eliminate these patterns here, and directly reference the ones that are defined in RdsUtils.java

log.logTrace(exceptionMessage);
throw ExceptionFactory.createException(exceptionMessage);
}
matcher = chinaMatcher;

Choose a reason for hiding this comment

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

do you need to do something with the matcher 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.

It gets used a lil further down.

*/
@Test
public void test_7_ValidChinaHostAndRegion() {
Assertions.assertNotNull(new AwsIamAuthenticationTokenHelper(

Choose a reason for hiding this comment

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

maybe you should add a couple of examples that have the .cn at the end but have other irregularities in the middle of the URL to be sure your regex is catching what you want

@aaronchung-bitquill aaronchung-bitquill merged commit 926d28f into main May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants