Skip to content

[RFC] add audit logging APIs - #66946

Closed
dparmar18 wants to merge 8 commits into
ceph:mainfrom
dparmar18:i71849
Closed

dparmar18 wants to merge 8 commits into
ceph:mainfrom
dparmar18:i71849

Conversation

@dparmar18

@dparmar18 dparmar18 commented Jan 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces APIs to enable writing audit logs into DBs backed by sqlite3 (via libcephsqlite which enables a ceph VFS allowing us to decentralise the DBs using RADOS) and marks the first step towards implementing audit logging of cluster-wide commands and standalone tools, starting with CephFS: https://tracker.ceph.com/issues/62856.

A talk on this topic was presented by me and @vshankar at FOSDEM 2026 which can be referred for more information about the objective, design and architecture of the entire feature.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@dparmar18
dparmar18 force-pushed the i71849 branch 6 times, most recently from addbe40 to 66c94e5 Compare January 19, 2026 10:57
@dparmar18
dparmar18 force-pushed the i71849 branch 7 times, most recently from 7a62b3d to 6a137bb Compare March 20, 2026 12:44
@dparmar18
dparmar18 force-pushed the i71849 branch 4 times, most recently from ae41aa2 to 9823851 Compare March 27, 2026 14:34
@dparmar18
dparmar18 force-pushed the i71849 branch 7 times, most recently from bf18c77 to 059769d Compare March 30, 2026 13:34
@github-actions github-actions Bot added the mgr label Apr 1, 2026
@dparmar18
dparmar18 force-pushed the i71849 branch 7 times, most recently from de282ad to 1acbec2 Compare April 16, 2026 20:11
@dparmar18 dparmar18 changed the title [NOT FOR REVIEW] add auditdb and audit logging APIs [NOT FOR REVIEW] add audit logging APIs Apr 16, 2026
@dparmar18 dparmar18 changed the title [NOT FOR REVIEW] add audit logging APIs [RFC] add audit logging APIs Apr 16, 2026
@dparmar18
dparmar18 marked this pull request as ready for review April 16, 2026 20:33
@vshankar

Copy link
Copy Markdown
Contributor

Also see: #68384

Comment thread src/common/AuditDB.cc
"seq INTEGER PRIMARY KEY, "
"cmd TEXT NOT NULL CHECK (length(trim(cmd)) > 0), "
"init_time INTEGER NOT NULL CHECK (init_time > 0), "
// second-phase commit therefore nullable until completion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to update the original record on command completion or should that update be a separate record by itself? In either case, we need an identifier to map a completion record to its dispatch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on command completion, yes.

In either case, we need an identifier to map a completion record to its dispatch.

it will be tracked as per seq, the second_phase_commit() checks for it before commencing the update query

Comment thread src/common/AuditDB.h
row_count_mismatch,
/** `sqlite3_vfs_find("ceph")` returned null (VFS not registered) */
ceph_vfs_not_found,
/** Ceph VFS has no `xDelete` implementation */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is xDelete and is there a reason we need is a failure reason during exception handling?

@dparmar18 dparmar18 Apr 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xDelete is called by vfs to delete the underlying db file.

is there a reason we need is a failure reason during exception handling?

its good to know what failed while trying to delete a file, libcephsqlite already maps Delete() to xDelete() so chances of Ceph VFS not implementing xDelete is null but this check is more of a belt and suspenders approach

Comment thread src/common/AuditDB.h

struct AuditEntry {
int64_t seq{0};
std::string cmd;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a separate field for command arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args needs to be optional, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe i guess the daemon/tool can just mark it as blank with a {} or null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been added, cmd_args as a string.

Comment thread src/common/AuditDB.h
using sqlite3_ptr = std::unique_ptr<sqlite3, decltype(&sqlite3_close)>;

struct AuditEntry {
int64_t seq{0};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally requires the paxos version for mon audit logs (which is different than the sequence number in LogEntry). For audit logs which are not relayed via mons, this version would be 0.

Comment thread src/common/AuditDB.cc
}

// prepare phase-two statement
if (auto e = prepare_sqlite3_stmt(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How costly is an sqlite update as compared to a new row insertion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the update query makes use of seq (which is the primary key) and comp_time (which is indexed), i think the update should be same as insert

Comment thread src/common/AuditDB.cc Outdated
// state.
initialised = true;
if (auto seq = get_last_committed_seq(); seq) {
last_seq = *seq;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be (paxos) version and not sequence. Also, the version is only valid for mon audit logs, so that would need special handling here (if not done already).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering your previous comments, im assuming more changes in the functions for handling mon logs. keep adding as things come to mind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been removed

dparmar18 added 7 commits May 4, 2026 15:30
a wrapper around AuditDB, consumers just need to call create_for_tool()
or create(). Also linked it with all the cephfs tools binaries

Fixes: https://tracker.ceph.com/issues/71849
Signed-off-by: Dhairya Parmar <[email protected]>
- add struct `tee_streambuf` in MDSUtility.h as file-scope entity,
  which is used to stream errors in both std::cerr and audit db (status field)
  via a new `std::ostream err` MDSUtility member making use of the new
  struct and an std::ostringstream.

- MDSUtility is the common parent for most classes in cephfs tools
  except a few which inherit from class RecoveryDriver like
  LocalFileDriver and MetadataDriver, they have been enabled to forward a
  ref of `err` ostream from the place of call i.e. in DataScan.cc

- certain error strings and buffer::error refs in catch block
  conflicted with new std::ostream `err`; had to be changed in
  DataScan.cc

- also modularized creating and getting rados connection which is needed
  in calling ToolsAuditLogger::create_for_tool()

Fixes: https://tracker.ceph.com/issues/71849
Signed-off-by: Dhairya Parmar <[email protected]>
@dparmar18

Copy link
Copy Markdown
Contributor Author

UPDATE: With the latest commits - AuditDB integration with CephFS DR tools is complete (open for reviews!). The complete feature is obviously integration with MON (#68384) and MGR but the plan is to do a phased release with Phase-1 being AuditDB APIs + CephFS DR Tools integration + auditman mgr module (reading audit logs).

Phase-2 will do the heavy lifting of integration with MON and MGR + an upkeep thread implemented in MGR to trim logs based on a conf val.

cc @vshankar

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants