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

F.40. sepgsql — SELinuxベースでラベルベースの強制アクセス制御(MAC)セキュリティモジュール #

<title>sepgsql &mdash; SELinux-, label-based mandatory access control (MAC) security module</title>

<filename>sepgsql</filename> is a loadable module that supports label-based mandatory access control (MAC) based on <productname>SELinux</productname> security policy. sepgsqlは、SELinuxのセキュリティポリシーに基づいた、ラベルベースの強制アクセス制御(MAC; Mandatory Access Control)機能を提供するモジュールです。

警告

The current implementation has significant limitations, and does not enforce mandatory access control for all actions. See <xref linkend="sepgsql-limitations"/>. 現在の実装にはいくつかの重要な制限事項があり、そのため、全ての操作に対して強制アクセス制御を適用するわけではありません。 詳細は F.40.7 をご覧ください。

F.40.1. 概要 #

<title>Overview</title>

This module integrates with <productname>SELinux</productname> to provide an additional layer of security checking above and beyond what is normally provided by <productname>PostgreSQL</productname>. From the perspective of <productname>SELinux</productname>, this module allows <productname>PostgreSQL</productname> to function as a user-space object manager. Each table or function access initiated by a DML query will be checked against the system security policy. This check is in addition to the usual SQL permissions checking performed by <productname>PostgreSQL</productname>. このモジュールは、PostgreSQLが標準で提供しているものに加えて、SELinuxと統合されたアクセス制御のレイヤーを追加します。 SELinuxの視点からは、このモジュールがPostgreSQLをユーザ空間オブジェクトマネージャとして機能することを可能にします。 すなわち、DMLクエリによる個々のテーブルや関数へのアクセスは、オペレーティングシステムのセキュリティポリシーによってチェックされます。 このチェックは、PostgreSQLによる通常のSQLパーミッションチェックに対して追加的に実施されます。

<productname>SELinux</productname> access control decisions are made using security labels, which are represented by strings such as <literal>system_u:object_r:sepgsql_table_t:s0</literal>. Each access control decision involves two labels: the label of the subject attempting to perform the action, and the label of the object on which the operation is to be performed. Since these labels can be applied to any sort of object, access control decisions for objects stored within the database can be (and, with this module, are) subjected to the same general criteria used for objects of any other type, such as files. This design is intended to allow a centralized security policy to protect information assets independent of the particulars of how those assets are stored. SELinuxにおけるアクセス制御の意思決定は、system_u:object_r:sepgsql_table_t:s0のような書式を持ったセキュリティラベルと呼ばれる文字列を用いて行われます。 個々のアクセス制御の意思決定には、2種類のラベルが利用されます。 すなわち、ある操作を行おうとする主体(サブジェクト)のラベルと、その操作の対象となるオブジェクトのラベルです。 これらのラベルはあらゆる種類のオブジェクトに対して適用されるため、(このモジュールを用いる事で)データベースに格納されたオブジェクトに対するアクセス制御は、他の一般的なオブジェクト、例えばファイルに対するものと同一の基準に従って意思決定される事になります。 このデザインは、情報資産を格納する方法とは独立に、一元管理されたセキュリティポリシーによって情報資産を保護することを意図しています。

The <link linkend="sql-security-label"><command>SECURITY LABEL</command></link> statement allows assignment of a security label to a database object. SECURITY LABELを用いてデータベースオブジェクトにセキュリティラベルを設定することができます。

F.40.2. インストール #

<title>Installation</title>

<filename>sepgsql</filename> can only be used on <productname>Linux</productname> 2.6.28 or higher with <productname>SELinux</productname> enabled. It is not available on any other platform. You will also need <productname>libselinux</productname> 2.1.10 or higher and <productname>selinux-policy</productname> 3.9.13 or higher (although some distributions may backport the necessary rules into older policy versions). sepgsqlSELinuxが有効なLinuxカーネル 2.6.28 以上で動作します。 その他のプラットフォーム上では利用する事はできません。 加えて、(ディストリビューションによっては、必要なルールを古いバージョンのポリシーにバックポートしている可能性がありますが)libselinux 2.1.10以上、selinux-policy 3.9.13以上が必要です。

The <command>sestatus</command> command allows you to check the status of <productname>SELinux</productname>. A typical display is: sestatusコマンドを用いてSELinuxの状態を確認することができます。典型的な出力例は以下の通りです。

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

If <productname>SELinux</productname> is disabled or not installed, you must set that product up first before installing this module. SELinuxが無効化されている、あるいはインストールされていない場合、このモジュールのインストールの前に、SELinuxのセットアップを行わねばなりません。

To build this module, include the option <literal>&#45;-with-selinux</literal> in your PostgreSQL <literal>configure</literal> command. Be sure that the <filename>libselinux-devel</filename> RPM is installed at build time. このモジュールをビルドするには、PostgreSQLのconfigureコマンドに--with-selinuxオプションを追加してください。 これは、ビルド時にlibselinux-develパッケージがインストールされている事を確認します。

To use this module, you must include <literal>sepgsql</literal> in the <xref linkend="guc-shared-preload-libraries"/> parameter in <filename>postgresql.conf</filename>. The module will not function correctly if loaded in any other manner. Once the module is loaded, you should execute <filename>sepgsql.sql</filename> in each database. This will install functions needed for security label management, and assign initial security labels. このモジュールを利用するには、postgresql.confshared_preload_librariesパラメータに sepgsqlを含める必要があります。これ以外の方法でロードされた場合、このモジュールは正しく機能しません。 このモジュールのロード後、各データベースに対してsepgsql.sqlを実行し、セキュリティラベル管理のための関数のインストールや、初期セキュリティラベルの設定を行うべきです。

Here is an example showing how to initialize a fresh database cluster with <filename>sepgsql</filename> functions and security labels installed. Adjust the paths shown as appropriate for your installation: 以下にsepgsql関数およびセキュリティラベルと共にデータベースクラスタを初期化する手順を示します。 インストール先に応じて、適宜パス名を読み替えるようにしてください。

$ export PGDATA=/path/to/data/directory
$ initdb
$ vi $PGDATA/postgresql.conf

  change

  この行を
    #shared_preload_libraries = ''                # (change requires restart)

  to

  以下に変更
    shared_preload_libraries = 'sepgsql'          # (change requires restart)
$ for DBNAME in template0 template1 postgres; do
    postgres --single -F -c exit_on_error=true $DBNAME \
      </usr/local/pgsql/share/contrib/sepgsql.sql >/dev/null
  done

Please note that you may see some or all of the following notifications depending on the particular versions you have of <productname>libselinux</productname> and <productname>selinux-policy</productname>: libselinuxselinux-policyのバージョンによっては以下のようなメッセージが出力される事があります。

/etc/selinux/targeted/contexts/sepgsql_contexts:  line 33 has invalid object type db_blobs
/etc/selinux/targeted/contexts/sepgsql_contexts:  line 36 has invalid object type db_language
/etc/selinux/targeted/contexts/sepgsql_contexts:  line 37 has invalid object type db_language
/etc/selinux/targeted/contexts/sepgsql_contexts:  line 38 has invalid object type db_language
/etc/selinux/targeted/contexts/sepgsql_contexts:  line 39 has invalid object type db_language
/etc/selinux/targeted/contexts/sepgsql_contexts:  line 40 has invalid object type db_language

These messages are harmless and should be ignored. これらのメッセージは無害ですので無視してください。

If the installation process completes without error, you can now start the server normally. インストール手順が正常に終了したら、通常通り、サーバを起動することができます。

F.40.3. リグレッションテスト #

<title>Regression Tests</title>

Due to the nature of <productname>SELinux</productname>, running the regression tests for <filename>sepgsql</filename> requires several extra configuration steps, some of which must be done as root. The regression tests will not be run by an ordinary <literal>make check</literal> or <literal>make installcheck</literal> command; you must set up the configuration and then invoke the test script manually. The tests must be run in the <filename>contrib/sepgsql</filename> directory of a configured PostgreSQL build tree. Although they require a build tree, the tests are designed to be executed against an installed server, that is they are comparable to <literal>make installcheck</literal> not <literal>make check</literal>. SELinuxの性質上、sepgsqlのリグレッションテストを実行するには、いくつかの追加的な設定が必要で、そのうちの幾つかはrootで実行する必要があります。 リグレッションテストは通常のmake checkmake installcheckコマンドで実行する事はできません。 必要な設定を行い、テスト用スクリプトを手動で実行する必要があります。 このテストはPostgreSQLビルドツリーのcontrib/sepgsqlディレクトリで実行する必要があります。 しかしビルドツリーを必要とする一方、このテストはインストールされたサーバに対して実行する必要があります。 これは、make checkではなく、make installcheckによく似ています。

First, set up <filename>sepgsql</filename> in a working database according to the instructions in <xref linkend="sepgsql-installation"/>. Note that the current operating system user must be able to connect to the database as superuser without password authentication. 最初に、F.40.2に従ってsepgsqlをデータベースにセットアップします。 使用するOS上のユーザは、認証無しでデータベース特権ユーザとして接続できる必要があることに留意してください。

Second, build and install the policy package for the regression test. The <filename>sepgsql-regtest</filename> policy is a special purpose policy package which provides a set of rules to be allowed during the regression tests. It should be built from the policy source file <filename>sepgsql-regtest.te</filename>, which is done using <command>make</command> with a Makefile supplied by SELinux. You will need to locate the appropriate Makefile on your system; the path shown below is only an example. (This Makefile is usually supplied by the <filename>selinux-policy-devel</filename> or <filename>selinux-policy</filename> RPM.) Once built, install this policy package using the <command>semodule</command> command, which loads supplied policy packages into the kernel. If the package is correctly installed, <literal><command>semodule</command> -l</literal> should list <literal>sepgsql-regtest</literal> as an available policy package: 次に、リグレッションテスト用のポリシーパッケージのビルドとインストールを行ってください。 sepgsql-regtestポリシーはリグレッションテストの実行に必要な一連のルールを含む特別な目的のポリシーパッケージです。 ポリシーのソースファイルであるsepgsql-regtest.teから、SELinuxの提供するMakefileを用いてmakeコマンドでビルドする事ができます。 この時、インストール先システムにおいて、適切なMakefileの位置を指定する必要があります。以下の例で示されているパスは一例です。 (このMakefileは通常selinux-policy-develselinux-policyパッケージで提供されています。) ビルドが完了したら、semoduleを用いてこのポリシーパッケージをインストールする事ができます。このコマンドは、指定されたポリシーパッケージをリンクし、カーネル空間にロードする役割を果たします。 インストールが正常終了したら、semodule -lにより有効なパッケージの一覧としてsepgsql-regtestが表示されるはずです。

$ cd .../contrib/sepgsql
$ make -f /usr/share/selinux/devel/Makefile
$ sudo semodule -u sepgsql-regtest.pp
$ sudo semodule -l | grep sepgsql
sepgsql-regtest 1.07

Third, turn on <literal>sepgsql_regression_test_mode</literal>. For security reasons, the rules in <filename>sepgsql-regtest</filename> are not enabled by default; the <literal>sepgsql_regression_test_mode</literal> parameter enables the rules needed to launch the regression tests. It can be turned on using the <command>setsebool</command> command: 次に、sepgsql_regression_test_modeを有効化してください。 安全のため、デフォルトではsepgsql-regtestに含まれる全てのルールが有効化されている訳ではありません。 sepgsql_regression_test_modeパラメータはリグレッションテストを起動するために必要となる幾つかのルールを有効にします。 setseboolコマンドによって有効化する事ができます。

$ sudo setsebool sepgsql_regression_test_mode on
$ getsebool sepgsql_regression_test_mode
sepgsql_regression_test_mode --> on

Fourth, verify your shell is operating in the <literal>unconfined_t</literal> domain: 次に、シェルがunconfined_tドメインで動作している事を確認して下さい。

$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

See <xref linkend="sepgsql-resources"/> for details on adjusting your working domain, if necessary. 利用者の動作ドメインを設定する方法について、必要であれば、詳細はF.40.8をご覧ください。

Finally, run the regression test script: 最後に、リグレッションテストのスクリプトを実行します。

$ ./test_sepgsql

This script will attempt to verify that you have done all the configuration steps correctly, and then it will run the regression tests for the <filename>sepgsql</filename> module. このスクリプトは全ての設定ステップが正常に行われていることを確認し、その後、sepgsqlモジュールに対するリグレッションテストを実行します。

After completing the tests, it's recommended you disable the <literal>sepgsql_regression_test_mode</literal> parameter: テストの実行後はsepgsql_regression_test_modeパラメータを無効化する事をお勧めします。

$ sudo setsebool sepgsql_regression_test_mode off

You might prefer to remove the <filename>sepgsql-regtest</filename> policy entirely: sepgsql-regtestポリシーをアンロードする際は、以下のコマンドを実行してください。

$ sudo semodule -r sepgsql-regtest

F.40.4. GUCパラメータ #

<title>GUC Parameters</title>
sepgsql.permissive (boolean) #

This parameter enables <filename>sepgsql</filename> to function in permissive mode, regardless of the system setting. The default is off. This parameter can only be set in the <filename>postgresql.conf</filename> file or on the server command line. このパラメータにより、オペレーティングシステムの設定に関わらず、sepgsqlをパーミッシブモードで動作させる事ができます。 デフォルトの設定値はoffです。 postgresql.conf内、およびサーバ起動時のコマンドラインでのみ、このパラメータを設定する事ができます。

When this parameter is on, <filename>sepgsql</filename> functions in permissive mode, even if SELinux in general is working in enforcing mode. This parameter is primarily useful for testing purposes. このパラメータがonの場合、たとえSELinuxがエンフォーシングモードで動作していたとしても、sepgsql関数はパーミッシブモードで動作します。 このパラメータは主としてテストの目的に有用です。

sepgsql.debug_audit (boolean) #

This parameter enables the printing of audit messages regardless of the system policy settings. The default is off, which means that messages will be printed according to the system settings. このパラメータにより、セキュリティポリシーの設定とは無関係に監査ログを出力する事が可能になります。 デフォルト値はoff(セキュリティポリシーの設定に従う)です。

