petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
63 stars 40 forks source link

IAM auth on localhost connection not allowed #96

Closed pgrunm-DrKlein closed 7 months ago

pgrunm-DrKlein commented 7 months ago

Hello,

I'm currently trying to create a new MySQL user for IAM authentication on AWS. We're running our RDS database instance behind a bastion host, so there is no way to connect directly.

As a result I'm running a ssh tunnel to the bastion and connecting to a local port on my machine. Unfortunately, the module doesn't allow me to create an IAM user while connecting to localhost. This is the offending line.

petoju commented 7 months ago

@pgrunm-DrKlein I believe the "offending line" is not really causing any issues.

MySQL identifies user by tuple like (username, hostname_or_ip). When you connect, it finds the record that matches both of these before checking the password. That hostname_or_ip part is found out by the server and your client cannot do a lot to change it.

I can't imagine someone would be connecting to RDS from localhost (as seen by RDS). You still have to allow connection from hostmask, that matches at least your bastion to be able to connect like that. So it will be like 10.1.2.3, or maybe 10.% or even something wider. % is wildcard.

I may be wrong; feel free to object if you see it differently.

pgrunm-DrKlein commented 7 months ago

Oh no. I'm totally wrong. I just noticed my mistake, let me explain.

I'm using a provisioner which points to localhost as endpoint:

provider "mysql" {
  alias                 = "dev"
  endpoint              = "localhost:3306"
}

I forgot to set the host attribute to something else than localhost. I changed this attribute now to % as you said and now it works like a flaw.

Thank you very much for your reply, I'm closing this issue now 👍.