forked from facebook/mysql-5.6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Port Control Cross-Table Access to 8.0
Summary: Port our v5.6 sysvar allow_noncurrent_db_rw, which detects when a query accesses data not in the current database. Depending on its setting, when a query tries to read or write to another database, it will: ON: Allow it. LOG: Allow it, but log that it occurred. LOG_WARN: Allow it, log it occurred, and send an error to client. OFF: Block it, and send an error to the client. Reference patch: facebook@b5f54b4 Differential Revision: D6071054 (facebook@d04eb6a) fbshipit-source-id: 690ab034efe
- Loading branch information
Showing
8 changed files
with
338 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
mysql-test/suite/sys_vars/r/allow_noncurrent_db_rw_basic.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
set @start_allow_noncurrent_db_rw= @@global.allow_noncurrent_db_rw; | ||
set global allow_noncurrent_db_rw = ALLOWED; | ||
ERROR 42000: Variable 'allow_noncurrent_db_rw' can't be set to the value of 'ALLOWED' | ||
Expected error ER_WRONG_VALUE_FOR_VAR | ||
show databases; | ||
Database | ||
information_schema | ||
mtr | ||
mysql | ||
performance_schema | ||
sys | ||
test | ||
set global allow_noncurrent_db_rw = OFF; | ||
connect (non_current_db,localhost,root,,*NO-ONE*); | ||
select database(); | ||
database() | ||
NULL | ||
create table test.allow_noncurrent_db_rw_create (id int); | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
set global allow_noncurrent_db_rw = LOG; | ||
connect (con1,localhost,root,,test); | ||
connection default; | ||
drop database if exists mysqltest_db1; | ||
drop database if exists mysqltest_db2; | ||
create database mysqltest_db1; | ||
create database mysqltest_db2; | ||
connect (con_test_db1,localhost,root,,mysqltest_db1); | ||
create table t1 (id int); | ||
create table t2 (id int); | ||
insert t1 values(1); | ||
insert t2 values(1); | ||
connect (con_test_db2,localhost,root,,mysqltest_db2); | ||
create table t1 (id int); | ||
create table t2 (id int); | ||
insert t1 values(1); | ||
insert t2 values(1); | ||
set allow_noncurrent_db_rw = LOG_WARN; | ||
select * from mysqltest_db1.t1; | ||
id | ||
1 | ||
Warnings: | ||
Warning 1290 The MySQL server is running with the --allow_noncurrent_db_rw=LOG_WARN option so it cannot execute this statement | ||
set allow_noncurrent_db_rw = OFF; | ||
select * from mysqltest_db1.t1; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
insert mysqltest_db1.t1 values(2); | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
update mysqltest_db1.t1 set id=11 where id =1; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
insert t1 values(100); | ||
insert into mysqltest_db1.t1 SELECT * from t1 where id=100; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
create table mysqltest_db1.t_create (id int) select * from t1; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
delete from mysqltest_db1.t1 where id=1; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
replace into mysqltest_db1.t1 SELECT * from t1 where id=100; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
alter table mysqltest_db1.t1 add column (id2 int); | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
1 2 3 (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) | ||
1 2 3 1 | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db1.t2 test2 WHERE test1.id = test2.id; | ||
id id | ||
1 1 | ||
set allow_noncurrent_db_rw = LOG_WARN; | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
1 2 3 (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) | ||
1 2 3 1 | ||
Warnings: | ||
Warning 1290 The MySQL server is running with the --allow_noncurrent_db_rw=LOG_WARN option so it cannot execute this statement | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db2.t2 test2 WHERE test1.id = test2.id; | ||
id id | ||
1 1 | ||
Warnings: | ||
Warning 1290 The MySQL server is running with the --allow_noncurrent_db_rw=LOG_WARN option so it cannot execute this statement | ||
set allow_noncurrent_db_rw = OFF; | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db2.t2 test2 WHERE test1.id = test2.id; | ||
ERROR HY000: The MySQL server is running with the --allow_noncurrent_db_rw=OFF option so it cannot execute this statement | ||
desc performance_schema.global_variables; | ||
Field Type Null Key Default Extra | ||
VARIABLE_NAME varchar(64) NO PRI NULL | ||
VARIABLE_VALUE varchar(1024) YES NULL | ||
desc information_schema.character_sets; | ||
Field Type Null Key Default Extra | ||
CHARACTER_SET_NAME varchar(64) NO NULL | ||
DEFAULT_COLLATE_NAME varchar(64) NO NULL | ||
DESCRIPTION varchar(2048) NO NULL | ||
MAXLEN int unsigned NO NULL | ||
desc sys.schema_table_statistics; | ||
Field Type Null Key Default Extra | ||
table_schema varchar(64) YES NULL | ||
table_name varchar(64) YES NULL | ||
total_latency varchar(11) YES NULL | ||
rows_fetched bigint unsigned NO NULL | ||
fetch_latency varchar(11) YES NULL | ||
rows_inserted bigint unsigned NO NULL | ||
insert_latency varchar(11) YES NULL | ||
rows_updated bigint unsigned NO NULL | ||
update_latency varchar(11) YES NULL | ||
rows_deleted bigint unsigned NO NULL | ||
delete_latency varchar(11) YES NULL | ||
io_read_requests decimal(42,0) YES NULL | ||
io_read varchar(11) YES NULL | ||
io_read_latency varchar(11) YES NULL | ||
io_write_requests decimal(42,0) YES NULL | ||
io_write varchar(11) YES NULL | ||
io_write_latency varchar(11) YES NULL | ||
io_misc_requests decimal(42,0) YES NULL | ||
io_misc_latency varchar(11) YES NULL | ||
set allow_noncurrent_db_rw = ON; | ||
rename table mysqltest_db1.t1 to mysqltest_db2.t2_1; | ||
rename table mysqltest_db2.t2_1 to mysqltest_db1.t1; | ||
select * from mysqltest_db1.t1; | ||
id | ||
1 | ||
drop database mysqltest_db1; | ||
drop database mysqltest_db2; | ||
set global allow_noncurrent_db_rw= @start_allow_noncurrent_db_rw; |
133 changes: 133 additions & 0 deletions
133
mysql-test/suite/sys_vars/t/allow_noncurrent_db_rw_basic.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
############## mysql-test\t\allow_noncurrent_db_rw_basic.test ################## | ||
# # | ||
# Variable Name: allow_noncurrent_db_rw # | ||
# Scope: GLOBAL & SESSION # | ||
# Access Type: Dynamic # | ||
# Data Type: Numeric # | ||
# Default Value: 0 # | ||
# Range: 0,1,2 & 3 # | ||
# # | ||
# # | ||
# Creation Date: 2012-11-06 # | ||
# Author: Mayank Agarwal # | ||
# # | ||
# Description: Allow/deny read/write to table not in the current database # | ||
# # | ||
# Reference: http://dev.mysql.com/doc/refman/5.1/en/ # | ||
# server-system-variables.html # | ||
# # | ||
################################################################################ | ||
|
||
--source include/load_sysvars.inc | ||
|
||
################################################################################ | ||
# START OF allow_noncurrent_db_rw TEST # | ||
################################################################################ | ||
|
||
set @start_allow_noncurrent_db_rw= @@global.allow_noncurrent_db_rw; | ||
|
||
--Error ER_WRONG_VALUE_FOR_VAR | ||
set global allow_noncurrent_db_rw = ALLOWED; | ||
--ECHO Expected error ER_WRONG_VALUE_FOR_VAR | ||
|
||
show databases; | ||
|
||
set global allow_noncurrent_db_rw = OFF; | ||
--echo connect (non_current_db,localhost,root,,*NO-ONE*); | ||
connect (non_current_db,localhost,root,,*NO-ONE*); | ||
select database(); | ||
--error ER_OPTION_PREVENTS_STATEMENT | ||
create table test.allow_noncurrent_db_rw_create (id int); | ||
|
||
set global allow_noncurrent_db_rw = LOG; | ||
|
||
--echo connect (con1,localhost,root,,test); | ||
connect (con1,localhost,root,,test); | ||
|
||
--echo connection default; | ||
connection default; | ||
|
||
--disable_warnings | ||
drop database if exists mysqltest_db1; | ||
drop database if exists mysqltest_db2; | ||
create database mysqltest_db1; | ||
create database mysqltest_db2; | ||
--enable_warnings | ||
|
||
--echo connect (con_test_db1,localhost,root,,mysqltest_db1); | ||
connect (con_test_db1,localhost,root,,mysqltest_db1); | ||
create table t1 (id int); | ||
create table t2 (id int); | ||
insert t1 values(1); | ||
insert t2 values(1); | ||
|
||
--echo connect (con_test_db2,localhost,root,,mysqltest_db2); | ||
connect (con_test_db2,localhost,root,,mysqltest_db2); | ||
create table t1 (id int); | ||
create table t2 (id int); | ||
insert t1 values(1); | ||
insert t2 values(1); | ||
|
||
connection con_test_db2; | ||
|
||
set allow_noncurrent_db_rw = LOG_WARN; | ||
select * from mysqltest_db1.t1; | ||
|
||
set allow_noncurrent_db_rw = OFF; | ||
--error ER_OPTION_PREVENTS_STATEMENT | ||
select * from mysqltest_db1.t1; | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
insert mysqltest_db1.t1 values(2); | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
update mysqltest_db1.t1 set id=11 where id =1; | ||
|
||
insert t1 values(100); | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
insert into mysqltest_db1.t1 SELECT * from t1 where id=100; | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
create table mysqltest_db1.t_create (id int) select * from t1; | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
delete from mysqltest_db1.t1 where id=1; | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
replace into mysqltest_db1.t1 SELECT * from t1 where id=100; | ||
|
||
--error ER_OPTION_PREVENTS_STATEMENT | ||
alter table mysqltest_db1.t1 add column (id2 int); | ||
|
||
connection con_test_db1; | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db1.t2 test2 WHERE test1.id = test2.id; | ||
|
||
set allow_noncurrent_db_rw = LOG_WARN; | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db2.t2 test2 WHERE test1.id = test2.id; | ||
|
||
set allow_noncurrent_db_rw = OFF; | ||
--error ER_OPTION_PREVENTS_STATEMENT | ||
SELECT 1, 2, 3, (SELECT * FROM mysqltest_db1.t1 WHERE id = T.id) FROM mysqltest_db2.t2 T; | ||
--error ER_OPTION_PREVENTS_STATEMENT | ||
SELECT test1.*, test2.* FROM mysqltest_db1.t1 test1, mysqltest_db2.t2 test2 WHERE test1.id = test2.id; | ||
# these schemas are filtered and should pass when the variable is set to OFF | ||
desc performance_schema.global_variables; | ||
desc information_schema.character_sets; | ||
desc sys.schema_table_statistics; | ||
|
||
set allow_noncurrent_db_rw = ON; | ||
rename table mysqltest_db1.t1 to mysqltest_db2.t2_1; | ||
rename table mysqltest_db2.t2_1 to mysqltest_db1.t1; | ||
select * from mysqltest_db1.t1; | ||
|
||
connection default; | ||
drop database mysqltest_db1; | ||
drop database mysqltest_db2; | ||
set global allow_noncurrent_db_rw= @start_allow_noncurrent_db_rw; | ||
|
||
################################################################################ | ||
# END OF allow_noncurrent_db_rw TEST # | ||
################################################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.