本节中的示例限制了一般用户的权限,或者删除了管理员的部分管理权限。说明了如何修改用户、角色和权限配置文件。有关权限的信息,请参见Chapter 1, 使用权限控制用户和进程。
从用户删除限制特权-Example 3–21
从用户删除基本特权-Example 3–22
从归您所有的 shell 进程删除基本特权-Example 3–23
创建使用受限的系统-Example 3–24
限制管理员使用显式指定的权限-Example 3–25
从系统的所有用户删除权限-Example 3–24、Example 3–28
防止应用程序创建子进程-Example 3–26
防止用户大量生成子进程Example 3–27
为来宾创建受限编辑器-Example 3–27
将受限编辑器指定给一个公共系统-Example 3–28
从权限配置文件的限制特权集合中删除特权-Example 5–6
为 Sun Ray 用户创建权限配置文件-Example 5–6
从权限配置文件删除权限-Example 5–6、Example 5–9
从用户删除授权-Example 5–10
删除角色指定-Example 5–13
在以下示例中,防止所有源自 jdoe 初始登录的会话使用 sys_linkdir 特权。即使在用户运行 su 命令之后,仍然不能生成指向目录的硬链接,并且也不能解除目录链接。
# usermod -K 'limitpriv=all,!sys_linkdir' jdoe # userattr limitpriv jdoe all,!sys_linkdir示例 3-22 从权限配置文件中删除基本特权
在以下示例中,在详尽测试后,安全管理员从 "Sun Ray User"(Sun Ray 用户)权限配置文件中删除了另一个基本特权。管理员在Example 5–6 中创建配置文件时,从限制特权集合删除了一个特权。此时,管理员删除了两个基本特权。指定有此配置文件的用户无法检查其当前会话外部的任何进程,也无法添加其他会话。
# profiles -p "Sun Ray Users" profiles:Sun Ray Users> set defaultpriv="basic,!proc_session,!proc_info" profiles:Sun Ray Users> end profiles:Sun Ray Users> exit示例 3-23 从自身删除基本特权
在以下示例中,一般用户修改 .bash_profile 以删除 proc_info 基本特权。ps 和 prstat 这类程序的输出仅包含用户自己的进程,可以突出显示有用信息。
## .bash_profile ## Remove proc_info privilege from my shell ## ppriv -s EI-proc_info $$
ppriv 行在当前 shell 进程 ($$) 中删除了用户的有效和可继承特权集合 (EI-) 中的 proc_info 特权。
在以下 prstat 输出中,总进程从 74 缩减为 3 个进程:
## With all basic privileges Total: 74 processes, 527 lwps, load averages: 0.01, 0.00, 0.00 ## With proc_info removed from the effective and inheritable set Total: 3 processes, 3 lwps, load averages: 0.00, 0.00, 0.00示例 3-24 修改系统以使权限仅对其用户可用
在以下示例中,管理员将创建一个仅可以用来管理网络的系统。管理员将从 policy.conf 文件中删除 "Basic Solaris User"(基本 Solaris 用户)权限配置文件和任何授权。不删除 "Console User"(控制台用户)权限配置文件。在生成的 policy.conf 文件中,受影响的行如下所示:
... ##AUTHS_GRANTED= ##AUTH_PROFS_GRANTED= ##PROFS_GRANTED=Basic Solaris User CONSOLE_USER=Console User ...
只有显式为其指定了授权、命令或权限配置文件的用户才能使用该系统。登录后,已授权的用户可以执行管理任务。如果授权的用户位于该系统控制台上,则该用户将拥有 "Console User"(控制台用户)权限。
示例 3-25 限制管理员使用显式指定的权限您可以通过下列两种方式限制角色或用户,使其执行有限数量的管理操作。
将 "Stop"(停止)权限配置文件指定为用户配置文件列表中的最后一个配置文件。
"Stop"(停止)权限配置文件是创建受限 shell 的最简单方式。policy.conf 文件中的授权和权限配置文件未指定给用户或角色。
修改系统的 policy.conf 文件,要求角色或用户使用该系统执行管理任务。请参见Example 3–24。
以下命令限制 auditrev 角色只能执行审计查看。
# rolemod -P "Audit Review,Stop" auditrev
由于 auditrev 角色不具有 "Console User"(控制台用户)权限配置文件,因此审计者无法关闭系统。由于该角色不包含 solaris.device.cdrw 授权,因此审计者无法读取或写入 CD-ROM 驱动器。由于该角色不具有 "Basic Solaris User"(基本 Solaris 用户)权限配置文件,因此该角色不能运行配置文件中的任何命令。因为没有指定 "All"(所有)权限配置文件,ls 命令不会运行。此角色使用 "File Browser"(文件浏览器)选择要查看的审计文件。
有关更多信息,请参见所指定权限的搜索顺序和权限配置文件参考信息。
示例 3-26 防止所选应用程序大量生成新进程在此示例中,管理员为无需子进程即可正常运行的应用程序创建了一个权限配置文件。为方便起见,管理员创建了一个目录保存这些可执行文件。添加了无需子进程的新应用程序后,可以将其可执行文件添加到此目录。或者,如果要求可执行文件位于特定目录,管理员可以通过 /opt/local/noex/app-executable 进行链接。
# profiles -p "Prevent App Subprocess" profiles:Prevent App Subprocess> set desc="Keep apps from execing processes" profiles:Prevent App Subprocess> add cmd=/opt/local/noex/mkmod ... Subprocess:mkmod> set limitprivs=all,!proc_exec ... Subprocess:mkmod> end ... Subprocess> add cmd=/opt/local/noex/gomap ... Subprocess:gomap> set limitprivs=all,!proc_exec ... Subprocess:gomap> end ... Subprocess> commit ... Subprocess> exit示例 3-27 防止来宾大量生成新子进程
在此示例中,管理员通过从编辑器命令中删除 proc_exec 基本特权,防止用户通过一个或多个编辑器创建子 shell。
管理员创建了一个权限配置文件,从 vim 编辑器的限制特权集合删除了 proc_exec。
# profiles -p -S ldap "Editor Restrictions" profiles:Editor Restrictions> set desc="Site Editor Restrictions" ... Restrictions> add cmd=/usr/bin/vim ... Restrictions:vim> set limitprivs=all,!proc_exec ... Restrictions:vim> end ... Restrictions> commit ... Restrictions> exit
管理员向权限配置文件添加其他常用编辑器。
# profiles -p "Editor Restrictions" profiles:Editor Restrictions> add cmd=/usr/bin/gedit ... Restrictions:gedit> set limitprivs=all,!proc_exec ... Restrictions:gedit> end ... Restrictions> add cmd=/usr/bin/gconf-editor ... Restrictions:gconf-editor> set limitprivs=all,!proc_exec ... Restrictions:gconf-editor> end ... Restrictions> add cmd=/usr/bin/ed ... Restrictions:ed> set limitprivs=all,!proc_exec ... Restrictions:ed> end ... Restrictions> add cmd=/usr/bin/ex ... Restrictions:ex> set limitprivs=all,!proc_exec ... Restrictions:ex> end ... Restrictions> add cmd=/usr/bin/edit ... Restrictions:edit> set limitprivs=all,!proc_exec ... Restrictions:edit> end ... Restrictions> commit ... Restrictions> exit
管理员检查权限配置文件条目有无错误,如拼写错误、缺失或重复。
# profiles -p "Editor Restrictions" info Found profile in files repository. name=Editor Restrictions desc=Site Editor Restrictions cmd=/usr/bin/vim limitprivs=all,!proc_exec ...
管理员将 "Editor Restrictions"(编辑器限制)权限配置文件指定给 guest 用户。
# usermod -K profiles+="Editor Restrictions" guest
使用 profiles+,管理员将此权限配置文件添加到帐户的当前权限配置文件。
为了验证已经限制编辑器特权,管理员在单独窗口中打开编辑器,检查编辑器进程的特权。
# ppriv -S $(pgrep vi) 2805: vi .bash_profile flags = PRIV_PFEXEC User is running a profile shell E: basic,!proc_info proc_info is removed from basic set I: basic,!proc_info P: basic,!proc_info L: all,!proc_exec proc_exec is removed from limit set
在此示例中,管理员将 "Editor Restrictions"(编辑器限制)权限配置文件添加到 policy.conf 文件。管理员确保将此文件分配给了来宾可以登录的所有公共系统。
# cd /etc/security; cp policy.conf policy.conf.orig # pfedit /etc/security/policy.conf ... AUTHS_GRANTED= AUTH_PROFS_GRANTED= #PROFS_GRANTED=Basic Solaris User PROFS_GRANTED=Editor Restrictions,Basic Solaris User
"User Security"(用户安全)管理员为每位用户指定了一个配置文件 shell。有关原因和过程,请参见为用户指定权限。