diff options
author | Varun Ravichandran <varun.ravichandran@mongodb.com> | 2021-01-23 00:31:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-03 17:03:23 +0000 |
commit | 952042b7e54148c3b9875ba5aa31a6a2adaf3af9 (patch) | |
tree | ee0901002e9adb92db287e33cb4f1143c35195fb /src/mongo | |
parent | 780295a9322938abbb1c5f9abbb2b22a4f707357 (diff) | |
download | mongo-952042b7e54148c3b9875ba5aa31a6a2adaf3af9.tar.gz |
SERVER-50993: Audit dropCollection for views
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/audit.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/audit.h | 11 | ||||
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 17 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/mongo/db/audit.cpp b/src/mongo/db/audit.cpp index c4880a92727..43eadc2954c 100644 --- a/src/mongo/db/audit.cpp +++ b/src/mongo/db/audit.cpp @@ -169,6 +169,12 @@ void mongo::audit::logDropIndex(Client* client, StringData indexname, StringData void mongo::audit::logDropCollection(Client* client, StringData nsname) {} +void mongo::audit::logDropView(Client* client, + StringData nsname, + StringData viewOn, + const std::vector<BSONObj>& pipeline, + ErrorCodes::Error code) {} + void mongo::audit::logDropDatabase(Client* client, StringData dbname) {} void mongo::audit::logRenameCollection(Client* client, StringData source, StringData target) {} diff --git a/src/mongo/db/audit.h b/src/mongo/db/audit.h index c01619ed580..5e2c0d633e5 100644 --- a/src/mongo/db/audit.h +++ b/src/mongo/db/audit.h @@ -308,11 +308,20 @@ void logCreateDatabase(Client* client, StringData dbname); void logDropIndex(Client* client, StringData indexname, StringData nsname); /** - * Logs the result of a dropCollection command. + * Logs the result of a dropCollection command on a collection. */ void logDropCollection(Client* client, StringData nsname); /** + * Logs the result of a dropCollection command on a view. + */ +void logDropView(Client* client, + StringData nsname, + StringData viewOn, + const std::vector<BSONObj>& pipeline, + ErrorCodes::Error code); + +/** * Logs the result of a dropDatabase command. */ void logDropDatabase(Client* client, StringData dbname); diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 80584fb0e6d..fbcd3b19919 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -33,6 +33,7 @@ #include "mongo/db/catalog/drop_collection.h" +#include "mongo/db/audit.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/uncommitted_collections.h" #include "mongo/db/client.h" @@ -74,12 +75,16 @@ Status _dropView(OperationContext* opCtx, DropReply* reply, bool clearBucketCatalog = false) { if (!db) { - return Status(ErrorCodes::NamespaceNotFound, "ns not found"); + Status status = Status(ErrorCodes::NamespaceNotFound, "ns not found"); + audit::logDropView(&cc(), collectionName.ns(), "", {}, status.code()); + return status; } auto view = ViewCatalog::get(db)->lookupWithoutValidatingDurableViews(opCtx, collectionName.ns()); if (!view) { - return Status(ErrorCodes::NamespaceNotFound, "ns not found"); + Status status = Status(ErrorCodes::NamespaceNotFound, "ns not found"); + audit::logDropView(&cc(), collectionName.ns(), "", {}, status.code()); + return status; } // Validates the view or throws an "invalid view" error. @@ -110,6 +115,10 @@ Status _dropView(OperationContext* opCtx, } WriteUnitOfWork wunit(opCtx); + + audit::logDropView( + &cc(), collectionName.ns(), view->viewOn().ns(), view->pipeline(), ErrorCodes::OK); + Status status = db->dropView(opCtx, collectionName); if (!status.isOK()) { return status; @@ -325,7 +334,9 @@ Status dropCollection(OperationContext* opCtx, auto view = ViewCatalog::get(db)->lookupWithoutValidatingDurableViews( opCtx, collectionName.ns()); if (!view) { - return Status(ErrorCodes::NamespaceNotFound, "ns not found"); + Status status = Status(ErrorCodes::NamespaceNotFound, "ns not found"); + audit::logDropView(&cc(), collectionName.ns(), "", {}, status.code()); + return status; } if (!view->timeseries()) { |