Repository navigation
Feat/admin audit logging #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GhassenKefi
wants to merge
4
commits into
main
Choose a base branch
from
feat/admin-audit-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,040
−26
Open
Feat/admin audit logging #1130
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
23e7251
feat(daemons): log deploy daemon changes to the audit log
GhassenKefi a8db189
feat(exapps): log the ExApp lifecycle to the audit log
GhassenKefi 1fb786d
feat(settings): log AppAPI admin settings changes to the audit log
GhassenKefi c02350b
feat(auth): log failed AppAPI authentication to the audit log
GhassenKefi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\AppAPI\AuditLog; | ||
|
|
||
| use OCP\EventDispatcher\IEventDispatcher; | ||
| use OCP\Log\Audit\CriticalActionPerformedEvent; | ||
|
|
||
| /** | ||
| * Writes entries to the admin audit log | ||
| */ | ||
| class AuditLogger { | ||
| public function __construct( | ||
| private readonly IEventDispatcher $eventDispatcher, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * The operation is only passed on to servers whose CriticalActionPerformedEvent supports it | ||
| * | ||
| * @param string $message message with a `%s` placeholder for each of the first parameters | ||
| * @param array<string, mixed> $parameters named values for the placeholders of $message, in order, optionally followed by more context | ||
| */ | ||
| public function log(Operation $operation, string $message, array $parameters = []): void { | ||
| $arguments = [$message, $parameters, false]; | ||
| if (method_exists(CriticalActionPerformedEvent::class, 'getOperation')) { | ||
| $arguments[] = $operation->value; | ||
| } | ||
| $this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(...$arguments)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\AppAPI\AuditLog; | ||
|
|
||
| /** | ||
| * Operations AppAPI writes to the admin audit log, in the form `app.entity.action` | ||
| * | ||
| * The values are matched by log consumers (filters, alert rules, SIEM imports), | ||
| * so changing one is a breaking change for them. Case names may be renamed. | ||
| */ | ||
| enum Operation: string { | ||
| // ExApps | ||
| case ExAppRegistered = 'app_api.ex_app.registered'; | ||
| case ExAppUpdated = 'app_api.ex_app.updated'; | ||
| case ExAppEnabled = 'app_api.ex_app.enabled'; | ||
| case ExAppDisabled = 'app_api.ex_app.disabled'; | ||
| case ExAppUnregistered = 'app_api.ex_app.unregistered'; | ||
| case ExAppDataDeleted = 'app_api.ex_app_data.deleted'; | ||
| case ExAppAuthFailed = 'app_api.ex_app_auth.failed'; | ||
|
|
||
| // Deploy daemons | ||
| case DaemonRegistered = 'app_api.daemon.registered'; | ||
| case DaemonUpdated = 'app_api.daemon.updated'; | ||
| case DaemonUnregistered = 'app_api.daemon.unregistered'; | ||
| case DaemonRegistryAdded = 'app_api.daemon_registry.added'; | ||
| case DaemonRegistryRemoved = 'app_api.daemon_registry.removed'; | ||
|
|
||
| // Settings | ||
| case AdminConfigUpdated = 'app_api.admin_config.updated'; | ||
|
|
||
| /** | ||
| * Short description of when the operation is logged, used for the documentation | ||
| */ | ||
| public function description(): string { | ||
| return match ($this) { | ||
| self::ExAppRegistered => 'An ExApp was registered and given its secret to authenticate to Nextcloud, before its deployment', | ||
| self::ExAppUpdated => 'An ExApp was switched to a new version, before the deployment of that version', | ||
| self::ExAppEnabled => 'An ExApp was enabled and started', | ||
| self::ExAppDisabled => 'An ExApp was disabled', | ||
| self::ExAppUnregistered => 'An ExApp was removed together with everything it had registered', | ||
| self::ExAppDataDeleted => 'The data volume of an ExApp was deleted on its deploy daemon', | ||
| self::ExAppAuthFailed => 'A request with AppAPI authentication was rejected for an unknown ExApp or a wrong secret', | ||
| self::DaemonRegistered => 'A deploy daemon that ExApps can be installed on was registered', | ||
| self::DaemonUpdated => 'The configuration of a deploy daemon was changed', | ||
| self::DaemonUnregistered => 'A deploy daemon was unregistered', | ||
| self::DaemonRegistryAdded => 'A deploy daemon was set to pull the images of a Docker registry from another registry', | ||
| self::DaemonRegistryRemoved => 'A Docker registry mapping was removed from a deploy daemon', | ||
| self::AdminConfigUpdated => 'An AppAPI admin setting, such as the default deploy daemon, was changed', | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: nextcloud/app_api
Length of output: 3870
🏁 Script executed:
Repository: nextcloud/app_api
Length of output: 41766
🏁 Script executed:
Repository: nextcloud/app_api
Length of output: 1683
Preserve additional audit context in the written log entry.
On Nextcloud 35,
admin_auditpasses all parameters tovsprintf(), but persists only formatted placeholders and{name}context fields. Extra values can disappear from the audit entry.Current callers pass extra values such as
reason,acceptsDeployId,host,secretChanged, andport. Include each audit-relevant value in its message, or use a logging path that persists additional context.