Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new audit-based table to collect SELinux events #4224

Merged
merged 3 commits into from Jul 8, 2018

Conversation

@alessandrogario
Copy link
Contributor

@alessandrogario alessandrogario commented Mar 27, 2018

This PR adds a new table called selinux_events that collects SELinux events using audit.

Here's how it looks:

osquery> SELECT * FROM selinux_events;
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+
| type | msg                                                                                                                                                                                                                             | time       | uptime |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+
| AVC  | audit(1522338316.682:32): avc:  denied  { getattr } for  pid=12900 comm="httpd" path="/var/www/html/testfile" dev="dm-0" ino=37944206 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file    | 1522338318 | 3697   |
| AVC  | audit(1522338316.682:33): avc:  denied  { getattr } for  pid=12900 comm="httpd" path="/var/www/html/testfile" dev="dm-0" ino=37944206 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file    | 1522338318 | 3697   |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+

Possible values for the type column:

USER_AVC
AVC
SELINUX_ERR
AVC_PATH
MAC_POLICY_LOAD
MAC_STATUS
MAC_CONFIG_CHANGE
MAC_UNLBL_ALLOW
MAC_CIPSOV4_ADD
MAC_CIPSOV4_DEL
MAC_MAP_ADD
MAC_MAP_DEL
MAC_IPSEC_ADDSA
MAC_IPSEC_DELSA
MAC_IPSEC_ADDSPD
MAC_IPSEC_DELSPD
MAC_IPSEC_EVENT
MAC_UNLBL_STCADD
MAC_UNLBL_STCDEL

How it works

The SELinux subsystem does not conform to the audit record syntax, meaning that the messages we receive can't be correctly parsed. To work around this issue, the data is stored and shown in raw format, similar to how it appears in the usual SELinux log files.

How to test it

As with the other audit-based tables, it is mandatory to enable audit, events and the required audit tables:

sudo ./build/linux/osquery/osqueryi --verbose --disable_audit=false \
--disable_events=false --audit_allow_config=true --audit_allow_selinux_events=true \
--audit_persist --audit_force_reconfigure=true --audit_force_unconfigure=true \
--disable_audit=false
@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented Mar 29, 2018

@alessandrogario has updated the pull request. View: changes

@alessandrogario alessandrogario changed the title WIP: Add a new audit-based table to collect SELinux events Add a new audit-based table to collect SELinux events Mar 29, 2018
@muffins
Copy link
Contributor

@muffins muffins commented May 10, 2018

ok to test

