1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Provide more help around GRANT errors, particularly for missing TEMPORARY TABLE permission

Summary:
Fixes T13622. Figuring out what permissions we have seems difficult, so address this a bit more narrowly:

  - Make the "access denied" error message a bit more helpful.
  - Tailor error handling for the "CREATE TEMPORARY TABLE" statement.

Test Plan:
  - Created a new user, granted them "SELECT ON *.*" but not "CREATE TEMPORARY TABLE", ran `bin/storage upgrade --force --apply phabricator:20210215.changeset.02.phid-populate.php`.
  - Before: fairly opaque error.
  - After: fairly useful error.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13622

Differential Revision: https://secure.phabricator.com/D21608
This commit is contained in:
epriestley 2021-03-11 14:28:41 -08:00
parent 31c9d4094f
commit 32da29b965
2 changed files with 24 additions and 7 deletions

View file

@ -11,12 +11,20 @@ $chunk_size = 4096;
$temporary_table = 'tmp_20210215_changeset_id_map'; $temporary_table = 'tmp_20210215_changeset_id_map';
queryfx( try {
$conn, queryfx(
'CREATE TEMPORARY TABLE %T ( $conn,
changeset_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 'CREATE TEMPORARY TABLE %T (
changeset_phid VARBINARY(64) NOT NULL)', changeset_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
$temporary_table); changeset_phid VARBINARY(64) NOT NULL)',
$temporary_table);
} catch (AphrontAccessDeniedQueryException $ex) {
throw new PhutilProxyException(
pht(
'Failed to "CREATE TEMPORARY TABLE". You may need to "GRANT" the '.
'current MySQL user this permission.'),
$ex);
}
$table_iterator = id(new LiskRawMigrationIterator($conn, $table_name)) $table_iterator = id(new LiskRawMigrationIterator($conn, $table_name))
->setPageSize($chunk_size); ->setPageSize($chunk_size);

View file

@ -347,7 +347,16 @@ abstract class AphrontBaseMySQLDatabaseConnection
case 1142: // Access denied to table case 1142: // Access denied to table
case 1143: // Access denied to column case 1143: // Access denied to column
case 1227: // Access denied (e.g., no SUPER for SHOW SLAVE STATUS). case 1227: // Access denied (e.g., no SUPER for SHOW SLAVE STATUS).
throw new AphrontAccessDeniedQueryException($message);
// See T13622. Try to help users figure out that this is a GRANT
// problem.
$more = pht(
'This error usually indicates that you need to "GRANT" the '.
'MySQL user additional permissions. See "GRANT" in the MySQL '.
'manual for help.');
throw new AphrontAccessDeniedQueryException("{$message}\n\n{$more}");
case 1045: // Access denied (auth) case 1045: // Access denied (auth)
throw new AphrontInvalidCredentialsQueryException($message); throw new AphrontInvalidCredentialsQueryException($message);
case 1146: // No such table case 1146: // No such table