SonarQube analysis via Maven fails with database access denied to MySQL - mysql

I have instances of MySQL, SonarQube, and TeamCity all running on the same Linux host. All are very vanilla installations (out of the box / insecure / local / behind company firewall).
These are my Maven settings ... where ${fullyQualifiedDomainName} is something like build.company.com
<profile>
<id>env-dev</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<sonar.jdbc.url>jdbc:mysql://${fullyQualifiedDomainName}:3306/sonar?useUnicode=true&characterEncoding=utf8</sonar.jdbc.url>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.host.url>http://${fullyQualifiedDomainName}:9000</sonar.host.url>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
I run the command mvn sonar:sonar to perform and upload SonarQube analysis.
The Maven settings above work OK from my Windows PC. However, if I run from the Linux server via TeamCity, I see this error: (giant Java stacktrace + ...):
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on project IMQuant:
Fail to connect to database:
Cannot create PoolableConnectionFactory
(Access denied for user 'sonar'#'${fullyQualifiedDomainName}'
(using password: YES)) -> [Help 1]
If I switch to use localhost in the Maven settings it runs OK on the Linux server. I am guessing this is one of the following issues:
MySQL config (I am a MySQL newbie)
Linux server config (network config / admin stuff beyond my control)
MySQL JDBC driver bug (localhost != fqdn from localhost)
For now I am using a second Maven profile in my settings for TeamCity / Linux with localhost.
Is there a solution for this issue? Has anyone seen this issue?
Update
Here are the commands to create my MySQL database for SonarQube. As noted by #Mithfindel, it may be the root cause.
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;
Ref: https://github.com/SonarSource/sonar-examples/blob/master/scripts/database/mysql/create_database.sql

It looks like a MySQL configuration issue: for MySQL, a GRANT on localhost is different from a GRANT on localhost's FQDN. You might want to check which permissions are granted to users 'sonar'#'localhost' and 'sonar'#'fqdn-of-localhost' or 'sonar'#'%'.

Related

Access denied for user developer#localhost (using password: YES) while connecting spring boot application to mysql server installed in EC2 instance

I created an EC2 instance and installed mySQL in it.
Then, I ran the following commands...
create user 'developer'#'%' identified by 'password';
grant all privileges on *.* to 'developer'#'%' with grant option;
flush privileges;
Then, I created a connection to the remote mySQL server from MySQL workbench installed on my local system. Connection was successful.
Then, to connect my spring boot application to the remote mySQL server I changed the configuration in the 'application.properties' file as shown below -
spring.datasource.url=jdbc:mysql://localhost:3306/exam?serverTimezone=UTC
spring.datasource.username=developer
spring.datasource.password=password
But then when I tried to run the application, it showed the following -
Access denied for user 'developer'#'localhost' (using password: YES)
I searched for a solution on stackoverflow and one of the answers said '%' does not include 'localhost' and that a separate user should be created for localhost.
Hence, I created another user 'developer'#'localhost' with same privileges but still the issue remains unsolved.

TALEND - Vagrant Mysql connexion issues

I'm pulling my hair over the following situation.
I'm unable to connect to my MySQL server in Vagrant (2.0.0 , OS: Ubuntu 16.04 ) with only specific applications (HeidiSQL and Talend 6.1).
This error happens with Talend MySQL components with the mysql-connector-java-5.1.30 jar and Java 1.8 JRE.
I receive the following error each time when connecting either directly (TCP/IP) or over SSH (TCP/IP over SSH) to the MySQL Server with the aforementionned applications:
Access denied for user 'user'#'IP' (using password: YES)
This however doesn't happens with MysqlWorkbench with both direct connection (TCP/IP) or over SSH with the same user credentials. Below are the settings of the MySQL server:
MySQL Server Network Info
Maria Db: 10.0.34
bind-address: 0.0.0.0
skip-name-resolve: true
The following have already been tried and tested:
Access credentials and privileges verification
DNS flush both on Guest and Host machines
Addition of MySQL server IP to host file
Verification of ports opening both on host and guest
The following solved the issue:
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'#'%' WITH **GRANT OPTION**;
The GRANT OPTION does the trick.
Alternatively this could be caused by wrong driver being used in your Talend workspace. To update the MySQL connector JAR follow the steps below:
Donwload the updated connector driver here
Replace the 'tMySQLOutput/tMySQLInput' component(s) with an equivalent tJDBC ones
Add the new connector JAR (No 2 on the image) and the class name com.mysql.jdbc.Driver (No 4 on the image) (ref https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing-classpath.html)

Cannot create PoolableConnectionFactory on jenkins

I am using Sonarqube with MySql. I have Jenkins in place and I would like to integrate Sonar runner with TC for differents projects mainly (Java, PHP). I have done following :
Download sonar zip (last version) in windows plateform.
StartSonar.bat
I have a MySQL in CentOS in Remote VM :
I connect to remote MySQL using Cygwin ssh:
then I create a schema, as follow :
MySQL:
CREATE DATABASE sonar CHARACTER SET UTF8;
CREATE USER 'sonar'#'*' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'*';
FLUSH PRIVILEGES;
Then I disabled the VM firewall with : sudo systemctl stop firewalld
When I start my sonar with StartSonar.bat, I have the following error:
Stacktrace:
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'sonar'#'10.1.162.61' (using password: YES))
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) ~[commons-dbcp-1.4.jar:1.4]
at org.sonar.core.persistence.DefaultDatabase.checkConnection(DefaultDatabase.java:115) ~[sonar-core-5.1.2.jar:na]
... 28 common frames omitted
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'10.1.162.61' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) ~[mysql-connector-java-5.1.34.jar:5.1.34]
What am I missing here, please ?
The solution is to enable sonar credentials in sonar.properties in conf folder as follow :
# User credentials.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- MySQL 5.x
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported.
sonar.jdbc.url=jdbc:mysql://10.1.163.103:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar login failure

i installed sonar on rhel 6.3 64 bit machine and integrated it with mysql database. Following is my sonar.properties file details:
#----- MySQL 5.x/6.x
# Comment the embedded database and uncomment the following line to use MySQL
sonar.jdbc.url: jdbc:mysql://10.217.14.40:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
# Optional properties
sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://10.217.14.40:9000/
also i created the sonar database, sonar user, and grant permissions by using the script provided in the sonar installation
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;
Now when i try to login to sonar i get "AUTHENTICATION FAILED" message please could somebody help me
The default built-in credentials for a first install of Sonar are "admin/admin".
Is it what you're using to log in?

Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)

I am trying to add Sonar to my Continuous Integration build system. I am using ANT as my build script and I am using the sonar-ant-task-1.1.jar for sonar to generate the reports based on my source code in SVN.
Problem
When the build runs and hits the sonar ant task I get the exception as follows:
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at org.sonar.jpa.session.DriverProxy.connect(DriverDatabaseConnector.java:160)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.sonar.jpa.session.DriverDatabaseConnector.getConnection(DriverDatabaseConnector.java:95)
at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:185)
... 40 more
What I have done
1. Install MySQL database.
2. Create the sonar database, sonar user, and grant permissions by using the script provided in the sonar installation
**CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;**
3. Added the following to my build script
4. Added the following external variables in Jenkins Freestyle build project
sonar.jdbc.url=jdbc:mysql://10.120.21.12:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://10.120.21.12:9000/
5. I was also available to connect to the database through my sql client tool to verify that the database, user and permissions statements were executed correctly.
However when Jenkins runs the build it does not seem to know how to connect to the MySQL database.
Any thoughts?
The solution was to run the following command:
GRANT ALL ON *.* TO 'sonar'#'%';
The right solution is this:
GRANT ALL PRIVILEGES ON `sonar`.* TO 'sonar'#'localhost';
As explained here, connections to localhost occur over a UNIX domain socket. You are likely logging in as an anonymous user to localhost (e.g. ''#localhost).
I just tried it with sonar 4.5.2 with grants only on sonar.* and its definitely not working.
It looks like sonarqube requires additionnal privileges to work, personnaly i haven't identified which ones yet, and i'm still using a grant all on the database.