Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(install) Get the ip address of an existing connection to set the permission correctly #7347

Merged
merged 4 commits into from
Apr 3, 2019

Conversation

lgcosta
Copy link
Contributor

@lgcosta lgcosta commented Mar 28, 2019

Pull Request Template

Description

When an installation of the Centreon is done using the database server (MySQL) on an external server and it is on another network being accessed only via NAT, an ip address is mistakenly assigned in the user permission centreon of MySQL.

Currently it uses a server variable to get the client ip ($_SERVER['SERVER_ADDR']). however, when the server is in another network location, the ip that needs to be allocated in the user's permission is the network gateway (which does the NAT).

As for getting to this centreon user creation function, it is necessary to have the connection using valid root, I am taking into account that there is a valid connection and functioning as root. So, I have a attribute available in the PDO connection object and with that, I use an attribute available PDO::ATTR_CONNECTION_STATUS in the object to get the valid ip address of the client for the connection.

Using mysql directly is more effective, the PDO was returning me the ip of the server.

mysql> select host from information_schema.processlist WHERE ID=connection_id();
+------------------+
| host             |
+------------------+
| 172.17.0.1:45842 |
+------------------+

This way, I use the Mysql information table and I can capture the ip of the current session.

Type of change

  • Patch fixing an issue (non-breaking change)
  • New functionality (non-breaking change)
  • Breaking change (patch or feature) that might cause side effects breaking part of the Software
  • Updating documentation (missing information, typo...)

Target serie

  • 2.8.x
  • 18.10.x
  • 19.04.x (master)

How this pull request can be tested ?

I came up with this problem using environments where I used MariaDB on docker instances in networks other than the Centreon installation. For example, I have the MariaDB docker on the 172.17.0.0/24 network and the Centreon installation on a Vagrant on the 10.1.0.0/24 network.

Checklist

Community contributors & Centreon team
  • I followed the coding style guidelines provided by Centreon
  • I have commented my code, especially new classes, functions or any legacy code modified. (docblock)
  • I have commented my code, especially hard-to-understand areas of the PR.
  • I have made corresponding changes to the documentation.
  •  I have rebased my development branch on the base branch (master, maintenance).
Centreon team only
  • I have made sure that the unit tests related to the story are successful.
  • I have made sure that unit tests covers 80% of the code written for the story.
  • I have made sure that acceptance tests related to the story are successful (local and CI)

@lgcosta lgcosta requested review from kduret, lpinsivy, sc979 and ganoze and removed request for lpinsivy March 28, 2019 13:08
@lgcosta lgcosta changed the title fix(install) Get the ip address of an existing connection to set the permission correctly WIP: fix(install) Get the ip address of an existing connection to set the permission correctly Mar 28, 2019
@lgcosta lgcosta requested a review from ganoze March 28, 2019 14:04
@lgcosta lgcosta changed the title WIP: fix(install) Get the ip address of an existing connection to set the permission correctly fix(install) Get the ip address of an existing connection to set the permission correctly Mar 28, 2019
www/install/steps/process/createDbUser.php Outdated Show resolved Hide resolved
Co-Authored-By: lgcosta <luizgustavo@luizgustavo.pro.br>
@lgcosta
Copy link
Contributor Author

lgcosta commented Apr 3, 2019

@kduret, @ganoze, @sc979 can I merge this PR?

@kduret
Copy link
Contributor

kduret commented Apr 3, 2019

is it possible that "SELECT host FROM information_schema.processlist WHERE ID = connection_id()" does not return anything ?
does it respect our MySQL/MariaDB compatibilities ?

@lgcosta
Copy link
Contributor Author

lgcosta commented Apr 3, 2019

is it possible that "SELECT host FROM information_schema.processlist WHERE ID = connection_id()" does not return anything ?
does it respect our MySQL/MariaDB compatibilities ?

  • The information_schema is a core table from Mysql, common in Mysql and Mariadb [1] and [2]
  • The function connection_id() is a core function, common in Mysql and Mariadb [3] and [4]

As it takes advantage of an active match from the root connection, the field will return a value in relation to an active connection_id(). This is only different if I connect a client directly to the Mysql socket file, the field will return empty (I did the test). However, we do not have the case of direct connection on the socket, we always do over inet (tcp).

[1] https://dev.mysql.com/doc/refman/8.0/en/processlist-table.html
[2] https://mariadb.com/kb/en/library/information-schema-processlist-table/
[3] https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_connection-id
[4] https://mariadb.com/kb/en/library/connection_id/

@kduret
Copy link
Contributor

kduret commented Apr 3, 2019

Ok thanks for reply. Then you can merge it ;)

@lgcosta lgcosta merged commit 74f3c75 into master Apr 3, 2019
@ganoze ganoze deleted the external_mysqld branch April 3, 2019 12:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants