Mailing List Archive

SFTP support for subsecond times
Hello,

This is probably a long email, but please bear with me. I plan to
submit a patch and would like to explain what I will do before doing
it so I don't lose time if there's some flaw in my plan.

I currently use sshfs to mount directories from some computers and a
NAS into other computers. I recently noticed that when copying some
files from one computer into one of these sshfs mounted directories
(supposedly preserving times) the files are losing the subsecond part
of mtime (and atime). So, for example, `stat foo` shows this locally:

Access: 2023-05-09 13:47:59.422975530 +0200
Modify: 2023-05-09 08:07:12.267263456 +0200

But `stat /mnt/whatever/foo` (the same file copied to the sshfs
mounted directory) shows:

Access: 2023-05-09 13:47:59.000000000 +0200
Modify: 2023-05-09 08:07:12.000000000 +0200

This is giving trouble to use those files indistinctly from both paths
by software that stores the mtime in a database to check if the files
changed since the last time they were processed.

Since sshfs basically uses sftp internally, I checked the openssh
implementation and indeed, it doesn't support subsecond times in file
attributes, so I'm considering adding support for that, but I'd like
to do it in a way that it can be approved officially, thus I'd like to
ask your opinions/ideas on the planned implementation.

As I said, I've been looking at the code and it seems there's no way
to do this "naturally" (adding u32 variables to the protocol stream
for the nsec parts of atime/mtime) since that would break the
compatibility with sftp clients/servers that don't expect those
variables in the stream.

I had a look at the protocol as defined in
https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13 and
that seems to have many differences (in some cases, even incompatible)
with the openssh sftp implementation, so I'll take the current code as
the main reference and just use
https://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt as
documentation.

After a careful look at the protocol, it seems it could be done by making use of
SSH_FILEXFER_ATTR_EXTENDED attribute. Adding a pair or keys
("atime-ns" and "mtime-ns" for example) and since the value string
seems to allow holding binary data, it could contain the u32 values
directly in order to keep overhead as low as possible . Or even better
both values could be transmitted in a single "nsec-times" key/value
pair to keep overhead really to a minimum and just add both u32
variables to a separate sshbuf temporary variable and write that
sshbuf as the value string with sshbuf_put_stringb().

I think subsecond time support could be implemented in all file
attribs related protocol functions with the main changes involving the
stat_to_attrib(), attrib_to_stat(), decode_attrib(), encode_attrib(),
attrib_to_tv() and attrib_to_ts() functions mainly.

This way, sftp servers/clients that don't understand this "nsec-times"
extended attribute would just ignore it and keep working as up to now,
while those who understand them could use them.

Also, another option would be to make the server announce an
"nsec-attribs@openssh" extension so that if a client that can fill
nsec attributes is connecting to a server that doesn't announce
support for that, then we can keep the stream simple and not introduce
extended attributes unnecessarily . I see in `4. Protocol
Initialization` in the IETF draft it's supposed to be possible for the
client to send <extension data> just after the version in the FXP_INIT
packet, but looking at the sources it seems right now openssh's sftp
implementation doesn't send any extension from the client nor the
server tries to process it in any way. So this processing of client
supported extensions would have to be added in order to minimize the
overhead from the server if the client doesn't support subsecond times
(or just always submit them and let the extended attribute get
ignored).

What do you think of this plan? Does it sound like something that
could be accepted? Of course, if anyone can think of a better way to
implement this, I'd also be glad to read it.

And just for completion, if this gets a "go ahead", I'll also work on
making sshfs support this.

--
Antonio Larrosa
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On 5/10/23 4:36 AM, Antonio Larrosa wrote:
> Hello,
>
> This is probably a long email, but please bear with me. I plan to
> submit a patch and would like to explain what I will do before doing
> it so I don't lose time if there's some flaw in my plan.
>
> I currently use sshfs to mount directories from some computers and a
> NAS into other computers. I recently noticed that when copying some
> files from one computer into one of these sshfs mounted directories
> (supposedly preserving times) the files are losing the subsecond part
> of mtime (and atime). So, for example, `stat foo` shows this locally:

My first thought after reading this is why aren't you using NFS?

I can't speak to what patches might get accepted, but it does seem like
this is the wrong tool for the job.

--
Lucas Holt
Luke@FoolishGames.com
________________________________________________________
MidnightBSD.org (Free OS)
JustJournal.com (Free blogging)

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On Wed, May 10, 2023 at 2:50?PM Lucas Holt <luke@foolishgames.com> wrote:
>
> On 5/10/23 4:36 AM, Antonio Larrosa wrote:
> > Hello,
> >
> > This is probably a long email, but please bear with me. I plan to
> > submit a patch and would like to explain what I will do before doing
> > it so I don't lose time if there's some flaw in my plan.
> >
> > I currently use sshfs to mount directories from some computers and a
> > NAS into other computers. I recently noticed that when copying some
> > files from one computer into one of these sshfs mounted directories
> > (supposedly preserving times) the files are losing the subsecond part
> > of mtime (and atime). So, for example, `stat foo` shows this locally:
>
> My first thought after reading this is why aren't you using NFS?
>
> I can't speak to what patches might get accepted, but it does seem like
> this is the wrong tool for the job.

A while ago I wrote a script so people can take their home directory
with them when they log into another machine (usage case for us is
development of embedded hardware, and we got sick of having to copy
data around with scp, or sometimes forgot to do so...), see
http://svn.nrubsig.org/svn/people/gisburn/scripts/sshnfs/sshnfs.ksh

----

MfG,
Roland Mainz
--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On 5/10/23 08:50, Lucas Holt wrote:
> On 5/10/23 4:36 AM, Antonio Larrosa wrote:
>> Hello,
>>
>> This is probably a long email, but please bear with me. I plan to
>> submit a patch and would like to explain what I will do before doing
>> it so I don't lose time if there's some flaw in my plan.
>>
>> I currently use sshfs to mount directories from some computers and a
>> NAS into other computers. I recently noticed that when copying some
>> files from one computer into one of these sshfs mounted directories
>> (supposedly preserving times) the files are losing the subsecond part
>> of mtime (and atime). So, for example, `stat foo` shows this locally:
>
> My first thought after reading this is why aren't you using NFS?
>
> I can't speak to what patches might get accepted, but it does seem like
> this is the wrong tool for the job.

Not sure what Antonio’s reason is, but using NFS securely is much harder
than SSH on all systems I know of, and impossible on OpenBSD without a VPN
tunnel.
--
Sincerely,
Demi Marie Obenour (she/her/hers)
Re: SFTP support for subsecond times [ In reply to ]
On Wed, 2023-05-10 at 10:36 +0200, Antonio Larrosa wrote:

> What do you think of this plan? Does it sound like something that
> could be accepted? Of course, if anyone can think of a better way to
> implement this, I'd also be glad to read it.
>
> And just for completion, if this gets a "go ahead", I'll also work on
> making sshfs support this.

I'd love to hear a maintainer's point of view here.

--
Hans Petter
Re: SFTP support for subsecond times [ In reply to ]
Historically the view has been if you want NFS-like filesystem over SSH
write a dedicated subsystem.  The OpenSSH project stopped following the
sftp spec when it tried to "be-everyting-to-everyone" protocol instead
of a clean and simple ftp/scp replacement.  As filesystem sharing
protocols have oddies between platforms that add a lot of complexity and
are unsuited for the original sftp purpose.

I suspect this view point still hasn't changed since I officially left
the project.

- Ben

Hans Petter Jansson wrote on 5/23/23 3:28 PM:
> On Wed, 2023-05-10 at 10:36 +0200, Antonio Larrosa wrote:
>
>> What do you think of this plan? Does it sound like something that
>> could be accepted? Of course, if anyone can think of a better way to
>> implement this, I'd also be glad to read it.
>>
>> And just for completion, if this gets a "go ahead", I'll also work on
>> making sshfs support this.
> I'd love to hear a maintainer's point of view here.
>
>
>
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On Tue, 2023-05-23 at 19:44 -0500, Ben Lindstrom wrote:

