[pve-devel] [PATCH v2 pve-storage-plugin-examples 0/2] SSHFS Example Storage Plugin

Max R. Carrara m.carrara at proxmox.com
Fri Jul 4 18:20:09 CEST 2025


SSHFS Example Storage Plugin - v2
=================================

Add a custom storage plugin based on SSHFS [0] to serve as an example
for an upcoming storage plugin development guide. This plugin should
also be ready for production usage, though it would be nice to get some
more testing (and potentially performance-tuning) done.

Previous version: https://lore.proxmox.com/pve-devel/20250416124735.320256-1-m.carrara@proxmox.com/

Notable Changes
---------------

- incorporated feedback on v1 (thanks Thomas!)

  - private key is now passed by value instead of by path in order to
    avoid TOCTOU races
    - this still isn't perfectly ideal, but better than before

  - use a separate known_hosts file for each SSHFS storage instead of
    /etc/pve/priv/known_hosts
    - this means that /etc/pve/priv/storage/${STOREID}_known_hosts is
      now used

  - allow overwriting an existing key file that wasn't cleaned up in
    /etc/pve/priv/storage/ when creating an SSHFS storage

  - Use the StrictHostKeyChecking=accept-new SSH option to trust the
    remote on first use if connecting to it via pubkey auth succeeds

- minor code cleanup & readability improvements here and there
- format via perltidy w/ our custom profile

How to Use & Test
-----------------

(updated because of changes to parameters)

You'll need some kind guest you can SSH into with pubkey auth.
On that host, it's best to create some directory for SSHFS, e.g.:

    mkdir -p /srv/sshfs && chmod 750 /srv/sshfs

The plugin can easily be built via `make deb` inside
`plugin-sshfs/`. Once built and installed on a different PVE host
of your choice, you should first deploy a private key for SSHFS, e.g.:

  ssh-copy-id -i ~/.ssh/id_my_private_key [USER]@[HOST]

Then, using the deployed key, the storage can be added as follows:

  pvesm add sshfs [STOREID] \
    --username [USER] \
    --server [HOST] \
    --path /mnt/path/to/storage \
    --remote-path /srv/sshfs \
    --sshfs-private-key "$(cat ~/.ssh/id_my_private_key)"

The storage should then pop up in the UI. It should be functionally
equivalent to most other dir-based network storages, except that imports
aren't supported in order to keep the example from becoming too complex.

References
----------

[0]: https://github.com/libfuse/sshfs

Older Versions
--------------

v1: https://lore.proxmox.com/pve-devel/20250416124735.320256-1-m.carrara@proxmox.com/
rfc-v1: https://lore.proxmox.com/pve-devel/20250328171209.503132-1-m.carrara@proxmox.com/

Summary of Changes
------------------

Max R. Carrara (2):
  plugin-sshfs: add example for custom storage plugin for SSHFS
  plugin-sshfs: package the SSHFS example plugin

 Makefile                                      |   1 +
 plugin-sshfs/Makefile                         |  71 ++++
 plugin-sshfs/debian/changelog                 |   5 +
 plugin-sshfs/debian/control                   |  22 +
 plugin-sshfs/debian/copyright                 |  20 +
 plugin-sshfs/debian/rules                     |   8 +
 plugin-sshfs/debian/source/format             |   1 +
 plugin-sshfs/debian/triggers                  |   1 +
 .../src/PVE/Storage/Custom/SSHFSPlugin.pm     | 395 ++++++++++++++++++
 9 files changed, 524 insertions(+)
 create mode 100644 plugin-sshfs/Makefile
 create mode 100644 plugin-sshfs/debian/changelog
 create mode 100644 plugin-sshfs/debian/control
 create mode 100644 plugin-sshfs/debian/copyright
 create mode 100755 plugin-sshfs/debian/rules
 create mode 100644 plugin-sshfs/debian/source/format
 create mode 100644 plugin-sshfs/debian/triggers
 create mode 100644 plugin-sshfs/src/PVE/Storage/Custom/SSHFSPlugin.pm

-- 
2.39.5





More information about the pve-devel mailing list