@muffins muffins added this to the 3.3.0 milestone May 10, 2018
description("Track SELinux events.")
schema([
Column("type", TEXT, "Event type"),
Column("msg", TEXT, "Message"),

This comment has been minimized.

@theopolis

theopolis May 14, 2018
Member

I will get back to a more-complete review later, but I don't want to forget things. I would recommend message as that is already used in asl and user_events. The msg shorthand is not used anywhere.

This comment has been minimized.

@alessandrogario

alessandrogario May 14, 2018
Author Contributor

The field names are trying to match what is shown in the default (i.e. without osquery) auditd log so that (hopefully) the syntax is similar. I can rename it to "message" if you prefer!

EDIT:
This also applies to the "type" field.

Reference I used for the syntax: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sec-understanding_audit_log_files

This comment has been minimized.

@theopolis

theopolis May 17, 2018
Member

Ah, my vote is still for message please :)

table_name("selinux_events")
description("Track SELinux events.")
schema([
Column("type", TEXT, "Event type"),

This comment has been minimized.

@theopolis

theopolis May 14, 2018
Member

note, in user_events this is an Integer.

This comment has been minimized.

@alessandrogario

alessandrogario May 17, 2018
Author Contributor

I have renamed msg to message, but for the type column I'm using text labels; would you like me to change this? I could move the label to another column (like type_name) and change type back to integer

@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented May 16, 2018

@alessandrogario has updated the pull request.

// clang-format off
// This map must contain exactly the same elements that
// SELinuxEventSubscriber::GetEventSet() returns!
const std::map<int, std::string> record_type_to_label = {

This comment has been minimized.

@theopolis

theopolis May 17, 2018
Member

This should be named kSELinuxRecordLabels or something similar.

// - USER_MAC_POLICY_LOAD
// - USER_ROLE_CHANGE
// - USER_LABEL_EXPORT
static const std::set<int> selinux_event_list = {

This comment has been minimized.

@theopolis

theopolis May 17, 2018
Member

This is weird, too many statics. I would define this const set somewhere outside of the class. Similar to the record-label lookup.

This comment has been minimized.

@theopolis

theopolis May 17, 2018
Member

If there's a requirement to have each of these in the label map above, please include a test!

description("Track SELinux events.")
schema([
Column("type", TEXT, "Event type"),
Column("msg", TEXT, "Message"),

This comment has been minimized.

@theopolis

theopolis May 17, 2018
Member

Ah, my vote is still for message please :)

@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented May 17, 2018

@alessandrogario has updated the pull request. View: changes

@osqueryer
Copy link

@osqueryer osqueryer commented May 17, 2018

👎 The commit e005708 (Job results: 3160) failed one or more tests (macOS/OS X).

@osqueryer
Copy link

@osqueryer osqueryer commented May 17, 2018

👎 The commit e005708 (Job results: 3161) failed one or more tests (macOS/OS X).

@osqueryer
Copy link

@osqueryer osqueryer commented May 17, 2018

👎 The commit e005708 (Job results: 4073) failed one or more tests (Windows).

@osqueryer
Copy link

@osqueryer osqueryer commented May 17, 2018

👎 The commit e005708 (Job results: 4074) failed one or more tests (Windows).

@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented May 17, 2018

@alessandrogario has updated the pull request.

@theopolis
Copy link
Member

@theopolis theopolis commented May 17, 2018

Does this change include any performance impact to machines configured to do process and socket auditing?

@theopolis theopolis merged commit 9497df6 into osquery:master Jul 8, 2018
5 checks passed
5 checks passed
Code Audit Build finished.
Details
FreeBSD Build finished.
Details
Linux Build finished.
Details
Windows Build finished.
Details
macOS/OS X Build finished.
Details
@alessandrogario alessandrogario deleted the alessandro/feature/selinux-audit-event-support branch Jul 9, 2018
trizt added a commit to trizt/osquery that referenced this pull request May 24, 2019
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request May 26, 2019
Although there's already a windows-only 3.4[1], the latest release for
Unix systems is 3.3.2[2] with the following changes:

* SELinux event recording[3]
* SMART drive information[4]
* ELF parsing to monitor compiler-level protections for binaries[5]

The diff became rather big in the end due to the following changes:

* The SMART information feature uses a custom fork of smartmontools to
  retrieve SMART data programatically[6].

* Replaced the old, bloated `misc.patch` by a simpler patch that only
  fixes two (actual) issues in the CMake build, unnecessary link targets
  and an invalid compiler flag.

* I tried to clean the derivation's code up a little bit by
  simplifying the `preConfigure` hook and adding only one build-input
  per line (that makes merging of several changes to the derivation
  easier as well).

[1] https://github.com/facebook/osquery/releases/tag/3.4.0
[2] https://github.com/facebook/osquery/releases/tag/3.3.2
[3] osquery/osquery#4224
[4] osquery/osquery#4133
[5] osquery/osquery#4708
[6] https://github.com/allanliu/smartmontools
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request May 26, 2019
Although there's already a windows-only 3.4[1], the latest release for
Unix systems is 3.3.2[2] with the following changes:

* SELinux event recording[3]
* SMART drive information[4]
* ELF parsing to monitor compiler-level protections for binaries[5]

The diff became rather big in the end due to the following changes:

* The SMART information feature uses a custom fork of smartmontools to
  retrieve SMART data programatically[6].

* Replaced the old, bloated `misc.patch` by a simpler patch that only
  fixes two (actual) issues in the CMake build, unnecessary link targets
  and an invalid compiler flag.

* I tried to clean the derivation's code up a little bit by
  simplifying the `preConfigure` hook and adding only one build-input
  per line (that makes merging of several changes to the derivation
  easier as well).

[1] https://github.com/facebook/osquery/releases/tag/3.4.0
[2] https://github.com/facebook/osquery/releases/tag/3.3.2
[3] osquery/osquery#4224
[4] osquery/osquery#4133
[5] osquery/osquery#4708
[6] https://github.com/allanliu/smartmontools
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request May 27, 2019
Although there's already a windows-only 3.4[1], the latest release for
Unix systems is 3.3.2[2] with the following changes:

* SELinux event recording[3]
* SMART drive information[4]
* ELF parsing to monitor compiler-level protections for binaries[5]

The diff became rather big in the end due to the following changes:

* The SMART information feature uses a custom fork of smartmontools to
  retrieve SMART data programatically[6].

* Replaced the old, bloated `misc.patch` by a simpler patch that only
  fixes two (actual) issues in the CMake build, unnecessary link targets
  and an invalid compiler flag.

* I tried to clean the derivation's code up a little bit by
  simplifying the `preConfigure` hook and adding only one build-input
  per line (that makes merging of several changes to the derivation
  easier as well).

[1] https://github.com/facebook/osquery/releases/tag/3.4.0
[2] https://github.com/facebook/osquery/releases/tag/3.3.2
[3] osquery/osquery#4224
[4] osquery/osquery#4133
[5] osquery/osquery#4708
[6] https://github.com/allanliu/smartmontools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.