snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.19k stars 3.2k forks source link

Official Docker images Fail Pre-Flight SQL Check #11978

Open alecisec opened 2 years ago

alecisec commented 2 years ago

Debug mode

Describe the bug

Docker containers fail mysql pre-flight check for reasons unknown

Pre-Flight check shows:

D'oh! Looks like we can't connect to your database. Please update your database settings in your .env file. Your database says: SQLSTATE[HY000] [1044] Access denied for user 'snipeit'@'%' to database 'snipeit' (SQL: select 2 + 2)

The following docker-compose.yml was used in testing

version: '2'

services: snipeit: image: snipe/snipe-it:latest environment:

The .env file correctly references this environment variable so it appears the problem lies elsewhere

Reproduction steps

  1. Create Docker containers for snipeit and mariadb using docker-compose with environment variables set
  2. Preflight check fails to connect to db

Expected behavior

.env file should be read and then the environment variable checked and used to test db connection

Snipe-IT Version

Any (tested several)

Operating System

Docker

Web Server

Docker

PHP Version

Docker

Additional context

Note that the container can connect fine using command: mysql -h mariadb -u snipeit -p

welcome[bot] commented 2 years ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

alecisec commented 2 years ago

It appears that changing the username made the error change but the app still fails to auth to the db

Error becomes:

D'oh! Looks like we can't connect to your database. Please update your database settings in your .env file. Your database says: SQLSTATE[HY000] [1045] Access denied for user 'snipeituser'@'172.31.0.3' (using password: YES) (SQL: select 2 + 2)

When changing ONLY the username, also again auth from command line inside the container works fine

alecisec commented 2 years ago

Debug logs show the following:

SQLSTATE[HY000] [1044] Access denied for user 'snipeit'@'%' to database '${MYSQL_DATABASE}' (SQL: select * from information_schema.tables where table_schema = ${MYSQL_DATABASE} and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712 708▕ // If an exception occurs when attempting to run a query, we'll format the error 709▕ // message to include the bindings with SQL, which will make this exception a 710▕ // lot more helpful to the developer instead of just the database's errors. 711▕ catch (Exception $e) { ➜ 712▕ throw new QueryException( 713▕ $query, $this->prepareBindings($bindings), $e 714▕ ); 715▕ } 716▕ } +33 vendor frames 34 artisan:35

PenguinPaws commented 2 years ago

I think this is because your docker-compose file isn't creating a database in the MariaDB server. Try adding this to your environment variables for your mariadb container: