Skip to content

Feature/aws iam authentication #12

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

Conversation

fabrizio11
Copy link

@fabrizio11 fabrizio11 commented Jul 17, 2025

Add AWS IAM authentication support for MySQL

This PR adds AWS IAM database authentication for Amazon RDS MySQL instances, enabling secure connections without hardcoded passwords.

Changes:

  • New CLI options: --aws-iam-auth and --aws-region
  • AWS SDK integration: Uses @aws-sdk/rds-signer for automatic token generation
  • SSL auto-configuration: Automatically enables SSL for AWS IAM connections
  • Error handling: Clear error messages for AWS credential/permission issues
  • Documentation: Updated README and connection reference with prerequisites

Usage:

node dist/src/index.js --mysql --aws-iam-auth \
  --host your-rds-endpoint.region.rds.amazonaws.com \
  --database your-database \
  --user your-aws-username \
  --aws-region us-east-1

Prerequisites:

AWS credentials must be configured via:

  • aws configure (default profile)
  • Environment variables (AWS_PROFILE, AWS_ACCESS_KEY_ID, etc.)
  • IAM roles (for EC2)

This enables secure AWS RDS connections using IAM authentication while maintaining full compatibility with existing MySQL authentication methods.

fab0492 added 2 commits July 16, 2025 17:20
- Add @aws-sdk/rds-signer dependency for RDS auth token generation
- Extend CLI arguments with --aws-iam-auth and --aws-region options
- Implement automatic AWS RDS auth token generation in MySQL adapter
- Auto-enable SSL for AWS IAM authentication (required by RDS)
- Add comprehensive error handling for AWS credential issues
- Update documentation with AWS IAM authentication examples
- Maintain backward compatibility with existing authentication methods

Resolves the need for secure AWS RDS connections without hardcoded passwords.
- Document requirement for AWS credentials configuration using default provider chain
- Add examples for different credential configuration methods (aws configure, env vars, IAM roles)
- Update both README.md and connection reference documentation
- Clarify that RDS Signer uses default credential provider chain as per AWS documentation
Copy link
Owner

@executeautomation executeautomation left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for an interesting PR. Love how it's addressing a problem which I didn't thought off !

}

try {
console.error(`[INFO] Generating AWS auth token for region: ${this.awsRegion}, host: ${this.host}, user: ${this.config.user}`);

Choose a reason for hiding this comment

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

appropriately, should be console.info

Choose a reason for hiding this comment

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

I agree, thanks for catching it @jrequioma

});

const token = await signer.getAuthToken();
console.error(`[INFO] AWS auth token generated successfully`);

Choose a reason for hiding this comment

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

appropriately, should be console.info

Choose a reason for hiding this comment

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

I agree, thanks for catching it @jrequioma

throw new Error(`AWS IAM authentication failed: ${(err as Error).message}. Please check your AWS credentials and IAM permissions.`);
}
}

/**
* Initialize MySQL connection
*/
async init(): Promise<void> {
try {
console.error(`[INFO] Connecting to MySQL: ${this.host}, Database: ${this.database}`);

Choose a reason for hiding this comment

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

appropriately, should be console.info


// Handle AWS IAM authentication
if (this.awsIamAuth) {
console.error(`[INFO] Using AWS IAM authentication for user: ${this.config.user}`);

Choose a reason for hiding this comment

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

appropriately, should be console.info

Choose a reason for hiding this comment

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

I agree, thanks for catching it @jrequioma

} else {
this.connection = await mysql.createConnection(this.config);
}

console.error(`[INFO] MySQL connection established successfully`);

Choose a reason for hiding this comment

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

appropriately, should be console.info

Choose a reason for hiding this comment

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

I agree, thanks for catching it @jrequioma

Copy link
Owner

@executeautomation executeautomation left a comment

Choose a reason for hiding this comment

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

Please fix the issue mentioned by @jrequioma

@fabrizio11
Copy link
Author

Please fix the issue mentioned by @jrequioma

thanks @jrequioma @executeautomation fixed

@executeautomation
Copy link
Owner

Perfect !

@executeautomation executeautomation merged commit f56a616 into executeautomation:main Jul 24, 2025
2 of 3 checks passed
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