compiled.rules
compiled fapolicyd rules to determine access rights fapolicyd.rules - deprecated fapolicyd rules to determine access rights
- Provided by: fapolicyd (Version: 2.0-1)
- Report a bug
compiled fapolicyd rules to determine access rights fapolicyd.rules - deprecated fapolicyd rules to determine access rights
compiled.rules is a file that is compiled by fagenrules which contains the rules that fapolicyd uses to make decisions about access rights. The rules follow a simple format of:
decision perm subject : object
They are evaluated from top to bottom with the first rule to match being used for the access control decision. The colon is mandatory to separate subject and object since they share keywords.
The decision is either allow, deny, allow_audit, deny_audit, allow_syslog, deny_syslog, allow_log, or deny_log. If the rule triggers, this is the access decision that fapolicyd will tell the kernel. If the decision is one of the audit variety, then the decision will trigger a FANOTIFY audit event with all relevant information. You must have at least one audit rule loaded to generate an audit event. If the decision is one of the syslog variety, then the decision will trigger writing an event into syslog. If the decision is of one the log variety, then it will create an audit event and a syslog event. Regardless of the notification, any rule with a deny in the keyword will deny access and any with an allow in the keyword will allow access.
Perm describes what kind permission is being asked for. The permission is either open, execute, or any. If none are given, then open is assumed.
The subject is the process that is performing actions on system resources. The fields in the rule that describe the subject are written in a name=value format. There can be one or more subject fields. Each field is and'ed with others to decide if a rule triggers. The name values can be any of the following:
fapolicyd-cli --ftype /path-to-file
The object is the file that the subject is interacting with. The fields in the rule that describe the object are written in a name=value format. There can be one or more object fields. Each field is and'ed with others to decide if a rule triggers. The name values can be any of the following:
Rule fields are separated by spaces. Enclose a complete string value in double quotes when it contains a space. The surrounding quotes are syntax and are not part of the value used for matching. This applies consistently to subject exe , subject and object dir , and object path:
allow perm=execute all : dir="/tmp/first last/" allow perm=execute exe="/tmp/first last/tool" : all allow perm=execute all : path="/tmp/first last/tool"
Double quotes can also be used in named string-set definitions and in each comma-separated string value. Within a quoted value, a backslash before a double quote or another backslash represents that character. Other backslashes are preserved, so glob patterns retain their normal backslash behavior.
Percent escapes are not interpreted in rules. For example, dir="/tmp/first%20last/" matches a literal percent sign followed by 20, not a space. A backslash before a space and shell-style single quotes are not rule-file quoting forms; double quotes are the only supported way to include a literal space in a rule value.
Rule values use exact matching by default. Prefix a value with glob: to request pattern matching. This explicit marker distinguishes exact paths from patterns, so path names containing literal *, ?, or [ characters keep their historical exact-match meaning. For example, path=/tmp/name[1] matches only that literal path, while path=glob:/tmp/name[1] uses [1] as a bracket expression and matches /tmp/name1.
The glob: prefix is supported only by the subject exe and object path attributes, and the pattern after the prefix must be an absolute path. The dir attribute remains a literal directory prefix; use it instead of a glob when a rule applies to a complete subtree rooted at a fixed directory. An unmarked dir value containing metacharacters remains literal. A glob: value assigned to dir, or to any attribute other than exe and path, is a rule error, including when the value comes from a named set. Use subject exe or object path when glob matching is required.
The pattern following glob: uses fnmatch(3) syntax. A * matches zero or more characters, ? matches one character, and bracket expressions such as [0-9] match one character from the expression. Matching is case-sensitive and must cover the complete path. Wildcards do not match a slash, so each variable path component must be written explicitly. A wildcard does not match a leading period in a path component unless the period appears explicitly in the pattern. Backslash quotes a metacharacter. Recursive ** globstar matching is not supported.
When a glob value contains a space, quote the complete value, including the glob: prefix. For example:
allow perm=execute all : path="glob:/tmp/first last/*" allow perm=execute exe="glob:/tmp/first last/*" : all
The quotes are removed before glob validation and matching. The dir attribute remains a literal prefix and does not accept a quoted or unquoted glob: value.
Bracket ranges such as [a-z] and named character classes such as [[:alpha:]] use the locale active in the daemon. Avoid ranges and named classes when policy must produce identical matches in every locale; use exact alternatives or enumerate the intended characters instead.
For example, glob:/home/*/bin/tool matches /home/alice/bin/tool but not /home/alice/project/bin/tool or /home/.admin/bin/tool. Each pattern in a comma-separated attribute value or named string set needs its own glob: prefix. Exact paths and patterns may be mixed in the same set. Rule order is unchanged: rules are evaluated from top to bottom, and the first complete rule match determines the decision.
The concrete object path is obtained from the event file descriptor through /proc/self/fd/, and the subject exe path is obtained through /proc/PID/exe. Symbolic links have therefore already been followed, so a rule normally matches the reported target path rather than the symbolic link name used by the application. Hard links and mount aliases can expose different concrete paths for the same inode; policy that must cover those aliases needs an exact value or pattern for each reported path.
Globbing selects paths; it does not expand the pattern, alter the path reported in logs, or make matching files trusted. Trust database entries continue to use concrete paths. An allow rule for a user-writable location should normally pair an object path glob with object trust=1 or an explicit FILE_HASH constraint. A subject exe glob in a user-writable location should normally require subject trust=1. Otherwise, any file whose name fits the pattern can receive the allow decision. Prefer exact paths, named sets of exact paths, or dir when they express the policy because exact and prefix matching are less expensive than glob evaluation.
deny_audit perm=execute all : path=glob:/opt/vendor/product-*/bin/tool allow perm=execute all : path=glob:/home/*/bin/tool trust=1
Set is a named group of values of the same type. Fapolicyd internally distinguishes between INT and STRING set types. You can define your own set and use it as a value for a specific rule attribute. The definition is in key=value syntax and starts with a set name. The set name has to start with '%' and the rest is alphanumeric or '_'. The value is a comma separated list. The set type is inherited from the first item in the list. If that can be turned into number then whole list is expected to carry numbers. One can use these sets as a value for subject and object attributes. It is also possible to use a plain list as an attribute value without previous definition. The assigned set has to match the attribute type. It is not possible set groups for TRUST and PATTERN attributes.
# definition # string set %python=/usr/bin/python2.7,/usr/bin/python3.6 allow exe=%python : all trust=1 # # definition # number set %uuids=0,1000 allow uid=%uuids : all
The installed %languages set identifies MIME types that policy treats as language or interpreter content. A package may add a MIME type without modifying the distribution-owned definition by placing a naturally ordered macro fragment after 10-languages.rules and before policy rules. For example, 11-vendor-languages.rules can contain:
%languages+=application/x-vendor-script
The += form is available only for %languages. It requires the base set to have been defined already, does not replace it, and treats an existing MIME type as a no-op. Run fagenrules after adding or removing a fragment. The added value must also be a MIME type emitted by fapolicyd's file type detector or the system magic database; adding it to the set alone does not add file type detection.
When writing rules, you should keep them focused to one goal and store them in one file. These rule files are kept in the /etc/fapolicyd/rules.d directory. During daemon startup, fagenrules will run and compile all these component files into one master file, compiled.rules. See the fagenrules man page for more information.
When you are writing a rule for the execute permission, remember that the file to be executed is an object. For example, you type ssh into the shell. The shell calls execve on /usr/bin/ssh. At that instant in time, ssh is the object that bash is working on. However, if you are blocking execution from a specific program, then you would normally state the program on the subject side and use all for the object side.
If you are writing rules that use patterns, just select any as the permission to be clear that this applies to anything. In reality, pattern matching ignores the permission but the suggestion is for documentation purposes.
Some interpreters do not immediately read all lines of input. Rather, they read content as needed until they get to end of file. This means that if they do stuff like networking or sleeping or anything that takes time, someone with the privileges to modify the file can add to it after the file's integrity has been checked. This is not unique to fapolicyd, it's simply how things work. Make sure that trusted file permissions are not excessive so that no unexpected file content modifications can occur.
The following rules illustrate the rule syntax.
deny_audit perm=open exe=/usr/bin/wget : dir=/tmp allow perm=open exe=/usr/bin/python3.7 : ftype=text/x-python trust=1 deny_audit perm=any pattern ld_so : all deny perm=any all : all
fapolicyd(8), fagenrules (8), fapolicyd-cli(8), fnmatch(3), and fapolicyd.conf(5)
Steve Grubb