Perforce 98.2 p4 User's Guide
<< Previous Chapter
System Administration:
Installation & Upkeep

Table of Contents
Index
Perforce on the Web
Next Chapter >>
System Administration:
Editing Job Specifications


Chapter 14
System Administration: Protections

Perforce provides a protection scheme to prevent unauthorized or inadvertent access to the depot. The protections determine which Perforce commands can be run, on which files, by whom, and from which host. Protections are set with the p4 protect command.

When Should Protections Be Set?


Before p4 protect is run, every Perforce user is a superuser, and can access and change anything in the depot. The first time protect is invoked, a protections table is created that gives the invoking user superuser access from all hosts, and lowers everyone else's access level to write permission on all files from all hosts. Therefore, protect should be run as the concluding step of all new Perforce installations; the superuser can change the access levels as needed at any time.

The Perforce protections are stored in the db.protect file in the server root directory; if p4 protect is first run by an unauthorized user, the depot can be brought back to its unprotected state by removing this file.

Setting Protections with p4 protect


The p4 protect form contains a single field with multiple lines. Each line specifies a particular permission; the contents look something like this:

Example
A sample protections table
Protections:
read   user  emily  *          //depot/elm_proj/...
write  group devgrp *          //...
write  user  *      195.3.9.*  //...
write  user  joe    *          -//...
write  user  lisag  *          -//depot/...
write  user  lisag  *          //depot/doc/...
super  user  edk    *          //...

(The four fields may not line up vertically on your screen; they are aligned here for ease of reading).

The Permission Lines' Five Fields

Each line specifies a particular permission; each permission is always described by five fields. The meanings of these fields are:

Field Meaning
AccessLevel Which access level is being granted: list, read, open, write, super, or review. These are described below.

User/Group Does this protection apply to a user or a group? The value must be user or group.

Name The user or group whose protection level is being defined. This field can contain the `*' wildcard: `*' by itself would grant this protection to everyone; `*e' would grant this protection to every user (or group) whose username ends with an `e'.

Host The TCP/IP address of the host being granted access. This must be provided as the numeric address of the host in dotted quad notation (e.g. 206.14.52.194).

This field may contain the `*' wildcard. A `*' by itself means that this protection is being granted for all hosts. The wildcard can be used as in any string, so `127.30.41.*' would define access to any subnet within 127.30.41, and `*3*' would refer to any IP address with a `3' in it.

Since the client's IP address is provided by IP itself, this field provides as much security as is provided by the network.