> Historically the view has been if you want NFS-like filesystem over SSH
> write a dedicated subsystem.  The OpenSSH project stopped following the
> sftp spec when it tried to "be-everyting-to-everyone" protocol instead
> of a clean and simple ftp/scp replacement.  As filesystem sharing
> protocols have oddies between platforms that add a lot of complexity and
> are unsuited for the original sftp purpose.
>
> I suspect this view point still hasn't changed since I officially left
> the project.

Thanks for the response --

If that is indeed the policy, I don't see that refining the metadata to
make timestamps more accurate, which is what Antonio is offering to
implement, necessarily contradicts it, though.

--
Hans Petter
Re: SFTP support for subsecond times [ In reply to ]
using "synchronized" subsecond timestamps imho only makes sense with synchronized time (ntp) through that ssh tunnel, too.
and with this assumption a "full VPN ssh usage" instead of "only filesystem timestamps" [maybe trying with target systems without subsecond timestamps?] seems impractical to me. or at least "not worth realizing in this way".

la tero brulas!
#VerdajDezertoj
Saluton,
Daja / Dahya
unua NovaUNPrezident

Am 21. Mai 2023 21:45:07 MESZ schrieb Demi Marie Obenour <demiobenour@gmail.com>:
>On 5/10/23 08:50, Lucas Holt wrote:
>> On 5/10/23 4:36 AM, Antonio Larrosa wrote:
>>> Hello,
>>>
>>> This is probably a long email, but please bear with me. I plan to
>>> submit a patch and would like to explain what I will do before doing
>>> it so I don't lose time if there's some flaw in my plan.
>>>
>>> I currently use sshfs to mount directories from some computers and a
>>> NAS into other computers. I recently noticed that when copying some
>>> files from one computer into one of these sshfs mounted directories
>>> (supposedly preserving times) the files are losing the subsecond part
>>> of mtime (and atime). So, for example, `stat foo` shows this locally:
>>
>> My first thought after reading this is why aren't you using NFS?
>>
>> I can't speak to what patches might get accepted, but it does seem like
>> this is the wrong tool for the job.
>
>Not sure what Antonio’s reason is, but using NFS securely is much harder
>than SSH on all systems I know of, and impossible on OpenBSD without a VPN
>tunnel.
>--
>Sincerely,
>Demi Marie Obenour (she/her/hers)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On 5/25/2023 8:28 PM, Daja / Dahya / Mark Dominik Bürkle wrote:
> using "synchronized" subsecond timestamps imho only makes sense with synchronized time (ntp) through that ssh tunnel, too.

This is not quite the case.

Assuming your goal of ntp-through-ssh is to have time sync: It is very
easy for modern-day implementations of NTP to achieve sub-second
precision: as simple as openntpd is (and as large as this NTP precision
flame war gets), it gets things right to 2 ms in its competitor chrony's
test, when network connection is permanent and jitter is 10 ms. Even in
the worst intermittent case, it is correct to hundreds of milliseconds.
As the table will tell you. And other implementations can do much better.[1]

[1]: https://chrony.tuxfamily.org/comparison.html

Assuming your goal of ntp-through-ssh is security: RFC 8915 NTS is a thing.

Regards,
Mingye Wang
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On 25.05.23 14:28, Daja / Dahya / Mark Dominik Bürkle wrote:
> using "synchronized" subsecond timestamps imho only makes sense with
> synchronized time (ntp) through that ssh tunnel, too.

I don't think that one'll get very good results from running NTP
*through SSH* (or any other kind of connection with the delay+jitter of
a crypto layer), though. And that's even *before* considering the
effects of the SSH connection occasionally getting closed and reopened
every now and then.

*If*¹ you need well-synced computer clocks to make use of those
precision timestamps, better use "conventional means" (which might
involve having the two sites' clocks "linked" by a suitable external
source like GPS or a 3rd party NTP server, rather than a direct NTP
peering).

