SQL-standard function bodies and creating SECURITY DEFINER routines securely

Поиск
Список
Период
Сортировка
От Erki Eessaar
Тема SQL-standard function bodies and creating SECURITY DEFINER routines securely
Дата
Msg-id AM9PR01MB8268BF5E74E119828251FD34FE409@AM9PR01MB8268.eurprd01.prod.exchangelabs.com
обсуждение исходный текст
Ответы Re: SQL-standard function bodies and creating SECURITY DEFINER routines securely  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-docs

Hello

PostgreSQL 14 added the feature: "Allow SQL-language functions and procedures to use SQL-standard function bodies."

If I understand correctly, then in this case the system  will track dependencies between tables and routines that use the tables. Thus, the SECURITY DEFINER routines that use the new approach do not require the following mitigation, i.e., SET search_path= is not needed. The following part of documentation does not mention this.

Here is a small demonstration.

DROP TABLE IF EXISTS T;

CREATE TABLE T(t_id INTEGER,
CONSTRAINT pk_t PRIMARY KEY (t_id));

INSERT INTO T(t_id) VALUES (1), (2);

CREATE OR REPLACE FUNCTION f_find_t_count_with_path_newer() RETURNS bigint
LANGUAGE sql SECURITY DEFINER
SET search_path = public, pg_temp
BEGIN ATOMIC
SELECT Count(*) AS cnt FROM T;
END;

CREATE OR REPLACE FUNCTION f_find_t_count_without_path_newer() RETURNS bigint
LANGUAGE sql SECURITY DEFINER
BEGIN ATOMIC
SELECT Count(*) AS cnt FROM T;
END;

/*I create a fake table in the temporary schema.*/
CREATE TABLE pg_temp.T(t_id INTEGER,
CONSTRAINT pk_t PRIMARY KEY (t_id));

SELECT f_find_t_count_with_path_newer();
Result: 2

SELECT f_find_t_count_without_path_newer();
Result: 2

/*In both cases table T in the schema public was used to return the result.*/

Best regards
Erki Eessaar

В списке pgsql-docs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ^@ operator for text
Следующее
От: PG Doc comments form
Дата:
Сообщение: Typo in "27.2.8. Synchronous Replication"