バージョンごとのドキュメント一覧

22.2. ロールの属性 #

<title>Role Attributes</title>

A database role can have a number of attributes that define its privileges and interact with the client authentication system. データベースロールは、権限を定義し、クライアント認証システムと相互作用する数多くの属性を持つことができます。

ログイン権限

Only roles that have the <literal>LOGIN</literal> attribute can be used as the initial role name for a database connection. A role with the <literal>LOGIN</literal> attribute can be considered the same as a <quote>database user</quote>. To create a role with login privilege, use either: LOGIN属性を持つロールのみがデータベース接続の初期ロール名として使用できます。 LOGIN 属性を持つロールはデータベースユーザと同じであるとみなすことができます。 ログイン権限を持つロールの作成方法は、以下のいずれかです。

CREATE ROLE name LOGIN;
CREATE USER name;

(<command>CREATE USER</command> is equivalent to <command>CREATE ROLE</command> except that <command>CREATE USER</command> includes <literal>LOGIN</literal> by default, while <command>CREATE ROLE</command> does not.) CREATE USERはデフォルトで LOGINを持ち、CREATE ROLEは持たないという点を除き、CREATE USERCREATE ROLEと同じです。)

スーパーユーザ状態

A database superuser bypasses all permission checks, except the right to log in. This is a dangerous privilege and should not be used carelessly; it is best to do most of your work as a role that is not a superuser. To create a new database superuser, use <literal>CREATE ROLE <replaceable>name</replaceable> SUPERUSER</literal>. You must do this as a role that is already a superuser. ログイン権限を除き、データベーススーパーユーザに対する権限検査は全て行われません。 これは危険な権限ですので、安易に使用してはいけません。 作業のほとんどを非スーパーユーザのロールで行うことが最善です。 新しいデータベーススーパーユーザを作成するには、CREATE ROLE name SUPERUSERを使用してください。 これはスーパーユーザのロールで実行しなければなりません。

データベース作成

A role must be explicitly given permission to create databases (except for superusers, since those bypass all permission checks). To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> CREATEDB</literal>. (全ての権限検査が行われないスーパーユーザを除き)ロールに明示的にデータベースを作成するための権限を指定しておかねばいけません。 そのようなロールを作るためにはCREATE ROLE name CREATEDBを使用してください。

ロールの作成

A role must be explicitly given permission to create more roles (except for superusers, since those bypass all permission checks). To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> CREATEROLE</literal>. A role with <literal>CREATEROLE</literal> privilege can alter and drop roles which have been granted to the <literal>CREATEROLE</literal> user with the <literal>ADMIN</literal> option. Such a grant occurs automatically when a <literal>CREATEROLE</literal> user that is not a superuser creates a new role, so that by default, a <literal>CREATEROLE</literal> user can alter and drop the roles which they have created. Altering a role includes most changes that can be made using <literal>ALTER ROLE</literal>, including, for example, changing passwords. It also includes modifications to a role that can be made using the <literal>COMMENT</literal> and <literal>SECURITY LABEL</literal> commands. あるロールがロールを作成するには、明示的な権限が付与されていなければなりません。 (スーパーユーザは、すべての権限検査を迂回しますので、例外です。) こうしたロールを作成するには、CREATE ROLE name CREATEROLEを使用してください。 CREATEROLE権限を持つロールは、ADMINオプションを持つCREATEROLEユーザのロールを変更したり削除したりすることもできます。 そのような権限付与は、スーパーユーザではないCREATEROLEユーザが新しいロールを作った時に自動的に行われ、CREATEROLEユーザが、作成したロールを変更したり削除できるようになります。 ロールの変更には、たとえばパスワードの変更などを含む、ALTER ROLEを使って実行できるほとんどの変更が含まれます。 また、COMMENTSECURITY LABELコマンドを使って実行できるロールの変更も含まれます。

However, <literal>CREATEROLE</literal> does not convey the ability to create <literal>SUPERUSER</literal> roles, nor does it convey any power over <literal>SUPERUSER</literal> roles that already exist. Furthermore, <literal>CREATEROLE</literal> does not convey the power to create <literal>REPLICATION</literal> users, nor the ability to grant or revoke the <literal>REPLICATION</literal> privilege, nor the ability to modify the role properties of such users. However, it does allow <literal>ALTER ROLE ... SET</literal> and <literal>ALTER ROLE ... RENAME</literal> to be used on <literal>REPLICATION</literal> roles, as well as the use of <literal>COMMENT ON ROLE</literal>, <literal>SECURITY LABEL ON ROLE</literal>, and <literal>DROP ROLE</literal>. Finally, <literal>CREATEROLE</literal> does not confer the ability to grant or revoke the <literal>BYPASSRLS</literal> privilege. しかし、CREATEROLEでは、SUPERUSERロールを作成する能力は移譲されませんし、既存のSUPERUSERロールに対する権限も移譲されません。 さらに、CREATEROLEでは、REPLICATIONユーザを作成する機能も、REPLICATION権限を付与または取り消す能力も、そのようなユーザのロール属性を変更する能力も移譲されません。 ただし、REPLICATIONロールでのALTER ROLE ... SETおよびALTER ROLE ... RENAMEの使用、およびCOMMENT ON ROLESECURITY LABEL ON ROLEDROP ROLEの使用は許可されます。 最後に、CREATEROLEでは、BYPASSRLS権限を付与または取り消す能力は付与されません。

レプリケーションの新規接続

A role must explicitly be given permission to initiate streaming replication (except for superusers, since those bypass all permission checks). A role used for streaming replication must have <literal>LOGIN</literal> permission as well. To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> REPLICATION LOGIN</literal>. あるロールがストリーミングレプリケーションの新規接続を実施するには、明示的な権限が付与されていなければなりません。 (スーパーユーザは、すべての権限検査を迂回しますので、例外です。) ストリーミングレプリケーションを行うロールは、LOGIN権限も持っていることが必要です。 こうしたロールを作成するには、CREATE ROLE name REPLICATION LOGINを使用してください。

パスワード

A password is only significant if the client authentication method requires the user to supply a password when connecting to the database. The <option>password</option> and <option>md5</option> authentication methods make use of passwords. Database passwords are separate from operating system passwords. Specify a password upon role creation with <literal>CREATE ROLE <replaceable>name</replaceable> PASSWORD '<replaceable>string</replaceable>'</literal>. パスワードは、クライアント認証方法においてデータベースに接続する際にユーザにパスワードを要求する場合にのみ重要になります。 passwordmd5認証方式でパスワードが使用されます。 データベースパスワードはオペレーティングシステムのパスワードとは異なります。 ロール作成時にCREATE ROLE name PASSWORD 'string'のようにパスワードを指定します。

権限の継承

A role inherits the privileges of roles it is a member of, by default. However, to create a role which does not inherit privileges by default, use <literal>CREATE ROLE <replaceable>name</replaceable> NOINHERIT</literal>. Alternatively, inheritance can be overridden for individual grants by using <literal>WITH INHERIT TRUE</literal> or <literal>WITH INHERIT FALSE</literal>. ロールは、デフォルトでメンバであるロールの権限を継承します。 ただし、デフォルトで権限を継承しないロールを作成するには、CREATE ROLE name NOINHERITを使用します。 別の方法として、WITH INHERIT TRUE、あるいはWITH INHERIT FALSEを使用して個々の権限の継承を上書きすることもできます。

行単位セキュリティのバイパス

A role must be explicitly given permission to bypass every row-level security (RLS) policy (except for superusers, since those bypass all permission checks). To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> BYPASSRLS</literal> as a superuser. (全ての権限検査が行われないスーパーユーザを除き)ロールに明示的にすべての行単位セキュリティ(RLS)ポリシーをバイパスするための権限を指定しておかねばなりません。 そのようなロールを作るためには、スーパーユーザでCREATE ROLE name BYPASSRLSを使用してください。

接続制限

Connection limit can specify how many concurrent connections a role can make. -1 (the default) means no limit. Specify connection limit upon role creation with <literal>CREATE ROLE <replaceable>name</replaceable> CONNECTION LIMIT '<replaceable>integer</replaceable>'</literal>. 接続制限では、ロールが作成できる同時接続数を指定できます。 -1(デフォルト)は制限なしを意味します。 CREATE ROLE name CONNECTION LIMIT 'integer'でロール作成時に接続制限を指定します。

A role's attributes can be modified after creation with <command>ALTER ROLE</command>.<indexterm><primary>ALTER ROLE</primary></indexterm> See the reference pages for the <xref linkend="sql-createrole"/> and <xref linkend="sql-alterrole"/> commands for details. ロール属性は、ロールを作成した後でもALTER ROLEコマンドで変更できます。 詳細はCREATE ROLEALTER ROLEのマニュアルページを参照してください。

A role can also have role-specific defaults for many of the run-time configuration settings described in <xref linkend="runtime-config"/>. For example, if for some reason you want to disable index scans (hint: not a good idea) anytime you connect, you can use: ロールは、第20章で説明されている実行時の設定の多くをロールごとのデフォルトに設定することもできます。 例えば何らかの理由で、自分が接続する時は常にインデックススキャンを無効にしたい場合(注:お勧めしません)、次のようにします。

ALTER ROLE myname SET enable_indexscan TO off;

This will save the setting (but not set it immediately). In subsequent connections by this role it will appear as though <literal>SET enable_indexscan TO off</literal> had been executed just before the session started. You can still alter this setting during the session; it will only be the default. To remove a role-specific default setting, use <literal>ALTER ROLE <replaceable>rolename</replaceable> RESET <replaceable>varname</replaceable></literal>. Note that role-specific defaults attached to roles without <literal>LOGIN</literal> privilege are fairly useless, since they will never be invoked. このようにして設定を保存します(ただし、すぐに反映はされません)。 以降のこのロールによる接続においては、セッションの開始の直前にSET enable_indexscan TO off;が呼び出されたのと同様になります。 これはデフォルトとする設定をするだけなので、設定をセッション途中いつでも変更できます。 ロール固有のデフォルト設定を削除するには、ALTER ROLE rolename RESET varnameを使用してください。 呼び出されることがありませんので、LOGIN権限を持たないロールにロール固有のデフォルトを持たせることに意味がないことに注意してください。

When a non-superuser creates a role using the <literal>CREATEROLE</literal> privilege, the created role is automatically granted back to the creating user, just as if the bootstrap superuser had executed the command <literal>GRANT created_user TO creating_user WITH ADMIN TRUE, SET FALSE, INHERIT FALSE</literal>. Since a <literal>CREATEROLE</literal> user can only exercise special privileges with regard to an existing role if they have <literal>ADMIN OPTION</literal> on it, this grant is just sufficient to allow a <literal>CREATEROLE</literal> user to administer the roles they created. However, because it is created with <literal>INHERIT FALSE, SET FALSE</literal>, the <literal>CREATEROLE</literal> user doesn't inherit the privileges of the created role, nor can it access the privileges of that role using <literal>SET ROLE</literal>. However, since any user who has <literal>ADMIN OPTION</literal> on a role can grant membership in that role to any other user, the <literal>CREATEROLE</literal> user can gain access to the created role by simply granting that role back to themselves with the <literal>INHERIT</literal> and/or <literal>SET</literal> options. Thus, the fact that privileges are not inherited by default nor is <literal>SET ROLE</literal> granted by default is a safeguard against accidents, not a security feature. Also note that, because this automatic grant is granted by the bootstrap user, it cannot be removed or changed by the <literal>CREATEROLE</literal> user; however, any superuser could revoke it, modify it, and/or issue additional such grants to other <literal>CREATEROLE</literal> users. Whichever <literal>CREATEROLE</literal> users have <literal>ADMIN OPTION</literal> on a role at any given time can administer it. 非スーパーユーザがCREATEROLE権限を使用してロールを作成すると、作成されたロールは自動的に作成元のユーザに再度付与されます。これは、ブートストラップスーパーユーザがコマンドGRANT created_user TO creating_user WITH ADMIN OPTION, SET FALSE, INHERIT FALSEを実行した場合と同じです。 CREATEROLEユーザが、既存のロールに関して特別な権限を行使できるのは、そのロールに対するADMIN OPTION権限がある場合のみですので、この権限は、CREATEROLEユーザが作成したロールを管理するのに十分なだけです。 一方、INHERIT FALSE, SET FALSEで作成されたため、このCREATEROLEユーザは作成されたロールの権限をデフォルトで継承していませんし、SET ROLEを使ってそのロールの権限にアクセスできません。 しかし、ロールに対するADMIN OPTIONを持つユーザは、そのロールのメンバシップを他のユーザに付与できるため、CREATEROLEユーザは、そのロールを自分自身にINHERITまたはSETオプションで付与するだけで、作成したロールへのアクセス権を獲得できます。 したがって、権限がデフォルトで継承されないこと、またはデフォルトでSET ROLEが付与されないことは、事故に対する安全策であり、セキュリティ機能ではありません。 また、この自動的な付与はブートストラップユーザによって与えられるため、CREATEROLEユーザによって削除または変更することはできないことに注意してください。しかし、スーパーユーザはそれを取り消したり、修正したり、他のCREATEROLEユーザに対してそのようなグラントを追加したりすることができます。 どのCREATEROLEユーザも、ある時点でロールに対してADMIN OPTIONを持っているかどうかに関係なく、それを管理できます。