Skip to content

Commit

Permalink
Add a daemon config option HidePII.
Browse files Browse the repository at this point in the history
This new configuration option excludes USB device serial numbers and
the devices hashes (which include the serial number) from being
logged to the Audit backend. This is useful when you want the audit
entries without PII to be writen to the syslog.
  • Loading branch information
Allen-Webb committed Oct 15, 2018
1 parent 7178019 commit 5f68e4e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
15 changes: 14 additions & 1 deletion src/Daemon/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace usbguard
"DeviceManagerBackend",
"IPCAccessControlFiles",
"AuditFilePath",
"AuditBackend"
"AuditBackend",
"HidePII"
};

static const std::vector<std::pair<std::string, Daemon::DevicePolicyMethod>> device_policy_method_strings = {
Expand Down Expand Up @@ -335,6 +336,18 @@ namespace usbguard
}
}

/* HidePII */
if (_config.hasSettingValue("HidePII")) {
const std::string value = _config.getSettingValue("HidePII");

if (value == "true") {
_audit.setHidePII(true);
}
else if (value != "false") {
throw Exception("Configuration", "HidePII", "Invalid value");
}
}

USBGUARD_LOG(Info) << "Configuration loaded successfully.";
}

Expand Down
16 changes: 12 additions & 4 deletions src/Library/RulePrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ namespace usbguard
return;
}

std::string RulePrivate::toString(bool invalid) const
std::string RulePrivate::toString(bool invalid, bool hide_pii) const
{
std::string rule_string;

Expand All @@ -437,10 +437,18 @@ namespace usbguard
}

toString_appendNonEmptyAttribute(rule_string, _device_id);
toString_appendNonEmptyAttribute(rule_string, _serial);

if (!hide_pii) {
toString_appendNonEmptyAttribute(rule_string, _serial);
}

toString_appendNonEmptyAttribute(rule_string, _name);
toString_appendNonEmptyAttribute(rule_string, _hash);
toString_appendNonEmptyAttribute(rule_string, _parent_hash);

if (!hide_pii) {
toString_appendNonEmptyAttribute(rule_string, _hash);
toString_appendNonEmptyAttribute(rule_string, _parent_hash);
}

toString_appendNonEmptyAttribute(rule_string, _via_port);
toString_appendNonEmptyAttribute(rule_string, _with_interface);
toString_appendNonEmptyAttribute(rule_string, _conditions);
Expand Down
2 changes: 1 addition & 1 deletion src/Library/RulePrivate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace usbguard
const Rule::Attribute<RuleCondition>& attributeConditions() const;
Rule::Attribute<RuleCondition>& attributeConditions();

std::string toString(bool invalid = false) const;
std::string toString(bool invalid = false, bool hide_pii = false) const;

MetaData& metadata();
const MetaData& metadata() const;
Expand Down
23 changes: 14 additions & 9 deletions src/Library/public/usbguard/Audit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace usbguard
}

Audit::Audit(const AuditIdentity& identity)
: _identity(identity)
: _identity(identity), _hide_pii(false)
{
}

Expand All @@ -165,6 +165,11 @@ namespace usbguard
_backend = std::shared_ptr<AuditBackend>(std::move(backend));
}

void Audit::setHidePII(bool hide_pii)
{
_hide_pii = hide_pii;
}

AuditEvent Audit::policyEvent(std::shared_ptr<Rule> rule, Policy::EventType event)
{
return policyEvent(_identity, rule, event);
Expand Down Expand Up @@ -200,7 +205,7 @@ namespace usbguard
AuditEvent event(identity, _backend);
event.setKey("type", std::string("Policy.") + Policy::eventTypeToString(event_type));
event.setKey("rule.id", numberToString(rule->getRuleID()));
event.setKey("rule", rule->toString());
event.setKey("rule", rule->toString(false, _hide_pii));
return event;
}

