doc - improve description of default privileges

Поиск
Список
Период
Сортировка
Искать

doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:
Вложения:

I have not found a convenient presentation of the default privileges for 
different objects, and how to display them (if possible, not always).

The information is partly provided within the GRANT description, and not 
very explicit: eg it is said that owners have all possible perms, but 
which they are is not said explicitely, although they are implied by the 
different GRANT sysnopsys. Then some objects are given perms for the 
PUBLIC.

The attached patch tries to improve the documentation, in particular with 
an added table to summarizes my findings, so that they are recorded 
somewhere.

-- 
Fabien.

Re: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:
Вложения:

> I have not found a convenient presentation of the default privileges for 
> different objects, and how to display them (if possible, not always).
>
> The information is partly provided within the GRANT description, and not very 
> explicit: eg it is said that owners have all possible perms, but which they 
> are is not said explicitely, although they are implied by the different GRANT 
> sysnopsys. Then some objects are given perms for the PUBLIC.
>
> The attached patch tries to improve the documentation, in particular with an 
> added table to summarizes my findings, so that they are recorded somewhere.

The attached fixes the tablespace entry that I forgot to fill in full.

-- 
Fabien.

Re[2]: doc - improve description of default privileges

От:
"Bradley DeJong" <bpd0018@gmail.com>
Дата:
Hi Fabien,

Thanks for writing this up - in particular the psql backslash commands.

comments on the patch ...

1) I think that adding the "This privilege is abbreviated ... when 
displayed." lines to the privilege descriptions is redundant. The 
abbreviations are already listed after the "The entries shown by \dp are 
interpreted thus:" line. Just change that line to something like "The 
entries shown by the psql backslash commands, like \dp, are interpreted 
thus:".

2) I think that the psql command table should go with the current text 
on "Use psql's \dp command to obtain ..." rather than in the Examples 
section. It seems like changing the "For non-table objects there are 
other \d commands ..." line to an introductory comment like "The 
following table lists the \d commands that are used for non-table 
objects along with the default privileges granted to the object's owner 
and PUBLIC.

3) The table title, "Default hardcoded access privileges per object's 
type", seems incomplete because it does not mention the psql commands 
part of the table.


------ Original Message ------
From: "Fabien COELHO" 
To: "PostgreSQL Developers" 
Sent: 8/4/2018 4:40:33 AM
Subject: Re: doc - improve description of default privileges

>
>>I have not found a convenient presentation of the default privileges 
>>for different objects, and how to display them (if possible, not 
>>always).
>>
>>The information is partly provided within the GRANT description, and 
>>not very explicit: eg it is said that owners have all possible perms, 
>>but which they are is not said explicitely, although they are implied 
>>by the different GRANT sysnopsys. Then some objects are given perms 
>>for the PUBLIC.
>>
>>The attached patch tries to improve the documentation, in particular 
>>with an added table to summarizes my findings, so that they are 
>>recorded somewhere.
>
>The attached fixes the tablespace entry that I forgot to fill in full.
>
>-- Fabien.


Re[2]: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:
Вложения:

Hello Bradley,

> comments on the patch ...

Thanks for the review.

> 1) I think that adding the "This privilege is abbreviated ... when 
> displayed." lines to the privilege descriptions is redundant. The 
> abbreviations are already listed after the "The entries shown by \dp are 
> interpreted thus:" line. Just change that line to something like "The entries 
> shown by the psql backslash commands, like \dp, are interpreted thus:".

Ok, removed.

> 2) I think that the psql command table should go with the current text on 
> "Use psql's \dp command to obtain ..." rather than in the Examples section. 
> It seems like changing the "For non-table objects there are other \d commands 
> ..." line to an introductory comment like "The following table lists the \d 
> commands that are used for non-table objects along with the default 
> privileges granted to the object's owner and PUBLIC.

Ok, moved to the previous section.

> 3) The table title, "Default hardcoded access privileges per object's type", 
> seems incomplete because it does not mention the psql commands part of the 
> table.

Ok, added reference to psql backslash commands in title.

Find v3 attached.

-- 
Fabien.

Re[3]: doc - improve description of default privileges

От:
"Bradley DeJong" <bpd0018@gmail.com>
Дата:
on 2018-08-30, Fabien Coelho wrote ...
 > ... Find v3 attached. ...

Hi Fabien,

As we're coming up on the end of this commitfest ...

Is the reviewer supposed to move this to "ready for committer" or is the 
author supposed to do that?

Is the reviewer supposed to explicitly state "I've looked at your v3 
patch and have no further suggestions" (which is true) or is a lack of 
additional comments normally taken as acceptance?


Cheers.


Re: Re[3]: doc - improve description of default privileges

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Bradley DeJong"  writes:
> Is the reviewer supposed to move this to "ready for committer" or is the 
> author supposed to do that?

The reviewer does that, indicating signoff.

			regards, tom lane

Re: Re[3]: doc - improve description of default privileges

От:
Brad DeJong <bpd0018@gmail.com>
Дата:
On 2018-09-12 Tom Lane wrote ...
> The reviewer does that, indicating signoff.
Thanks. I have now changed the status to "Ready for Committer".

Re: doc - improve description of default privileges

От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
Some thoughts:

We should keep the GRANT reference page about GRANT.  There is a section
about Privileges in the Data Definition chapter, which we could use to
expand on general concepts.

The ALTER DEFAULT PRIVILEGES reference page would be another place this
could be put.

The Owner column is redundant, because it's always all applicable
privileges.  (Having this column would give the impression that it's not
always all privileges, so it would be confusing.)

