Repository navigation
feat: expand 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
Merged
Merged
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,34 @@ | ||
| <?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, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @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 { | ||
| // The logger replaces `{placeholders}` in the message and admin_audit formats it again, so values are escaped here | ||
| $values = array_map(static fn (mixed $value): mixed => is_string($value) ? strtr($value, ['{' => '(', '}' => ')']) : $value, array_values($parameters)); | ||
| $message = str_replace('%', '%%', vsprintf($message, $values)); | ||
| $this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent($message, $parameters, false, $operation->value)); | ||
| } | ||
| } | ||
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,65 @@ | ||
| <?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; log consumers match the values, so they never change | ||
| */ | ||
| enum Operation: string { | ||
| // ExApps | ||
| case ExAppInstallRequested = 'app_api.ex_app.install_requested'; | ||
| case ExAppRegistered = 'app_api.ex_app.registered'; | ||
| case ExAppUpdateRequested = 'app_api.ex_app.update_requested'; | ||
| case ExAppUpdated = 'app_api.ex_app.updated'; | ||
| case ExAppEnabled = 'app_api.ex_app.enabled'; | ||
| case ExAppDisabled = 'app_api.ex_app.disabled'; | ||
| case ExAppUninstallRequested = 'app_api.ex_app.uninstall_requested'; | ||
| case ExAppUnregistered = 'app_api.ex_app.unregistered'; | ||
| case ExAppDataDeleted = 'app_api.ex_app_data.deleted'; | ||
| case ExAppAuthFailed = 'app_api.ex_app_auth.failed'; | ||
| case HarpAuthFailed = 'app_api.harp_auth.failed'; | ||
| case TalkBotAuthFailed = 'app_api.talk_bot_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::ExAppInstallRequested => 'The installation of an ExApp was started in the web interface, with the names of its environment variables and its mounts', | ||
| self::ExAppRegistered => 'An ExApp was registered and given its secret to authenticate to Nextcloud, before its deployment', | ||
| self::ExAppUpdateRequested => 'The update of an ExApp was started in the web interface', | ||
| self::ExAppUpdated => 'The version of an ExApp changed, at an update before the deployment of that version, or when the ExApp reported a newer one', | ||
| self::ExAppEnabled => 'An ExApp was enabled and started', | ||
| self::ExAppDisabled => 'An ExApp was disabled', | ||
| self::ExAppUninstallRequested => 'The removal of the test deploy ExApp was started in the deploy daemon settings', | ||
| self::ExAppUnregistered => 'An ExApp was removed from Nextcloud', | ||
| self::ExAppDataDeleted => 'The deploy daemon confirmed that the data volume of an ExApp is removed', | ||
| self::ExAppAuthFailed => 'A request with AppAPI authentication was rejected for an unknown ExApp or a wrong secret', | ||
| self::HarpAuthFailed => 'A request made as HaRP was rejected for a missing or wrong shared key, logged with the user whose request HaRP forwarded', | ||
| self::TalkBotAuthFailed => 'A message for the Talk bot of an ExApp was rejected for a wrong signature', | ||
| 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 Docker registry mapping was added to a deploy daemon', | ||
| 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 or removed', | ||
| }; | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.