The security policy of <productname>SELinux</productname> also has rules to control whether or not particular accesses are logged. By default, access violations are logged, but allowed accesses are not. SELinuxのセキュリティポリシーには、特定のアクセスを監査ログに記録するか否かを制御するルールも存在します。 デフォルトでは、ポリシーに違反したアクセスを記録し、それ以外はログに記録されません。

This parameter forces all possible logging to be turned on, regardless of the system policy. システムのポリシーとは無関係に、このパラメータは全ての監査ログの出力を強制します。

F.40.5. 機能 #

<title>Features</title>

F.40.5.1. 制御されるオブジェクトの種類 #

<title>Controlled Object Classes</title>

The security model of <productname>SELinux</productname> describes all the access control rules as relationships between a subject entity (typically, a client of the database) and an object entity (such as a database object), each of which is identified by a security label. If access to an unlabeled object is attempted, the object is treated as if it were assigned the label <literal>unlabeled_t</literal>. SELinuxのセキュリティモデルでは、全てのアクセス制御ルールは動作主体(サブジェクト; 典型的にはデータベースクライアント)と対象オブジェクト間の関係として記述し、これらはセキュリティラベルによって識別されます。 ラベル付けされていないオブジェクトに対するアクセスが発生した場合、そのオブジェクトはあたかもunlabeled_tタイプが割り当てられているかのように振舞います。

Currently, <filename>sepgsql</filename> allows security labels to be assigned to schemas, tables, columns, sequences, views, and functions. When <filename>sepgsql</filename> is in use, security labels are automatically assigned to supported database objects at creation time. This label is called a default security label, and is decided according to the system security policy, which takes as input the creator's label, the label assigned to the new object's parent object and optionally name of the constructed object. 現在のsepgsqlでは、スキーマ、テーブル、カラム、シーケンス、ビューおよび関数に対するラベル付けがサポートされています。 sepgsqlの利用時には、これらのデータベースオブジェクトに対して、その生成時に自動的にセキュリティラベルが割り当てられます。 このラベルはデフォルトセキュリティラベルと呼ばれ、作成者のラベル、親関係にあたるオブジェクトのラベル、そして場合によっては作成されたオブジェクトの名前に基づいて、システムのセキュリティポリシーが決定します。

A new database object basically inherits the security label of the parent object, except when the security policy has special rules known as type-transition rules, in which case a different label may be applied. For schemas, the parent object is the current database; for tables, sequences, views, and functions, it is the containing schema; for columns, it is the containing table. 新しいデータベースオブジェクトのラベルは、タイプ遷移と呼ばれる異なったラベルを設定するための特別なルールがセキュリティポリシーに設定されている場合を除き、親関係にあるオブジェクトのラベルを引き継ぎます。 スキーマの親オブジェクトはデータベースであり、テーブル、シーケンス、ビュー、および関数はその属するスキーマが、カラムはその属するテーブルが親オブジェクトという事になります。

F.40.5.2. DMLパーミッション #

<title>DML Permissions</title>

For tables, <literal>db_table:select</literal>, <literal>db_table:insert</literal>, <literal>db_table:update</literal> or <literal>db_table:delete</literal> are checked for all the referenced target tables depending on the kind of statement; in addition, <literal>db_table:select</literal> is also checked for all the tables that contain columns referenced in the <literal>WHERE</literal> or <literal>RETURNING</literal> clause, as a data source for <literal>UPDATE</literal>, and so on. テーブルに対しては、構文の種類に応じてdb_table:selectdb_table:insertdb_table:updateあるいはdb_table:delete権限が全ての被参照テーブルに対してチェックされます。 加えて、WHERE句やRETURNING句で参照されるカラム、又はUPDATEの際のデータ元として利用されるカラムの属するテーブルに対してdb_table:select権限もチェックされます。

Column-level permissions will also be checked for each referenced column. <literal>db_column:select</literal> is checked on not only the columns being read using <literal>SELECT</literal>, but those being referenced in other DML statements; <literal>db_column:update</literal> or <literal>db_column:insert</literal> will also be checked for columns being modified by <literal>UPDATE</literal> or <literal>INSERT</literal>. 参照された全てのカラムに対して列レベルの権限チェックが行われます。 SELECT構文で読み出されるカラムに対してだけでなく、他のDML構文で参照されているカラムに対してもdb_column:select権限がチェックされます。 また、UPDATEINSERTによって操作の対象となっているカラムに対しても、db_column:updatedb_column:insert権限がそれぞれチェックされます。

For example, consider: 以下の例を見てください

UPDATE t1 SET x = 2, y = func1(y) WHERE z = 100;

