plugins: os-sftp-backup does not work correctly because of identity file being created with CRLF on line ends
Important notices Before you add a new report, we ask you kindly to acknowledge the following:
- I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
- I have searched the existing issues, open and closed, and I’m convinced that mine is new.
- The title contains the plugin to which this issue belongs
Describe the bug
When a backup configuration is created and setup/test configuration is pressed, an error message is shown:
The following input errors were detected:
Load key "/conf/backup/sftp/identity": error in libcrypto opnsense@blob: Permission denied (publickey,keyboard-interactive).
Connection closed
Saved settings, but remote backup failed.
Tip: to validate your setup was working with the previous version, use opnsense-revert (https://docs.opnsense.org/manual/opnsense_tools.html#opnsense-revert)
To Reproduce
Create a backup configuration and press “setup/test configuration”.
Expected behavior
The backup should be created.
Screenshots
Relevant log files
Additional context
To verify that the permissions were indeed the culprit, I tried two things:
-
I called “/usr/local/bin/sftp -o StrictHostKeyChecking=accept-new -o PasswordAuthentication=no -o ChallengeResponseAuthentication=no -i /conf/backup/sftp/identity sftp://opnsense@blob:3000//backup/opnsense” directly from CLI, which works nicely, given that I am root and can access the identity file. I could browse the directory and create files there.
-
I changed the permissions of /conf/backup/sftp/identity to something more open with “chmod 640 /conf/backup/sftp/identity” and reapplied the “test/setup” button. The error then given was:
The following input errors were detected:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/conf/backup/sftp/identity' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "/conf/backup/sftp/identity": bad permissions opnsense@blob: Permission denied (publickey,keyboard-interactive). Connection closed
Saved settings, but remote backup failed.
This leads me to believe that the identity file is correct, but the permissions are either too prohibitive or too open. Maybe the php script is executed with another user’s permissions? The identity file itself is created as “root:wheel”.
Environment OPNsense 25.1.3 (amd64).
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 17 (15 by maintainers)
Commits related to this issue
- Update Sftp.php Remove errorneous CRLF line endings and replace with LF. See issue https://github.com/opnsense/plugins/issues/4582. — committed to meyergru/plugins by meyergru 2 years ago
- sysutils/sftp-backup : remove carriage return for windows users and possible excess line endings, closes https://github.com/opnsense/plugins/issues/4582 — committed to tank0226/opnsense-plugins by AdSchellevis 2 years ago
- sysutils/sftp-backup : fix identity comparison for https://github.com/opnsense/plugins/issues/4582 — committed to opnsense/plugins by AdSchellevis 2 years ago
I’ll push a hotfix in a bit.
@rkubes fixed in https://github.com/opnsense/plugins/commit/50c9cb095a04c05f83367c2922ecdea0d79aa8d4 ?
@rkubes it’s not a huge deal to flush it again, but you are right indeed. I’ll change it for the next version
I just created a pull request that fixes the problem by removing the CRs.
Wow. It is whitespace at the end of each line of the created identity file that is causing trouble,
I copied the private key into the textarea and the resulting file, upon inspection with VI showed “^M” at the end of each line.
When I delete those whitespace characters manually, I can immediately use the identify file from the CLI, but I cannot enter the content into the textarea without producing those “^M” line ends. Any time I press “setup/test”, the file is being re-created.
I am using Firefox for this and also tried Chrome and Opera (all under Windows 11). I even tried inputting the lines one-by-one.
I can see on each line end in the <privkey> in config.xml. That is the same, BTW, with the privkey for os-git-backup, but that seems less picky about it.