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

fix: Do not log an error when connecting to SFTP without a logged in user #45938

Conversation

danxuliu
Copy link
Member

When connecting to a SFTP server from a SFTP storage the host key is checked against the known host keys stored in a file in the data directory of the logged in Nextcloud user. The path to the file is (indirectly) got using OC_App::getStorage, which logs an error (Can't get app storage, app files_external, user not logged in) if called when there is no logged in user; this can happen, for example, if the storage is used from a background job or a command (like occ files:scan).

Not being able to read or write the file just causes the host key check to be skipped, but it has no other consequence. Moreover, even with logged in users it is likely that the file can not be read either and the check is also skipped, as the file needs to have been manually created by an admin (once created it will be updated with the host key when connecting to an SFTP server for the first time, but this will not happen unless the file was manually created first).

Due to all that now the path to the file is directly created using a View rather than relying on OC_App::getStorage to prevent the unneeded error from being logged.

Note that, in order to make it backporteable, this is just a backwards compatible* change that simply removes the error log; it does not address any of the issues mentioned in #14108

*Or, at least, it should be :-) But I am a bit lost with storages, mount points, views... so please check carefully ;-)

How to test

  • Setup a SSH server
  • Enable external storages
  • Open the external storages settings
  • Add a new SFTP storage for the SSH server
  • Run occ files:scan --all

Result with this pull request

No errors are logged

Result without this pull request

Can't get app storage, app files_external, user not logged in error is logged (several times if there are several Nextcloud users with access to the SFTP storage)

@danxuliu danxuliu added this to the Nextcloud 30 milestone Jun 18, 2024
@danxuliu danxuliu requested review from a team, ArtificialOwl, yemkareems and sorbaugh and removed request for a team June 18, 2024 04:57
@danxuliu
Copy link
Member Author

/backport to stable29

@danxuliu
Copy link
Member Author

/backport to stable28

@danxuliu danxuliu requested review from artonge and removed request for sorbaugh June 18, 2024 04:59
…user

When connecting to a SFTP server from a SFTP storage the host key is
checked against the known host keys stored in a file in the data
directory of the logged in Nextcloud user. The path to the file is
(indirectly) got using "OC_App::getStorage", which logs an error if
called when there is no logged in user; this can happen, for example, if
the storage is used from a background job or a command.

Not being able to read or write the file just causes the host key check
to be skipped, but it has no other consequence. Moreover, even with
logged in users it is likely that the file can not be read either and
the check is also skipped, as the file needs to have been manually
created by an admin.

Due to all that now the path to the file is directly created using a
View rather than relying on "OC_App::getStorage" to prevent the unneeded
error from being logged.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu danxuliu force-pushed the do-not-log-an-error-when-connecting-to-sftp-without-a-logged-in-user branch from 4329317 to 733e3f6 Compare June 18, 2024 05:07
@artonge artonge requested a review from icewind1991 June 18, 2024 08:38
@artonge artonge merged commit 0245271 into master Jun 24, 2024
166 checks passed
@artonge artonge deleted the do-not-log-an-error-when-connecting-to-sftp-without-a-logged-in-user branch June 24, 2024 08:35
@blizzz blizzz mentioned this pull request Jul 24, 2024
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.

3 participants