Here, <literal>db_column:update</literal> will be checked for <literal>t1.x</literal>, since it is being updated, <literal>db_column:{select update}</literal> will be checked for <literal>t1.y</literal>, since it is both updated and referenced, and <literal>db_column:select</literal> will be checked for <literal>t1.z</literal>, since it is only referenced. <literal>db_table:{select update}</literal> will also be checked at the table level. ここでは、更新されるt1.xに対してdb_column:update権限が、更新と同時に参照されるt1.yに対してはdb_column:{select update}権限が、そして参照されるだけのt1.zにはdb_column:select権限がチェックされます。 また、テーブルレベルではdb_table:{select update}権限がチェックされます。

For sequences, <literal>db_sequence:get_value</literal> is checked when we reference a sequence object using <literal>SELECT</literal>; however, note that we do not currently check permissions on execution of corresponding functions such as <literal>lastval()</literal>. SELECT構文を用いてシーケンスを参照する場合、db_sequence:get_valueがチェックされます。 しかし、現在のところlastval()など関連する関数の実行時にはパーミッションチェックを行わない事に留意してください。

For views, <literal>db_view:expand</literal> will be checked, then any other required permissions will be checked on the objects being expanded from the view, individually. ビューに対してはdb_view:expand権限がチェックされ、次いで、ビューから展開されたオブジェクトに対するパーミッションが個別にチェックされます。

For functions, <literal>db_procedure:{execute}</literal> will be checked when user tries to execute a function as a part of query, or using fast-path invocation. If this function is a trusted procedure, it also checks <literal>db_procedure:{entrypoint}</literal> permission to check whether it can perform as entry point of trusted procedure. 利用者がクエリの一部として、あるいは近道インタフェースを用いた呼び出しによって関数を実行しようとするとき、db_procedure:{execute}権限がチェックされます。 関数がトラステッドプロシージャである場合、関数がトラステッドプロシージャのエントリーポイントとして振る舞う事ができるかどうかを検査するためにdb_procedure:{entrypoint}権限がチェックされます。

In order to access any schema object, <literal>db_schema:search</literal> permission is required on the containing schema. When an object is referenced without schema qualification, schemas on which this permission is not present will not be searched (just as if the user did not have <literal>USAGE</literal> privilege on the schema). If an explicit schema qualification is present, an error will occur if the user does not have the requisite permission on the named schema. あらゆるスキーマオブジェクトにアクセスするためには、それらを含むスキーマに対するdb_schema:search権限が必要です。 あるスキーマオブジェクトがスキーマ修飾無しに参照された場合、この権限を与えられていないスキーマは探索されません(あたかも利用者がスキーマに対するUSAGE権限を有していないかのように振る舞います)。 明示的なスキーマ修飾があり、このスキーマに対して利用者が要求された権限を有していない場合、エラーが発生します。

The client must be allowed to access all referenced tables and columns, even if they originated from views which were then expanded, so that we apply consistent access control rules independent of the manner in which the table contents are referenced. クライアントは全ての被参照テーブル・カラムに対して参照の権限を有している必要があります。それらがビューに由来し、展開されたものであっても同様です。これにより、テーブルの内容がどのような方法によって参照されるかに関係なく、一貫したアクセス制御ルールを適用する事ができます。

The default database privilege system allows database superusers to modify system catalogs using DML commands, and reference or modify toast tables. These operations are prohibited when <filename>sepgsql</filename> is enabled. データベーススーパーユーザに対して、標準のデータベース権限システムはDMLを用いたシステムカタログの更新と、TOASTテーブルの参照および更新を許していますが、sepgsqlが有効なとき、これらの操作は禁止されます。

F.40.5.3. DDLパーミッション #

<title>DDL Permissions</title>

<productname>SELinux</productname> defines several permissions to control common operations for each object type; such as creation, alter, drop and relabel of security label. In addition, several object types have special permissions to control their characteristic operations; such as addition or deletion of name entries within a particular schema. オブジェクトの作成、変更、削除やセキュリティラベルの変更など、SELinuxは各オブジェクトに共通の操作を制御するためのパーミッションを何個か定義しています。 また、特定のスキーマに対する名前の追加や削除など、いくつかのオブジェクトにはそれ固有の操作を制御するための特別なパーミッションも定義されています。