Files The files in the depot that permission is being granted on. `//...' means all files in all depots.

Access Levels

The access level is described by the first value on each line. The six access levels are:

Access Level Meaning
list Permission is granted to run Perforce commands that display data about files, (e.g. p4 filelog). No permission is granted to view or change the contents of the files.

read The user(s) can run those Perforce commands that are needed to read files, such as p4 client and p4 sync. The read permission includes list access.

open Grants permission to read files from the depot into the client workspace, and gives permission to open and edit those files. This permission does not allow the user to write the files back to the depot. open is similar to write, except that with open permission, users are not allowed to run p4 submit or p4 lock.

The open permission includes read and list access.

write Permission is granted to run those commands that edit, delete, or add files. Write permission includes read, list, and open access.

This permission allows use of all Perforce commands except protect, depot, obliterate, and verify.

review A special permission granted to review daemons. It includes list and read access, plus use of the p4 review command. It is needed only by review daemons.

super For Perforce superusers; grants permission to run all Perforce commands. Provides write and review access plus the added ability to edit protections, create depots, obliterate files, and verify files.

Each Perforce command is associated with a particular minimum access level; for example, to run p4 sync on a particular file, the user must have been granted at least read access on that file. The access level required to run a particular command can usually be reasoned from knowledge of what the command does; for example, it is somewhat obvious that p4 print would require read access. A full list of the minimum access levels required to run each Perforce command is provided later in this chapter.

Which Users Should Receive Which Permissions?

The simplest method of granting permissions is to give write permission to all users who don't need to manage the Perforce system, and give super access to those who do. But there are times when this simple solution isn't sufficient.

Read access to particular files should be granted to users who don't ever need to edit those files. For example, an engineer might have write permissions for source files, but have only read access to the documentation; managers might be granted only read access to all files.

Because open access allows local editing of files, but doesn't allow these files to be written to the depot, open access is usually granted only in unusual circumstances. Choose open access over write access when users will be testing their changes locally, but when these changes should not be seen by other users. For example, bug testers may want to change code in order to test theories as to why particular bugs occur, but these changes would be for their own use, and would not be written to the depot. Or, a codeline might be frozen, with local changes submitted to the depot only after careful review by the development team. In this case, open access would be granted until the code changes have been approved; at that time, the protection level would be upgraded to write.

Default Protections

When p4 protect is first run, two permissions are set by default. The default protections form looks like this:

write user *   * //...
super user edk * //...

This indicates that write access is granted to all users, on all hosts, to all files. Additionally, the user who first invokes p4 protect (in this case, edk) is granted superuser privileges.

Interpreting Multiple Permission Lines

The access rights granted to any user are defined by the union of mappings in the protection lines that match her user name and client IP address. (This behavior is slightly different when exclusionary protections are provided; this is described in the next section).
Example
How protections work.
Lisa, whose Perforce username is lisag, is using a client with the IP address 195.42.39.17. The protections file reads as follows:

read   user  *         195.42.39.17  //...
write  user  lisag     195.42.39.17  //depot/elm_proj/doc/...
read   user  lisag     *             //...
super  user  edk       *             //...

The union of the first three permissions apply to Lisa. Her username is lisag, and she's currently using a client workspace on the host specified in lines 1 and 2. Thus, she can write files located in the depot's doc subdirectory, but can only read other files. Lisa tries the following:

She types p4 edit //lisag/doc/elm-help.1, and is successful.

She types p4 edit //lisag/READ.ME, and is told that she doesn't have the proper permission. She is trying to write a file that she only has read access to. She types p4 sync //lisag/READ.ME, and this command succeeds; only read access is needed, and this is granted to her on line 1.

Lisa later switches to another machine with IP address 195.42.39.13. She types p4 edit //lisag/doc/elm-help.1, and the command fails; when she's using this host, only the third permission applies to her, and she only has read privileges.

Exclusionary Protections

A user can be denied access from particular files by prefacing the fourth field in a permission line with a minus sign ( - ). This is useful for giving most users access to a particular set of files, while denying access to the same files to only a few users.

To use exclusionary mappings properly, it is necessary to understand some peculiarities associated with them:

  • When an exclusionary protection is included in the protections table, the order of the protections is relevant: the exclusionary protection is used to remove any matching protections above it in the table.

  • No matter what access level is provided in an exclusionary protection, all access levels for the matching files and IP addresses are denied. The access levels provided in exclusionary protections are irrelevant.

The reasons for this seemingly strange behavior are described in the section How Protections are Implemented.
Example
Exclusionary protections
Ed has used p4 protect to set up protections as follows:

read   user  emily  *  //depot/elm_proj/...
write  user  *      *  //...
super  user  joe    *  -//...
list   user  lisag  *  -//...
write  user  lisag  *  //depot/elm_proj/doc/...

The second permission seemingly grants write access to all users to all files in all depots, but this is overruled by later exclusionary protections for certain users:

  • The third permission denies Joe permission to access any file from any host. No subsequent lines grant Joe any further permissions; thus, Joe has been effectively locked out of Perforce.

  • The fourth permission denies Lisa all access to all files on all hosts, but the fifth permission gives her back write access on all files within a specific directory. If the fourth and fifth lines were switched, Lisa would be unable to run any Perforce command.

Granting Access to Groups of Users


Perforce groups ease maintenance of the protections table. The names of users with identical access requirements can be stored in a single group; rather then enter each user individually into the protections table, the group name can be entered in the table, and all the users in that group will receive the specified accesses.

Creating and Editing Groups

The command p4 group groupname displays a form with two fields: Group: and Users:. The Group: field stores the group name, and can't be edited; Users: is empty when the group is first created, and must be filled in. User names are entered under the Users: field header; each user name must be typed on its own line, and should be indented. A single user may be listed in any number of groups.

User names and group names occupy separate namespaces; thus, groups and users can have the same names.

If p4 group groupname is called with a non-existent groupname, a new group with the name groupname will be created. Calling this command with an existing groupname allows editing of the user list for this group.

Only Perforce superusers may invoke p4 group.

Groups and Protections

To use a group with the p4 protect form, specify a group name instead of a user name in any line in the protections table, and set the value of the second field on the line to group instead of user. All the users in that group will be granted the specified access. For example, the following protections table gives write access to all members of the group devgroup, and super access to user edk:

list  group devgroup *  //...
super user  edk      *  //...

If a user belongs to multiple groups, one permission may override another, but the actual permissions granted to a specific user can be determined by replacing the names of all groups that a particular user belongs to with the users name within the protections table, and applying the rules described earlier in this chapter.

Deleting Groups

To delete a group, invoke p4 group groupname and delete all the users from the group. The group will be deleted when the form is closed.

Access Levels Required by Perforce Commands


The following table lists the minimum access level required to run each command. For example, since p4 add requires at least open access, p4 add can be run if open, write or super protections are granted.

Command

Access Level

Command

Access Level

add
open

jobs  1
list
branch  1 2
open

jobspec  1 2
super
branches
list

label  1
open
change
open

labels  1 2
list
changes  1
list

labelsync
open
client  2
list

lock
write
clients  
list

obliterate
super
delete
open

open
open
depot  1 2
super

opened
list
depots  1
list

print
read
describe
read

protect  1
super
describe  -s
list

refresh
read
diff
read

reopen
open
diff2
read

reresolve
open
edit
open

resolve
open
files
list

resolved
open
filelog
list

revert
open
fix  1
open

review  1
review
fixes  1
list

reviews  1
list
group  1 2
super

submit
write
groups  1
list

sync
read
have
list

unlock
open
help
none

user  1 2
list
info
none

users  1
list
integrate  3
open

verify
review
integrated
list

where  1
none
job  2
open



1 This command doesn't operate on specific files. Thus, permission is granted to run these commands if the user has the specified access to at least one file in the depot.
2 The -o flag to this command, which allows the form to be read but not edited, requires only list access.
3 To run p4 integrate, the user needs open access on the target files and read access on the donor files.

Those commands that list files, such as p4 describe, will only list those files to which the user has at least list access.

Some of these commands take a -f flag which can only be run by Perforce superusers. Please see Forcing Operations with the -f Flag.

How Protections are Implemented


This section describes the algorithm that Perforce follows to implement its protection scheme. Protections can be used properly without reading this section; the material here is provided to explain some of the more eccentric behavior described above.

Users' access to files is determined by the following steps:

  • The command is looked up in the command access level table shown on this page to determine the minimum access level needed to run that command. In our example, p4 print is the command, and the minimum access level required to run that command is read.

  • Perforce makes the first of two passes through the protections table. Both passes move up the protections table, bottom to top, looking for the first relevant line. The first pass is used to determine whether or not the user is allowed to know whether or not the file exists, and this search simply looks for the first line encountered that matches the user name, host IP address, and file argument. If the first matching line found is an inclusionary protection, then the user has permission to list the file, and Perforce proceeds to the second pass. If the first mapping found is an exclusionary mapping, or if the top of the protections table is reached without a matching protection being found, then the user has no permission to even list the file, and will receive a message like File not on client.

  • As an example, suppose that our protections table is set as follows:

    write  user  *    *   //...
    read   user  edk  *  -//...
    read   user  edk  *   //depot/elm_proj/...

    If Ed runs p4 print //depot/foo, Perforce examines the protections table bottom to top, and first encounters the last line. The files specified there don't match the file that Ed wants to print, so this line is irrelevant. The second-to-last line is examined next; this line matches Ed's user name, his IP address, and the file he wants to print; since this line is an exclusionary mapping, Ed isn't allowed to even list the file.

  • If the first pass is successful, a second pass is made at the protections table, again reading bottom to top; this pass is the same as the first, except that access level is now taken into account. If an inclusionary protection line is the first line encountered that matches the user name, IP address, file argument, and has an access level greater than or equal to the access level required by the given command, then the user is given permission to run the command. If an exclusionary mapping is the first line encountered that matches according to the above criteria, or if the top of the protections table is reached without finding a matching protection, then the user has no permission to run the command, and will receive the message You don't have permission for this operation.

Other Perforce Security Measures


By default, any system user can impersonate any Perforce user with the -u flag, or by setting P4USER to a Perforce user's username. Perforce passwords will protect against this happening, but only if all users' passwords have been set. The alert Perforce superuser, will, of course, require that each user set a Perforce password, and will make sure that no access higher than list is granted to *.


Perforce 98.2 p4 User's Guide
<< Previous Chapter
System Administration:
Installation & Upkeep

Table of Contents
Index
Perforce on the Web
Next Chapter >>
System Administration:
Editing Job Specifications

Please send comments and questions about this manual to [email protected].
Copyright 1997, 1998 Perforce Software. All rights reserved.
Last updated: 08/15/98