Expand All @@ -209,8 +214,8 @@ namespace usbguard
AuditEvent event(identity, _backend);
event.setKey("type", std::string("Policy.") + Policy::eventTypeToString(Policy::EventType::Update));
event.setKey("rule.id", numberToString(old_rule->getRuleID()));
event.setKey("rule.old", old_rule->toString());
event.setKey("rule.new", new_rule->toString());
event.setKey("rule.old", old_rule->toString(false, _hide_pii));
event.setKey("rule.new", new_rule->toString(false, _hide_pii));
return event;
}

Expand All @@ -220,7 +225,7 @@ namespace usbguard
event.setKey("type", std::string("Policy.Device.") + Policy::eventTypeToString(event_type));
event.setKey("target", Rule::targetToString(device->getTarget()));
event.setKey("device.system_name", device->getSystemName());
event.setKey("device.rule", device->getDeviceRule()->toString());
event.setKey("device.rule", device->getDeviceRule()->toString(false, _hide_pii));
return event;
}

Expand All @@ -232,7 +237,7 @@ namespace usbguard
event.setKey("target.old", Rule::targetToString(old_target));
event.setKey("target.new", Rule::targetToString(new_target));
event.setKey("device.system_name", device->getSystemName());
event.setKey("device.rule", device->getDeviceRule()->toString());
event.setKey("device.rule", device->getDeviceRule()->toString(false, _hide_pii));
return event;
}

Expand All @@ -242,7 +247,7 @@ namespace usbguard
AuditEvent event(identity, _backend);
event.setKey("type", std::string("Device.") + DeviceManager::eventTypeToString(event_type));
event.setKey("device.system_name", device->getSystemName());
event.setKey("device.rule", device->getDeviceRule()->toString());
event.setKey("device.rule", device->getDeviceRule()->toString(false, _hide_pii));
return event;
}

Expand All @@ -252,8 +257,8 @@ namespace usbguard
AuditEvent event(identity, _backend);
event.setKey("type", std::string("Device.") + DeviceManager::eventTypeToString(DeviceManager::EventType::Update));
event.setKey("device.system_name", new_device->getSystemName());
event.setKey("device.rule.old", old_device->getDeviceRule()->toString());
event.setKey("device.rule.new", new_device->getDeviceRule()->toString());
event.setKey("device.rule.old", old_device->getDeviceRule()->toString(false, _hide_pii));
event.setKey("device.rule.new", new_device->getDeviceRule()->toString(false, _hide_pii));
return event;
}
} /* namespace usbguard */
Expand Down
8 changes: 8 additions & 0 deletions src/Library/public/usbguard/Audit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ namespace usbguard

void setBackend(std::unique_ptr<AuditBackend> backend);

/*
* Sets whether personally identifiable information such as device serial
* numbers and hashes of the descriptors (which include the serial number)
* should be excluded from audit entries.
*/
void setHidePII(bool hide_pii);

AuditEvent policyEvent(std::shared_ptr<Rule> rule, Policy::EventType event);
AuditEvent policyEvent(std::shared_ptr<Rule> new_rule, std::shared_ptr<Rule> old_rule);
AuditEvent policyEvent(std::shared_ptr<Device> device, Policy::EventType event);
Expand Down Expand Up @@ -149,6 +156,7 @@ namespace usbguard
private:
AuditIdentity _identity;
std::shared_ptr<AuditBackend> _backend;
bool _hide_pii;
};
} /* namespace usbguard */

Expand Down
4 changes: 2 additions & 2 deletions src/Library/public/usbguard/Rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ namespace usbguard
getTarget() == Target::Empty);
}

std::string Rule::toString(bool invalid) const
std::string Rule::toString(bool invalid, bool hide_serial) const
{
return d_pointer->toString(invalid);
return d_pointer->toString(invalid, hide_serial);
}

void Rule::updateMetaDataCounters(bool applied, bool evaluated)
Expand Down
2 changes: 1 addition & 1 deletion src/Library/public/usbguard/Rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ namespace usbguard


operator bool() const;
std::string toString(bool invalid = false) const;
std::string toString(bool invalid = false, bool hide_serial = false) const;

void updateMetaDataCounters(bool applied = true, bool evaluated = false);

Expand Down

0 comments on commit 5f68e4e

Please sign in to comment.