Creating a new database object requires <literal>create</literal> permission. <productname>SELinux</productname> will grant or deny this permission based on the client's security label and the proposed security label for the new object. In some cases, additional privileges are required: 新しいデータベースオブジェクトの作成にはcreate権限が必要です。 SELinuxは利用者のセキュリティラベルと新しいオブジェクトに付与される事になるセキュリティラベルの対に基づいて、この権限を許可、あるいは拒否します。 いくつかの場合では、追加的な権限チェックが行われます。

  • <link linkend="sql-createdatabase"><command>CREATE DATABASE</command></link> additionally requires <literal>getattr</literal> permission for the source or template database. CREATE DATABASEは、複製元またはテンプレートのデータベースに対するgetattr権限を要求します。

  • Creating a schema object additionally requires <literal>add_name</literal> permission on the parent schema. スキーマオブジェクトの作成は、それを含むスキーマに対してadd_name権限を要求します。

  • Creating a table additionally requires permission to create each individual table column, just as if each table column were a separate top-level object. テーブルの作成は同時に、それがあたかも独立したオブジェクトであるかのように、個々のテーブル列を作成する権限を要求します。

  • Creating a function marked as <literal>LEAKPROOF</literal> additionally requires <literal>install</literal> permission. (This permission is also checked when <literal>LEAKPROOF</literal> is set for an existing function.) LEAKPROOF属性を持った関数の作成はinstall権限を要求します。(これはまた、既存の関数にLEAKPROOF属性を設定する時にも要求されます)

When <literal>DROP</literal> command is executed, <literal>drop</literal> will be checked on the object being removed. Permissions will be also checked for objects dropped indirectly via <literal>CASCADE</literal>. Deletion of objects contained within a particular schema (tables, views, sequences and procedures) additionally requires <literal>remove_name</literal> on the schema. DROP構文の実行時、削除されるオブジェクトに対してdrop権限がチェックされます。 CASCADEにより間接的に削除されるオブジェクトに対してもチェックは行われます。 特定のスキーマに含まれるオブジェクト(テーブル、ビュー、シーケンスや関数)の削除に際しては、スキーマに対するremove_name権限も併せてチェックされます。

When <literal>ALTER</literal> command is executed, <literal>setattr</literal> will be checked on the object being modified for each object types, except for subsidiary objects such as the indexes or triggers of a table, where permissions are instead checked on the parent object. In some cases, additional permissions are required: ALTER構文の実行時、テーブルに対するインデックスやトリガなど別オブジェクトに従属するもの(これらは代わりに親オブジェクトに対する権限がチェックされる)を除き、setattrがチェックされます。 いくつかの場合では、追加的な権限チェックが行われます。

  • Moving an object to a new schema additionally requires <literal>remove_name</literal> permission on the old schema and <literal>add_name</literal> permission on the new one. オブジェクトを新しいスキーマに移動させるには、古いスキーマに対してremove_name権限が、新しいスキーマに対してadd_name権限が必要です。

  • Setting the <literal>LEAKPROOF</literal> attribute on a function requires <literal>install</literal> permission. 関数に対するLEAKPROOF属性の設定はinstall権限を要求します。

  • Using <link linkend="sql-security-label"><command>SECURITY LABEL</command></link> on an object additionally requires <literal>relabelfrom</literal> permission for the object in conjunction with its old security label and <literal>relabelto</literal> permission for the object in conjunction with its new security label. (In cases where multiple label providers are installed and the user tries to set a security label, but it is not managed by <productname>SELinux</productname>, only <literal>setattr</literal> should be checked here. This is currently not done due to implementation restrictions.) SECURITY LABELコマンドの実行時、ラベル付けされるオブジェクトの古いラベルに対してsetattr権限とrelabelfrom権限が、入力された新しいラベルに対してrelabelto権限がチェックされます。 (複数のラベルプロバイダがインストールされており、利用者がSELinuxの管理下にないラベルを設定しようとした場合、setattr権限だけがチェックされるべきです。しかし実装上の制約により、現在はこれをチェックしていません。)

F.40.5.4. トラステッドプロシージャ #

<title>Trusted Procedures</title>

Trusted procedures are similar to security definer functions or setuid commands. <productname>SELinux</productname> provides a feature to allow trusted code to run using a security label different from that of the client, generally for the purpose of providing highly controlled access to sensitive data (e.g., rows might be omitted, or the precision of stored values might be reduced). Whether or not a function acts as a trusted procedure is controlled by its security label and the operating system security policy. For example: トラステッドプロシージャはSECURITY DEFINER関数やSet-UIDコマンドに似ています。 通常、機密データに対する高度にコントロールされたアクセス手段(例えば行を削除したり、保存された値の精度をさげたりします)を提供する目的で、SELinuxは利用者のものとは異なるセキュリティラベルで信頼済みのコードを実行するための機能を持っています。 関数がトラステッドプロシージャとして振舞うかどうかは、関数のセキュリティラベルおよびオペレーティングシステムのセキュリティポリシーに従って決まります。 例えば:

postgres=# CREATE TABLE customer (
               cid     int primary key,
               cname   text,
               credit  text
           );
CREATE TABLE
postgres=# SECURITY LABEL ON COLUMN customer.credit
               IS 'system_u:object_r:sepgsql_secret_table_t:s0';
SECURITY LABEL
postgres=# CREATE FUNCTION show_credit(int) RETURNS text
             AS 'SELECT regexp_replace(credit, ''-[0-9]+$'', ''-xxxx'', ''g'')
                        FROM customer WHERE cid = $1'
           LANGUAGE sql;
CREATE FUNCTION
postgres=# SECURITY LABEL ON FUNCTION show_credit(int)
               IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0';
SECURITY LABEL

The above operations should be performed by an administrative user. これらの操作は管理権限を持つ利用者で行ってください。

postgres=# SELECT * FROM customer;
ERROR:  SELinux: security policy violation
postgres=# SELECT cid, cname, show_credit(cid) FROM customer;
 cid | cname  |     show_credit
-----+--------+---------------------
   1 | taro   | 1111-2222-3333-xxxx
   2 | hanako | 5555-6666-7777-xxxx
(2 rows)

In this case, a regular user cannot reference <literal>customer.credit</literal> directly, but a trusted procedure <literal>show_credit</literal> allows the user to print the credit card numbers of customers with some of the digits masked out. この場合、一般の利用者はcustomer.creditを直接参照することはできませんが、トラステッドプロシージャであるshow_creditを用いる事で、一部の桁がマスクされた顧客のクレジットカード番号をプリントする事が可能になります。

F.40.5.5. 動的ドメイン遷移 #

<title>Dynamic Domain Transitions</title>

It is possible to use SELinux's dynamic domain transition feature to switch the security label of the client process, the client domain, to a new context, if that is allowed by the security policy. The client domain needs the <literal>setcurrent</literal> permission and also <literal>dyntransition</literal> from the old to the new domain. セキュリティポリシーによって許可されている場合、SELinuxの動的ドメイン遷移機能を用いて、利用者のラベルを新しいものに切り替える事ができます。 利用者のドメインはsetcurrent権限および、古いドメインから新しいドメインに遷移するためのdyntransition権限を有している必要があります。

Dynamic domain transitions should be considered carefully, because they allow users to switch their label, and therefore their privileges, at their option, rather than (as in the case of a trusted procedure) as mandated by the system. Thus, the <literal>dyntransition</literal> permission is only considered safe when used to switch to a domain with a smaller set of privileges than the original one. For example: 利用者に自身のラベル、すなわち権限を切り替える事を可能にする動的ドメイン遷移は、システムによる自動切り替え(トラステッドプロシージャの場合)に比べて慎重に取り扱う必要があります。 dyntransition権限は元々のドメインよりも小さな権限セットを持つドメインに切り替える場合にのみ安全であると考えられます。 例えば、

regression=# select sepgsql_getcon();
                    sepgsql_getcon
-------------------------------------------------------
 unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
(1 row)

regression=# SELECT sepgsql_setcon('unconfined_u:unconfined_r:unconfined_t:s0-s0:c1.c4');
 sepgsql_setcon
----------------
 t
(1 row)

regression=# SELECT sepgsql_setcon('unconfined_u:unconfined_r:unconfined_t:s0-s0:c1.c1023');
ERROR:  SELinux: security policy violation

In this example above we were allowed to switch from the larger MCS range <literal>c1.c1023</literal> to the smaller range <literal>c1.c4</literal>, but switching back was denied. 上記の例では、広いMCSレンジc1.c1023から狭いMCSレンジc1.c4への遷移は許可されているものの、その逆は禁止されています。

A combination of dynamic domain transition and trusted procedure enables an interesting use case that fits the typical process life-cycle of connection pooling software. Even if your connection pooling software is not allowed to run most of SQL commands, you can allow it to switch the security label of the client using the <literal>sepgsql_setcon()</literal> function from within a trusted procedure; that should take some credential to authorize the request to switch the client label. After that, this session will have the privileges of the target user, rather than the connection pooler. The connection pooler can later revert the security label change by again using <literal>sepgsql_setcon()</literal> with <literal>NULL</literal> argument, again invoked from within a trusted procedure with appropriate permissions checks. The point here is that only the trusted procedure actually has permission to change the effective security label, and only does so when given proper credentials. Of course, for secure operation, the credential store (table, procedure definition, or whatever) must be protected from unauthorized access. 動的ドメイン遷移とトラステッドプロシージャの組み合わせは、典型的なコネクションプーラのライフサイクルに適合する興味深い利用法を提供します。 たとえコネクションプーリングソフトウェアが大半のSQLの実行を許可されていない場合でも、トラステッドプロシージャの内側からsepgsql_setcon()関数を用いて利用者のセキュリティラベルを切り替える事ができます。(トラステッドプロシージャは利用者のセキュリティラベルを切り替えるための認証情報を要求すべきです。) この後、現在のセッションはコネクションプーラの権限ではなく、対象となる利用者の権限で動作する事になります。 また、sepgsql_setcon()NULL引数を与えて(適切な権限チェックを行う)トラステッドプロシージャから再び呼び出す事で、コネクションプーラは後でセキュリティラベルを元に戻す事ができます。 ここでのポイントは、トラステッドプロシージャだけが実際に有効なセキュリティラベルを変更する権限を持っており、正しい認証情報が与えられた場合にのみそれを実行するという事です。 言うまでもなく、安全な操作のためには、権限のないアクセスから認証情報を保持するテーブルや関数定義などを保護しなければなりません。

F.40.5.6. その他 #

<title>Miscellaneous</title>

We reject the <link linkend="sql-load"><command>LOAD</command></link> command across the board, because any module loaded could easily circumvent security policy enforcement. ロードされたモジュールは、セキュリティポリシーの適用を容易にバイパスできるため、LOADコマンドの実行は全面的に禁止されています。

F.40.6. sepgsql関数 #

<title>Sepgsql Functions</title>

<xref linkend="sepgsql-functions-table"/> shows the available functions. 表 F.31に利用可能な関数を示します。

表F.31 sepgsql関数

<title>Sepgsql Functions</title>

Function 関数

Description 説明

sepgsql_getcon () → text

Returns the client domain, the current security label of the client. 利用者のドメイン、つまり、現在の利用者ラベルを返却します。

sepgsql_setcon ( text ) → boolean

Switches the client domain of the current session to the new domain, if allowed by the security policy. It also accepts <literal>NULL</literal> input as a request to transition to the client's original domain. セキュリティポリシーで許可されている場合、現在のセッションの利用者ドメインを新しいドメインへと切り替えます。 NULLを引数に取る事も可能で、その場合、元々の利用者ドメインへの遷移を意味します。

sepgsql_mcstrans_in ( text ) → text

Translates the given qualified MLS/MCS range into raw format if the mcstrans daemon is running. mcstransデーモンが動作している場合、入力されたMLS/MCSレンジを修飾フォーマットから直接フォーマットに変換します。

sepgsql_mcstrans_out ( text ) → text

Translates the given raw MLS/MCS range into qualified format if the mcstrans daemon is running. mcstransデーモンが動作している場合、入力されたMLS/MCSレンジを直接フォーマットから修飾フォーマットに変換します。

sepgsql_restorecon ( text ) → boolean

Sets up initial security labels for all objects within the current database. The argument may be <literal>NULL</literal>, or the name of a specfile to be used as alternative of the system default. 現在のデータベース内のすべてのオブジェクトに対して初期セキュリティラベルを割り当てます。 引数はNULLもしくはシステムの標準に代わる定義ファイルの名前です。


F.40.7. 制限事項 #

<title>Limitations</title>
Data Definition Language (DDL) パーミッション

Due to implementation restrictions, some DDL operations do not check permissions. 実装上の制約により、いくつかのDDL操作はパーミッションをチェックしません。

Data Control Language (DCL) パーミッション

Due to implementation restrictions, DCL operations do not check permissions. 実装上の制約により、DCL操作はパーミッションをチェックしません。

行レベルアクセス制御

<productname>PostgreSQL</productname> supports row-level access, but <filename>sepgsql</filename> does not. PostgreSQLは行レベルアクセス制御をサポートしていますが、sepgsqlはサポートしていません。

隠れチャネル

<filename>sepgsql</filename> does not try to hide the existence of a certain object, even if the user is not allowed to reference it. For example, we can infer the existence of an invisible object as a result of primary key conflicts, foreign key violations, and so on, even if we cannot obtain the contents of the object. The existence of a top secret table cannot be hidden; we only hope to conceal its contents. たとえ利用者が参照を許可されていないオブジェクトであっても、sepgsqlはその存在を隠すことを意図していません。 例えば、我々があるオブジェクトの内容を参照する事ができなくても、主キーの競合や外部キー違反、その他の方法によって不可視なオブジェクトが存在する事を推測できます。 "最高機密"テーブルの存在を隠すことは不可能であり、その内容を秘匿することだけを意図しています。

F.40.8. 外部リソース #

<title>External Resources</title>
SE-PostgreSQL Introduction

This wiki page provides a brief overview, security design, architecture, administration and upcoming features. このwikiページでは、概要、セキュリティ・デザイン、アーキテクチャ、管理、および将来の機能について紹介しています。

SELinux User's and Administrator's Guide

This document provides a wide spectrum of knowledge to administer <productname>SELinux</productname> on your systems. It focuses primarily on Red Hat operating systems, but is not limited to them. このドキュメントはSELinuxシステム管理に対する広範な知識を提供しています。 主としてRed Hatオペレーティングシステムを対象としていますが、それに限ったものではありません。

Fedora SELinux FAQ

This document answers frequently asked questions about <productname>SELinux</productname>. It focuses primarily on Fedora, but is not limited to Fedora. このドキュメントはSELinuxに関するよくある質問と回答(FAQ)です。 主としてFedoraを対象としていますが、それに限ったものではありません。

F.40.9. 作者 #

<title>Author</title>

KaiGai Kohei