gooderp18绿色标准版
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

490 líneas
34KB

  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>F.35. sepgsql</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 V1.79.1" /><link rel="prev" href="seg.html" title="F.34. seg" /><link rel="next" href="contrib-spi.html" title="F.36. spi" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.35. sepgsql</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="seg.html" title="F.34. seg">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="contrib-spi.html" title="F.36. spi">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="SEPGSQL"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.35. sepgsql</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-OVERVIEW">F.35.1. Overview</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-INSTALLATION">F.35.2. Installation</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-REGRESSION">F.35.3. Regression Tests</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-PARAMETERS">F.35.4. GUC Parameters</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-FEATURES">F.35.5. Features</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-FUNCTIONS">F.35.6. Sepgsql Functions</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-LIMITATIONS">F.35.7. Limitations</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-RESOURCES">F.35.8. External Resources</a></span></dt><dt><span class="sect2"><a href="sepgsql.html#SEPGSQL-AUTHOR">F.35.9. Author</a></span></dt></dl></div><a id="id-1.11.7.44.2" class="indexterm"></a><p>
  3. <code class="filename">sepgsql</code> is a loadable module that supports label-based
  4. mandatory access control (MAC) based on <span class="productname">SELinux</span> security
  5. policy.
  6. </p><div class="warning"><h3 class="title">Warning</h3><p>
  7. The current implementation has significant limitations, and does not
  8. enforce mandatory access control for all actions. See
  9. <a class="xref" href="sepgsql.html#SEPGSQL-LIMITATIONS" title="F.35.7. Limitations">Section F.35.7</a>.
  10. </p></div><div class="sect2" id="SEPGSQL-OVERVIEW"><div class="titlepage"><div><div><h3 class="title">F.35.1. Overview</h3></div></div></div><p>
  11. This module integrates with <span class="productname">SELinux</span> to provide an
  12. additional layer of security checking above and beyond what is normally
  13. provided by <span class="productname">PostgreSQL</span>. From the perspective of
  14. <span class="productname">SELinux</span>, this module allows
  15. <span class="productname">PostgreSQL</span> to function as a user-space object
  16. manager. Each table or function access initiated by a DML query will be
  17. checked against the system security policy. This check is in addition to
  18. the usual SQL permissions checking performed by
  19. <span class="productname">PostgreSQL</span>.
  20. </p><p>
  21. <span class="productname">SELinux</span> access control decisions are made using
  22. security labels, which are represented by strings such as
  23. <code class="literal">system_u:object_r:sepgsql_table_t:s0</code>. Each access control
  24. decision involves two labels: the label of the subject attempting to
  25. perform the action, and the label of the object on which the operation is
  26. to be performed. Since these labels can be applied to any sort of object,
  27. access control decisions for objects stored within the database can be
  28. (and, with this module, are) subjected to the same general criteria used
  29. for objects of any other type, such as files. This design is intended to
  30. allow a centralized security policy to protect information assets
  31. independent of the particulars of how those assets are stored.
  32. </p><p>
  33. The <a class="xref" href="sql-security-label.html" title="SECURITY LABEL"><span class="refentrytitle">SECURITY LABEL</span></a> statement allows assignment of
  34. a security label to a database object.
  35. </p></div><div class="sect2" id="SEPGSQL-INSTALLATION"><div class="titlepage"><div><div><h3 class="title">F.35.2. Installation</h3></div></div></div><p>
  36. <code class="filename">sepgsql</code> can only be used on <span class="productname">Linux</span>
  37. 2.6.28 or higher with <span class="productname">SELinux</span> enabled.
  38. It is not available on any other platform. You will also need
  39. <span class="productname">libselinux</span> 2.1.10 or higher and
  40. <span class="productname">selinux-policy</span> 3.9.13 or higher (although some
  41. distributions may backport the necessary rules into older policy
  42. versions).
  43. </p><p>
  44. The <code class="command">sestatus</code> command allows you to check the status of
  45. <span class="productname">SELinux</span>. A typical display is:
  46. </p><pre class="screen">
  47. $ sestatus
  48. SELinux status: enabled
  49. SELinuxfs mount: /selinux
  50. Current mode: enforcing
  51. Mode from config file: enforcing
  52. Policy version: 24
  53. Policy from config file: targeted
  54. </pre><p>
  55. If <span class="productname">SELinux</span> is disabled or not installed, you must set
  56. that product up first before installing this module.
  57. </p><p>
  58. To build this module, include the option <code class="literal">--with-selinux</code> in
  59. your PostgreSQL <code class="literal">configure</code> command. Be sure that the
  60. <code class="filename">libselinux-devel</code> RPM is installed at build time.
  61. </p><p>
  62. To use this module, you must include <code class="literal">sepgsql</code>
  63. in the <a class="xref" href="runtime-config-client.html#GUC-SHARED-PRELOAD-LIBRARIES">shared_preload_libraries</a> parameter in
  64. <code class="filename">postgresql.conf</code>. The module will not function correctly
  65. if loaded in any other manner. Once the module is loaded, you
  66. should execute <code class="filename">sepgsql.sql</code> in each database.
  67. This will install functions needed for security label management, and
  68. assign initial security labels.
  69. </p><p>
  70. Here is an example showing how to initialize a fresh database cluster
  71. with <code class="filename">sepgsql</code> functions and security labels installed.
  72. Adjust the paths shown as appropriate for your installation:
  73. </p><pre class="screen">
  74. $ export PGDATA=/path/to/data/directory
  75. $ initdb
  76. $ vi $PGDATA/postgresql.conf
  77. change
  78. #shared_preload_libraries = '' # (change requires restart)
  79. to
  80. shared_preload_libraries = 'sepgsql' # (change requires restart)
  81. $ for DBNAME in template0 template1 postgres; do
  82. postgres --single -F -c exit_on_error=true $DBNAME \
  83. &lt;/usr/local/pgsql/share/contrib/sepgsql.sql &gt;/dev/null
  84. done
  85. </pre><p>
  86. Please note that you may see some or all of the following notifications
  87. depending on the particular versions you have of
  88. <span class="productname">libselinux</span> and <span class="productname">selinux-policy</span>:
  89. </p><pre class="screen">
  90. /etc/selinux/targeted/contexts/sepgsql_contexts: line 33 has invalid object type db_blobs
  91. /etc/selinux/targeted/contexts/sepgsql_contexts: line 36 has invalid object type db_language
  92. /etc/selinux/targeted/contexts/sepgsql_contexts: line 37 has invalid object type db_language
  93. /etc/selinux/targeted/contexts/sepgsql_contexts: line 38 has invalid object type db_language
  94. /etc/selinux/targeted/contexts/sepgsql_contexts: line 39 has invalid object type db_language
  95. /etc/selinux/targeted/contexts/sepgsql_contexts: line 40 has invalid object type db_language
  96. </pre><p>
  97. These messages are harmless and should be ignored.
  98. </p><p>
  99. If the installation process completes without error, you can now start the
  100. server normally.
  101. </p></div><div class="sect2" id="SEPGSQL-REGRESSION"><div class="titlepage"><div><div><h3 class="title">F.35.3. Regression Tests</h3></div></div></div><p>
  102. Due to the nature of <span class="productname">SELinux</span>, running the
  103. regression tests for <code class="filename">sepgsql</code> requires several extra
  104. configuration steps, some of which must be done as root.
  105. The regression tests will not be run by an ordinary
  106. <code class="literal">make check</code> or <code class="literal">make installcheck</code> command; you must
  107. set up the configuration and then invoke the test script manually.
  108. The tests must be run in the <code class="filename">contrib/sepgsql</code> directory
  109. of a configured PostgreSQL build tree. Although they require a build tree,
  110. the tests are designed to be executed against an installed server,
  111. that is they are comparable to <code class="literal">make installcheck</code> not
  112. <code class="literal">make check</code>.
  113. </p><p>
  114. First, set up <code class="filename">sepgsql</code> in a working database
  115. according to the instructions in <a class="xref" href="sepgsql.html#SEPGSQL-INSTALLATION" title="F.35.2. Installation">Section F.35.2</a>.
  116. Note that the current operating system user must be able to connect to the
  117. database as superuser without password authentication.
  118. </p><p>
  119. Second, build and install the policy package for the regression test.
  120. The <code class="filename">sepgsql-regtest</code> policy is a special purpose policy package
  121. which provides a set of rules to be allowed during the regression tests.
  122. It should be built from the policy source file
  123. <code class="filename">sepgsql-regtest.te</code>, which is done using
  124. <code class="command">make</code> with a Makefile supplied by SELinux.
  125. You will need to locate the appropriate
  126. Makefile on your system; the path shown below is only an example.
  127. Once built, install this policy package using the
  128. <code class="command">semodule</code> command, which loads supplied policy packages
  129. into the kernel. If the package is correctly installed,
  130. <code class="literal"><code class="command">semodule</code> -l</code> should list <code class="literal">sepgsql-regtest</code> as an
  131. available policy package:
  132. </p><pre class="screen">
  133. $ cd .../contrib/sepgsql
  134. $ make -f /usr/share/selinux/devel/Makefile
  135. $ sudo semodule -u sepgsql-regtest.pp
  136. $ sudo semodule -l | grep sepgsql
  137. sepgsql-regtest 1.07
  138. </pre><p>
  139. Third, turn on <code class="literal">sepgsql_regression_test_mode</code>.
  140. For security reasons, the rules in <code class="filename">sepgsql-regtest</code>
  141. are not enabled by default;
  142. the <code class="literal">sepgsql_regression_test_mode</code> parameter enables
  143. the rules needed to launch the regression tests.
  144. It can be turned on using the <code class="command">setsebool</code> command:
  145. </p><pre class="screen">
  146. $ sudo setsebool sepgsql_regression_test_mode on
  147. $ getsebool sepgsql_regression_test_mode
  148. sepgsql_regression_test_mode --&gt; on
  149. </pre><p>
  150. Fourth, verify your shell is operating in the <code class="literal">unconfined_t</code>
  151. domain:
  152. </p><pre class="screen">
  153. $ id -Z
  154. unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
  155. </pre><p>
  156. See <a class="xref" href="sepgsql.html#SEPGSQL-RESOURCES" title="F.35.8. External Resources">Section F.35.8</a> for details on adjusting your
  157. working domain, if necessary.
  158. </p><p>
  159. Finally, run the regression test script:
  160. </p><pre class="screen">
  161. $ ./test_sepgsql
  162. </pre><p>
  163. This script will attempt to verify that you have done all the configuration
  164. steps correctly, and then it will run the regression tests for the
  165. <code class="filename">sepgsql</code> module.
  166. </p><p>
  167. After completing the tests, it's recommended you disable
  168. the <code class="literal">sepgsql_regression_test_mode</code> parameter:
  169. </p><pre class="screen">
  170. $ sudo setsebool sepgsql_regression_test_mode off
  171. </pre><p>
  172. You might prefer to remove the <code class="filename">sepgsql-regtest</code> policy
  173. entirely:
  174. </p><pre class="screen">
  175. $ sudo semodule -r sepgsql-regtest
  176. </pre></div><div class="sect2" id="SEPGSQL-PARAMETERS"><div class="titlepage"><div><div><h3 class="title">F.35.4. GUC Parameters</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt id="GUC-SEPGSQL-PERMISSIVE"><span class="term">
  177. <code class="varname">sepgsql.permissive</code> (<code class="type">boolean</code>)
  178. <a id="id-1.11.7.44.8.2.1.1.3" class="indexterm"></a>
  179. </span></dt><dd><p>
  180. This parameter enables <code class="filename">sepgsql</code> to function
  181. in permissive mode, regardless of the system setting.
  182. The default is off.
  183. This parameter can only be set in the <code class="filename">postgresql.conf</code>
  184. file or on the server command line.
  185. </p><p>
  186. When this parameter is on, <code class="filename">sepgsql</code> functions
  187. in permissive mode, even if SELinux in general is working in enforcing
  188. mode. This parameter is primarily useful for testing purposes.
  189. </p></dd><dt id="GUC-SEPGSQL-DEBUG-AUDIT"><span class="term">
  190. <code class="varname">sepgsql.debug_audit</code> (<code class="type">boolean</code>)
  191. <a id="id-1.11.7.44.8.2.2.1.3" class="indexterm"></a>
  192. </span></dt><dd><p>
  193. This parameter enables the printing of audit messages regardless of
  194. the system policy settings.
  195. The default is off, which means that messages will be printed according
  196. to the system settings.
  197. </p><p>
  198. The security policy of <span class="productname">SELinux</span> also has rules to
  199. control whether or not particular accesses are logged.
  200. By default, access violations are logged, but allowed
  201. accesses are not.
  202. </p><p>
  203. This parameter forces all possible logging to be turned on, regardless
  204. of the system policy.
  205. </p></dd></dl></div></div><div class="sect2" id="SEPGSQL-FEATURES"><div class="titlepage"><div><div><h3 class="title">F.35.5. Features</h3></div></div></div><div class="sect3" id="id-1.11.7.44.9.2"><div class="titlepage"><div><div><h4 class="title">F.35.5.1. Controlled Object Classes</h4></div></div></div><p>
  206. The security model of <span class="productname">SELinux</span> describes all the access
  207. control rules as relationships between a subject entity (typically,
  208. a client of the database) and an object entity (such as a database
  209. object), each of which is
  210. identified by a security label. If access to an unlabeled object is
  211. attempted, the object is treated as if it were assigned the label
  212. <code class="literal">unlabeled_t</code>.
  213. </p><p>
  214. Currently, <code class="filename">sepgsql</code> allows security labels to be
  215. assigned to schemas, tables, columns, sequences, views, and functions.
  216. When <code class="filename">sepgsql</code> is in use, security labels are
  217. automatically assigned to supported database objects at creation time.
  218. This label is called a default security label, and is decided according
  219. to the system security policy, which takes as input the creator's label,
  220. the label assigned to the new object's parent object and optionally name
  221. of the constructed object.
  222. </p><p>
  223. A new database object basically inherits the security label of the parent
  224. object, except when the security policy has special rules known as
  225. type-transition rules, in which case a different label may be applied.
  226. For schemas, the parent object is the current database; for tables,
  227. sequences, views, and functions, it is the containing schema; for columns,
  228. it is the containing table.
  229. </p></div><div class="sect3" id="id-1.11.7.44.9.3"><div class="titlepage"><div><div><h4 class="title">F.35.5.2. DML Permissions</h4></div></div></div><p>
  230. For tables, <code class="literal">db_table:select</code>, <code class="literal">db_table:insert</code>,
  231. <code class="literal">db_table:update</code> or <code class="literal">db_table:delete</code> are
  232. checked for all the referenced target tables depending on the kind of
  233. statement; in addition, <code class="literal">db_table:select</code> is also checked for
  234. all the tables that contain columns referenced in the
  235. <code class="literal">WHERE</code> or <code class="literal">RETURNING</code> clause, as a data source
  236. for <code class="literal">UPDATE</code>, and so on.
  237. </p><p>
  238. Column-level permissions will also be checked for each referenced column.
  239. <code class="literal">db_column:select</code> is checked on not only the columns being
  240. read using <code class="literal">SELECT</code>, but those being referenced in other DML
  241. statements; <code class="literal">db_column:update</code> or <code class="literal">db_column:insert</code>
  242. will also be checked for columns being modified by <code class="literal">UPDATE</code> or
  243. <code class="literal">INSERT</code>.
  244. </p><p>
  245. For example, consider:
  246. </p><pre class="synopsis">
  247. UPDATE t1 SET x = 2, y = func1(y) WHERE z = 100;
  248. </pre><p>
  249. Here, <code class="literal">db_column:update</code> will be checked for
  250. <code class="literal">t1.x</code>, since it is being updated,
  251. <code class="literal">db_column:{select update}</code> will be checked for
  252. <code class="literal">t1.y</code>, since it is both updated and referenced, and
  253. <code class="literal">db_column:select</code> will be checked for <code class="literal">t1.z</code>, since
  254. it is only referenced.
  255. <code class="literal">db_table:{select update}</code> will also be checked
  256. at the table level.
  257. </p><p>
  258. For sequences, <code class="literal">db_sequence:get_value</code> is checked when we
  259. reference a sequence object using <code class="literal">SELECT</code>; however, note that we
  260. do not currently check permissions on execution of corresponding functions
  261. such as <code class="literal">lastval()</code>.
  262. </p><p>
  263. For views, <code class="literal">db_view:expand</code> will be checked, then any other
  264. required permissions will be checked on the objects being
  265. expanded from the view, individually.
  266. </p><p>
  267. For functions, <code class="literal">db_procedure:{execute}</code> will be checked when
  268. user tries to execute a function as a part of query, or using fast-path
  269. invocation. If this function is a trusted procedure, it also checks
  270. <code class="literal">db_procedure:{entrypoint}</code> permission to check whether it
  271. can perform as entry point of trusted procedure.
  272. </p><p>
  273. In order to access any schema object, <code class="literal">db_schema:search</code>
  274. permission is required on the containing schema. When an object is
  275. referenced without schema qualification, schemas on which this
  276. permission is not present will not be searched (just as if the user did
  277. not have <code class="literal">USAGE</code> privilege on the schema). If an explicit schema
  278. qualification is present, an error will occur if the user does not have
  279. the requisite permission on the named schema.
  280. </p><p>
  281. The client must be allowed to access all referenced tables and
  282. columns, even if they originated from views which were then expanded,
  283. so that we apply consistent access control rules independent of the manner
  284. in which the table contents are referenced.
  285. </p><p>
  286. The default database privilege system allows database superusers to
  287. modify system catalogs using DML commands, and reference or modify
  288. toast tables. These operations are prohibited when
  289. <code class="filename">sepgsql</code> is enabled.
  290. </p></div><div class="sect3" id="id-1.11.7.44.9.4"><div class="titlepage"><div><div><h4 class="title">F.35.5.3. DDL Permissions</h4></div></div></div><p>
  291. <span class="productname">SELinux</span> defines several permissions to control common
  292. operations for each object type; such as creation, alter, drop and
  293. relabel of security label. In addition, several object types have
  294. special permissions to control their characteristic operations; such as
  295. addition or deletion of name entries within a particular schema.
  296. </p><p>
  297. Creating a new database object requires <code class="literal">create</code> permission.
  298. <span class="productname">SELinux</span> will grant or deny this permission based on the
  299. client's security label and the proposed security label for the new
  300. object. In some cases, additional privileges are required:
  301. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  302. <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a> additionally requires
  303. <code class="literal">getattr</code> permission for the source or template database.
  304. </p></li><li class="listitem"><p>
  305. Creating a schema object additionally requires <code class="literal">add_name</code>
  306. permission on the parent schema.
  307. </p></li><li class="listitem"><p>
  308. Creating a table additionally requires permission to create each
  309. individual table column, just as if each table column were a
  310. separate top-level object.
  311. </p></li><li class="listitem"><p>
  312. Creating a function marked as <code class="literal">LEAKPROOF</code> additionally
  313. requires <code class="literal">install</code> permission. (This permission is also
  314. checked when <code class="literal">LEAKPROOF</code> is set for an existing function.)
  315. </p></li></ul></div><p>
  316. When <code class="literal">DROP</code> command is executed, <code class="literal">drop</code> will be
  317. checked on the object being removed. Permissions will be also checked for
  318. objects dropped indirectly via <code class="literal">CASCADE</code>. Deletion of objects
  319. contained within a particular schema (tables, views, sequences and
  320. procedures) additionally requires <code class="literal">remove_name</code> on the schema.
  321. </p><p>
  322. When <code class="literal">ALTER</code> command is executed, <code class="literal">setattr</code> will be
  323. checked on the object being modified for each object types, except for
  324. subsidiary objects such as the indexes or triggers of a table, where
  325. permissions are instead checked on the parent object. In some cases,
  326. additional permissions are required:
  327. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  328. Moving an object to a new schema additionally requires
  329. <code class="literal">remove_name</code> permission on the old schema and
  330. <code class="literal">add_name</code> permission on the new one.
  331. </p></li><li class="listitem"><p>
  332. Setting the <code class="literal">LEAKPROOF</code> attribute on a function requires
  333. <code class="literal">install</code> permission.
  334. </p></li><li class="listitem"><p>
  335. Using <a class="xref" href="sql-security-label.html" title="SECURITY LABEL"><span class="refentrytitle">SECURITY LABEL</span></a> on an object additionally
  336. requires <code class="literal">relabelfrom</code> permission for the object in
  337. conjunction with its old security label and <code class="literal">relabelto</code>
  338. permission for the object in conjunction with its new security label.
  339. (In cases where multiple label providers are installed and the user
  340. tries to set a security label, but it is not managed by
  341. <span class="productname">SELinux</span>, only <code class="literal">setattr</code> should be checked here.
  342. This is currently not done due to implementation restrictions.)
  343. </p></li></ul></div></div><div class="sect3" id="id-1.11.7.44.9.5"><div class="titlepage"><div><div><h4 class="title">F.35.5.4. Trusted Procedures</h4></div></div></div><p>
  344. Trusted procedures are similar to security definer functions or setuid
  345. commands. <span class="productname">SELinux</span> provides a feature to allow trusted
  346. code to run using a security label different from that of the client,
  347. generally for the purpose of providing highly controlled access to
  348. sensitive data (e.g. rows might be omitted, or the precision of stored
  349. values might be reduced). Whether or not a function acts as a trusted
  350. procedure is controlled by its security label and the operating system
  351. security policy. For example:
  352. </p><pre class="screen">
  353. postgres=# CREATE TABLE customer (
  354. cid int primary key,
  355. cname text,
  356. credit text
  357. );
  358. CREATE TABLE
  359. postgres=# SECURITY LABEL ON COLUMN customer.credit
  360. IS 'system_u:object_r:sepgsql_secret_table_t:s0';
  361. SECURITY LABEL
  362. postgres=# CREATE FUNCTION show_credit(int) RETURNS text
  363. AS 'SELECT regexp_replace(credit, ''-[0-9]+$'', ''-xxxx'', ''g'')
  364. FROM customer WHERE cid = $1'
  365. LANGUAGE sql;
  366. CREATE FUNCTION
  367. postgres=# SECURITY LABEL ON FUNCTION show_credit(int)
  368. IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0';
  369. SECURITY LABEL
  370. </pre><p>
  371. The above operations should be performed by an administrative user.
  372. </p><pre class="screen">
  373. postgres=# SELECT * FROM customer;
  374. ERROR: SELinux: security policy violation
  375. postgres=# SELECT cid, cname, show_credit(cid) FROM customer;
  376. cid | cname | show_credit
  377. -----+--------+---------------------
  378. 1 | taro | 1111-2222-3333-xxxx
  379. 2 | hanako | 5555-6666-7777-xxxx
  380. (2 rows)
  381. </pre><p>
  382. In this case, a regular user cannot reference <code class="literal">customer.credit</code>
  383. directly, but a trusted procedure <code class="literal">show_credit</code> allows the user
  384. to print the credit card numbers of customers with some of the digits
  385. masked out.
  386. </p></div><div class="sect3" id="id-1.11.7.44.9.6"><div class="titlepage"><div><div><h4 class="title">F.35.5.5. Dynamic Domain Transitions</h4></div></div></div><p>
  387. It is possible to use SELinux's dynamic domain transition feature
  388. to switch the security label of the client process, the client domain,
  389. to a new context, if that is allowed by the security policy.
  390. The client domain needs the <code class="literal">setcurrent</code> permission and also
  391. <code class="literal">dyntransition</code> from the old to the new domain.
  392. </p><p>
  393. Dynamic domain transitions should be considered carefully, because they
  394. allow users to switch their label, and therefore their privileges,
  395. at their option, rather than (as in the case of a trusted procedure)
  396. as mandated by the system.
  397. Thus, the <code class="literal">dyntransition</code> permission is only considered
  398. safe when used to switch to a domain with a smaller set of privileges than
  399. the original one. For example:
  400. </p><pre class="screen">
  401. regression=# select sepgsql_getcon();
  402. sepgsql_getcon
  403. -------------------------------------------------------
  404. unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
  405. (1 row)
  406. regression=# SELECT sepgsql_setcon('unconfined_u:unconfined_r:unconfined_t:s0-s0:c1.c4');
  407. sepgsql_setcon
  408. ----------------
  409. t
  410. (1 row)
  411. regression=# SELECT sepgsql_setcon('unconfined_u:unconfined_r:unconfined_t:s0-s0:c1.c1023');
  412. ERROR: SELinux: security policy violation
  413. </pre><p>
  414. In this example above we were allowed to switch from the larger MCS
  415. range <code class="literal">c1.c1023</code> to the smaller range <code class="literal">c1.c4</code>, but
  416. switching back was denied.
  417. </p><p>
  418. A combination of dynamic domain transition and trusted procedure
  419. enables an interesting use case that fits the typical process life-cycle
  420. of connection pooling software.
  421. Even if your connection pooling software is not allowed to run most
  422. of SQL commands, you can allow it to switch the security label
  423. of the client using the <code class="literal">sepgsql_setcon()</code> function
  424. from within a trusted procedure; that should take some
  425. credential to authorize the request to switch the client label.
  426. After that, this session will have the privileges of the target user,
  427. rather than the connection pooler.
  428. The connection pooler can later revert the security label change by
  429. again using <code class="literal">sepgsql_setcon()</code> with
  430. <code class="literal">NULL</code> argument, again invoked from within a trusted
  431. procedure with appropriate permissions checks.
  432. The point here is that only the trusted procedure actually has permission
  433. to change the effective security label, and only does so when given proper
  434. credentials. Of course, for secure operation, the credential store
  435. (table, procedure definition, or whatever) must be protected from
  436. unauthorized access.
  437. </p></div><div class="sect3" id="id-1.11.7.44.9.7"><div class="titlepage"><div><div><h4 class="title">F.35.5.6. Miscellaneous</h4></div></div></div><p>
  438. We reject the <a class="xref" href="sql-load.html" title="LOAD"><span class="refentrytitle">LOAD</span></a> command across the board, because
  439. any module loaded could easily circumvent security policy enforcement.
  440. </p></div></div><div class="sect2" id="SEPGSQL-FUNCTIONS"><div class="titlepage"><div><div><h3 class="title">F.35.6. Sepgsql Functions</h3></div></div></div><p>
  441. <a class="xref" href="sepgsql.html#SEPGSQL-FUNCTIONS-TABLE" title="Table F.29. Sepgsql Functions">Table F.29</a> shows the available functions.
  442. </p><div class="table" id="SEPGSQL-FUNCTIONS-TABLE"><p class="title"><strong>Table F.29. Sepgsql Functions</strong></p><div class="table-contents"><table class="table" summary="Sepgsql Functions" border="1"><colgroup><col /><col /></colgroup><tbody><tr><td><code class="literal">sepgsql_getcon() returns text</code></td><td>
  443. Returns the client domain, the current security label of the client.
  444. </td></tr><tr><td><code class="literal">sepgsql_setcon(text) returns bool</code></td><td>
  445. Switches the client domain of the current session to the new domain,
  446. if allowed by the security policy.
  447. It also accepts <code class="literal">NULL</code> input as a request to transition
  448. to the client's original domain.
  449. </td></tr><tr><td><code class="literal">sepgsql_mcstrans_in(text) returns text</code></td><td>Translates the given qualified MLS/MCS range into raw format if
  450. the mcstrans daemon is running.
  451. </td></tr><tr><td><code class="literal">sepgsql_mcstrans_out(text) returns text</code></td><td>Translates the given raw MLS/MCS range into qualified format if
  452. the mcstrans daemon is running.
  453. </td></tr><tr><td><code class="literal">sepgsql_restorecon(text) returns bool</code></td><td>
  454. Sets up initial security labels for all objects within the
  455. current database. The argument may be NULL, or the name of a specfile
  456. to be used as alternative of the system default.
  457. </td></tr></tbody></table></div></div><br class="table-break" /></div><div class="sect2" id="SEPGSQL-LIMITATIONS"><div class="titlepage"><div><div><h3 class="title">F.35.7. Limitations</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">Data Definition Language (DDL) Permissions</span></dt><dd><p>
  458. Due to implementation restrictions, some DDL operations do not
  459. check permissions.
  460. </p></dd><dt><span class="term">Data Control Language (DCL) Permissions</span></dt><dd><p>
  461. Due to implementation restrictions, DCL operations do not check
  462. permissions.
  463. </p></dd><dt><span class="term">Row-level access control</span></dt><dd><p>
  464. <span class="productname">PostgreSQL</span> supports row-level access, but
  465. <code class="filename">sepgsql</code> does not.
  466. </p></dd><dt><span class="term">Covert channels</span></dt><dd><p>
  467. <code class="filename">sepgsql</code> does not try to hide the existence of
  468. a certain object, even if the user is not allowed to reference it.
  469. For example, we can infer the existence of an invisible object as
  470. a result of primary key conflicts, foreign key violations, and so on,
  471. even if we cannot obtain the contents of the object. The existence
  472. of a top secret table cannot be hidden; we only hope to conceal its
  473. contents.
  474. </p></dd></dl></div></div><div class="sect2" id="SEPGSQL-RESOURCES"><div class="titlepage"><div><div><h3 class="title">F.35.8. External Resources</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term"><a class="ulink" href="https://wiki.postgresql.org/wiki/SEPostgreSQL" target="_top">SE-PostgreSQL Introduction</a></span></dt><dd><p>
  475. This wiki page provides a brief overview, security design, architecture,
  476. administration and upcoming features.
  477. </p></dd><dt><span class="term"><a class="ulink" href="https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/" target="_top">SELinux User's and Administrator's Guide</a></span></dt><dd><p>
  478. This document provides a wide spectrum of knowledge to administer
  479. <span class="productname">SELinux</span> on your systems.
  480. It focuses primarily on Red Hat operating systems, but is not limited to them.
  481. </p></dd><dt><span class="term"><a class="ulink" href="https://fedoraproject.org/wiki/SELinux_FAQ" target="_top">Fedora SELinux FAQ</a></span></dt><dd><p>
  482. This document answers frequently asked questions about
  483. <span class="productname">SELinux</span>.
  484. It focuses primarily on Fedora, but is not limited to Fedora.
  485. </p></dd></dl></div></div><div class="sect2" id="SEPGSQL-AUTHOR"><div class="titlepage"><div><div><h3 class="title">F.35.9. Author</h3></div></div></div><p>
  486. KaiGai Kohei <code class="email">&lt;<a class="email" href="mailto:kaigai@ak.jp.nec.com">kaigai@ak.jp.nec.com</a>&gt;</code>
  487. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="seg.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="contrib-spi.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.34. seg </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.36. spi</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1