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

Prevent user that has no acces rights to some table T from creating FOREIGN KEY that references to this T. [CORE4308] #4631

Open
firebird-automations opened this issue Dec 30, 2013 · 5 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

Non-privileged user which has NO any rights to some table with PK can create new ("own") table with FOREIGN KEY and reference to the table that he even can not SELECT.
Perhaps, SELECT privilege for that table can help him to fill the child table with data faster and in such way he can forbid to owner of PARENT table to delete rows.
Scenario:
#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠
C:\MIX\firebird\fb25>isql 192.168.0.201/3252:employee
Database: 192.168.0.201/3252:employee
SQL> create user boss password 'boss'; commit;
SQL> create user junior password 'junior'; commit;

SQL> commit; connect '192.168.0.201/3252:employee' user 'boss' password 'boss';
Database: '192.168.0.201/3252:employee', User: boss
SQL> create table tboss(x int primary key, f01 int);
SQL> insert into tboss values(1, 100);
SQL> insert into tboss values(2, 200);
SQL> insert into tboss values(3, 300);
SQL> commit;

-- indeed not necessary but suppose that DBA gave such priv to BOTH users: tboss and tjunior
-- (or even BOSS really want JUNIOR reads - and only reads - such table);
SQL> grant select on tboss to junior; commit;

SQL> commit; connect '192.168.0.201/3252:employee' user 'junior' password 'junior';
Database: '192.168.0.201/3252:employee', User: junior
SQL>

SQL> show table tboss; -- BTW: why non-priv user can explore DDL of tables ?
X INTEGER Not Null
F01 INTEGER Nullable
CONSTRAINT INTEG_82:
Primary key (X)

SQL> select * from tboss; -- obtain data to write them into 'own` child table

       X          F01

============ ============
1 100
2 200
3 300

-- This statement PASSED OK. Why ?
SQL> create table tjunior(id int primary key, pid int, constraint tjunior_fk_tboss foreign key(pid)
CON> references tboss using index tjunior_fk_idx);

SQL> commit;
SQL> create sequence tjunior; commit;
SQL> insert into tjunior(id, pid) select gen_id(tjunior,1),x from tboss;
SQL> commit;
SQL>

SQL> commit; connect '192.168.0.201/3252:employee' user 'boss' password 'boss';
Database: '192.168.0.201/3252:employee', User: boss
SQL>
SQL> delete from tboss;
Statement failed, SQLSTATE = 23000
violation of FOREIGN KEY constraint "TJUNIOR_FK_TBOSS" on table "TJUNIOR"
-Foreign key references are present for the record

SQL> select * from tjunior;
Statement failed, SQLSTATE = 28000
no permission for read/select access to TABLE TJUNIOR

SQL> alter table tjunior drop constraint TJUNIOR_FK_TBOSS;
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-ERASE RDB$RELATION_CONSTRAINTS failed
-no permission for control access to TABLE TJUNIOR
-<Missing arg #⁠1 - possibly status vector overflow>

It seems to me that user should NOT have any possibility to create FK with reference to tables in case he has no rights on it (to alter or drop).

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

This would sooner mean that the REFERENCES privilege is not enforced.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

I think that such privilege must be granted explicitly by the owner of 'parent' table or SYSDBA.

@firebird-automations
Copy link
Collaborator Author

Commented by: Claudio Valderrama C. (robocop)

IB checked this permission at DML time, for each operation.
After consulting with an SQL expert from Cognos, I changed FB1 to check REFERENCES at DDL time, when a table constraint definition references another table. I created this example as user Claudio:
SQL> show table t;
A INTEGER Nullable
B INTEGER Not Null
CONSTRAINT INTEG_2:
Primary key (B)
SQL> ^Z

Now, I log in with another user and try:

SQL> create table t2(c int references t(b));
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-CREATE TABLE T2 failed
-no permission for REFERENCES access to TABLE T

I don't see the problem and I don't know which DBMS forbids non privileged users to see metatada.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

> IB checked this permission at DML time, for each operation.
> After consulting with an SQL expert from Cognos, I changed FB1 to check REFERENCES at DDL time

Claudio,

sorry, but I don`t understand which version of FIREBIRD did you used in this sample.
What is "FB1" ?...

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

I suppose Claudio used v2.5 to test. As for "FB1", he means FB v1.0 where REFERENCES privilege was moved from DML level to DDL level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant