Granting mysql access rights to all machines on subnet - mysql

I have a mysql instance (and schema) running on windows that I can access via a connection string based on localhost as the server.
now I want to be able to access this db from another machine on the same subnet.
If possible I would like to use a single user but allow it to access from any machine on the same subnet.
how do I setup security for this?
(I already opened the relevant firewall port)
Thanks,
Eyal

You can do it like this:
GRANT ALL PRIVILEGES ON mydb TO 'username'#'192.168.1.0/255.255.255.0';
change subnet and IP accordingly

You can also use wildcards, rather than a masks.
You can specify wildcards in the host name. For example,
user_name#'%.example.com' applies to user_name for any host in the
example.com domain, and user_name#'192.168.1.%' applies to user_name
for any host in the 192.168.1 class C subnet.
See the Account Names and Passwords section of the in the GRANT docs.

Related

mysql database allow external access from specific ip only ubuntu 16

I would like to allow one of my mysql database access from an external, however I would like to restrict it to be access from 1 ip only. Is there any way to do so:
only apply the setting to 1 database
only allow access to that database from a specific ip
My server is ubuntu 16.
thank you!
A MySQL user can be created for a specific origin address:
CREATE USER bob#'202.1.1.3' IDENTIFIED BY 'very very secure password';
GRANT ALL ON db.* TO bob#'202.1.1.3'
Provided no other GRANTS are given to db, then the bob user from '202.1.1.2' is the only allowed user.
Its generally more secure to give a ssh tunnel access, or access on a non-standard port however. Publicly accessible database servers will have their authentication brute forced.

Grant Mysql anonymous user access from other machines apart from localhost?

Mysql server allows access to anonymous user from localhost. I would like to extend this privelege to other machines as well... i.e. access to mysql_server running in machine A from mysql client from machine B using the anonymous user without any password.
I understand this is not practice and I want to do it only for certain dev purposes. Can anyone let me know how this is possible for mysql server.
The version I am using is - mysql_server 5.0.15
To allow anonymous access to any host must use % wildcard:
GRANT ALL ON your_db.* TO ''#'%';
MySQL does not support wildcards in user names, but I think is better creating a guest username:
CREATE USER 'guest'#'%';
GRANT ALL ON your_db.* TO 'guest'#'%';

HAProxy IP forwarding to MySQL to control user access based on IP

We can create users in MySQL which are allowed from a particular IP or range of IPs. For e.g, CREATE USER 'username'#'IP' IDENTIFIED BY ...
Here if I give a particular IP, it means users from that IP only can access MySQL.
Now there is a need of a load balancer (HAProxy) on top of many MySQL nodes behind it. The issue is : When a request comes from HAProxy to MySQL, it is the HAProxy's IP which comes to MySQL. So the way I want to use the IP while creating a user, doesn't work. My question is particularly with this USE-CASE only and I would like to know is there any solution for it ?
You have to create a user with the haproxy IP since DB traffic will be coming from there.
Instead of specific IPs, you can also opt for wildcard IPs e.g. user#10.10.10.%. Users can access MySQL from machines with IPs starting from 10.10.10. If both the DB and haproxy machines are on the same network (10.10.10.x), you only need to create one account.
Explore more options in the documentation: https://dev.mysql.com/doc/refman/5.7/en/account-names.html
If you decide to fully transition the users to use the proxy to access mysql, you can change the host of they user account as mentioned here: https://stackoverflow.com/a/12045483/255523

MySQL allow access from specific domain?

I'm trying to allow access to the MySQL instance I have running on a local server here. I know I can bind remote access to certain IP's and certain IP ranges in the my.cnf file. I was curious if it was possible to allow access from entire domains rather than having to list out all the possible IP's that might be connecting.
I know you can grant access to entire domains via the GRANT command but i guess my disconnect is how the my.cnf file works with this.
Example if I
GRANT ALL PRIVILEGES ON mydatabase.* to jsmith#'somedomain' IDENTIFIED BY 'jimspassword';
but then don't have any IP's bound in the my.cnf file will it still work?
thanks for any help
As documented under GRANT Syntax:
 Account Names and Passwords
[ deletia ]
You can specify wildcards in the host name. For example, user_name#'%.example.com' applies to user_name for any host in the example.com domain, and user_name#'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.

MySQL connection for every host

I'm making a winforms app in vb.net that connects to a mysql database on my webserver to read and write data, this all works fine.
But i have to allow the users ip to remote connect to the database.
Is it possible to give everyone access to the database? The user account will not have all rights an the data isn't very important if it got lost.
The user account and connection details are hard coded.
I know this isnt secure but that doesnt really matter.
Yes, that's very well possible. In your mysql privileges table you'll have to grant a wildcard (%) host access to the user. Then in your VB.NET code simply use the address in the connectionString.
Yes, you can GRANT permissions on the database to the same user with wildcards in the host. More information here.
You can specify wildcards in the host name. For example, user_name#'%.example.com' applies to user_name for any host in the example.com domain, and user_name#'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.
The simple form user_name is a synonym for user_name#'%'.
That way every application connects to the database from random hosts and uses the same username/password in the connection string to authenticate, and MySQL will allow it because the host part of the permissions isn't explicitly specified.
But i have to allow the users ip to remote connect to the database.
Why?
Two other options:
1 - Expose the data as a web service. It's already on the web server...
2 - Build a web app instead of a desktop app.