31.3 Design
To create this program, we build modules that fit together to supply security services that satisfy the requirements. First, we create a general framework to guide the development of each interface. Then we examine each requirement separately, and design a component for each requirement.
31.3.1 Framework
The framework begins with the user interface and then breaks down the internals of the program into modules that implement the various requirements.
31.3.1.1 User Interface
The user can run the program in two ways. The first is to request unrestricted access to the account. The second is to request that a specific program be run from the role account. Any interface must be able to handle both.
The simplest interface is a command line. Other interfaces, such as graphical user interfaces, are possible and may make the program easier to use. However, these GUIs will be built in such a way that they construct and execute a command-line version of the program.
The interface chosen is
role role_account [ command ]
where role_account is the name of the role account and command is the (optional) command to execute under that account. If the user wants unrestricted access to the role account, he omits command. Otherwise, the user is given restricted access and command is executed with the privileges of the role account.
The user need not specify the time of day using the interface, because the program can obtain such information from the system. It can also obtain the location from which the user requests access, although the method used presents potential problems (see Section 31.4.3.1). The individual modules handle the remainder of the issues.
31.3.1.2 High-Level Design
The basic algorithm is as follows.
Obtain the role account, command, user, location, and time of day. If the command is omitted, the user is requesting unrestricted access to the role account.
Check that the user is allowed to access the role account
at the specified location;
at the specified time; and
for the specified command (or without restriction).
If the user is not, log the attempt and quit.
Obtain the user and group information for the role account. Change the privileges of the process to those of the role account.
If the user has requested that a specific command be run, overlay the child process with a command interpreter that spawns the named command.
If the user has requested unrestricted access, overlay the child process with a command interpreter.
This algorithm points out an important ambiguity in the requirements. Requirements 31.1 and 31.4 do not indicate whether the ability of the user to execute a command in the given role account requires that the user work from a particular location or access the account at a particular time. This design uses the interpretation that a user’s ability to run a command in a role account is conditioned on location and time.
The alternative interpretation, that access only is controlled by location and time, and that commands are restricted by role and user, is equally valid. But sometimes the ability to run commands may require that users work at particular times. For example, an operator may create the daily backups at 1 a.m. The operator is not to do backups at other times because of the load on the system. The interpretation of the design allows this. The alternative interpretation requires the backup program, or some other mechanism, to enforce this restriction. Furthermore, the design interpretation includes the alternative interpretation, because any control expressed in the alternative interpretation can be expressed in the design interpretation.
Requirement 31.4 can now be clarified. The addition is in boldface.
Requirement 31.6. The mechanism shall allow both restricted access and unrestricted access to a role account. For unrestricted access, the user shall have access to a standard command interpreter. For restricted access, the user shall be able to execute only a specified set of commands. The level of access (restricted or unrestricted) shall depend on the user, the role, the time, and the location.
Thus, the design phase feeds back into the requirements phase, here clarifying the meaning of the requirements. It is left as an exercise for the reader to verify that the new form of this requirement counters the appropriate threats (see Exercise 2).
31.3.2 Access to Roles and Commands
The user attempting access, the location (host or terminal), the time of day, and the type of access (restricted or unrestricted) control access to the role account. The access checking module returns a value indicating success (meaning that access is allowed) or failure (meaning that access is not allowed). By the principle of fail-safe defaults, an error causes a denial of access.
We consider two aspects of the design of this module. The interface controls how information is passed to the module from its caller, and how the module returns success or failure. The internal structure of the module includes how it handles errors. This leads to a discussion of how the access control data is stored. We consider these issues separately to emphasize that the interface provides an entry point into the module, and that the entry point will remain fixed even if the internal design of the module is completely changed. The internal design and structures are hidden from the caller.
31.3.2.1 Interface
Following the practice of hiding information among modules,4 we minimize the amount of information to be passed to the access checking module. The module requires the user requesting access, the role to which access is requested, the location, the time, and the command (if any). The return value must indicate success or failure. The question is how this information is to be obtained.
The command (or request for unrestricted access) must come from the caller, because the caller provides the interface for the processing of that command. The command is supplied externally, so the principles of layering require it to pass through the program to the module.
The caller could also pass the other information to the module. This would allow the module to provide an access control result without obtaining the information directly. The advantage is that a different program could use this module to determine whether or not access had been or would be granted at some past or future point in time, or from some other location. The disadvantage is a lack of portability, because the interface is tied to a particular representation of the data. Also, if the caller of the module is untrusted but the module is trusted, the module might make trusted decisions based on untrusted data, violating a principle of integrity.5 So we choose to have the module determine all of the data.
This suggests the following interface:
boolean accessok(role rname, command cmd);
where rname is the name of the requested role and cmd is the command to be executed (or is empty if unrestricted access is desired). The routine returns true if access is to be granted, and false otherwise.
31.3.2.2 Internals
This module has three parts. The first part gathers the data on which access is to be based. The second part retrieves the access control information. The third part determines whether the data and the access control information require access to be granted.
The module queries the operating system to determine the needed data. The real user identification data is obtained through a system call, as is the current time of day. The location consists of two components: the entry point (terminal or network connection) and the remote host from which the user is accessing the local system. The latter component may indicate that the entry point is directly connected to the system, rather than using a remote host.
Part I: Obtain user ID, time of day, entry point, and remote host.
Next, the module must access the access control information. The access control information resides in a file. The file contains a sequence of records of the following form:
role account user names locations from which the role account can be accessed times when the role account can be accessed command and arguments
If the “command and arguments” line is omitted, the user is granted unrestricted access. Multiple command lines may be listed in a single record.
Part II: Obtain a handle (or descriptor) to the access control information. The programmer will use this handle to read the access control records from the access control information.
Finally, the program iterates through the access control information. If the role in the current record does not match the requested role, it is ignored. Otherwise, the user name, location, time, and command are compared with the appropriate fields of the record. If they all match, the module releases the handle and returns success.6 If any of them does not match, the module continues on to the next record. If the module reaches the end of the access control information, the handle is released and the module returns failure. Note that records never deny access, but only grant it. The default action is to deny. Granting access requires an explicit record.7
If any record is invalid (for example, if there is a syntax error in one of the fields or if the user field contains a nonexistent user name), the module logs the error and ignores the record. This again follows the principle of fail-safe defaults, in which the system falls into a secure state when there is an error.
Part III: Iterate through the records until one matches the data or there are no more records. In the first case, return success; in the second case, return failure.
31.3.2.3 Storage of the Access Control Data
The system administrators of the local system control access to privileged accounts. To keep maintenance of this information simple, the administrators store the access control information in a file. Then they need only edit the file to change a user’s ability to access the privileged account. The file consists of a set of records, each containing the components listed above. This raises the issue of expression. How should each part of the record be written?
For example, must each entry point be listed, or are wildcards acceptable? Strictly speaking, the principle of fail-safe defaults8 says that we should list explicitly those locations from which access may be obtained. In practice, this is too cumbersome. Suppose a particular user was trusted to assume a role from any system on the Internet. Requiring the administrators to list all hosts would be time-consuming as well as infeasible. Worse, if the user were not allowed to access the role account from one system, the administrators would need to check the list to see which system was missing. This would violate the principle of least astonishment.9 Given the dynamic nature of the Internet, this requirement would be absurd. Instead, we allow the following special host names, both of which are illegal [1365]:
*any* (a wildcard matching any system)
*local* (matches the local host name)
In BNF form, the language used to express location is
location ::= ‘(’ location ‘)’ | ‘not’ location | location ‘or’ location | basic
basic ::= ‘*any*’ | ‘*local*’ | ‘.’ domain | host
where domain and host are domain names and host names, respectively. The strings in single quotation marks are literals. The parentheses are grouping operators, the “not” complements the associated locations, and the “or” allows either location.
EXAMPLE: A user is allowed to assume a role only when logged into the local system, the system “control. xit.com”, and the domain “watchu.edu”. The appropriate entry would be
*local* | control.fixit.com | .watchu.edu
A similar question arises for times. Ignoring how times are expressed, how do we indicate when users may access the role account? Considerations similar to those above lead us to the following language, in which the keyword
*any*
allows access at any time. In BNF form, the language used to express time is
time ::= ‘(’ time ‘)’ | ‘not’ time | time ‘or’ time | time time | time ‘–’ time | basic
basic ::= day of year day of week time_of_day | ‘*any*’
day_of_year ::= month [ day ] [ ‘,’year ] | nmonth ‘/’ [ day ‘/’ ] year | empty
day_of_week ::= ‘Sunday’ | ... | ‘Saturday’ | ‘Weekend’ | ‘Weekday’ | empty
time_of_day ::= hour [ ‘:’ min ] [ ‘:’ sec ] [ ‘AM’ | ‘PM’ ] | special | empty
special ::= ‘noon’ | ‘midnight’ | ‘morning’ | ‘afternoon’ | ‘evening’
empty ::= ‘’
where month is a string naming the month, nmonth is an integer naming the month, day is an integer naming the day of the month, and year is an integer specifying the year. Similarly, hour, min, and sec are integers specifying the hour, minute, and second. If basic is empty, it is treated as not allowing access.10
EXAMPLE: A user is allowed to assume a role between the hours of 9 o’clock in the morning and 5 o’clock in the evening on Monday through Thursday. An appropriate entry would be
Monday-Thursday 9a.m.-5p.m.
This is different than saying
Monday 9a.m.-Thursday 5p.m.
because the latter allows access on Monday at 10 p.m., whereas the former does not.
Finally, the users field of the record has a similar structure:
*any*
In BNF form, the language used to express the set of users who may access a role is
userlist ::= ‘(’ userlist ‘)’ | ‘not’ userlist | userlist ‘,’ userlist | user
where user is the name of a user on the system.
These “little languages” are straightforward and simple (but incomplete; see Exercise 5). Various implementation details, such as allowing abbreviations for day and month names, can be added, as can an option to change the American expression of days of the year to an international one. These points must be considered in light of where the program is to be used. Whatever changes are made, the administrators must be able to configure times and places quickly and easily, and in a manner that a reader of the access control file can understand quickly.11
The listing of commands requires some thought about how to represent arguments. If no arguments are listed, is the command to be run without arguments, or should it allow any set of arguments? Conversely, if arguments are listed, should the command be run only with those arguments? Our approach is to force the administrator to indicate how arguments are to be treated.
Each command line contains a command followed by zero or more arguments. If the first word after the command is an asterisk (“ * ”), then the command may be run with any arguments. Otherwise, the command must be run with the exact arguments provided.
EXAMPLE: Charles is allowed to run the install command when he accesses the bin role. He may supply any arguments. The line in the access control file is
/bin/install *
He may also copy the file log from the current working directory to the directory /var/install. The line for this is
/bin/cp log /var/install/log
Finally, he may run the id command to ensure that he is working as bin. He may not supply other arguments to the command, however. This would be expressed by
/usr/bin/id
The user must type the command as given in the access control file. The full path names are present to prevent the user from accidentally executing the command id with bin privileges when id is a command in the local directory, rather than the system id command.12