powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Firebird, InterBase [игнор отключен] [закрыт для гостей] / execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
7 сообщений из 7, страница 1 из 1
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940065
Таблоид
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
hi all

Дано:
1) таблица test, на выборку данных которой имеет право только ХП sp_test;
2) усер john_senior, лишенный всех прав, кроме вызова ХП sp_test;
3) усер mick_junior, лишенный всех прав;

Скрипт:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
-- Готовим базу:
shell del C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb 2>nul;
create database 'localhost/3333:C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb';
commit;

drop user john_senior;
drop user mick_junior;
commit;
create user john_senior password 'qwe';
create user mick_junior password '123';
commit;

create or alter procedure sp_test as
begin
end;

recreate table test(id int, x int);
commit;

insert into test values(1, 100);
commit;

set term ^;
create or alter procedure sp_test returns(id int, x int) as
begin
  for select id, x from test into id, x do suspend;
end
^
set term ;^

revoke all on all from john_senior;
revoke all on all from mick_junior;
commit;

 grant select on test to procedure sp_test;
grant execute on procedure sp_test to john_senior;
commit; 


-- Теперь коннектимся от имени john_senior'a, который может вызывать ХП:
 connect  'localhost/3333:C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb' user ' john_senior ' password 'qwe';
-- (эффект от коннекта от имени 'mick_junior'a будет таким же)

set list on;

set term ^;

-- Этот ЕВ отработает ОК
execute block returns(who_am_i varchar(31), what_is_my_role varchar(31), id int, x int) as
begin
  for
      execute statement
      'select current_user, current_role, id, x from sp_test'
      as user 'john_senior' password 'qwe'
      into who_am_i, what_is_my_role, id, x
  do
      suspend;

end
^

-- А этот - обломается:
-- Statement failed, SQLSTATE = 28000
-- no permission for EXECUTE access to PROCEDURE SP_TEST
execute block returns(who_am_i varchar(31), what_is_my_role varchar(31), id int, x int) as
begin
  for
      execute statement
      'select current_user, current_role, id, x from sp_test'
       WITH CALLER PRIVILEGES 
      as user 'mick_junior' password '123'
      into who_am_i, what_is_my_role, id, x
  do
      suspend;

end
^
set term ;^


Если выкинуть из output'a предупреждалки и сообщения об отсутствии учетных записей (в ответ на drop), то получим на консоли:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
WHO_AM_I                        JOHN_SENIOR
WHAT_IS_MY_ROLE                 NONE
ID                              1
X                               100


Statement failed, SQLSTATE = 28000
no permission for EXECUTE access to PROCEDURE SP_TEST

В доке сказано:By default, the SQL statement is executed with the privileges of the current user . Specifying WITH CALLER PRIVILEGES adds to this the privileges of the calling SP or trigger, just as if the statement were executed directly by the routine.
В вышеприведенном скрипте:
1) "is executed with the privileges of the current user" -- это привилегии текущего усера, т.е. того, который указан в 'as user', а значит - это привилегии mick_junior . На самом деле у него нет никаких привилегий (см выше);
2) "adds to this the privileges of the calling SP" -- это привилегии хранимой процедуры, т.е. это право на селект из таблицы 'test', которое дано было этой ХП.

Ну, и в где тут было "добавление привилегий" ? Почему 'mick_jounor' получил облом при выборке через ES, хотя там явно указано 'WITH CALLER PRIVILEGES' ?
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940068
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
ТаблоидПочему 'mick_jounor' получил облом при выборке через ES, хотя там явно
указано 'WITH CALLER PRIVILEGES' ?
Ты этому EB какие-нибудь привилегии грантовал? Нет. Вот и нет их у него.
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940076
Таблоид
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Разобрался, спс!
Вот скрипт, иллюстрирующий необходимость 'WITH CALLER PRIVILEGES', может пригодится кому:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
shell del C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb 2>nul;
create database 'localhost/3333:C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb';
commit;

drop user john_senior;
drop user mick_junior;
drop role role_for_mick;
commit;
create user john_senior password 'qwe';
create user mick_junior password '123';
commit;

create role role_for_mick;
commit;

create or alter procedure sp_test as
begin
end;

recreate table test(id int, x int);
commit;

insert into test values(1, 100);
commit;

set term ^;
create or alter procedure sp_test returns(id int, x int) as
begin
  for select id, x from test into id, x do suspend;
end
^

create or alter procedure sp_main(a_usr varchar(31), a_pwd varchar(31))
  returns(who_am_i varchar(31), what_is_my_role varchar(31), id int, x int) as
begin
  for
      execute statement
      'select current_user, current_role, id, x from sp_test'
      WITH CALLER PRIVILEGES -- если закомментарить, то выборки обломаются
      as user a_usr password a_pwd
      into who_am_i, what_is_my_role, id, x
  do
      suspend;
end
^
set term ;^
commit;

revoke all on all from john_senior;
revoke all on all from mick_junior;
revoke all on all from role_for_mick;
commit;

grant select on test to procedure sp_test;
grant execute on procedure sp_main to john_senior;
grant execute on procedure sp_main to role_for_mick;
grant execute on procedure sp_test to procedure sp_main;
grant role_for_mick to mick_junior;
commit;

set list on;

connect 'localhost/3333:C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb' user 'john_senior' password 'qwe';
select current_user, current_role from rdb$database;
select * from sp_main('john_senior', 'qwe');
commit;

connect 'localhost/3333:C:\FBTESTING\qa\fbt-repo\tmp\c0805.fdb' user 'mick_junior' password '123' role 'ROLE_FOR_MICK';
select current_user, current_role from rdb$database;
select * from sp_main('mick_junior', '123');
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940079
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Хотя, конечно, в доке зря написано "adds", поскольку оно, похоже, права замещает, а не
добавляет.
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940086
hvlad
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Dimitry SibiryakovХотя, конечно, в доке зря написано "adds", поскольку оно, похоже, права замещает, а не
добавляет.В каком месте это похоже ?
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940092
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
hvladВ каком месте это похоже ?
В стартовом посте. Второй запрос не должен был получить ошибку.
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
    #38940095
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ой, блин, не заметил в куче буковок "as user". Был неправ, извиняюсь.
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Firebird, InterBase [игнор отключен] [закрыт для гостей] / execute statement: не понимаю Великого Замысла кляузы "WITH CALLER PRIVILEGES"
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]