Skip to content

Commit b239ec1

Browse files
committed
Update docs (ebuild backend)
Also: - properly nest FAQ content - fix indentation of code block under notes - fix table formatting (at least, as good as GFM tables get)
1 parent 4f98c4a commit b239ec1

1 file changed

Lines changed: 112 additions & 97 deletions

File tree

README.md

Lines changed: 112 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ that are designed to work together. They are copied into /etc/fapolicyd/rules.d/
2121
When the service starts, the systemd service file runs fagenrules which
2222
assembles the units of rules into a comprehensive policy. The policy is
2323
evaluated from top to bottom with the first match winning. You can see the
24-
assembled policy by running
24+
assembled policy by running
2525

2626
```
2727
fapolicyd-cli --list
@@ -161,7 +161,7 @@ Policy. But you can do that. It is not recommended to do this except when
161161
necessary. Every rule that is added has to potentially be evaluated - which
162162
delays the decision.
163163

164-
If you needed to allow admins access to ping, but deny it to everyone
164+
If you needed to allow admins access to ping, but deny it to everyone
165165
else, you could do that with the following rules:
166166

167167
```
@@ -224,10 +224,10 @@ The report gives some basic forensic information about what was being accessed.
224224

225225
PERFORMANCE
226226
-----------
227-
When a program opens a file or calls execve, that thread has to wait for
227+
When a program opens a file or calls execve, that thread has to wait for
228228
fapolicyd to make a decision. To make a decision, fapolicyd has to lookup
229229
information about the process and the file being accessed. Each system call
230-
fapolicyd has to make slows down the system.
230+
fapolicyd has to make slows down the system.
231231

232232
To speed things up, fapolicyd caches everything it looks up so that
233233
subsequent access uses the cache rather than looking things up from
@@ -324,7 +324,7 @@ in the lmdb database is 512 bytes. So, for each 4k page, we can have data on
324324
8 trusted files.
325325

326326
An ideal size for the database is for the statistics to come up around 75% in
327-
case you decide to install new software some day. The formula is
327+
case you decide to install new software some day. The formula is
328328