¹ I seem to remember that the OP had a problem when the server the files
*originally came from* saw differing timestamps on the remote copies,
which would IMHO be fixed by copying the exact timestamps over even if
the remote clock is *not* in sync.

Kind regards,
--
Jochen Bern
Systemingenieur

Binect GmbH
Re: SFTP support for subsecond times [ In reply to ]
> using "synchronized" subsecond timestamps imho only makes sense with
> synchronized time (ntp) through that ssh tunnel, too.

Having more than second granularity also helps when
synchronizing files -- it's a bit more protection
against close-vs.-rsync race conditions etc.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On 5/24/2023 8:44 AM, Ben Lindstrom wrote:
> As filesystem sharing
> protocols have oddies between platforms that add a lot of complexity and
> are unsuited for the original sftp purpose.

OpenSSH has done this platform thing before. In 2008, Damien Miller
introduced extensions to perform statvfs(2), df(1), and rename over
sftp. The code survives to this day and the extension request remains
documented in PROTOCOL.[1]

[1]:
https://github.com/openssh/openssh-portable/commit/d671e5a978efd5ba949d3fdcd03f728dcd68c636

Maybe it should do it again. Timestamps are a lot less tied to the
platform compared to these extensions.

Sincerely,
Mingye Wang
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
using "synchronized" subsecond timestamps imho only makes sense with synchronized time (ntp) through that ssh tunnel, too.
and with this assumption a "full VPN ssh usage" instead of "only filesystem timestamps" [maybe trying with target systems without subsecond timestamps?] seems impractical to me. or at least "...
[sry, didnt have internet to send,
incomplete but readable imho.]
.
la tero brulas!
#VerdajDezertoj
Saluton,
Daja / Dahya
unua NovaUNPrezident

Am 21. Mai 2023 21:45:07 MESZ schrieb Demi Marie Obenour <demiobenour@gmail.com>:
>On 5/10/23 08:50, Lucas Holt wrote:
>> On 5/10/23 4:36 AM, Antonio Larrosa wrote:
>>> Hello,
>>>
>>> This is probably a long email, but please bear with me. I plan to
>>> submit a patch and would like to explain what I will do before doing
>>> it so I don't lose time if there's some flaw in my plan.
>>>
>>> I currently use sshfs to mount directories from some computers and a
>>> NAS into other computers. I recently noticed that when copying some
>>> files from one computer into one of these sshfs mounted directories
>>> (supposedly preserving times) the files are losing the subsecond part
>>> of mtime (and atime). So, for example, `stat foo` shows this locally:
>>
>> My first thought after reading this is why aren't you using NFS?
>>
>> I can't speak to what patches might get accepted, but it does seem like
>> this is the wrong tool for the job.
>
>Not sure what Antonio’s reason is, but using NFS securely is much harder
>than SSH on all systems I know of, and impossible on OpenBSD without a VPN
>tunnel.
>--
>Sincerely,
>Demi Marie Obenour (she/her/hers)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: SFTP support for subsecond times [ In reply to ]
On Sun, 2023-07-16 at 17:26 +0200, Daja / Dahya / Mark Dominik Bürkle
wrote:
> using "synchronized" subsecond timestamps imho only makes sense with
> synchronized time (ntp) through that ssh tunnel, too.
> and with this assumption a "full VPN ssh usage" instead of "only
> filesystem timestamps" [maybe trying with target systems without
> subsecond timestamps?] seems impractical to me. or at least "...
> [.sry, didnt have internet to send,
> incomplete but readable imho.]

I don't want to put words in Antonio's mouth, but what he pointed out
seems to me to be this:

- sftp strips the low-order bits from timestamps.
- This is arguably a bug.
- It's fixable with a small patch.
- The fix is both backwards-compatible and standards-compatible.
- He'd be willing to implement it.

I think his analysis is correct.

The ensuing discussion about backups, file servers, tunnels etc. is
hardly relevant.

--
Hans Petter