MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
759 stars 438 forks source link

GRANT FILE directive on docker-entrypoint being ignored/dropped with docker-compose #493

Closed wakatara closed 1 year ago

wakatara commented 1 year ago

Heya MariaDB Docker devs,

TLDR

GRANT FILE ON is being ignored in the entrpoint init script. How do I fix this (as I want to automate loading database csv's etc)?

Longer Tale

(first off, thanks for all your hard work. MariaDB has been super smooth on Docker so far. 😍)

I've got an issue where not all GRANTS are being taken into account on my startup spinup though. In docker-compose, my section for maria looks like this (I am using it with alembic to automate migrations and build of DB:

  mariadb:
    container_name: mariadb
    build:
      context: .
      dockerfile: ./config/mariadb/Dockerfile
    environment:
      MYSQL_ROOT_PASSWORD: SuperSuperSekrit
      MYSQL_DATABASE: coma_dev
      MYSQL_USER: coma_dev
      MYSQL_PASSWORD: JustSuperSekrit
    restart: always
    ports:
      - 3306:3306
    volumes: 
      - maria-db-data-volume:/var/lib/mysql
      - maria-db-logs-volume:/var/log/mysql
      - ./config/mariadb/init:/docker-entrypoint-initdb.d
      - ./alembic:/usr/src/alembic

Under the docker-entrypoint I am copying over an ./config/mariadb/init/sql/01.sql file to kickstart the DB.

CREATE DATABASE IF NOT EXISTS 'coma_dev';
GRANT ALL ON 'coma_dev'.* TO 'coma_dev'@'%';
GRANT FILE ON *.* TO 'coma_dev'@'%';

The first two lines work, but for some reason the GRANT FILE does not and since I'm loading heaps of static tables via alembic on the migration (it's a scientific database), it means I have to log into the docker container manually as root on the mariadb cli and run the grant file privilege which does not lend to automation.

Is this a bug or is there something I need to do in order to allow this to happen? (I had assumed the kickstart sql ran as the root user or at least had special privileges.

Note: I am building and installing a modified version of the DB as I need additional packages and pips but had assumed that does not affect this entrypoint script (which I'm assuming happened on docker-compose up -d

grooverdan commented 1 year ago
$ podman run --env MYSQL_ROOT_PASSWORD=SuperSuperSekrit --env MYSQL_DATABASE=coma_dev --env MYSQL_USER=coma_dev --env MYSQL_PASSWORD=JustSuperSekrit -v ./x:/docker-entrypoint-initdb.d:z --rm --name m mariadb:latest
....
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''coma_dev'' at line 

create database cannot single quote the database name. Also with MYSQL_DATABASE specified, the database is created, and with MYSQL_USER/PASSWORD the default database grants are there.

With the one remaining needed grant left in the sql file GRANT FILE ON *.* TO 'coma_dev'@'%';:

Starts correctly and the FILE grant is created:

$ podman exec -ti m mariadb -pSuperSuperSekrit -e 'show grants for coma_dev; show databases'
+--------------------------------------------------------------------------------------------------------+
| Grants for coma_dev@%                                                                                  |
+--------------------------------------------------------------------------------------------------------+
| GRANT FILE ON *.* TO `coma_dev`@`%` IDENTIFIED BY PASSWORD '*3290434C5A9A682CF48AE407BD540430E61B0306' |
| GRANT ALL PRIVILEGES ON `coma\_dev`.* TO `coma_dev`@`%`                                                |
+--------------------------------------------------------------------------------------------------------+
+--------------------+
| Database           |
+--------------------+
| coma_dev           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

The other possibility is your own Dockerfile/entrypoint has broken this somehow.