329329
```
330330
(db_max_size x percentage in use) / desired percentage = new db_max_size
@@ -419,22 +419,22 @@ to debug the policy is:
419419

420420
Look at the rule that triggered and see if it makes sense that it triggered. If
421421
the rule is a catch all denial, then check if the file is in the trust db. To see the rule that is being triggered, either reproduce the problem with the daemon running in debug-deny mode or change the rules from deny_audit to deny_syslog. If you choose this method, the denials will go into syslog. To see them run:
422+
422423
```
423424
journalctl -b -u fapolicyd.service
424425
```
426+
425427
to list out any events since boot by the fapolicyd service.
426428

427429
Starting with 1.1, fapolicyd-cli includes some diagnostic capabilities.
428430

429-
| Option | What it does |
430-
|------------------------|--------------------------------------------|
431-
| --check-config | Opens fapolicyd.conf and parses it to see if there are any syntax errors in the file. |
432-
| --check-path | Check that every file in $PATH is in the trustdb. (New in 1.1.5) |
433-
| --check-status | Output internal metrics kept by the daemon. (New in 1.1.4) |
434-
| --check-trustdb | Check the trustdb against the files on disk to look for mismatches that will cause problems at run time. |
435-
| --check-watch_fs | Check the mounted file systems against the watch_fs daemon config entry to determine if any file systems need to be added to the configuration. |
436-
437-
431+
| Option | What it does |
432+
| :----------------: | ----------------------------------------------------------------------------------------------------------------------------------------------- |
433+
| `--check-config` | Opens fapolicyd.conf and parses it to see if there are any syntax errors in the file. |
434+
| `--check-path` | Check that every file in `$PATH` is in the trustdb. (New in 1.1.5) |
435+
| `--check-status` | Output internal metrics kept by the daemon. (New in 1.1.4) |
436+
| `--check-trustdb` | Check the trustdb against the files on disk to look for mismatches that will cause problems at run time. |
437+
| `--check-watch_fs` | Check the mounted file systems against the watch_fs daemon config entry to determine if any file systems need to be added to the configuration. |
438438

439439
MANAGING TRUST
440440
--------------
@@ -497,113 +497,129 @@ FAQ
497497
---
498498
1) Can this work with other distributions?
499499

500-
Absolutely! There is a backend API that any trust source has to implement.
501-
This API is located in fapolicyd-backend.h. A new backend needs an init, load,
502-
and destroy function. So, someone who knows the debian package database,
503-
for example, could implement a new backend and send a pull request. We are
504-
looking for collaborators.
500+
Absolutely! There is a backend API that any trust source has to implement.
501+
This API is located in `fapolicyd-backend.h`. A new backend needs an init, load,
502+
and destroy function.
505503

506-
An initial implementation for Debian distributions has been added.
507-
Run:
508-
```
509-
cd deb
510-
./build_deb.sh
511-
```
504+
An initial implementation for Debian distributions has been added, run:
505+
506+
```
507+
cd deb
508+
./build_deb.sh
509+
```
510+
511+
To build the `.deb` package that uses the `debdb` backend.
512+
You must add rules to `/etc/fapolicyd/rules.d/` and change configuration
513+
in `/etc/fapolicyd/fapolicyd.conf` to use `trust=debdb` after installation.
514+
515+
Gentoo-based distributions can try using the ebuild backend:
512516

513-
To build the `.deb` package that uses the `debdb` backend.
514-
You must add rules to `/etc/fapolicyd/rules.d/` and change configuration
515-
in `/etc/fapolicyd/fapolicyd.conf` to use `trust=debdb` after installation.
517+
```
518+
./configure --with-ebuild --with-audit
519+
make -j
520+
make install
521+
```
516522

517-
Also, if the distribution is very small, you can use the file trust database
518-
file. Just add the places where libraries and applications are stored.
523+
To use the ebuild backend:
524+
525+
1. Enable the ebuild backend by adding `trust = ebuilddb` to `/etc/fapolicyd/fapolicyd.conf`
526+
2. Increase `db_max_size` to 100 or more in `/etc/fapolicyd/fapolicyd.conf`
527+
3. Copy the example rules to `/etc/fapolicyd/rules.d/` and run `fagenrules` to compile them.
528+
529+
There is also an ebuild in the Gentoo Repository to simplify installation which
530+
does these things automatically.
531+
532+
Finally, if the distribution is very small (or in an embedded context), consider using
533+
the trust file database - Just whitelist applications or libraries and their hashes.
519534

520535
2) Can SE Linux or AppArmor do this instead?
521536

522-
SE Linux is modeling how an application behaves. It is not concerned about
523-
where the application came from or whether it's known to the system. Basically,
524-
anything in /bin gets bin_t type by default which is not a very restrictive
525-
label. MAC systems serve a different purpose. Fapolicyd by design cares solely
526-
about if this is a known application/library. These are complimentary security
527-
subsystems. There is more information about application whitelisting use cases
528-
at the following NIST website:
537+
SE Linux is modeling how an application behaves. It is not concerned about
538+
where the application came from or whether it's known to the system. Basically,
539+
anything in /bin gets bin_t type by default which is not a very restrictive
540+
label. MAC systems serve a different purpose. Fapolicyd by design cares solely
541+
about if this is a known application/library. These are complimentary security
542+
subsystems. There is more information about application whitelisting use cases
543+
at the following NIST website:
529544

530-
https://www.nist.gov/publications/guide-application-whitelisting
545+
https://www.nist.gov/publications/guide-application-whitelisting
531546

532547
3) Does the daemon check file integrity?
533548

534-
Version 0.9.5 and later supports 3 modes of integrity checking. The first is
535-
based on file size. In this mode, fapolicyd will take the size information
536-
from the trust db and compare it with the measured file size. This test
537-
incurs no overhead since the file size is collected when establishing
538-
uniqueness for caching purposes. It is intended to detect accidental overwrites
539-
as opposed to malicious activity where the attacker can make the file size
540-
match.
549+
Version 0.9.5 and later supports 3 modes of integrity checking. The first is
550+
based on file size. In this mode, fapolicyd will take the size information
551+
from the trust db and compare it with the measured file size. This test
552+
incurs no overhead since the file size is collected when establishing
553+
uniqueness for caching purposes. It is intended to detect accidental overwrites
554+
as opposed to malicious activity where the attacker can make the file size
555+
match.
541556

542-
The second mode is based on using IMA to calculate sha256 hashes and make them
543-
available through extended attributes. This incurs only the overhead of calling
544-
fgetxattr which is fast since there is no path name resolution. The file system
545-
must support i_version. For XFS, this is enabled by default. For other file
546-
systems, this means you need to add the i_version mount option. In either
547-
case, IMA must be setup appropriately.
557+
The second mode is based on using IMA to calculate sha256 hashes and make them
558+
available through extended attributes. This incurs only the overhead of calling
559+
fgetxattr which is fast since there is no path name resolution. The file system
560+
must support i_version. For XFS, this is enabled by default. For other file
561+
systems, this means you need to add the i_version mount option. In either
562+
case, IMA must be setup appropriately.
548563

549-
The third mode is where fapolicyd calculates a SHA256 hash of the file itself
550-
and compares that with what is stored in the trust db.
564+
The third mode is where fapolicyd calculates a SHA256 hash of the file itself
565+
and compares that with what is stored in the trust db.
551566

552567
4) This is only looking at location. Can't this be defeated by simply moving
553568
the files to another location?
554569

555-
Yes, this is checking to see if this is a known file. Known files have a known
556-
location. The shipped policy prevents execution from /tmp, /var/tmp, and $HOME
557-
based on the fact that no rpm package puts anything there. Also, moving a file
558-
means it's no longer "known" and will be blocked from executing. And if
559-
something were moved to overwrite it, then the hash is no longer the same and
560-
that will make it no longer trusted.
570+
Yes, this is checking to see if this is a known file. Known files have a known
571+
location. The shipped policy prevents execution from /tmp, /var/tmp, and $HOME
572+
based on the fact that no rpm package puts anything there. Also, moving a file
573+
means it's no longer "known" and will be blocked from executing. And if
574+
something were moved to overwrite it, then the hash is no longer the same and
575+
that will make it no longer trusted.
561576

562577
5) Does this protect against root modifications?
563578

564-
If you are root, you can change the fapolicyd rules or simply turn off the
565-
daemon. So, this is not designed to prevent root from doing things. None of
566-
the integrity subsystems on Linux are designed to prevent root from doing
567-
things. There has to be a way of doing updates or disabling something for
568-
troubleshooting. For example, you can change IMA to ima_appraise=fix in
569-
/etc/default/grub. You can run setenforce=0 to turn off selinux. You can also
570-
set selinux=0 for the boot prompt. The IPE integrity subsystem can be turned
571-
off via
579+
If you are root, you can change the fapolicyd rules or simply turn off the
580+
daemon. So, this is not designed to prevent root from doing things. None of
581+
the integrity subsystems on Linux are designed to prevent root from doing
582+
things. There has to be a way of doing updates or disabling something for
583+
troubleshooting. For example, you can change IMA to ima_appraise=fix in
584+
/etc/default/grub. You can run setenforce=0 to turn off selinux. You can also
585+
set selinux=0 for the boot prompt. The IPE integrity subsystem can be turned
586+
off via
572587

573-
```
574-
echo -n 0 > "/sys/kernel/security/ipe/Ex Policy/active"
575-
```
588+
```
589+
echo -n 0 > "/sys/kernel/security/ipe/Ex Policy/active"
590+
```
576591

577-
and so on. Since they can all be disabled, the fact that an admin can issue a
578-
service stop command is not a unique weakness.
592+
and so on. Since they can all be disabled, the fact that an admin can issue a
593+
service stop command is not a unique weakness.
579594

580595
6) How do you prevent race conditions on startup? Can something execute before
581596
the daemon takes control?
582597

583-
One of the design goals is to take control before users can login. Users are
584-
the main problem being addressed. They can pip install apps to the home dir
585-
or do other things an admin may wish to prevent. Only root can install things
586-
that run before login. And again, root can change the rules or turn off the
587-
daemon.
598+
One of the design goals is to take control before users can login. Users are
599+
the main problem being addressed. They can pip install apps to the home dir
600+
or do other things an admin may wish to prevent. Only root can install things
601+
that run before login. And again, root can change the rules or turn off the
602+
daemon.
588603

589-
Another design goal is to prevent malicious apps from running. Suppose someone
590-
guesses your password and they login to your account. Perhaps they wish to
591-
ransomware your home dir. The app they try to run is not known to the system
592-
and will be stopped. Or suppose there is an exploitable service on your system.
593-
The attacker is lucky enough to pop a shell. Now they want to download
594-
privilege escalation tools or perhaps an LD_PRELOAD key logger. Since neither
595-
of these are in the trust database, they won't be allowed to run.
604+
Another design goal is to prevent malicious apps from running. Suppose someone
605+
guesses your password and they login to your account. Perhaps they wish to
606+
ransomware your home dir. The app they try to run is not known to the system
607+
and will be stopped. Or suppose there is an exploitable service on your system.
608+
The attacker is lucky enough to pop a shell. Now they want to download
609+
privilege escalation tools or perhaps an LD_PRELOAD key logger. Since neither
610+
of these are in the trust database, they won't be allowed to run.
596611

597-
This is really about stopping escalation or exploitation before the attacker
598-
can gain any advantage to install root kits. If we can do that, UEFI secure
599-
boot can make sure no other problems exist during boot.
612+
This is really about stopping escalation or exploitation before the attacker
613+
can gain any advantage to install root kits. If we can do that, UEFI secure
614+
boot can make sure no other problems exist during boot.
600615

601-
Wrt to the second question being asked, fapolicyd starts very early in the
602-
boot process and startup is very fast. It's running well before other login
603-
daemons.
616+
Wrt to the second question being asked, fapolicyd starts very early in the
617+
boot process and startup is very fast. It's running well before other login
618+
daemons.
604619

605620
NOTES
606621
-----
622+
607623
* It's highly recommended to run in permissive mode while you are testing the
608624
daemon's policy.
609625

@@ -624,12 +640,11 @@ file content modifications can occur.
624640
* If for some reason rpm database errors are detected, you may need to do
625641
the following:
626642

627-
```
628-
1. db_verify /var/lib/rpm/Packages
629-
if OK, then
630-
2. rm -f /var/lib/rpm/__db*
631-
3. rpm --rebuilddb
632-
```
643+
```
644+
1. db_verify /var/lib/rpm/Packages
645+
if OK, then
646+
2. rm -f /var/lib/rpm/__db*
647+
3. rpm --rebuilddb
648+
```
633649

634650
[1] - https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?id=66917a3130f218dcef9eeab4fd11a71cd00cd7c9
635-

0 commit comments

Comments
 (0)