Privileges should be listed using their full name (e.g., "SELECT"), not
their internal abbreviation letter.

The psql commands seem out of place here.  If you want to learn about
how to use psql, you can go to the psql documentation.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Re: doc - improve description of default privileges

От:
Alvaro Herrera <alvherre@2ndquadrant.com>
Дата:
On 2018-Sep-28, Peter Eisentraut wrote:

> The psql commands seem out of place here.  If you want to learn about
> how to use psql, you can go to the psql documentation.

There is a legitimate point in doing this, though, since the GRANT page
is already explaining how does psql display privileges.  Maybe the right
solution is move that stuff all to the psql documentation, and alter the
GRANT page to list privileges in terms of their names rather than the
way psql displays them.  (And of course add cross-links, so that it all
makes sense.)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Re: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:

> The Owner column is redundant, because it's always all applicable
> privileges.  (Having this column would give the impression that it's not
> always all privileges, so it would be confusing.)

The reason I put the owner column is to show (1) the privileges that apply 
to the objects (i.e. what is under "ALL") and (2) whether public's 
privileges are the same or not, because there are subtles differences, so 
I think it is interesting to have them side by side somewhere.

> Privileges should be listed using their full name (e.g., "SELECT"), not
> their internal abbreviation letter.

Hmmm... the psql commands listed in the table output the abbreviated 
letters. Using the words would result in a large table, but maybe it 
could use multiline cells.

> The psql commands seem out of place here.  If you want to learn about
> how to use psql, you can go to the psql documentation.

The information about how to display the permissions is currently not 
easily available, I had to test/look for it, noticed that it is not 
accessible on some objects, so ISTM that it is useful to have it 
somewhere.

Basically your points suggest that the table is maybe in the wrong place
and could be improved.

About the place, there is no simple choice:

  - backslash commands are "psql" specific
  - abbreviated letters are aclitem function specific, which
    happend to be used by psql.
  - full names are SQL specific (GRANT)
  - default permissions are object specific and can be modified...

Which means that the information tends to be scattered everywhere and 
overall pretty unclear unless you have read all the pages, hence my 
proposal to put some unified summary somewhere with all the relevant 
information. Any choice will have its downside, and removing information 
to better suit one place means that my point of having some kind of 
summary in one place is lost, which is the initial motivation for this 
patch.

-- 
Fabien.

Re: doc - improve description of default privileges

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Fri, Sep 28, 2018 at 04:15:13PM -0300, Alvaro Herrera wrote:
> There is a legitimate point in doing this, though, since the GRANT page
> is already explaining how does psql display privileges.  Maybe the right
> solution is move that stuff all to the psql documentation, and alter the
> GRANT page to list privileges in terms of their names rather than the
> way psql displays them.  (And of course add cross-links, so that it all
> makes sense.)

This point is interesting, and that looks rather right to me.  I looked
at the patch and listing psql commands on the page for GRANT is a
strange concept in my opinion.  Moved to next CF.
--
Michael

Re: doc - improve description of default privileges

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Progress on this patch seems to be blocked on the question of whether
we want to keep enlarging the amount of psql-specific information
in the GRANT reference page, or move that all somewhere else.

FWIW, I think I agree with Peter's position that moving it somewhere
else is the better option.  Section 5.6 "Privileges" seems like a
reasonable choice.

One reason for preferring that is that I don't think putting a  in
a reference page is a great idea.  I tried the patch in HEAD, and what
I see is that the table cross-reference renders as "Table 244", which is
a number that has no chance at all of holding still for any long period.
It's especially weird to read that in "man GRANT.7", where you're
supposedly reading a standalone document.  And while my version of "man"
makes a valiant effort to render the table in ASCII, it still doesn't look
great, and older man versions might do very poorly with that.  So I'm for
moving this to a part of the docs where we only need to worry about two
output formats not three.

A few thoughts on other issues:

* Perhaps we could fix Peter's complaint about the "Owner" column by
relabeling it "All Privileges".  I'd be inclined to label the last
column "Default PUBLIC Privileges", too, if we can fit that in.

* The phrase "relation-like objects" seems way too vague, especially since
one has to read it as excluding sequences, which surely are relations for
most purposes.  Is there a good reason not to just leave that entry as
"TABLE", full stop?  Or maybe it could be "TABLE, VIEW, etc" or some such.

* I don't think the use of "hardcoded" adds anything.

* Is it worth adding another table matching privilege names ("INSERT")
with their aclitem letters ("a"), rather than having the semi-formal
format currently appearing in grant.sgml?  There's also some related
material in 9.25 with the aclitem functions; it'd be worth unifying
that too maybe.

			regards, tom lane

Re: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:
Вложения:

Hello Tom,

Thanks for this precise feedback.

> Progress on this patch seems to be blocked on the question of whether
> we want to keep enlarging the amount of psql-specific information
> in the GRANT reference page, or move that all somewhere else.

Yep.

> FWIW, I think I agree with Peter's position that moving it somewhere
> else is the better option.  Section 5.6 "Privileges" seems like a
> reasonable choice.

Ok.

> * Perhaps we could fix Peter's complaint about the "Owner" column by
> relabeling it "All Privileges".

Ok.

> I'd be inclined to label the last column "Default PUBLIC Privileges", 
> too, if we can fit that in.

Ok.

> * The phrase "relation-like objects" seems way too vague, especially since
> one has to read it as excluding sequences, which surely are relations for
> most purposes.  Is there a good reason not to just leave that entry as
> "TABLE", full stop?  Or maybe it could be "TABLE, VIEW, etc" or some such.

Ok.

> * I don't think the use of "hardcoded" adds anything.

Hmmm. As "default privileges" can be altered, the point is to describe the 
"default default privileges", but this looks absurd, hence the look for 
something to add the idea that there is another one. ISTM that removing 
"hardcoded" without replacing it makes the thing slightly ambiguous.
No big deal.

> * Is it worth adding another table matching privilege names ("INSERT")
> with their aclitem letters ("a"), rather than having the semi-formal
> format currently appearing in grant.sgml?

Indeed I thought about that, because the description is not easy to read.

> There's also some related material in 9.25 with the aclitem functions; 
> it'd be worth unifying that too maybe.

I've put a reference to it at least.

Attached v4:
  - moves the table to the privileges section
  - updates the table column headers
  - adds a privilege/aclitem letter mapping table
  - adds some appropriate links towards psql & aclitem

-- 
Fabien.

Re: doc - improve description of default privileges

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Fabien COELHO  writes:
> Attached v4:
>   - moves the table to the privileges section
>   - updates the table column headers
>   - adds a privilege/aclitem letter mapping table
>   - adds some appropriate links towards psql & aclitem

TBH, I don't think this goes nearly far enough.  It seems like it
is making the fragmentation of aclitem information worse not better.
I feel if we're going to do anything, we should put a unified description
of privileges and aclitem-reading into section 5.6, and take that material
out of the various places where it lives now.  Like the attached, in which
I failed to resist the temptation to wordsmith some stuff as well as move
it around.

			regards, tom lane

diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index c134bca..18c38e4 100644
*** a/doc/src/sgml/catalogs.sgml
--- b/doc/src/sgml/catalogs.sgml
*************** SCRAM-SHA-256$<iteration
*** 1973,1982 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
  
--- 1973,1979 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 2679,2688 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
      
--- 2676,2682 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
      
*************** SCRAM-SHA-256$<iteration
*** 3491,3500 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
  
--- 3485,3491 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 3587,3596 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
  
--- 3578,3584 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 4052,4060 ****
        
        
         The initial access privileges; see
!         and
!        
!        for details
        
       
  
--- 4040,4046 ----
        
        
         The initial access privileges; see
!         for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 4179,4188 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
      
--- 4165,4171 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
      
*************** SCRAM-SHA-256$<iteration
*** 4319,4328 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
  
--- 4302,4308 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 4386,4395 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
      
--- 4366,4372 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
      
*************** SCRAM-SHA-256$<iteration
*** 5396,5405 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
      
--- 5373,5379 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
      
*************** SCRAM-SHA-256$<iteration
*** 6810,6819 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
  
--- 6784,6790 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
  
*************** SCRAM-SHA-256$<iteration
*** 7923,7932 ****
        aclitem[]
        
        
!        Access privileges; see
!         and
!        
!        for details
        
       
      
--- 7894,7900 ----
        aclitem[]
        
        
!        Access privileges; see  for details
        
       
      
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index bfe89ef..f0cf75f 100644
*** a/doc/src/sgml/ddl.sgml
--- b/doc/src/sgml/ddl.sgml
*************** ALTER TABLE products RENAME TO items;
*** 1396,1401 ****
--- 1396,1405 ----
     REVOKE
    
  
+   
+    ACL
+   
+ 
    
     When an object is created, it is assigned an owner. The
     owner is normally the role that executed the creation statement.
*************** ALTER TABLE products RENAME TO items;
*** 1413,1423 ****
     EXECUTE, and USAGE.
     The privileges applicable to a particular
     object vary depending on the object's type (table, function, etc).
!    For complete information on the different types of privileges
!    supported by PostgreSQL, refer to the
!     reference
!    page.  The following sections and chapters will also show you how
!    those privileges are used.
    
  
    
--- 1417,1425 ----
     EXECUTE, and USAGE.
     The privileges applicable to a particular
     object vary depending on the object's type (table, function, etc).
!    More detail about the meanings of these privileges is provided below.
!    The following sections and chapters will also show you how
!    these privileges are used.
    
  
    
*************** ALTER TABLE products RENAME TO items;
*** 1435,1441 ****
    
  
    
!    To assign privileges, the GRANT command is
     used. For example, if joe is an existing role, and
     accounts is an existing table, the privilege to
     update the table can be granted with:
--- 1437,1443 ----
    
  
    
!    To assign privileges, the  command is
     used. For example, if joe is an existing role, and
     accounts is an existing table, the privilege to
     update the table can be granted with:
*************** GRANT UPDATE ON accounts TO joe;
*** 1456,1462 ****
  
    
     To revoke a privilege, use the fittingly named
!    REVOKE command:
  
  REVOKE ALL ON accounts FROM PUBLIC;
  
--- 1458,1464 ----
  
    
     To revoke a privilege, use the fittingly named
!     command:
  
  REVOKE ALL ON accounts FROM PUBLIC;
  
*************** REVOKE ALL ON accounts FROM PUBLIC;
*** 1478,1483 ****
--- 1480,1983 ----
     privilege.  For details see the  and
      reference pages.
    
