Skip to content
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

feat: only load available commands in maintenance mode #37178

Closed
wants to merge 1 commit into from

Conversation

kesselb
Copy link
Contributor

@kesselb kesselb commented Mar 10, 2023

  • Resolves: #

Summary

Nextcloud is in maintenance mode, hence the database isn't accessible.
Cannot perform any command except 'maintenance:mode --off'

In maintenance mode, the above message is printed for every command.
A customer brought to our attention that the message is misleading.

"isn't accessible" is a simplified statement.
Technically, the database is accessible, but it's probably unsafe to run commands that modify the system.

server/lib/base.php

Lines 1032 to 1053 in bb4b34f

// Always load authentication apps
OC_App::loadApps(['authentication']);
OC_App::loadApps(['extended_authentication']);
// Load minimum set of apps
if (!\OCP\Util::needUpgrade()
&& !((bool) $systemConfig->getValue('maintenance', false))) {
// For logged-in users: Load everything
if (Server::get(IUserSession::class)->isLoggedIn()) {
OC_App::loadApps();
} else {
// For guests: Load only filesystem and logging
OC_App::loadApps(['filesystem', 'logging']);
// Don't try to login when a client is trying to get a OAuth token.
// OAuth needs to support basic auth too, so the login is not valid
// inside Nextcloud and the Login exception would ruin it.
if ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') {
self::handleLogin($request);
}
}
}

if (\OCP\Util::needUpgrade()) {
throw new NeedsUpdateException();
} elseif ($this->config->getSystemValueBool('maintenance')) {
$this->writeMaintenanceModeInfo($input, $output);
} else {
OC_App::loadApps();

In maintenance mode, only a minimum set of apps is loaded.

The commands available in maintenance mode are mainly related to system operations.
It's fine and for some even recommended to run those commands in maintenance mode.

However, some commands are difficult:

Just to name some examples.

My thought is, if we already know that a command is potentially unsafe, we should prevent the execution.

TODO

  • Make interface public
  • Rename IAvailableInMaintenanceMode to IUnavailableInMaintenanceMode (and flip the logic)

Checklist

@szaimen szaimen added this to the Nextcloud 27 milestone Mar 11, 2023
@szaimen szaimen added the 2. developing Work in progress label Mar 11, 2023
* Implement if a core command is available in maintenance mode.
*
* A core command is a command registered in core/register_command.php.
* Don't implement the interface if the command is registered in IBootstrap or info.xml
Copy link
Member

Choose a reason for hiding this comment

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

Why not? Talk has commands that could be run while maintenance is on?
Similar for files and others, maybe an admin restored a folder from a backup and wants to run file scan before sync clients interfere?
support:system-report, transfer-ownership, user-migration and others are also good examples for commands that could (maybe even should) be run in maintenance-mode.
As mentioned in #37365 also all the db:* commands are recommended to run in maintenance mode.

Copy link
Member

Choose a reason for hiding this comment

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

I would even argue to default to "is available in maintenance mode" and have commands opt out of it.
But at the same time I would not know which command I would opt-out of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

I updated the pull request description to add some more context.

To opt out is indeed much better than opt in here. Most commands in register_commands.php are okay to run in maintenance mode.

*
*/

namespace OC\Console;
Copy link
Member

Choose a reason for hiding this comment

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

Should definitely be in OCP for better usage.

violethaze74

This comment was marked as spam.

@kesselb kesselb force-pushed the feat-add-iavaialble-in-maintenance-mode branch 2 times, most recently from a2e623a to 22c6c28 Compare April 24, 2023 15:32
* @return Command|null The registered command if enabled or null
*/
public function add(Command $command) {
if ($this->maintenanceMode && in_array(IUnavailableInMaintenanceMode::class, class_implements($command, false))) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ($this->maintenanceMode && in_array(IUnavailableInMaintenanceMode::class, class_implements($command, false))) {
if ($this->maintenanceMode && $command instanceof IUnavailableInMaintenanceMode) {

???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your puzzlement ;)

class_implements is a leftover from an experiment. My idea was to change Command to Command|string and use the dependency injection to build the class when a string is given to clean up register_command.php a bit.

Will use instanceof for now and submit another pr sometime for the dependency injection feature.

Copy link
Member

Choose a reason for hiding this comment

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

Can't find any changes apart from s/$application/$this/ correct?
The new interface is not being added anywhere (totally okay, just asking)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep.

@kesselb kesselb force-pushed the feat-add-iavaialble-in-maintenance-mode branch 2 times, most recently from 8edc702 to ae9457d Compare April 24, 2023 16:39
@kesselb kesselb force-pushed the feat-add-iavaialble-in-maintenance-mode branch from ae9457d to 0f32ed8 Compare April 24, 2023 18:29
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb kesselb force-pushed the feat-add-iavaialble-in-maintenance-mode branch from 0f32ed8 to 19ddc24 Compare April 24, 2023 18:36
@nickvergessen
Copy link
Member

In maintenance mode, only a minimum set of apps is loaded.

So if that is the reason, I would change the other half and also make sure to load all apps in CLI?
I would find it quite disturbing to not be able to prepopulate and manage an instance during maintenance mode.

Since we are approaching the next deadline in light speed maybe we can merge the interface and Application change in a single PR and discuss the implementing this quite restrictive behaviour in another one.

@kesselb kesselb modified the milestones: Nextcloud 27, Nextcloud 28 Apr 24, 2023
@kesselb
Copy link
Contributor Author

kesselb commented Apr 24, 2023

So if that is the reason, I would change the other half and also make sure to load all apps in CLI?

As reference:

owncloud/core#20939
owncloud/core#21076

I would find it quite disturbing to not be able to prepopulate and manage an instance during maintenance mode.

You put your instance in maintenance mode to delete a user 🤔

Since we are approaching the next deadline in light speed maybe we can merge the interface and Application change in a single PR and discuss the implementing this quite restrictive behaviour in another one.

I see your concern, we don't need to rush. Let's continue the work on this feature when 27 is done.

My next task is to update the documentation: nextcloud/documentation#10063

@kesselb kesselb removed this from the Nextcloud 28 milestone Apr 24, 2023
@kesselb kesselb self-assigned this Apr 24, 2023
@blizzz blizzz added this to the Nextcloud 29 milestone Nov 23, 2023
This was referenced Mar 12, 2024
@Altahrim Altahrim mentioned this pull request Mar 20, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
@skjnldsv skjnldsv closed this Aug 14, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 31 milestone Aug 14, 2024
@skjnldsv skjnldsv deleted the feat-add-iavaialble-in-maintenance-mode branch August 30, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants