Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
role-attributes.html146 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>22.2. Role Attributes</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="database-roles.html" title="22.1. Database Roles" /><link rel="next" href="role-membership.html" title="22.3. Role Membership" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">22.2. Role Attributes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="database-roles.html" title="22.1. Database Roles">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="user-manag.html" title="Chapter 22. Database Roles">Up</a></td><th width="60%" align="center">Chapter 22. Database Roles</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="role-membership.html" title="22.3. Role Membership">Next</a></td></tr></table><hr /></div><div class="sect1" id="ROLE-ATTRIBUTES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">22.2. Role Attributes <a href="#ROLE-ATTRIBUTES" class="id_link">#</a></h2></div></div></div><p>3    A database role can have a number of attributes that define its4    privileges and interact with the client authentication system.5 6    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">login privilege<a id="id-1.6.9.6.2.1.1.1.1" class="indexterm"></a></span></dt><dd><p>7        Only roles that have the <code class="literal">LOGIN</code> attribute can be used8        as the initial role name for a database connection.  A role with9        the <code class="literal">LOGIN</code> attribute can be considered the same10        as a <span class="quote">“<span class="quote">database user</span>”</span>.  To create a role with login privilege,11        use either:12</p><pre class="programlisting">13CREATE ROLE <em class="replaceable"><code>name</code></em> LOGIN;14CREATE USER <em class="replaceable"><code>name</code></em>;15</pre><p>16        (<code class="command">CREATE USER</code> is equivalent to <code class="command">CREATE ROLE</code>17        except that <code class="command">CREATE USER</code> includes <code class="literal">LOGIN</code> by18        default, while <code class="command">CREATE ROLE</code> does not.)19       </p></dd><dt><span class="term">superuser status<a id="id-1.6.9.6.2.1.2.1.1" class="indexterm"></a></span></dt><dd><p>20        A database superuser bypasses all permission checks, except the right21        to log in.  This is a dangerous privilege and should not be used22        carelessly; it is best to do most of your work as a role that is not a23        superuser.  To create a new database superuser, use <code class="literal">CREATE24        ROLE <em class="replaceable"><code>name</code></em> SUPERUSER</code>.  You must do25        this as a role that is already a superuser.26       </p></dd><dt><span class="term">database creation<a id="id-1.6.9.6.2.1.3.1.1" class="indexterm"></a></span></dt><dd><p>27        A role must be explicitly given permission to create databases28        (except for superusers, since those bypass all permission29        checks). To create such a role, use <code class="literal">CREATE ROLE30        <em class="replaceable"><code>name</code></em> CREATEDB</code>.31       </p></dd><dt><span class="term" id="ROLE-CREATION">role creation<a id="id-1.6.9.6.2.1.4.1.1" class="indexterm"></a></span></dt><dd><p>32        A role must be explicitly given permission to create more roles33        (except for superusers, since those bypass all permission34        checks). To create such a role, use <code class="literal">CREATE ROLE35        <em class="replaceable"><code>name</code></em> CREATEROLE</code>.36        A role with <code class="literal">CREATEROLE</code> privilege can alter and drop37        roles which have been granted to the <code class="literal">CREATEROLE</code>38        user with the <code class="literal">ADMIN</code> option. Such a grant occurs39        automatically when a <code class="literal">CREATEROLE</code> user that is not40        a superuser creates a new role, so that by default, a41        <code class="literal">CREATEROLE</code> user can alter and drop the roles42        which they have created.43        Altering a role includes most changes that can be made using44        <code class="literal">ALTER ROLE</code>, including, for example, changing45        passwords.  It also includes modifications to a role that can46        be made using the <code class="literal">COMMENT</code> and47        <code class="literal">SECURITY LABEL</code> commands.48       </p><p>49        However, <code class="literal">CREATEROLE</code> does not convey the ability to50        create <code class="literal">SUPERUSER</code> roles, nor does it convey any51        power over <code class="literal">SUPERUSER</code> roles that already exist.52        Furthermore, <code class="literal">CREATEROLE</code> does not convey the power53        to create <code class="literal">REPLICATION</code> users, nor the ability to54        grant or revoke the <code class="literal">REPLICATION</code> privilege, nor the55        ability to modify the role properties of such users.  However, it does56        allow <code class="literal">ALTER ROLE ... SET</code> and57        <code class="literal">ALTER ROLE ... RENAME</code> to be used on58        <code class="literal">REPLICATION</code> roles, as well as the use of59        <code class="literal">COMMENT ON ROLE</code>,60        <code class="literal">SECURITY LABEL ON ROLE</code>,61        and <code class="literal">DROP ROLE</code>.62        Finally, <code class="literal">CREATEROLE</code> does not63        confer the ability to grant or revoke the <code class="literal">BYPASSRLS</code>64        privilege.65       </p></dd><dt><span class="term">initiating replication<a id="id-1.6.9.6.2.1.5.1.1" class="indexterm"></a></span></dt><dd><p>66        A role must explicitly be given permission to initiate streaming67        replication (except for superusers, since those bypass all permission68        checks). A role used for streaming replication must69        have <code class="literal">LOGIN</code> permission as well. To create such a role, use70        <code class="literal">CREATE ROLE <em class="replaceable"><code>name</code></em> REPLICATION71        LOGIN</code>.72       </p></dd><dt><span class="term">password<a id="id-1.6.9.6.2.1.6.1.1" class="indexterm"></a></span></dt><dd><p>73        A password is only significant if the client authentication74        method requires the user to supply a password when connecting75        to the database. The <code class="option">password</code> and76        <code class="option">md5</code> authentication methods77        make use of passwords. Database passwords are separate from78        operating system passwords. Specify a password upon role79        creation with <code class="literal">CREATE ROLE80        <em class="replaceable"><code>name</code></em> PASSWORD '<em class="replaceable"><code>string</code></em>'</code>.81       </p></dd><dt><span class="term">inheritance of privileges<a id="id-1.6.9.6.2.1.7.1.1" class="indexterm"></a></span></dt><dd><p>82        A role inherits the privileges of roles it is a member of, by default.83        However, to create a role which does not inherit privileges by84        default, use <code class="literal">CREATE ROLE <em class="replaceable"><code>name</code></em>85        NOINHERIT</code>.  Alternatively, inheritance can be overridden86        for individual grants by using <code class="literal">WITH INHERIT TRUE</code>87        or <code class="literal">WITH INHERIT FALSE</code>.88       </p></dd><dt><span class="term">bypassing row-level security<a id="id-1.6.9.6.2.1.8.1.1" class="indexterm"></a></span></dt><dd><p>89        A role must be explicitly given permission to bypass every row-level security (RLS) policy90        (except for superusers, since those bypass all permission checks).91        To create such a role, use <code class="literal">CREATE ROLE <em class="replaceable"><code>name</code></em> BYPASSRLS</code> as a superuser.92       </p></dd><dt><span class="term">connection limit<a id="id-1.6.9.6.2.1.9.1.1" class="indexterm"></a></span></dt><dd><p>93        Connection limit can specify how many concurrent connections a role can make.94        -1 (the default) means no limit. Specify connection limit upon role creation with95        <code class="literal">CREATE ROLE <em class="replaceable"><code>name</code></em> CONNECTION LIMIT '<em class="replaceable"><code>integer</code></em>'</code>.96       </p></dd></dl></div><p>97 98    A role's attributes can be modified after creation with99    <code class="command">ALTER ROLE</code>.<a id="id-1.6.9.6.2.3" class="indexterm"></a>100    See the reference pages for the <a class="xref" href="sql-createrole.html" title="CREATE ROLE"><span class="refentrytitle">CREATE ROLE</span></a>101    and <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a> commands for details.102   </p><p>103   A role can also have role-specific defaults for many of the run-time104   configuration settings described in <a class="xref" href="runtime-config.html" title="Chapter 20. Server Configuration">Chapter 20</a>.  For example, if for some reason you105   want to disable index scans (hint: not a good idea) anytime you106   connect, you can use:107</p><pre class="programlisting">108ALTER ROLE myname SET enable_indexscan TO off;109</pre><p>110   This will save the setting (but not set it immediately).  In111   subsequent connections by this role it will appear as though112   <code class="literal">SET enable_indexscan TO off</code> had been executed113   just before the session started.114   You can still alter this setting during the session; it will only115   be the default. To remove a role-specific default setting, use116   <code class="literal">ALTER ROLE <em class="replaceable"><code>rolename</code></em> RESET <em class="replaceable"><code>varname</code></em></code>.117   Note that role-specific defaults attached to roles without118   <code class="literal">LOGIN</code> privilege are fairly useless, since they will never119   be invoked.120  </p><p>121   When a non-superuser creates a role using the <code class="literal">CREATEROLE</code>122   privilege, the created role is automatically granted back to the creating123   user, just as if the bootstrap superuser had executed the command124   <code class="literal">GRANT created_user TO creating_user WITH ADMIN TRUE, SET FALSE,125   INHERIT FALSE</code>. Since a <code class="literal">CREATEROLE</code> user can126   only exercise special privileges with regard to an existing role if they127   have <code class="literal">ADMIN OPTION</code> on it, this grant is just sufficient128   to allow a <code class="literal">CREATEROLE</code> user to administer the roles they129   created. However, because it is created with <code class="literal">INHERIT FALSE, SET130   FALSE</code>, the <code class="literal">CREATEROLE</code> user doesn't inherit the131   privileges of the created role, nor can it access the privileges of that132   role using <code class="literal">SET ROLE</code>. However, since any user who has133   <code class="literal">ADMIN OPTION</code> on a role can grant membership in that134   role to any other user, the <code class="literal">CREATEROLE</code> user can gain135   access to the created role by simply granting that role back to136   themselves with the <code class="literal">INHERIT</code> and/or <code class="literal">SET</code>137   options. Thus, the fact that privileges are not inherited by default nor138   is <code class="literal">SET ROLE</code> granted by default is a safeguard against139   accidents, not a security feature. Also note that, because this automatic140   grant is granted by the bootstrap user, it cannot be removed or changed by141   the <code class="literal">CREATEROLE</code> user; however, any superuser could142   revoke it, modify it, and/or issue additional such grants to other143   <code class="literal">CREATEROLE</code> users. Whichever <code class="literal">CREATEROLE</code>144   users have <code class="literal">ADMIN OPTION</code> on a role at any given time145   can administer it.146  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="database-roles.html" title="22.1. Database Roles">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-manag.html" title="Chapter 22. Database Roles">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="role-membership.html" title="22.3. Role Membership">Next</a></td></tr><tr><td width="40%" align="left" valign="top">22.1. Database Roles </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 22.3. Role Membership</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai