Perforce provides a protection scheme to prevent unauthorized or inadvertent access to the depot. The protections determines which Perforce commands can be run, on which files, by whom, and from which host. Since any user can change their Perforce username with
P4USER
, user level protections provide safety, not security. At the host level, protections are as secure as the host itself.p4 protect
command. When Should Protections Be Set?
Before p4 protect
is run, there are no protections against a user running Perforce commands that access or change the depot. The first time protect
is invoked, a protections table is created that gives the invoking user superuser access from all hosts. Therefore, protect
should be run as the concluding step of all new Perforce installations. 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:
Protections: |
(The four fields may not line up vertically on your screen; they are aligned here for ease of reading).
The Permission Lines' Four Fields
Each line specifies a particular permission; each permission is always described by four fields. The meanings of these four fields are:
Access Levels
The access level is described by the first field, and the five access levels are
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 at the end of this section. Default Protections
When p4 protect
is first run, two permissions are set by default. The default protect form looks like this:
Protections: write * * //... super 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 mappings in the protection
lines that match his user name and client IP address. As in any other type of mapping, order matters: later lines have higher precedence.lisag
, is using a client with the IP address 195.42.39.17
. The protections file reads as follows:
Protections:
read emily * //depot/elm_proj/...
read * 195.42.39.17 //...
write lisag * //depot/elm_proj/doc/...
super edk * //...
doc
subdirectory, but can only read other files. Lisa tries the following:p4 edit //lisag/doc/elm-help.1
, and is successful. 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 get //lisag/READ.ME
, and this command succeeds; only read
access is needed.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 second permission applies to her, and she only has read privileges. Permissions that Deny Access
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 a particular access level, while denying that same access level to only a few users.p4 protect
to set up protections as follows:
Protections:
read emily * //depot/elm_proj/...
write * 195.3.21.* //...
write joe * -//...
write lisag * -//...
write lisag * //depot/elm_proj/doc/...
super edk * //...
write
access to all users to all files in all depots, but this is overruled by later exclusionary protections for certain users:
in all depots from all hosts.
fifth line, which gives her write permission in the Elm doc
subdirectory. Access Levels Required by Perforce Commands
The following table lists the minimum access level required to run each command.