MySQL allow access from specific domain? - mysql

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.

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.

I'm able to login on phpMyAdmin with root, even it's restricted to localhost

I'm able to login on phpMyAdmin with a root user and other users, even though I have restricted login to localhost. How can I fix this problem and restrict access to only one specified user remotely. Every other user account shouldn't be accessible remotely, especially root.
phpMyAdmin user accounts
As #Matt Clark points out, the MySQL user privileges consider the connection between MySQL and the web server. In order to restrict users from connecting to phpMyAdmin, you'll have to either configure your webserver to be more restrictive or use some of the protections included with phpMyAdmin.
Luuk mentioned that the AllowRoot directive can allow you to restrict root from connecting, but you might want to look at the allow/deny rules instead (or in addition): https://docs.phpmyadmin.net/en/latest/config.html#cfg_Servers_AllowDeny_rules. These go in your phpMyAdmin configuration file, config.inc.php, in the server-specific section. If you don't already have a config.inc.php file, you can create one in the same directory as the main phpMyAdmin installation, with this content, then put any additional directives at the end.
<?php
$i=0;
$i++;
If you'll always connect from the same IP address or range, something like this might be to your liking, adjusted of course for the proper username and addresses:
$cfg['Servers'][$i]['AllowDeny']['order'] = 'allow,deny';
$cfg['Servers'][$i]['AllowDeny']['rules'] = array('allow jan from 192.168.74.[0-255]');
Or, to allow access from any IP address,
$cfg['Servers'][$i]['AllowDeny']['order'] = 'allow,deny';
$cfg['Servers'][$i]['AllowDeny']['rules'] = array('allow jan from any');
By the way, as two other common security measures, phpMyAdmin also has support for two-factor authentication and can log failed login attempts such that a tool like fail2ban can be used.

Handling users of phpMyAdmin

Hi stackoverflow community,
I have some doubts in how to manage the users in phpMyAdmin, I am starting a project but I see multiple users with ALL PRIVILEGES.
I should choose one user, set my password, and then delete the other ones?
Having multiple users with ALL PRIVILEGES and without any password can be a security trouble?
What is the difference between the root users? And servers 127.0.0.1, ::1 and localhost?
I leave here an image to be more specific and show graphically what I meaning.
http://i.imgur.com/w2Ga8XS.jpg
http://i.stack.imgur.com/hVFW7.jpg
I would appreciate detailed and understandable answers.
Thank you in advance.
MySQL allows you to restrict permissions to a username, host pair. This means that the user only has the permissions when they login from the specified host. Typically you restrict MySQL admin permissions only if the user on the local machine (ie: the one that is running MySQL). The local machine can be called localhost, 127.0.0.0, or, in IPv6, ::1. So you only have one root user. They will only be given admin privileges when they login from the local host. You shouldn't delete any of them. You should set the password on the ::1 line (I don't know why it's not set).

How do I allow mysql client connections to be established with our mysql web server?

It seems that the web server is preventing me to change permissions to the user. It does not allow me to GRANT ALL ON foo.* TO bar#'202.54.10.20' IDENTIFIED BY 'PASSWORD'; and returns an error message of access denied for the username that I'm using.
It also appears that the folder etc in the file manager is empty whereas in the given link below, it shows that the bind address can be edited in the my.cnf inside etc folder.
How do I allow my mysql database to be accessible remotely by any computer?
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
The bind option in my.cnf is not that problem (since you can connect, the MySQL server is just not letting you in), and judging from the screenshot, you don't seem to have the permissions to edit that file anyways.
Most likely, your request is not coming from 202.54.10.20, or you have mistyped username/password. If the web application runs on the same machine as the MySQL server, connections will come from somewhere in the 127.0.0.0/8 range.
Look at the connection string in your web application:
If it is a public IP address, check username/password and originating IP.
If it starts with 127., GRANT to your local address.
If it is localhost, you're connecting via Unix socket instead of TCP. This is a good thing, and you can simply GRANT to localhost.
To issue this command:
GRANT ALL ON foo.* TO bar#'202.54.10.20' IDENTIFIED BY 'PASSWORD';
You MUST connect to the database first. So if you don't have permissions to remotely access database, you should go to the database server host and login locally, using root#localhost.
I just found out that there is an option which basically do the same thing as what I wanted it to be doing. There is an option for the user to enable remote database access to its clients.

Granting mysql access rights to all machines on subnet

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.