Merge branch 'master' of git://github.com/illumos/illumos-gate
[unleashed.git] / usr / src / man / man5 / rbac.5
blob69f00ced9cac30a629c2e50465025f825d03c11e
1 '\" te
2 .\" Copyright (c) 2002, Sun Microsystems, Inc.  All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH RBAC 5 "Jul 15, 2003"
7 .SH NAME
8 rbac, RBAC \- role-based access control
9 .SH DESCRIPTION
10 .sp
11 .LP
12 The addition of role-based access control (RBAC) to the Solaris operating
13 environment gives developers the opportunity to deliver fine-grained security
14 in new and modified applications. RBAC is an alternative to the all-or-nothing
15 security model of traditional superuser-based systems. With RBAC, an
16 administrator can assign privileged functions to specific user accounts (or
17 special accounts called roles).
18 .sp
19 .LP
20 There are two ways to give applications privileges:
21 .RS +4
22 .TP
24 Administrators can assign special attributes such as setUID to application
25 binaries (executable files).
26 .RE
27 .RS +4
28 .TP
30 Administrators can assign special attributes such as setUID to applications
31 using execution profiles.
32 .RE
33 .sp
34 .LP
35 Special attribute assignment along with the theory behind RBAC is discussed in
36 detail in "Role Based Access Control" chapter of the \fISystem Administration
37 Guide: Security Services\fR. This chapter describes what authorizations are and
38 how to code for them.
39 .SS "Authorizations"
40 .sp
41 .LP
42 An authorization is a unique string that represents a user's right to perform
43 some operation or class of operations. Authorization definitions are stored in
44 a database called \fBauth_attr\fR(4). For programming authorization checks,
45 only the authorization name is significant.
46 .sp
47 .LP
48 Some typical values in an \fBauth_attr\fR database are shown below.
49 .sp
50 .in +2
51 .nf
52 solaris.jobs.:::Cron and At Jobs::help=JobHeader.html
53 solaris.jobs.grant:::Delegate Cron & At \e
54     Administration::help=JobsGrant.html
55 solaris.jobs.admin:::Manage All Jobs::help=AuthJobsAdmin.html
56 solaris.jobs.user:::Cron & At User::help=JobsUser.html
57 .fi
58 .in -2
60 .sp
61 .LP
62 Authorization name strings ending with the \fBgrant\fR suffix are special
63 authorizations that give a user the ability to delegate authorizations with the
64 same prefix and functional area to other users.
65 .SS "Creating Authorization Checks"
66 .sp
67 .LP
68 To check authorizations, use the \fBchkauthattr\fR(3SECDB) library function,
69 which verifies whether or not a user has a given authorization. The synopsis
70 is:
71 .sp
72 .in +2
73 .nf
74 int chkauthattr(const char *authname, const char *username);
75 .fi
76 .in -2
78 .sp
79 .LP
80 The \fBchkauthattr()\fR function checks the \fBpolicy.conf\fR(4),
81 \fBuser_attr\fR(4), and \fBprof_attr\fR(4) databases in order for a match to
82 the given authorization.
83 .sp
84 .LP
85 If you are modifying existing code that tests for root UID, you should find the
86 test in the code and replace it with the \fBchkauthattr()\fR function. A
87 typical root UID check is shown in the first code segment below. An
88 authorization check replacing it is shown in the second code segment; it uses
89 the \fBsolaris.jobs.admin\fR authorization and a variable called
90 \fBreal_login\fR representing the user.
91 .LP
92 \fBExample 1 \fRStandard root check
93 .sp
94 .in +2
95 .nf
96 ruid = getuid();
98 if ((eflag || lflag || rflag) && argc == 1) {
99         if ((pwp = getpwnam(*argv)) == NULL)
100                 crabort(INVALIDUSER);
102         if (ruid != 0) {
103                 if (pwp->pw_uid != ruid)
104                         crabort(NOTROOT);
105                 else
106                         pp = getuser(ruid);
107         } else
108                 pp = *argv++;
109 } else {
111 .in -2
114 \fBExample 2 \fRAuthorization check
116 .in +2
118 ruid = getuid();
119 if ((pwp = getpwuid(ruid)) == NULL)
120         crabort(INVALIDUSER);
122 strcpy(real_login, pwp->pw_name);
124 if ((eflag || lflag || rflag) && argc == 1) {
125         if ((pwp = getpwnam(*argv)) == NULL)
126                 crabort(INVALIDUSER);
128         if (!chkauthattr("solaris.jobs.admin", real_login)) {
129                 if (pwp->pw_uid != ruid)
130                         crabort(NOTROOT);
131                 else
132                         pp = getuser(ruid);
133         } else
134                 pp = *argv++;
135 } else {
137 .in -2
141 For new applications, find an appropriate location for the test and use
142 \fBchkauthattr()\fR as shown above. Typically the authorization check makes an
143 access decision based on the identity of the calling user to determine if a
144 privileged action (for example, a system call) should be taken on behalf of
145 that user.
148 Applications that perform a test to restrict who can perform their
149 security-relevant functionality are generally \fBsetuid\fR to root. Programs
150 that were written prior to RBAC and that are only available to the root user
151 may not have such checks. In most cases, the kernel requires an effective user
152 \fBID\fR of root to override policy enforcement. Therefore, authorization
153 checking is most useful in programs that are \fBsetuid\fR to root.
156 For instance, if you want to write a program that allows authorized users to
157 set the system date, the command must be run with an effective user \fBID\fR of
158 root. Typically, this means that the file modes for the file would be
159 \fB-rwsr-xr-x\fR with root ownership.
162 Use caution, though, when making programs \fBsetuid\fR to root. For example,
163 the effective \fBUID\fR should be set to the real \fBUID\fR as early as
164 possible in the program's initialization function. The effective \fBUID\fR can
165 then be set back to root after the authorization check is performed and before
166 the system call is made. On return from the system call, the effective UID
167 should be set back to the real \fBUID\fR again to adhere to the principle of
168 least privilege.
171 Another consideration is that \fBLD_LIBRARY\fR path is ignored for setuid
172 programs (see SECURITY section in \fBld.so.1\fR(1)) and that shell scripts must
173 be modified to work properly when the effective and real \fBUID\fRs are
174 different. For example, the \fB-p\fR flag in Bourne shell is required to avoid
175 resetting the effective \fBUID\fR back to the real \fBUID\fR.
178 Using an effective \fBUID\fR of root instead of the real \fBUID\fR requires
179 extra care when writing shell scripts. For example, many shell scripts check to
180 see if the user is root before executing their functionality. With RBAC, these
181 shell scripts may be running with the effective \fBUID\fR of root and with a
182 real \fBUID\fR of a user or role. Thus, the shell script should check
183 \fBeuid\fR instead of \fBuid\fR. For example,
185 .in +2
187 WHO=`id | cut -f1 -d" "`
188 if [ ! "$WHO" = "uid=0(root)" ]
189 then
190        echo "$PROG: ERROR: you must be super-user to run this script."
191        exit 1
194 .in -2
198 should be changed to
200 .in +2
202 WHO=`/usr/xpg4/bin/id -n -u`
203 if [ ! "$WHO" = "root" ]
204 then
205        echo "$PROG: ERROR: you are not authorized to run this script."
206        exit 1
209 .in -2
213 Authorizations can be explicitly checked in shell scripts by checking the
214 output of the \fBauths\fR(1) utility. For example,
216 .in +2
218 for auth in `auths | tr , " "` NOTFOUND
220     [ "$auth" = "solaris.date" ] && break       # authorization found
221 done
223 if [ "$auth" != "solaris.date" ]
224 then
225     echo >&2 "$PROG: ERROR: you are not authorized to set the date"
226     exit 1
229 .in -2
231 .SH SEE ALSO
234 \fBld.so.1\fR(1), \fBchkauthattr\fR(3SECDB), \fBauth_attr\fR(4),
235 \fBpolicy.conf\fR(4), \fBprof_attr\fR(4), \fBuser_attr\fR(4)
238 \fISystem Administration Guide: Security Services\fR