Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires user to have full database permissions to be able to use "--write-sql" - Security issue #1188

Closed
rimvislt opened this issue Jul 29, 2021 · 3 comments

Comments

@rimvislt
Copy link

Version - "doctrine/migrations": "^3.2",

migrations:migrate --write-sql ~/migration.sql
In ConnectionError.php line 19:
REFERENCES command denied to user 'xxxuser'@'x.x.x.x' for table 'xx_table';

This user does not have full database permissions for most of it - can not create tables, can not alter tables etc..

Previously with doctrine/migrations v 1.x was not executing migrations inside database and no need for user to have all permissions.

We need this functionality because during release we are passing migration.sql file to hosting to review it and execute it on production server.

We do not want to have this web server user all permissions on database to be able to generate migration script.

As a work around we found that running with dry-run we can almost achieve it.
migrations:migrate --dry-run --write-sql ~/migration.sql

but we need to go into migration.sql file and add insert versions into migrations table.

INSERT INTO doctrine_migration_versions (version) VALUES ('Migrations\Version2021xxxxxxxx');

@goetas
Copy link
Member

goetas commented Aug 22, 2021

is there a migration in your list that uses the REFERENCES keyword?

@rimvislt
Copy link
Author

rimvislt commented Aug 23, 2021

yes it is and it is denied for the user which is running migrations:migrate --write-sql ~/migration.sql

   $this->addSql("SET SQL_SAFE_UPDATES=1");

    $this->addSql("ALTER TABLE xx_table " .
        "ADD COLUMN aaa_id INT(11) DEFAULT NULL, " .
        "ADD CONSTRAINT `fk_xxxxx1`".
        "FOREIGN KEY (`aaa_id`) REFERENCES `aaa_table` (`aaa_id`)" .
        "ON DELETE NO ACTION ON UPDATE NO ACTION"
    );

@wiistriker
Copy link
Contributor

i think this can be closed
#1265

@greg0ire greg0ire closed this as completed Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants