mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Restrict lo_import()/lo_export() via SQL permissions not hard-wired checks.
While it's generally unwise to give permissions on these functions to
anyone but a superuser, we've been moving away from hard-wired permission
checks inside functions in favor of using the SQL permission system to
control access. Bring lo_import() and lo_export() into compliance with
that approach.
In particular, this removes the manual configuration option
ALLOW_DANGEROUS_LO_FUNCTIONS. That dates back to 1999 (commit 4cd4a54c8
);
it's unlikely anyone has used it in many years. Moreover, if you really
want such behavior, now you can get it with GRANT ... TO PUBLIC instead.
Michael Paquier
Discussion: https://postgr.es/m/CAB7nPqRHmNOYbETnc_2EjsuzSM00Z+BWKv9sy6tnvSd5gWT_JA@mail.gmail.com
This commit is contained in:
@ -1115,12 +1115,14 @@ LANGUAGE INTERNAL
|
||||
STRICT IMMUTABLE PARALLEL SAFE
|
||||
AS 'jsonb_insert';
|
||||
|
||||
--
|
||||
-- The default permissions for functions mean that anyone can execute them.
|
||||
-- A number of functions shouldn't be executable by just anyone, but rather
|
||||
-- than use explicit 'superuser()' checks in those functions, we use the GRANT
|
||||
-- system to REVOKE access to those functions at initdb time. Administrators
|
||||
-- can later change who can access these functions, or leave them as only
|
||||
-- available to superuser / cluster owner, if they choose.
|
||||
--
|
||||
REVOKE EXECUTE ON FUNCTION pg_start_backup(text, boolean, boolean) FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION pg_stop_backup() FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION pg_stop_backup(boolean, boolean) FROM public;
|
||||
@ -1138,8 +1140,16 @@ REVOKE EXECUTE ON FUNCTION pg_stat_reset_shared(text) FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_table_counters(oid) FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM public;
|
||||
|
||||
REVOKE EXECUTE ON FUNCTION lo_import(text) FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION lo_import(text, oid) FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION lo_export(oid, text) FROM public;
|
||||
|
||||
REVOKE EXECUTE ON FUNCTION pg_ls_logdir() FROM public;
|
||||
REVOKE EXECUTE ON FUNCTION pg_ls_waldir() FROM public;
|
||||
|
||||
--
|
||||
-- We also set up some things as accessible to standard roles.
|
||||
--
|
||||
GRANT EXECUTE ON FUNCTION pg_ls_logdir() TO pg_monitor;
|
||||
GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO pg_monitor;
|
||||
|
||||
|
@ -448,14 +448,6 @@ lo_import_internal(text *filename, Oid lobjOid)
|
||||
LargeObjectDesc *lobj;
|
||||
Oid oid;
|
||||
|
||||
#ifndef ALLOW_DANGEROUS_LO_FUNCTIONS
|
||||
if (!superuser())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("must be superuser to use server-side lo_import()"),
|
||||
errhint("Anyone can use the client-side lo_import() provided by libpq.")));
|
||||
#endif
|
||||
|
||||
CreateFSContext();
|
||||
|
||||
/*
|
||||
@ -514,14 +506,6 @@ be_lo_export(PG_FUNCTION_ARGS)
|
||||
LargeObjectDesc *lobj;
|
||||
mode_t oumask;
|
||||
|
||||
#ifndef ALLOW_DANGEROUS_LO_FUNCTIONS
|
||||
if (!superuser())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("must be superuser to use server-side lo_export()"),
|
||||
errhint("Anyone can use the client-side lo_export() provided by libpq.")));
|
||||
#endif
|
||||
|
||||
CreateFSContext();
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user