+ 
+   
+    The available privileges are:
+ 
+    
+     
+      SELECT
+      
+       
+        Allows  from
+        any column, or specific column(s), of a table, view, materialized
+        view, or other table-like object.
+        Also allows use of  TO.
+        This privilege is also needed to reference existing column values in
+         or .
+        For sequences, this privilege also allows the use of the
+        currval function.
+        For large objects, this privilege allows the object to be read.
+       
+      
+     
+ 
+     
+      INSERT
+      
+       
+        Allows  of a new row into a table, view,
+        etc.  Can be granted on specific column(s), in which case
+        only those columns may be assigned to in the INSERT
+        command (other columns will therefore receive default values).
+        Also allows use of  FROM.
+       
+      
+     
+ 
+     
+      UPDATE
+      
+       
+        Allows  of any
+        column, or specific column(s), of a table, view, etc.
+        (In practice, any nontrivial UPDATE command will
+        require SELECT privilege as well, since it must
+        reference table columns to determine which rows to update, and/or to
+        compute new values for columns.)
+        SELECT ... FOR UPDATE
+        and SELECT ... FOR SHARE
+        also require this privilege on at least one column, in addition to the
+        SELECT privilege.  For sequences, this
+        privilege allows the use of the nextval and
+        setval functions.
+        For large objects, this privilege allows writing or truncating the
+        object.
+       
+      
+     
+ 
+     
+      DELETE
+      
+       
+        Allows  of a row from a table, view, etc.
+        (In practice, any nontrivial DELETE command will
+        require SELECT privilege as well, since it must
+        reference table columns to determine which rows to delete.)
+       
+      
+     
+ 
+     
+      TRUNCATE
+      
+       
+        Allows  on a table, view, etc.
+       
+      
+     
+ 
+     
+      REFERENCES
+      
+       
+        Allows creation of a foreign key constraint referencing a
+        table, or specific column(s) of a table.
+       
+      
+     
+ 
+     
+      TRIGGER
+      
+       
+        Allows creation of a trigger on a table, view, etc.
+       
+      
+     
+ 
+     
+      CREATE
+      
+       
+        For databases, allows new schemas and publications to be created within
+        the database.
+       
+       
+        For schemas, allows new objects to be created within the schema.
+        To rename an existing object, you must own the
+        object and have this privilege for the containing
+        schema.
+       
+       
+        For tablespaces, allows tables, indexes, and temporary files to be
+        created within the tablespace, and allows databases to be created that
+        have the tablespace as their default tablespace.  (Note that revoking
+        this privilege will not alter the placement of existing objects.)
+       
+      
+     
+ 
+     
+      CONNECT
+      
+       
+        Allows the grantee to connect to the database.  This
+        privilege is checked at connection startup (in addition to checking
+        any restrictions imposed by pg_hba.conf).
+       
+      
+     
+ 
+     
+      TEMPORARY
+      
+       
+        Allows temporary tables to be created while using the database.
+       
+      
+     
+ 
+     
+      EXECUTE
+      
+       
+        Allows calling a function or procedure, including use of
+        any operators that are implemented on top of the function.  This is the
+        only type of privilege that is applicable to functions and procedures.
+       
+      
+     
+ 
+     
+      USAGE
+      
+       
+        For procedural languages, allows use of a language for
+        the creation of functions in that language.  This is the only type
+        of privilege that is applicable to procedural languages.
+       
+       
+        For schemas, allows access to objects contained in a
+        schema (assuming that the objects' own privilege requirements are
+        also met).  Essentially this allows the grantee to look up
+        objects within the schema.  Without this permission, it is still
+        possible to see the object names, e.g. by querying system catalogs.
+        Also, after revoking this permission, existing sessions might have
+        statements that have previously performed this lookup, so this is not
+        a completely secure way to prevent object access.
+       
+       
+        For sequences, this privilege allows the use of the
+        currval and nextval functions.
+       
+       
+        For types and domains, this privilege allows the use of the type or
+        domain in the creation of tables, functions, and other schema objects.
+        (Note that it does not control general usage of the type,
+        such as values of the type appearing in queries.  It only prevents
+        objects from being created that depend on the type.  The main purpose of
+        this privilege is controlling which users create dependencies on a type,
+        which could prevent the owner from changing the type later.)
+       
+       
+        For foreign-data wrappers, this privilege allows creation of
+        new servers using the foreign-data wrapper.
+       
+       
+        For servers, this privilege allows creation of foreign tables using
+        the server.  Grantees may also create, alter, or drop their own
+        user mappings associated with that server.
+       
+      
+     
+    
+ 
+    The privileges required by other commands are listed on the
+    reference page of the respective command.
+   
+ 
+   
+    PostgreSQL grants privileges on some types of objects to
+    PUBLIC by default when the objects are created.
+    No privileges are granted to PUBLIC by default on
+    tables,
+    table columns,
+    sequences,
+    foreign data wrappers,
+    foreign servers,
+    large objects,
+    schemas,
+    or tablespaces.
+    For other types of objects, the default privileges
+    granted to PUBLIC are as follows:
+    CONNECT and TEMPORARY (create
+    temporary tables) privileges for databases;
+    EXECUTE privilege for functions and procedures; and
+    USAGE privilege for languages and data types
+    (including domains).
+    The object owner can, of course, REVOKE
+    both default and expressly granted privileges. (For maximum
+    security, issue the REVOKE in the same transaction that
+    creates the object; then there is no window in which another user
+    can use the object.)
+    Also, these default privilege settings can be overridden using the
+     command.
+   
+ 
+   
+     shows the one-letter
+    abbreviations that are used for these privilege types in
+    ACL (Access Control List) values.
+    You will see these letters in the output of the 
+    commands listed below, or when looking at ACL columns of system catalogs.
+   
+ 
+   
+    ACL Privilege Abbreviations
+    
+     
+      
+       Privilege
+       Abbreviation
+       Applicable Object Types
+      
+     
+     
+      
+       SELECT
+       r (read)
+       
+        LARGE OBJECT,
+        SEQUENCE,
+        TABLE (and table-like objects),
+        table column
+       
+      
+      
+       INSERT
+       a (append)
+       TABLE, table column
+      
+      
+       UPDATE
+       w (write)
+       
+        LARGE OBJECT,
+        SEQUENCE,
+        TABLE,
+        table column
+       
+      
+      
+       DELETE
+       d
+       TABLE
+      
+      
+       TRUNCATE
+       D
+       TABLE
+      
+      
+       REFERENCES
+       x
+       TABLE, table column
+      
+      
+       TRIGGER
+       t
+       TABLE
+      
+      
+       CREATE
+       C
+       
+        DATABASE,
+        SCHEMA,
+        TABLESPACE
+       
+      
+      
+       CONNECT
+       c
+       DATABASE
+      
+      
+       TEMPORARY
+       T
+       DATABASE
+      
+      
+       EXECUTE
+       X
+       FUNCTION, PROCEDURE
+      
+      
+       USAGE
+       U
+       
+        DOMAIN,
+        FOREIGN DATA WRAPPER,
+        FOREIGN SERVER,
+        LANGUAGE,
+        SCHEMA,
+        SEQUENCE,
+        TYPE
+       
+      
+      
+    
+   
+ + + summarizes the privileges + available for each type of SQL object, using the abbreviations shown + above. + It also shows the psql command + that can be used to examine privilege settings for each object type. + + + + Summary of Access Privileges + + + + Object Type + All Privileges + Default PUBLIC Privileges + psql Command + + + + + DATABASE + CTc + Tc + \l + + + DOMAIN + U + U + \dD+ + + + FUNCTION or PROCEDURE + X + X + \df+ + + + FOREIGN DATA WRAPPER + U + none + \dew+ + + + FOREIGN SERVER + U + none + \des+ + + + LANGUAGE + U + U + \dL+ + + + LARGE OBJECT + rw + none + + + + SCHEMA + UC + none + \dn+ + + + SEQUENCE + rwU + none + \dp + + + TABLE (and table-like objects) + arwdDxt + none + \dp + + + Table column + arwx + none + \dp + + + TABLESPACE + C + none + \db+ + + + TYPE + U + U + \dT+ + + + +
+ + + + aclitem + + The privileges that have been granted for a particular object are + displayed as a list of aclitem entries, where each + aclitem describes the permissions of one grantee that + have been granted by a particular grantor. For example, + calvin=r*w/hobbes specifies that the role + calvin has the privilege + SELECT (r) with grant option + (*) as well as the non-grantable + privilege UPDATE (w), both granted + by the role hobbes. If calvin + also has some privileges on the same object granted by a different + grantor, those would appear as a separate aclitem entry. + An empty grantee field in an aclitem stands + for PUBLIC. + + + + As an example, suppose that user miriam creates + table mytable and does: + + GRANT SELECT ON mytable TO PUBLIC; + GRANT SELECT, UPDATE, INSERT ON mytable TO admin; + GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw; + + Then psql's \dp command + would show: + + => \dp mytable + Access privileges + Schema | Name | Type | Access privileges | Column privileges | Policies + --------+---------+-------+-----------------------+-----------------------+---------- + public | mytable | table | miriam=arwdDxt/miriam+| col1: +| + | | | =r/miriam +| miriam_rw=rw/miriam | + | | | admin=arw/miriam | | + (1 row) + + + + + If the Access privileges column is empty for a given object, + it means the object has default privileges (that is, its privileges column + is null). Default privileges always include all privileges for the owner, + and can include some privileges for PUBLIC depending on the + object type, as explained above. The first GRANT or + REVOKE on an object + will instantiate the default privileges (producing, for example, + miriam=arwdDxt/miriam) and then modify them per the + specified request. Similarly, entries are shown in Column + privileges only for columns with nondefault privileges. + (Note: for this purpose, default privileges always means the + built-in default privileges for the object's type. An object whose + privileges have been affected by an ALTER DEFAULT PRIVILEGES + command will always be shown with an explicit privilege entry that + includes the effects of the ALTER.) + + + + Notice that the owner's implicit grant options are not marked in the + access privileges display. A * will appear only when + grant options have been explicitly granted to someone. + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 112d962..952614a 100644 *** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** SELECT has_function_privilege('joeuser', *** 16932,16953 **** shows the operators ! available for the aclitem type, which is the internal ! representation of access privileges. An aclitem entry ! describes the permissions of a grantee, whether they are grantable ! or not, and which grantor granted them. For instance, ! calvin=r*w/hobbes specifies that the role ! calvin has the grantable privilege ! SELECT (r*) and the non-grantable ! privilege UPDATE (w), granted by ! the role hobbes. An empty grantee stands for ! PUBLIC. - aclitem - - acldefault --- 16932,16943 ---- shows the operators ! available for the aclitem type, which is the catalog ! representation of access privileges. See ! for information about how to read access privilege values. acldefault *************** SELECT has_function_privilege('joeuser', *** 17015,17023 **** acldefault(type, ! ownerId) aclitem[] ! get the hardcoded default access privileges for an object belonging to ownerId aclexplode(aclitem[]) --- 17005,17013 ---- acldefault(type, ! ownerId) aclitem[] ! get the default access privileges for an object belonging to ownerId aclexplode(aclitem[]) *************** SELECT has_function_privilege('joeuser', *** 17034,17049 **** ! acldefault returns the hardcoded default access privileges ! for an object of type belonging to role ownerId. ! Notice that these are used in the absence of any pg_default_acl ! () entry. Default access privileges are described in ! and can be overwritten with ! . In other words, this function will return ! results which may be misleading when the defaults have been overridden. ! Type is a CHAR, use 'c' for COLUMN, ! 'r' for relation-like objects such as TABLE or VIEW, 's' for SEQUENCE, 'd' for DATABASE, 'f' for FUNCTION or PROCEDURE, --- 17024,17037 ---- ! acldefault returns the built-in default access ! privileges for an object of type type belonging to ! role ownerId. These represent the access ! privileges that will be assumed when an object's ACL entry is null. ! (The default access privileges are described in .) ! The type parameter is a CHAR: write 'c' for COLUMN, ! 'r' for TABLE and table-like objects, 's' for SEQUENCE, 'd' for DATABASE, 'f' for FUNCTION or PROCEDURE, *************** SELECT has_function_privilege('joeuser', *** 17053,17064 **** 't' for TABLESPACE, 'F' for FOREIGN DATA WRAPPER, 'S' for FOREIGN SERVER, 'T' for TYPE or DOMAIN. aclexplode returns an aclitem array ! as a set rows. Output columns are grantor oid, grantee oid (0 for PUBLIC), granted privilege as text (SELECT, ...) and whether the prilivege is grantable as boolean. --- 17041,17053 ---- 't' for TABLESPACE, 'F' for FOREIGN DATA WRAPPER, 'S' for FOREIGN SERVER, + or 'T' for TYPE or DOMAIN. aclexplode returns an aclitem array ! as a set of rows. Output columns are grantor oid, grantee oid (0 for PUBLIC), granted privilege as text (SELECT, ...) and whether the prilivege is grantable as boolean. diff --git a/doc/src/sgml/ref/alter_default_privileges.sgml b/doc/src/sgml/ref/alter_default_privileges.sgml index 0c09f1d..583f65f 100644 *** a/doc/src/sgml/ref/alter_default_privileges.sgml --- b/doc/src/sgml/ref/alter_default_privileges.sgml *************** REVOKE [ GRANT OPTION FOR ] *** 112,118 **** ! As explained under , the default privileges for any object type normally grant all grantable permissions to the object owner, and may grant some privileges to PUBLIC as well. However, this behavior can be changed by --- 112,118 ---- ! As explained in , the default privileges for any object type normally grant all grantable permissions to the object owner, and may grant some privileges to PUBLIC as well. However, this behavior can be changed by *************** REVOKE [ GRANT OPTION FOR ] *** 173,181 **** Use 's \ddp command to obtain information about existing assignments of default privileges. ! The meaning of the privilege values is the same as explained for ! \dp under ! . --- 173,180 ---- Use 's \ddp command to obtain information about existing assignments of default privileges. ! The meaning of the privilege display is the same as explained for ! \dp in . diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_function.sgml index 06be04e..4072543 100644 *** a/doc/src/sgml/ref/create_function.sgml --- b/doc/src/sgml/ref/create_function.sgml *************** $$ LANGUAGE plpgsql *** 761,767 **** Another point to keep in mind is that by default, execute privilege is granted to PUBLIC for newly created functions ! (see for more information). Frequently you will wish to restrict use of a security definer function to only some users. To do that, you must revoke the default PUBLIC privileges and then grant execute --- 761,767 ---- Another point to keep in mind is that by default, execute privilege is granted to PUBLIC for newly created functions ! (see for more information). Frequently you will wish to restrict use of a security definer function to only some users. To do that, you must revoke the default PUBLIC privileges and then grant execute diff --git a/doc/src/sgml/ref/grant.sgml b/doc/src/sgml/ref/grant.sgml index ff64c7a..d38c5e2 100644 *** a/doc/src/sgml/ref/grant.sgml --- b/doc/src/sgml/ref/grant.sgml *************** GRANT rol *** 157,386 **** - PostgreSQL grants default privileges on some types of objects to - PUBLIC. No privileges are granted to - PUBLIC by default on - tables, - table columns, - sequences, - foreign data wrappers, - foreign servers, - large objects, - schemas, - or tablespaces. - For other types of objects, the default privileges - granted to PUBLIC are as follows: - CONNECT and TEMPORARY (create - temporary tables) privileges for databases; - EXECUTE privilege for functions and procedures; and - USAGE privilege for languages and data types - (including domains). - The object owner can, of course, REVOKE - both default and expressly granted privileges. (For maximum - security, issue the REVOKE in the same transaction that - creates the object; then there is no window in which another user - can use the object.) - Also, these initial default privilege settings can be changed using the - - command. - - - The possible privileges are: SELECT - - - Allows from - any column, or the specific columns listed, of the specified table, - view, or sequence. - Also allows the use of - TO. - This privilege is also needed to reference existing column values in - or - . - For sequences, this privilege also allows the use of the - currval function. - For large objects, this privilege allows the object to be read. - - - - - INSERT - - - Allows of a new - row into the specified table. If specific columns are listed, - only those columns may be assigned to in the INSERT - command (other columns will therefore receive default values). - Also allows FROM. - - - - - UPDATE - - - Allows of any - column, or the specific columns listed, of the specified table. - (In practice, any nontrivial UPDATE command will require - SELECT privilege as well, since it must reference table - columns to determine which rows to update, and/or to compute new - values for columns.) - SELECT ... FOR UPDATE - and SELECT ... FOR SHARE - also require this privilege on at least one column, in addition to the - SELECT privilege. For sequences, this - privilege allows the use of the nextval and - setval functions. - For large objects, this privilege allows writing or truncating the - object. - - - - - DELETE - - - Allows of a row - from the specified table. - (In practice, any nontrivial DELETE command will require - SELECT privilege as well, since it must reference table - columns to determine which rows to delete.) - - - - - TRUNCATE - - - Allows on - the specified table. - - - - - REFERENCES - - - Allows creation of a foreign key constraint referencing the specified - table, or specified column(s) of the table. (See the - statement.) - - - - - TRIGGER - - - Allows the creation of a trigger on the specified table. (See the - statement.) - - - - - CREATE - - - For databases, allows new schemas and publications to be created within the database. - - - For schemas, allows new objects to be created within the schema. - To rename an existing object, you must own the object and - have this privilege for the containing schema. - - - For tablespaces, allows tables, indexes, and temporary files to be - created within the tablespace, and allows databases to be created that - have the tablespace as their default tablespace. (Note that revoking - this privilege will not alter the placement of existing objects.) - - - - - CONNECT - - - Allows the user to connect to the specified database. This - privilege is checked at connection startup (in addition to checking - any restrictions imposed by pg_hba.conf). - - - - - TEMPORARY - TEMP - - - Allows temporary tables to be created while using the specified database. - - - - - EXECUTE ! Allows the use of the specified function or procedure and the use of ! any operators that are implemented on top of the function. This is the ! only type of privilege that is applicable to functions and procedures. ! The FUNCTION syntax also works for aggregate ! functions. Alternatively, use ROUTINE to refer to a function, ! aggregate function, or procedure regardless of what it is. ! USAGE ! For procedural languages, allows the use of the specified language for ! the creation of functions in that language. This is the only type ! of privilege that is applicable to procedural languages. ! ! ! For schemas, allows access to objects contained in the specified ! schema (assuming that the objects' own privilege requirements are ! also met). Essentially this allows the grantee to look up ! objects within the schema. Without this permission, it is still ! possible to see the object names, e.g. by querying the system tables. ! Also, after revoking this permission, existing backends might have ! statements that have previously performed this lookup, so this is not ! a completely secure way to prevent object access. ! ! ! For sequences, this privilege allows the use of the ! currval and nextval functions. ! ! ! For types and domains, this privilege allows the use of the type or ! domain in the creation of tables, functions, and other schema objects. ! (Note that it does not control general usage of the type, ! such as values of the type appearing in queries. It only prevents ! objects from being created that depend on the type. The main purpose of ! the privilege is controlling which users create dependencies on a type, ! which could prevent the owner from changing the type later.) ! ! ! For foreign-data wrappers, this privilege allows creation of ! new servers using the foreign-data wrapper. ! ! ! For servers, this privilege allows creation of foreign tables using ! the server. Grantees may also create, alter, or drop their own ! user mappings associated with that server. --- 157,190 ---- The possible privileges are: SELECT INSERT UPDATE DELETE TRUNCATE REFERENCES TRIGGER CREATE CONNECT TEMPORARY EXECUTE + USAGE ! Specific types of privileges, as defined in . ! TEMP ! Alternative spelling for TEMPORARY. *************** GRANT rol *** 389,395 **** ALL PRIVILEGES ! Grant all of the available privileges at once. The PRIVILEGES key word is optional in PostgreSQL, though it is required by strict SQL. --- 193,199 ---- ALL PRIVILEGES ! Grant all of the privileges available for the object's type. The PRIVILEGES key word is optional in PostgreSQL, though it is required by strict SQL. *************** GRANT rol *** 397,405 **** ! The privileges required by other commands are listed on the ! reference page of the respective command. --- 201,215 ---- + ! ! The FUNCTION syntax works for plain functions, ! aggregate functions, and window functions, but not for procedures; ! use PROCEDURE for those. ! Alternatively, use ROUTINE to refer to a function, ! aggregate function, window function, or procedure regardless of its ! precise type. *************** GRANT rol *** 520,598 **** ! Use 's \dp command ! to obtain information about existing privileges for tables and ! columns. For example: ! ! => \dp mytable ! Access privileges ! Schema | Name | Type | Access privileges | Column access privileges ! --------+---------+-------+-----------------------+-------------------------- ! public | mytable | table | miriam=arwdDxt/miriam | col1: ! : =r/miriam : miriam_rw=rw/miriam ! : admin=arw/miriam ! (1 row) ! ! The entries shown by \dp are interpreted thus: ! ! rolename=xxxx -- privileges granted to a role ! =xxxx -- privileges granted to PUBLIC ! ! r -- SELECT ("read") ! w -- UPDATE ("write") ! a -- INSERT ("append") ! d -- DELETE ! D -- TRUNCATE ! x -- REFERENCES ! t -- TRIGGER ! X -- EXECUTE ! U -- USAGE ! C -- CREATE ! c -- CONNECT ! T -- TEMPORARY ! arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects) ! * -- grant option for preceding privilege ! ! /yyyy -- role that granted this privilege ! ! ! The above example display would be seen by user miriam after ! creating table mytable and doing: ! ! ! GRANT SELECT ON mytable TO PUBLIC; ! GRANT SELECT, UPDATE, INSERT ON mytable TO admin; ! GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw; ! ! ! ! ! For non-table objects there are other \d commands ! that can display their privileges. ! ! ! ! If the Access privileges column is empty for a given object, ! it means the object has default privileges (that is, its privileges column ! is null). Default privileges always include all privileges for the owner, ! and can include some privileges for PUBLIC depending on the ! object type, as explained above. The first GRANT or ! REVOKE on an object ! will instantiate the default privileges (producing, for example, ! {miriam=arwdDxt/miriam}) and then modify them per the ! specified request. Similarly, entries are shown in Column access ! privileges only for columns with nondefault privileges. ! (Note: for this purpose, default privileges always means the ! built-in default privileges for the object's type. An object whose ! privileges have been affected by an ALTER DEFAULT PRIVILEGES ! command will always be shown with an explicit privilege entry that ! includes the effects of the ALTER.) ! ! ! ! Notice that the owner's implicit grant options are not marked in the ! access privileges display. A * will appear only when ! grant options have been explicitly granted to someone. --- 330,337 ---- ! See for more information about specific ! privilege types, as well as how to inspect objects' privileges. diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 47714eb..6c76cf2 100644 *** a/doc/src/sgml/ref/psql-ref.sgml --- b/doc/src/sgml/ref/psql-ref.sgml *************** testdb=> *** 1324,1331 **** The command is used to set default access privileges. The meaning of the ! privilege display is explained under ! . --- 1324,1331 ---- The command is used to set default access privileges. The meaning of the ! privilege display is explained in ! . *************** testdb=> *** 1372,1378 **** specified, only those servers whose name matches the pattern are listed. If the form \des+ is used, a full description of each server is shown, including the ! server's ACL, type, version, options, and description. --- 1372,1378 ---- specified, only those servers whose name matches the pattern are listed. If the form \des+ is used, a full description of each server is shown, including the ! server's access privileges, type, version, options, and description. *************** testdb=> *** 1425,1432 **** If pattern is specified, only those foreign-data wrappers whose name matches the pattern are listed. If the form \dew+ ! is used, the ACL, options, and description of the foreign-data ! wrapper are also shown. --- 1425,1432 ---- If pattern is specified, only those foreign-data wrappers whose name matches the pattern are listed. If the form \dew+ ! is used, the access privileges, options, and description of the ! foreign-data wrapper are also shown. *************** testdb=> *** 1639,1646 **** The and commands are used to set access privileges. The meaning of the ! privilege display is explained under ! . --- 1639,1646 ---- The and commands are used to set access privileges. The meaning of the ! privilege display is explained in ! . diff --git a/doc/src/sgml/ref/revoke.sgml b/doc/src/sgml/ref/revoke.sgml index 5317f8c..e96d45e 100644 *** a/doc/src/sgml/ref/revoke.sgml --- b/doc/src/sgml/ref/revoke.sgml *************** REVOKE [ ADMIN OPTION FOR ] *** 178,191 **** Notes - Use 's \dp command to - display the privileges granted on existing tables and columns. See for information about the - format. For non-table objects there are other \d commands - that can display their privileges. - - - A user can only revoke privileges that were granted directly by that user. If, for example, user A has granted a privilege with grant option to user B, and user B has in turn granted it to user --- 178,183 ---- *************** REVOKE [ ADMIN OPTION FOR ] *** 244,249 **** --- 236,246 ---- lead to revoking privileges other than the ones you intended, or not revoking anything at all. + + + See for more information about specific + privilege types, as well as how to inspect objects' privileges. + *************** REVOKE admins FROM joe; *** 293,301 **** See Also ! ! ! --- 290,299 ---- See Also ! ! ! !

Re: doc - improve description of default privileges

От:
Alvaro Herrera <alvherre@2ndquadrant.com>
Дата:
On 2018-Nov-30, Tom Lane wrote:

> I feel if we're going to do anything, we should put a unified description
> of privileges and aclitem-reading into section 5.6, and take that material
> out of the various places where it lives now.  Like the attached, in which
> I failed to resist the temptation to wordsmith some stuff as well as move
> it around.

I looked at the psql manpage and the HTML rendering of section 5.6 and
it all looks good to me.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Re: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:


>> I feel if we're going to do anything, we should put a unified description
>> of privileges and aclitem-reading into section 5.6, and take that material
>> out of the various places where it lives now.  Like the attached, in which
>> I failed to resist the temptation to wordsmith some stuff as well as move
>> it around.
>
> I looked at the psql manpage and the HTML rendering of section 5.6 and
> it all looks good to me.

Indeed, this looks great, a precise and full description of privileges 
just in one place.

-- 
Fabien.

Re: doc - improve description of default privileges

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Fabien COELHO  writes:
>>> I feel if we're going to do anything, we should put a unified description
>>> of privileges and aclitem-reading into section 5.6, and take that material
>>> out of the various places where it lives now.  Like the attached, in which
>>> I failed to resist the temptation to wordsmith some stuff as well as move
>>> it around.

>> I looked at the psql manpage and the HTML rendering of section 5.6 and
>> it all looks good to me.

> Indeed, this looks great, a precise and full description of privileges 
> just in one place.

Pushed (with a little bit more tweaking).

			regards, tom lane

Re: doc - improve description of default privileges

От:
Fabien COELHO <coelho@cri.ensmp.fr>
Дата:

>>> I looked at the psql manpage and the HTML rendering of section 5.6 and
>>> it all looks good to me.
>
>> Indeed, this looks great, a precise and full description of privileges
>> just in one place.
>
> Pushed (with a little bit more tweaking).

Thanks for the rewrite, extensions, improvements and final push.

-- 
Fabien.

FAQ