Skip to content

audit log: record the versions the revision cleanup deletes #4068

Description

@pbleser-oc

Is your feature request related to a problem? Please describe.

The revision cleanup (#1419, opencloud-eu/reva#895, #3778) deletes old versions of files according to a strategy: automatically whenever a file gets a new version, and on demand with opencloud storage-users revisions cleanup. The deleted versions are gone for good.

The audit log doesn't record any of this. When a user asks where the version of a document from March went, an administrator finds nothing in the audit log: no entry says that it was deleted, when, by which strategy, or because of which upload. The server only logs each deleted version at debug level, and the metrics only count totals.

That is unlike the trash: purging it is audited (file_trash_delete), and so is restoring a version (file_version_restore). The automatic case matters most, as no person decided about that particular file: an administrator set a strategy, a user saved the file, and older versions disappeared.

The reason is technical: the audit service logs the events it receives, and most of them are published by reva for the requests users make. The cleanup deletes versions inside the storage driver, not through such a request, so no event is published. AuditEventFileVersionDeleted exists in services/audit/pkg/types/types.go, with the comment "TODO: is this even possible?", but nothing uses it.

Describe the solution you'd like

An audit entry for every file whose versions the cleanup deleted:

  • one entry per file, not per version: a cleanup with --all, or with the strategy 0, can delete thousands of versions. The entry lists the deleted versions (their dates), how many, and the bytes freed. No entry for files where nothing was deleted, and none for dry runs.
  • why: the strategy, and what triggered the cleanup: an upload, a restore, a change on disk (posix), or the command.
  • who: the user whose upload or restore triggered the automatic cleanup, if there is one. Entries of the command are marked as such (the audit entries already have a CLI flag and users like "CLI").

How it could be built:

  • reva: a new event, published by the revision cleanup after a cleanup (not a dry run) that deleted something, through the event stream of the storage driver. It carries the resource id, the space owner, the path, the deleted revisions, the bytes, the strategy, the trigger and the executant.
  • the command: it runs the storage driver in a process of its own. With posix it already sets up an event stream, with decomposed it would need one too.
  • audit service: subscribe to the new event and log it as AuditEventFileVersionDeleted, extended with the fields above, with an action like file_version_delete and a message.
  • delivery: best effort, like all events: if publishing fails, it is logged, and the versions are still deleted.

Describe alternatives you've considered

  • One entry per deleted version: closer to the existing per-file entries, but a single cleanup can produce thousands of entries for one file.
  • Logging the deletions in the server log at info level instead: no extra event, but the server log is not where audit entries are collected, and the command's output is not kept anywhere by default.

Additional context

Follow-up of #1419, like #3733 and #3734. Needs a reva PR (the event) and an opencloud PR (the audit service, and the event stream of the command).

AI assistance: Claude Code (claude-opus-5-5) looked into how the audit service gets its events and wrote the first draft of this issue.

Activity

  1. pbleser-oc commented on Nov 25, 2026

    @pbleser-oc
    MemberAuthor

    @micbar, now that the new audit log is almost done (opencloud-eu/reva#956, #3864), I checked this issue against it, so that I can build it on your package rather than next to it.

    Most of it fits: the catalog already has file.version.delete (F014), the actor types include system and cli, and change.before / change.after have room for the details. One part doesn't, and it may matter before your PRs are merged:

    Who emits the record. In your design, the records come from the events middleware after a CS3 call, and from the data provider. Storage drivers only report the item of a call. The revision cleanup deletes versions inside the storage driver, without a CS3 call of its own:

    • in a background worker after an upload or a restore, without the request context,
    • after a change on disk with posix,
    • in opencloud storage-users revisions cleanup, which runs the driver in a process of its own.

    No middleware sees any of these. The audit settings of storage-users only go to the middleware and the data provider, not to the driver. So the driver would need an emitter of its own (audit.EmitterFromConfig with the driver's events config), which would mean passing the audit settings to the driver too. Would that be fine with you, or would you rather have it go another way?

    A few smaller questions, where I'd follow your lead:

    1. Actor of an automatic cleanup. It is triggered by a user's upload, but done by OpenCloud according to the administrator's strategy, often later in a worker. I'd use system, and name the user whose upload triggered it in change. Or would you rather have the user as the actor?
    2. One record per file or per version. One cleanup can delete thousands of versions of a file (with --all, or with the strategy 0). I'd write one file.version.delete per file, with the target being the file, and the deleted versions, their number and the bytes freed in change.before. One record per version would fit "the target is the object" better, but could flood the log.
    3. The command. Actor cli for the records of opencloud storage-users revisions cleanup? And cli.command for the command itself, once that event is emitted?
    4. Who does it. I'd do it here after your PRs are merged, unless you'd like to have it in your next part.

    AI assistance: Claude Code (claude-opus-5-5) compared this issue with the audit PRs and wrote the first draft of this comment; I reviewed it.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions