Skip to content

Commit

Permalink
s/audit: Remove old now unused ocsf hash methods
Browse files Browse the repository at this point in the history
(cherry picked from commit 8af1348)
  • Loading branch information
graphcareful authored and michael-redpanda committed Jan 19, 2024
1 parent a978fd8 commit d69f7f5
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 286 deletions.
6 changes: 0 additions & 6 deletions src/v/security/audit/schemas/application_activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ class api_activity final : public ocsf_base_event<api_activity> {
return _api.operation;
}

size_t hash() const final { return std::hash<api_activity>()(*this); }

friend inline void rjson_serialize(
::json::Writer<::json::StringBuffer>& w, const api_activity& a) {
w.StartObject();
Expand Down Expand Up @@ -308,10 +306,6 @@ class application_lifecycle final
activity_id _activity_id;
product _app;

size_t hash() const final {
return std::hash<application_lifecycle>()(*this);
}

friend inline void rjson_serialize(
::json::Writer<::json::StringBuffer>& w, const application_lifecycle& a) {
w.StartObject();
Expand Down
2 changes: 0 additions & 2 deletions src/v/security/audit/schemas/iam.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class authentication final : public ocsf_base_event<authentication> {

ss::sstring api_info() const final { return _user.name; }

size_t hash() const final { return std::hash<authentication>()(*this); }

friend inline void rjson_serialize(
::json::Writer<::json::StringBuffer>& w, const authentication& a) {
w.StartObject();
Expand Down
21 changes: 0 additions & 21 deletions src/v/security/audit/schemas/schemas.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ocsf_base_impl {

virtual ss::sstring api_info() const = 0;
virtual ss::sstring to_json() const = 0;
virtual size_t key() const noexcept = 0;
virtual size_t estimated_size() const noexcept = 0;
virtual void increment(timestamp_t) const = 0;
virtual category_uid get_category_uid() const = 0;
Expand All @@ -74,13 +73,6 @@ class ocsf_base_event : public ocsf_base_impl {

ss::sstring api_info() const override { return ""; }

size_t key() const noexcept final {
size_t h = 0;
boost::hash_combine(h, this->hash());
boost::hash_combine(h, this->base_hash());
return h;
}

ss::sstring to_json() const final {
return ::security::audit::rjson_serialize(
*(static_cast<const Derived*>(this)));
Expand Down Expand Up @@ -135,8 +127,6 @@ class ocsf_base_event : public ocsf_base_impl {
config::node().node_id().value_or(model::node_id{0}));
}

virtual size_t hash() const = 0;

void rjson_serialize(::json::Writer<::json::StringBuffer>& w) const {
w.Key("category_uid");
::json::rjson_serialize(w, _category_uid);
Expand Down Expand Up @@ -179,17 +169,6 @@ class ocsf_base_event : public ocsf_base_impl {
timestamp_t _time;
type_uid _type_uid;

size_t base_hash() const {
size_t h = 0;
boost::hash_combine(h, std::hash<category_uid>()(_category_uid));
boost::hash_combine(h, std::hash<class_uid>()(_class_uid));
boost::hash_combine(h, std::hash<metadata>()(_metadata));
boost::hash_combine(h, std::hash<severity_id>()(_severity_id));
boost::hash_combine(h, std::hash<type_uid>()(_type_uid));

return h;
}

/// Method to estimate the size of an ocsf message
///
/// This works by iterating on the fields within the tuple returned by the
Expand Down
216 changes: 0 additions & 216 deletions src/v/security/audit/schemas/tests/ocsf_schemas_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,222 +483,6 @@ BOOST_AUTO_TEST_CASE(validate_increment) {
BOOST_REQUIRE_EQUAL(ser, ::json::minify(expected));
}

BOOST_AUTO_TEST_CASE(validate_api_activity_hash) {
{
size_t hash1 = 0, hash2 = 0;
{
auto dst_endpoint = rp_kafka_endpoint;
auto src_endpoint = client_kafka_endpoint;
auto now = sa::timestamp_t{1};
auto api_act = sa::api_activity{
sa::api_activity::activity_id::create,
sa::actor{
.authorizations = {authz_success}, .user = default_user},
sa::api{api_create_topic},
std::move(dst_endpoint),
test_http_request(),
{resource_detail},
sa::severity_id::informational,
std::move(src_endpoint),
sa::api_activity::status_id::success,
now,
sa::api_activity_unmapped{unmapped}};
hash1 = api_act.key();
}
{
auto dst_endpoint = rp_kafka_endpoint;
auto src_endpoint = client_kafka_endpoint;
std::vector<sa::resource_detail> resources{resource_detail};
auto now = sa::timestamp_t{2};
auto api_act = sa::api_activity{
sa::api_activity::activity_id::create,
sa::actor{
.authorizations = {authz_success}, .user = default_user},
sa::api{api_create_topic},
std::move(dst_endpoint),
test_http_request(),
{resource_detail},
sa::severity_id::informational,
std::move(src_endpoint),
sa::api_activity::status_id::success,
now,
sa::api_activity_unmapped{unmapped}};
hash2 = api_act.key();
// Should expect that incrementing does _not_ change the value
// of the hash
api_act.increment(now);
BOOST_REQUIRE_EQUAL(api_act.key(), hash2);
}
// Two items should be the same even if their creation time is
// different
BOOST_CHECK_EQUAL(hash1, hash2);
}

{
size_t hash1 = 0, hash2 = 0;
{
auto dst_endpoint = rp_kafka_endpoint;
auto src_endpoint = client_kafka_endpoint;
auto now = sa::timestamp_t{3};
auto api_act = sa::api_activity{
sa::api_activity::activity_id::create,
sa::actor{
.authorizations = {authz_success}, .user = default_user},
sa::api{api_create_topic},
std::move(dst_endpoint),
test_http_request(),
{resource_detail},
sa::severity_id::informational,
std::move(src_endpoint),
sa::api_activity::status_id::success,
now,
sa::api_activity_unmapped{unmapped}};
hash1 = api_act.key();
}
{
auto dst_endpoint = rp_kafka_endpoint;
auto src_endpoint = client_kafka_endpoint;
auto now = sa::timestamp_t{4};
auto api_act = sa::api_activity{
sa::api_activity::activity_id::create,
sa::actor{
.authorizations = {authz_success}, .user = default_user},
sa::api{api_create_topic},
std::move(dst_endpoint),
std::nullopt,
{resource_detail},
sa::severity_id::informational,
std::move(src_endpoint),
sa::api_activity::status_id::success,
now,
sa::api_activity_unmapped{unmapped}};
hash2 = api_act.key();
// Should expect that incrementing does _not_ change the value
// of the hash
api_act.increment(now);
BOOST_REQUIRE_EQUAL(api_act.key(), hash2);
}
BOOST_REQUIRE_NE(hash1, hash2);
}
}

BOOST_AUTO_TEST_CASE(validate_application_lifecycle_hash) {
size_t hash1 = 0, hash2 = 0;

// validate that timestamp has no effect
{
auto app_lifecycle1 = sa::application_lifecycle(
sa::application_lifecycle::activity_id::start,
sa::product{test_product},
sa::severity_id::informational,
sa::timestamp_t{1});

auto app_lifecycle2 = sa::application_lifecycle(
sa::application_lifecycle::activity_id::start,
sa::product{test_product},
sa::severity_id::informational,
sa::timestamp_t{2});

hash1 = app_lifecycle1.key();
hash2 = app_lifecycle2.key();

BOOST_REQUIRE_EQUAL(hash1, hash2);

app_lifecycle1.increment(sa::timestamp_t{3});

BOOST_REQUIRE_EQUAL(hash1, app_lifecycle1.key());
}

// Validate that a change in activity results in a different hash
{
auto app_lifecycle1 = sa::application_lifecycle(
sa::application_lifecycle::activity_id::start,
sa::product{test_product},
sa::severity_id::informational,
sa::timestamp_t{1});
auto app_lifecycle2 = sa::application_lifecycle(
sa::application_lifecycle::activity_id::stop,
sa::product{test_product},
sa::severity_id::informational,
sa::timestamp_t{1});

BOOST_REQUIRE_NE(app_lifecycle1.key(), app_lifecycle2.key());
}
}

BOOST_AUTO_TEST_CASE(validate_authn_hash) {
// validate that timestamp has no effect
{
auto authn1 = sa::authentication(
sa::authentication::activity_id::logon,
"SCRAM-SHA256",
rp_kafka_endpoint,
sa::authentication::used_cleartext::no,
sa::authentication::used_mfa::no,
client_kafka_endpoint,
test_service,
sa::severity_id::informational,
sa::authentication::status_id::success,
std::nullopt,
sa::timestamp_t{1},
sa::user{default_user});
auto authn2 = sa::authentication(
sa::authentication::activity_id::logon,
"SCRAM-SHA256",
rp_kafka_endpoint,
sa::authentication::used_cleartext::no,
sa::authentication::used_mfa::no,
client_kafka_endpoint,
test_service,
sa::severity_id::informational,
sa::authentication::status_id::success,
std::nullopt,
sa::timestamp_t{2},
sa::user{default_user});

auto hash1 = authn1.key();
auto hash2 = authn2.key();

BOOST_REQUIRE_EQUAL(hash1, hash2);

authn1.increment(sa::timestamp_t{3});

BOOST_REQUIRE_EQUAL(hash1, authn1.key());
}

// validate that changing the authn type results in a different hash
{
auto authn1 = sa::authentication(
sa::authentication::activity_id::logon,
sa::authentication::auth_protocol_id::kerberos,
rp_kafka_endpoint,
sa::authentication::used_cleartext::no,
sa::authentication::used_mfa::no,
client_kafka_endpoint,
test_service,
sa::severity_id::informational,
sa::authentication::status_id::failure,
"Failure",
sa::timestamp_t{1},
sa::user{default_user});
auto authn2 = sa::authentication(
sa::authentication::activity_id::logon,
"SCRAM-SHA256",
rp_kafka_endpoint,
sa::authentication::used_cleartext::no,
sa::authentication::used_mfa::no,
client_kafka_endpoint,
test_service,
sa::severity_id::informational,
sa::authentication::status_id::failure,
"Failure",
sa::timestamp_t{2},
sa::user{default_user});

BOOST_REQUIRE_NE(authn1.key(), authn2.key());
}
}

BOOST_AUTO_TEST_CASE(make_api_activity_event_authorized) {
const ss::socket_address client_addr{ss::ipv4_addr("10.0.0.1", 12345)};
const ss::socket_address server_addr{ss::ipv4_addr("10.1.1.1", 23456)};
Expand Down
41 changes: 0 additions & 41 deletions src/v/security/audit/schemas/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,44 +610,3 @@ inline void rjson_serialize(Writer<StringBuffer>& w, const sa::cloud& c) {
w.EndObject();
}
} // namespace json

namespace std {

namespace sa = security::audit;

template<typename T>
struct hash<std::vector<T>> {
size_t operator()(const std::vector<T>& v) const {
size_t h = 0;
for (const auto& val : v) {
boost::hash_combine(h, std::hash<T>()(val));
}

return h;
}
};

template<typename T>
struct hash<ss::bool_class<T>> {
size_t operator()(const ss::bool_class<T>& val) const {
size_t h = 0;
boost::hash_combine(h, std::hash<bool>()(bool(val)));
return h;
}
};

template<sa::has_equality_fields T>
struct hash<T> {
size_t operator()(const T& val) const {
size_t h = 0;
std::apply(
[&h](const auto&... arg) {
(boost::hash_combine(
h, std::hash<std::remove_cvref_t<decltype(arg)>>()(arg)),
...);
},
val.equality_fields());
return h;
}
};
} // namespace std

0 comments on commit d69f7f5

Please sign in to comment.